Skip to content

Commit 08ba0c9

Browse files
committed
add tree doc
1 parent 57f03b8 commit 08ba0c9

File tree

16 files changed

+270
-126
lines changed

16 files changed

+270
-126
lines changed

components/input/Search.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export default {
8484
},
8585
attrs: this.$attrs,
8686
on: {
87+
...this.$listeners,
8788
pressEnter: this.onSearch,
8889
},
8990
}

components/table/index.en-US.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ One of the Table `columns` prop for describing the table's columns, Column has t
101101
102102
| Property | Description | Type | Default |
103103
| -------- | ----------- | ---- | ------- |
104-
| className | className of this column | string | - |
105104
| colSpan | Span of this column's title | number | |
106105
| dataIndex | Display field of the data record, could be set like `a.b.c` | string | - |
107106
| defaultSortOrder | Default order of sorted values: `'ascend'` `'descend'` `null` | string | - |

components/table/index.zh-CN.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const columns = [{
3535

3636
| 参数 | 说明 | 类型 | 默认值 |
3737
| --- | --- | --- | --- |
38-
| className | 列的 className | string | - |
3938
| bordered | 是否展示外边框和列边框 | boolean | false |
4039
| columns | 表格列的配置描述,具体项见下表 | array | - |
4140
| components | 覆盖默认的 table 元素 | object | - |

components/tree/demo/basic-controlled.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ basic controlled example
1515
@expand="onExpand"
1616
:expandedKeys="expandedKeys"
1717
:autoExpandParent="autoExpandParent"
18-
@check="onCheck"
19-
:checkedKeys="checkedKeys"
18+
v-model="checkedKeys"
2019
@select="onSelect"
2120
:selectedKeys="selectedKeys"
22-
:data="treeData"
21+
:treeNodes="treeData"
2322
/>
2423
</template>
2524
<script>
@@ -69,6 +68,11 @@ export default {
6968
treeData,
7069
}
7170
},
71+
watch: {
72+
checkedKeys(val) {
73+
console.log('onCheck', val)
74+
}
75+
},
7276
methods: {
7377
onExpand (expandedKeys) {
7478
console.log('onExpand', arguments)

components/tree/demo/basic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The most basic usage, tell you how to use checkable, selectable, disabled, defau
1212
<template>
1313
<a-tree
1414
checkable
15-
:data="treeData"
15+
:treeNodes="treeData"
1616
:defaultExpandedKeys="['0-0-0', '0-0-1']"
1717
:defaultSelectedKeys="['0-0-0', '0-0-1']"
1818
:defaultCheckedKeys="['0-0-0', '0-0-1']"

components/tree/demo/customized-icon.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You can customize icons for different nodes.
1111
```html
1212
<template>
1313
<a-tree
14-
:data="treeData"
14+
:treeNodes="treeData"
1515
showIcon
1616
defaultExpandAll
1717
:defaultSelectedKeys="['0-0-0']"

components/tree/demo/draggable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Drag treeNode to insert after the other treeNode or insert into the other parent
1616
draggable
1717
@dragenter="onDragEnter"
1818
@drop="onDrop"
19-
:data="gData"
19+
:treeNodes="gData"
2020
/>
2121
</template>
2222

components/tree/demo/dynamic.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,42 @@ To load data asynchronously when click to expand a treeNode.
1010

1111
```html
1212
<template>
13-
13+
<a-tree
14+
:loadData="onLoadData"
15+
:treeNodes="treeData"
16+
/>
1417
</template>
15-
<script>
1618

19+
<script>
20+
export default {
21+
data () {
22+
return {
23+
treeData: [
24+
{ title: 'Expand to load', key: '0' },
25+
{ title: 'Expand to load', key: '1' },
26+
{ title: 'Tree Node', key: '2', isLeaf: true },
27+
],
28+
}
29+
},
30+
methods: {
31+
onLoadData (treeNode) {
32+
return new Promise((resolve) => {
33+
if (treeNode.dataRef.children) {
34+
resolve()
35+
return
36+
}
37+
setTimeout(() => {
38+
treeNode.dataRef.children = [
39+
{ title: 'Child Node', key: `${treeNode.eventKey}-0` },
40+
{ title: 'Child Node', key: `${treeNode.eventKey}-1` },
41+
]
42+
this.treeData = [...this.treeData]
43+
resolve()
44+
}, 100)
45+
})
46+
},
47+
},
48+
}
1749
</script>
50+
1851
```

components/tree/demo/index.vue

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script>
2+
import BasicControlled from './basic-controlled'
3+
import Basic from './basic'
4+
import CustomizedIcon from './customized-icon'
5+
import Draggable from './draggable'
6+
import Dynamic from './dynamic'
7+
import Line from './line'
8+
import Search from './search'
9+
10+
import CN from '../index.zh-CN.md'
11+
import US from '../index.en-US.md'
12+
13+
const md = {
14+
cn: `# 树形控件
15+
## 何时使用
16+
17+
文件夹、组织架构、生物分类、国家地区等等,世间万物的大多数结构都是树形结构。使用\`树控件\`可以完整展现其中的层级关系,并具有展开收起选择等交互功能。
18+
19+
## 代码演示`,
20+
us: `# Tree
21+
## When To Use
22+
23+
Almost anything can be represented in a tree structure.
24+
Examples include directories, organization hierarchies, biological classifications, countries, etc. The \`Tree\` component is a way of representing the hierarchical relationship between these things. You can also expand, collapse, and select a treeNode within a \`Tree\`.
25+
## Examples
26+
`,
27+
}
28+
export default {
29+
category: 'Components',
30+
type: 'Data Display',
31+
title: 'Tree',
32+
subtitle: '树形控件',
33+
render () {
34+
return (
35+
<div>
36+
<md cn={md.cn} us={md.us}/>
37+
<BasicControlled/>
38+
<Basic/>
39+
<CustomizedIcon/>
40+
<Draggable/>
41+
<Dynamic/>
42+
<Line/>
43+
<Search/>
44+
<api>
45+
<template slot='cn'>
46+
<CN/>
47+
</template>
48+
<US/>
49+
</api>
50+
</div>
51+
)
52+
},
53+
}
54+
</script>

components/tree/demo/search.md

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,112 @@ Searchable Tree.
1010

1111
```html
1212
<template>
13-
13+
<div>
14+
<a-input-search style="margin-bottom: 8px" placeholder="Search" @change="onChange" />
15+
<a-tree
16+
@expand="onExpand"
17+
:expandedKeys="expandedKeys"
18+
:autoExpandParent="autoExpandParent"
19+
:treeNodes="gData"
20+
>
21+
<template slot="title" slot-scope="{key}">
22+
<span v-if="key.indexOf(searchValue) > -1">
23+
{{key.substr(0, key.indexOf(searchValue))}}
24+
<span style="color: #f50">{{searchValue}}</span>
25+
{{key.substr(key.indexOf(searchValue) + searchValue.length)}}
26+
</span>
27+
<span v-else>{{key}}</span>
28+
</template>
29+
</a-tree>
30+
</div>
1431
</template>
32+
1533
<script>
34+
const x = 3
35+
const y = 2
36+
const z = 1
37+
const gData = []
38+
39+
const generateData = (_level, _preKey, _tns) => {
40+
const preKey = _preKey || '0'
41+
const tns = _tns || gData
1642
43+
const children = []
44+
for (let i = 0; i < x; i++) {
45+
const key = `${preKey}-${i}`
46+
tns.push({ key, scopedSlots: { title: 'title' }})
47+
if (i < y) {
48+
children.push(key)
49+
}
50+
}
51+
if (_level < 0) {
52+
return tns
53+
}
54+
const level = _level - 1
55+
children.forEach((key, index) => {
56+
tns[index].children = []
57+
return generateData(level, key, tns[index].children)
58+
})
59+
}
60+
generateData(z)
61+
62+
const dataList = []
63+
const generateList = (data) => {
64+
for (let i = 0; i < data.length; i++) {
65+
const node = data[i]
66+
const key = node.key
67+
dataList.push({ key, title: key })
68+
if (node.children) {
69+
generateList(node.children, node.key)
70+
}
71+
}
72+
}
73+
generateList(gData)
74+
75+
const getParentKey = (key, tree) => {
76+
let parentKey
77+
for (let i = 0; i < tree.length; i++) {
78+
const node = tree[i]
79+
if (node.children) {
80+
if (node.children.some(item => item.key === key)) {
81+
parentKey = node.key
82+
} else if (getParentKey(key, node.children)) {
83+
parentKey = getParentKey(key, node.children)
84+
}
85+
}
86+
}
87+
return parentKey
88+
}
89+
export default {
90+
data () {
91+
return {
92+
expandedKeys: [],
93+
searchValue: '',
94+
autoExpandParent: true,
95+
gData,
96+
}
97+
},
98+
methods: {
99+
onExpand (expandedKeys) {
100+
this.expandedKeys = expandedKeys
101+
this.autoExpandParent = false
102+
},
103+
onChange (e) {
104+
const value = e.target.value
105+
const expandedKeys = dataList.map((item) => {
106+
if (item.key.indexOf(value) > -1) {
107+
return getParentKey(item.key, gData)
108+
}
109+
return null
110+
}).filter((item, i, self) => item && self.indexOf(item) === i)
111+
Object.assign(this, {
112+
expandedKeys,
113+
searchValue: value,
114+
autoExpandParent: true,
115+
})
116+
},
117+
},
118+
}
17119
</script>
120+
18121
```

0 commit comments

Comments
 (0)