Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add custom node #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
idcpj wants to merge 1 commit into wsfe:dev from idcpj:dev
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ import '@wsfe/vue-tree/style.css'
| :------ | :--------------- |
| empty | 暂无数据 |
| loading | 加载中显示的图标 |
| node | 自定义节点,参数为 {title,node} |

### VTree Data Fields

Expand All @@ -173,6 +174,7 @@ import '@wsfe/vue-tree/style.css'
| \_level | 节点层级,默认从 0 开始 |
| \_loading | 节点是否正在加载 |
| \_loaded | 节点是否已经加载过,异步加载下有效 |
| type | 自定义节点类型 |

## VTreeSearch API

Expand Down
55 changes: 55 additions & 0 deletions examples/Feature.vue
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@
</div>
</div>

<div class="panel">
<div class="header">基本用法-自定义节点</div>
<div class="body">
<div class="interface">
<div style="height: 300px">
<VTree
ref="basicTreeRef"
:data="basicUsageCustomNode"
:nodeClassName="node => `generated-class-${node.id}`"
@click="handleClick"
@node-dblclick="handleDblClick"
@node-right-click="handleRightClick"
>
<!--自定义 Node 样式-->
<template v-slot:node="{title,node,}">
<template v-if="node.type=='dept'"><div >{{title}}</div></template>
<template v-else-if="node.type=='user'"><img src="https://picsum.photos/20" > {{title}} </template>
</template>
</VTree>
</div>
</div>
<div class="desc">
<div>纯展示</div>
<div class="desc-block">
<button @click="handleExpandAll">展开全部节点</button>
<button @click="handleCollapseAll">折叠全部节点</button>
</div>
</div>
</div>
</div>

<!-- 数据正确性验证 -->
<!-- <div class="panel">
<div class="header">数据正确性验证</div>
Expand Down Expand Up @@ -181,6 +212,28 @@ const genData = (extra = {}) => {
)
)
}
const genOrg=()=>{
const org=[];

for (let i = 0; i < 5; i++) {
const dept={
title:"部门-"+i,
id:"dept-"+i,
type:"dept",
children:[],
};

for (let j = 0; j < 10; j++) {
dept.children.push({
title:"人员-"+j,
id:`user-${i}-${j}`,
type:"user",
})
}
org.push(dept)
}
return org
}

const genChildrenData = (nodeCount = 2) => {
return treeDataGenerator({
Expand All @@ -206,6 +259,7 @@ export default defineComponent({
const selectableValue = ref('')
const checkableValue = ref<(string | number)[]>([checkableData[0].id!])
const basicUsage = ref(genData().data)
const basicUsageCustomNode = ref(genOrg())
const orderData = ref(genData({ inOrder: true }).data)
const selectable = ref(selectableData)
const showCheckable = ref(true)
Expand Down Expand Up @@ -288,6 +342,7 @@ export default defineComponent({
return {
// 基本用法
basicUsage,
basicUsageCustomNode,
basicTreeRef,
handleClick,
handleDblClick,
Expand Down
7 changes: 6 additions & 1 deletion src/components/Tree.vue
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
@select="handleNodeSelect"
@expand="handleNodeExpand"
@node-drop="handleNodeDrop"
/>
>
<template #default="{title,node}">
<slot name="node" :title="title" :node="node" >{{title}}</slot>
</template>
</CTreeNode>

<div :style="bottomSpaceStyles"></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/TreeNode.vue
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
:draggable="draggable && !disableAll && !data?.disabled"
>
<component v-if="renderFunction" :is="renderComponent"></component>
<template v-else>{{ data ? data[titleField] : '' }}</template>
<template v-else><slot name="default" :title="data ? data[titleField] : ''" :node="data">{{ data ? data[titleField] : '' }}</slot></template>
</div>
</div>
<div :class="dropAfterCls"></div>
Expand Down
3 changes: 3 additions & 0 deletions src/store/tree-node.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export default class TreeNode {
/** 是否是子节点 */
isLeaf: boolean = false

/** 节点类型,用于对节点进行分类 */
type: string = ''

/** 节点是否正在加载 */
_loading: boolean = false

Expand Down

AltStyle によって変換されたページ (->オリジナル) /