iov-design 2.15.60 → 2.15.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -148
- package/lib/alert.js +24 -105
- package/lib/aside.js +24 -34
- package/lib/autocomplete.js +36 -240
- package/lib/avatar.js +21 -20
- package/lib/backtop.js +27 -52
- package/lib/badge.js +30 -58
- package/lib/breadcrumb-item.js +24 -53
- package/lib/breadcrumb.js +24 -37
- package/lib/button-group.js +24 -29
- package/lib/button.js +38 -60
- package/lib/calendar.js +29 -146
- package/lib/card.js +24 -51
- package/lib/carousel-item.js +30 -68
- package/lib/carousel.js +27 -159
- package/lib/cascader-panel.js +41 -64
- package/lib/cascader.js +37 -470
- package/lib/checkbox-button.js +28 -164
- package/lib/checkbox-group.js +24 -37
- package/lib/checkbox.js +35 -189
- package/lib/col.js +1 -0
- package/lib/collapse-item.js +27 -125
- package/lib/collapse.js +24 -37
- package/lib/color-picker.js +104 -424
- package/lib/container.js +24 -34
- package/lib/date-picker.js +126 -1981
- package/lib/descriptions-item.js +1 -0
- package/lib/descriptions.js +1 -0
- package/lib/dialog.js +24 -137
- package/lib/divider.js +29 -64
- package/lib/drawer.js +24 -139
- package/lib/dropdown-item.js +27 -45
- package/lib/dropdown-menu.js +24 -51
- package/lib/dropdown.js +21 -20
- package/lib/empty.js +24 -61
- package/lib/footer.js +24 -34
- package/lib/form-item.js +42 -128
- package/lib/form.js +27 -40
- package/lib/header.js +24 -34
- package/lib/icon.js +24 -29
- package/lib/image.js +36 -220
- package/lib/index.js +1 -1
- package/lib/infinite-scroll.js +1 -0
- package/lib/input-number.js +30 -163
- package/lib/input.js +42 -274
- package/lib/iov-design.common.js +1635 -11132
- package/lib/link.js +31 -56
- package/lib/loading.js +24 -77
- package/lib/locale/format.js +10 -10
- package/lib/main.js +24 -29
- package/lib/menu-item-group.js +24 -40
- package/lib/menu-item.js +27 -83
- package/lib/menu.js +21 -20
- package/lib/message-box.js +24 -321
- package/lib/message.js +30 -82
- package/lib/mixins/migrating.js +20 -20
- package/lib/notification.js +24 -109
- package/lib/option-group.js +24 -50
- package/lib/option.js +27 -76
- package/lib/page-header.js +24 -56
- package/lib/pagination.js +24 -97
- package/lib/popconfirm.js +24 -97
- package/lib/popover.js +24 -89
- package/lib/progress.js +30 -133
- package/lib/radio-button.js +29 -111
- package/lib/radio-group.js +24 -39
- package/lib/radio.js +36 -152
- package/lib/rate.js +24 -94
- package/lib/result.js +72 -187
- package/lib/row.js +1 -0
- package/lib/scrollbar.js +1 -0
- package/lib/select.js +48 -637
- package/lib/skeleton-item.js +36 -68
- package/lib/skeleton.js +28 -70
- package/lib/slider.js +36 -267
- package/lib/spinner.js +24 -51
- package/lib/statistic.js +24 -76
- package/lib/step.js +29 -118
- package/lib/steps.js +27 -40
- package/lib/submenu.js +21 -20
- package/lib/switch.js +24 -130
- package/lib/tab-pane.js +24 -52
- package/lib/table-column.js +1 -0
- package/lib/table.js +93 -633
- package/lib/tabs.js +34 -49
- package/lib/tag.js +21 -20
- package/lib/theme-chalk/button.css +1 -1
- package/lib/theme-chalk/calendar.css +1 -1
- package/lib/theme-chalk/dropdown.css +1 -1
- package/lib/theme-chalk/index.css +1 -1
- package/lib/theme-chalk/link.css +1 -1
- package/lib/theme-chalk/message-box.css +1 -1
- package/lib/theme-chalk/transfer.css +1 -1
- package/lib/time-picker.js +58 -820
- package/lib/time-select.js +42 -303
- package/lib/timeline-item.js +29 -75
- package/lib/timeline.js +21 -20
- package/lib/tooltip.js +1 -0
- package/lib/transfer.js +36 -299
- package/lib/tree.js +54 -243
- package/lib/upload.js +86 -654
- package/lib/utils/clickoutside.js +7 -7
- package/lib/utils/vue-popper.js +7 -7
- package/package.json +154 -154
- package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
- package/packages/autocomplete/src/autocomplete.vue +285 -285
- package/packages/button/src/button.vue +90 -90
- package/packages/calendar/src/date-table.vue +200 -200
- package/packages/calendar/src/main.vue +280 -280
- package/packages/carousel/src/item.vue +138 -138
- package/packages/carousel/src/main.vue +315 -315
- package/packages/cascader/src/cascader.vue +776 -776
- package/packages/cascader-panel/src/cascader-menu.vue +138 -138
- package/packages/cascader-panel/src/cascader-node.vue +246 -246
- package/packages/cascader-panel/src/cascader-panel.vue +391 -391
- package/packages/cascader-panel/src/node.js +166 -166
- package/packages/cascader-panel/src/store.js +58 -58
- package/packages/checkbox/src/checkbox-button.vue +199 -199
- package/packages/checkbox/src/checkbox-group.vue +49 -49
- package/packages/checkbox/src/checkbox.vue +225 -225
- package/packages/collapse/src/collapse-item.vue +114 -114
- package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
- package/packages/color-picker/src/main.vue +188 -188
- package/packages/date-picker/src/basic/date-table.vue +441 -441
- package/packages/date-picker/src/basic/month-table.vue +269 -269
- package/packages/date-picker/src/basic/time-spinner.vue +304 -304
- package/packages/date-picker/src/basic/year-table.vue +111 -111
- package/packages/date-picker/src/panel/date-range.vue +680 -680
- package/packages/date-picker/src/panel/date.vue +609 -609
- package/packages/date-picker/src/panel/month-range.vue +289 -289
- package/packages/date-picker/src/panel/time-range.vue +248 -248
- package/packages/date-picker/src/panel/time-select.vue +178 -178
- package/packages/date-picker/src/panel/time.vue +186 -186
- package/packages/date-picker/src/picker.vue +967 -967
- package/packages/descriptions/src/index.js +180 -180
- package/packages/dialog/src/component.vue +262 -262
- package/packages/drawer/src/main.vue +205 -205
- package/packages/dropdown/src/dropdown-item.vue +37 -37
- package/packages/dropdown/src/dropdown-menu.vue +63 -63
- package/packages/dropdown/src/dropdown.vue +293 -293
- package/packages/empty/src/index.vue +70 -70
- package/packages/form/src/form-item.vue +324 -324
- package/packages/form/src/form.vue +182 -182
- package/packages/image/src/image-viewer.vue +330 -330
- package/packages/image/src/main.vue +249 -249
- package/packages/infinite-scroll/src/main.js +150 -150
- package/packages/input/src/input.vue +477 -477
- package/packages/input-number/src/input-number.vue +283 -283
- package/packages/loading/src/directive.js +133 -133
- package/packages/loading/src/index.js +106 -106
- package/packages/menu/src/menu-item.vue +112 -112
- package/packages/menu/src/menu.vue +325 -325
- package/packages/menu/src/submenu.vue +349 -349
- package/packages/message/src/main.js +91 -91
- package/packages/message-box/src/main.js +216 -216
- package/packages/message-box/src/main.vue +333 -333
- package/packages/notification/src/main.js +94 -94
- package/packages/page-header/src/main.vue +30 -30
- package/packages/pagination/src/pagination.js +390 -390
- package/packages/popconfirm/src/main.vue +104 -104
- package/packages/popover/src/main.vue +239 -239
- package/packages/radio/src/radio-button.vue +115 -115
- package/packages/radio/src/radio-group.vue +115 -115
- package/packages/radio/src/radio.vue +148 -148
- package/packages/rate/src/main.vue +348 -348
- package/packages/scrollbar/src/bar.js +92 -92
- package/packages/scrollbar/src/main.js +130 -130
- package/packages/select/src/option-group.vue +60 -60
- package/packages/select/src/option.vue +171 -171
- package/packages/select/src/select-dropdown.vue +74 -74
- package/packages/select/src/select.vue +979 -979
- package/packages/slider/src/button.vue +238 -238
- package/packages/slider/src/main.vue +427 -427
- package/packages/statistic/src/main.vue +204 -204
- package/packages/steps/src/steps.vue +68 -68
- package/packages/switch/src/component.vue +182 -182
- package/packages/table/src/config.js +153 -153
- package/packages/table/src/filter-panel.vue +194 -194
- package/packages/table/src/store/current.js +76 -76
- package/packages/table/src/store/helper.js +41 -41
- package/packages/table/src/store/index.js +147 -147
- package/packages/table/src/store/watcher.js +502 -502
- package/packages/table/src/table-body.js +469 -469
- package/packages/table/src/table-column.js +328 -328
- package/packages/table/src/table-header.js +571 -571
- package/packages/table/src/table-layout.js +249 -249
- package/packages/table/src/table-row.js +101 -101
- package/packages/table/src/table.vue +740 -740
- package/packages/table/src/util.js +273 -273
- package/packages/tabs/src/tab-bar.vue +57 -57
- package/packages/tabs/src/tab-nav.vue +294 -294
- package/packages/tabs/src/tabs.vue +201 -201
- package/packages/theme-chalk/src/button.scss +416 -416
- package/packages/theme-chalk/src/cascader.scss +252 -252
- package/packages/theme-chalk/src/checkbox.scss +419 -419
- package/packages/theme-chalk/src/common/var.scss +795 -795
- package/packages/theme-chalk/src/form.scss +201 -201
- package/packages/theme-chalk/src/input.scss +591 -591
- package/packages/theme-chalk/src/iovfont.scss +803 -803
- package/packages/theme-chalk/src/link.scss +8 -8
- package/packages/theme-chalk/src/message-box.scss +207 -207
- package/packages/theme-chalk/src/mixins/_button.scss +136 -136
- package/packages/theme-chalk/src/mixins/mixins.scss +190 -190
- package/packages/theme-chalk/src/radio-button.scss +115 -115
- package/packages/theme-chalk/src/select.scss +270 -270
- package/packages/theme-chalk/src/tabs.scss +755 -755
- package/packages/theme-chalk/src/upload.scss +568 -568
- package/packages/tooltip/src/main.js +242 -242
- package/packages/transfer/src/main.vue +231 -231
- package/packages/transfer/src/transfer-panel.vue +251 -251
- package/packages/tree/src/model/node.js +484 -484
- package/packages/tree/src/tree-node.vue +279 -279
- package/packages/tree/src/tree.vue +496 -496
- package/packages/upload/src/index.vue +420 -420
- package/packages/upload/src/upload-file.vue +98 -98
- package/packages/upload/src/upload-list.vue +115 -115
- package/packages/upload/src/upload-picture.vue +98 -98
- package/packages/upload/src/upload.vue +231 -231
- package/packages/upload/src/utils.js +31 -31
- package/src/directives/repeat-click.js +26 -26
- package/src/index.js +259 -259
- package/src/locale/format.js +46 -46
- package/src/locale/index.js +48 -48
- package/src/locale/lang/lo-LA.js +126 -126
- package/src/mixins/locale.js +9 -9
- package/src/mixins/migrating.js +54 -54
- package/src/transitions/collapse-transition.js +77 -77
- package/src/utils/clickoutside.js +76 -76
- package/src/utils/date-util.js +282 -282
- package/src/utils/popup/index.js +218 -218
- package/src/utils/popup/popup-manager.js +194 -194
- package/src/utils/util.js +245 -245
- package/src/utils/vdom.js +5 -5
- package/src/utils/vue-popper.js +198 -198
|
@@ -1,496 +1,496 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
class="el-tree"
|
|
4
|
-
:class="{
|
|
5
|
-
'el-tree--highlight-current': highlightCurrent,
|
|
6
|
-
'is-dragging': !!dragState.draggingNode,
|
|
7
|
-
'is-drop-not-allow': !dragState.allowDrop,
|
|
8
|
-
'is-drop-inner': dragState.dropType === 'inner'
|
|
9
|
-
}"
|
|
10
|
-
role="tree"
|
|
11
|
-
>
|
|
12
|
-
<el-tree-node
|
|
13
|
-
v-for="child in root.childNodes"
|
|
14
|
-
:node="child"
|
|
15
|
-
:props="props"
|
|
16
|
-
:render-after-expand="renderAfterExpand"
|
|
17
|
-
:show-checkbox="showCheckbox"
|
|
18
|
-
:key="getNodeKey(child)"
|
|
19
|
-
:render-content="renderContent"
|
|
20
|
-
@node-expand="handleNodeExpand">
|
|
21
|
-
</el-tree-node>
|
|
22
|
-
<div class="el-tree__empty-block" v-if="isEmpty">
|
|
23
|
-
<span class="el-tree__empty-text">{{ emptyText }}</span>
|
|
24
|
-
</div>
|
|
25
|
-
<div
|
|
26
|
-
v-show="dragState.showDropIndicator"
|
|
27
|
-
class="el-tree__drop-indicator"
|
|
28
|
-
ref="dropIndicator">
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
</template>
|
|
32
|
-
|
|
33
|
-
<script>
|
|
34
|
-
import TreeStore from './model/tree-store';
|
|
35
|
-
import { getNodeKey, findNearestComponent } from './model/util';
|
|
36
|
-
import ElTreeNode from './tree-node.vue';
|
|
37
|
-
import {t} from 'iov-design/src/locale';
|
|
38
|
-
import emitter from 'iov-design/src/mixins/emitter';
|
|
39
|
-
import { addClass, removeClass } from 'iov-design/src/utils/dom';
|
|
40
|
-
|
|
41
|
-
export default {
|
|
42
|
-
name: 'ElTree',
|
|
43
|
-
|
|
44
|
-
mixins: [emitter],
|
|
45
|
-
|
|
46
|
-
components: {
|
|
47
|
-
ElTreeNode
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
data() {
|
|
51
|
-
return {
|
|
52
|
-
store: null,
|
|
53
|
-
root: null,
|
|
54
|
-
currentNode: null,
|
|
55
|
-
treeItems: null,
|
|
56
|
-
checkboxItems: [],
|
|
57
|
-
dragState: {
|
|
58
|
-
showDropIndicator: false,
|
|
59
|
-
draggingNode: null,
|
|
60
|
-
dropNode: null,
|
|
61
|
-
allowDrop: true
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
props: {
|
|
67
|
-
data: {
|
|
68
|
-
type: Array
|
|
69
|
-
},
|
|
70
|
-
emptyText: {
|
|
71
|
-
type: String,
|
|
72
|
-
default() {
|
|
73
|
-
return t('el.tree.emptyText');
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
renderAfterExpand: {
|
|
77
|
-
type: Boolean,
|
|
78
|
-
default: true
|
|
79
|
-
},
|
|
80
|
-
nodeKey: String,
|
|
81
|
-
checkStrictly: Boolean,
|
|
82
|
-
defaultExpandAll: Boolean,
|
|
83
|
-
expandOnClickNode: {
|
|
84
|
-
type: Boolean,
|
|
85
|
-
default: true
|
|
86
|
-
},
|
|
87
|
-
checkOnClickNode: Boolean,
|
|
88
|
-
checkDescendants: {
|
|
89
|
-
type: Boolean,
|
|
90
|
-
default: false
|
|
91
|
-
},
|
|
92
|
-
autoExpandParent: {
|
|
93
|
-
type: Boolean,
|
|
94
|
-
default: true
|
|
95
|
-
},
|
|
96
|
-
defaultCheckedKeys: Array,
|
|
97
|
-
defaultExpandedKeys: Array,
|
|
98
|
-
currentNodeKey: [String, Number],
|
|
99
|
-
renderContent: Function,
|
|
100
|
-
showCheckbox: {
|
|
101
|
-
type: Boolean,
|
|
102
|
-
default: false
|
|
103
|
-
},
|
|
104
|
-
draggable: {
|
|
105
|
-
type: Boolean,
|
|
106
|
-
default: false
|
|
107
|
-
},
|
|
108
|
-
allowDrag: Function,
|
|
109
|
-
allowDrop: Function,
|
|
110
|
-
props: {
|
|
111
|
-
default() {
|
|
112
|
-
return {
|
|
113
|
-
children: 'children',
|
|
114
|
-
label: 'label',
|
|
115
|
-
disabled: 'disabled'
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
lazy: {
|
|
120
|
-
type: Boolean,
|
|
121
|
-
default: false
|
|
122
|
-
},
|
|
123
|
-
highlightCurrent: Boolean,
|
|
124
|
-
load: Function,
|
|
125
|
-
filterNodeMethod: Function,
|
|
126
|
-
accordion: Boolean,
|
|
127
|
-
indent: {
|
|
128
|
-
type: Number,
|
|
129
|
-
default: 18
|
|
130
|
-
},
|
|
131
|
-
iconClass: String
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
computed: {
|
|
135
|
-
children: {
|
|
136
|
-
set(value) {
|
|
137
|
-
this.data = value;
|
|
138
|
-
},
|
|
139
|
-
get() {
|
|
140
|
-
return this.data;
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
treeItemArray() {
|
|
145
|
-
return Array.prototype.slice.call(this.treeItems);
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
isEmpty() {
|
|
149
|
-
const { childNodes } = this.root;
|
|
150
|
-
return !childNodes || childNodes.length === 0 || childNodes.every(({visible}) => !visible);
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
watch: {
|
|
155
|
-
defaultCheckedKeys(newVal) {
|
|
156
|
-
this.store.setDefaultCheckedKey(newVal);
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
defaultExpandedKeys(newVal) {
|
|
160
|
-
this.store.defaultExpandedKeys = newVal;
|
|
161
|
-
this.store.setDefaultExpandedKeys(newVal);
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
data(newVal) {
|
|
165
|
-
this.store.setData(newVal);
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
checkboxItems(val) {
|
|
169
|
-
Array.prototype.forEach.call(val, (checkbox) => {
|
|
170
|
-
checkbox.setAttribute('tabindex', -1);
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
checkStrictly(newVal) {
|
|
175
|
-
this.store.checkStrictly = newVal;
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
methods: {
|
|
180
|
-
filter(value) {
|
|
181
|
-
if (!this.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter');
|
|
182
|
-
this.store.filter(value);
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
getNodeKey(node) {
|
|
186
|
-
return getNodeKey(this.nodeKey, node.data);
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
getNodePath(data) {
|
|
190
|
-
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in getNodePath');
|
|
191
|
-
const node = this.store.getNode(data);
|
|
192
|
-
if (!node) return [];
|
|
193
|
-
const path = [node.data];
|
|
194
|
-
let parent = node.parent;
|
|
195
|
-
while (parent && parent !== this.root) {
|
|
196
|
-
path.push(parent.data);
|
|
197
|
-
parent = parent.parent;
|
|
198
|
-
}
|
|
199
|
-
return path.reverse();
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
getCheckedNodes(leafOnly, includeHalfChecked) {
|
|
203
|
-
return this.store.getCheckedNodes(leafOnly, includeHalfChecked);
|
|
204
|
-
},
|
|
205
|
-
|
|
206
|
-
getCheckedKeys(leafOnly) {
|
|
207
|
-
return this.store.getCheckedKeys(leafOnly);
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
getCurrentNode() {
|
|
211
|
-
const currentNode = this.store.getCurrentNode();
|
|
212
|
-
return currentNode ? currentNode.data : null;
|
|
213
|
-
},
|
|
214
|
-
|
|
215
|
-
getCurrentKey() {
|
|
216
|
-
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in getCurrentKey');
|
|
217
|
-
const currentNode = this.getCurrentNode();
|
|
218
|
-
return currentNode ? currentNode[this.nodeKey] : null;
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
setCheckedNodes(nodes, leafOnly) {
|
|
222
|
-
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
|
|
223
|
-
this.store.setCheckedNodes(nodes, leafOnly);
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
setCheckedKeys(keys, leafOnly) {
|
|
227
|
-
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedKeys');
|
|
228
|
-
this.store.setCheckedKeys(keys, leafOnly);
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
setChecked(data, checked, deep) {
|
|
232
|
-
this.store.setChecked(data, checked, deep);
|
|
233
|
-
},
|
|
234
|
-
|
|
235
|
-
getHalfCheckedNodes() {
|
|
236
|
-
return this.store.getHalfCheckedNodes();
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
getHalfCheckedKeys() {
|
|
240
|
-
return this.store.getHalfCheckedKeys();
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
setCurrentNode(node) {
|
|
244
|
-
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentNode');
|
|
245
|
-
this.store.setUserCurrentNode(node);
|
|
246
|
-
},
|
|
247
|
-
|
|
248
|
-
setCurrentKey(key) {
|
|
249
|
-
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentKey');
|
|
250
|
-
this.store.setCurrentNodeKey(key);
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
getNode(data) {
|
|
254
|
-
return this.store.getNode(data);
|
|
255
|
-
},
|
|
256
|
-
|
|
257
|
-
remove(data) {
|
|
258
|
-
this.store.remove(data);
|
|
259
|
-
},
|
|
260
|
-
|
|
261
|
-
append(data, parentNode) {
|
|
262
|
-
this.store.append(data, parentNode);
|
|
263
|
-
},
|
|
264
|
-
|
|
265
|
-
insertBefore(data, refNode) {
|
|
266
|
-
this.store.insertBefore(data, refNode);
|
|
267
|
-
},
|
|
268
|
-
|
|
269
|
-
insertAfter(data, refNode) {
|
|
270
|
-
this.store.insertAfter(data, refNode);
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
handleNodeExpand(nodeData, node, instance) {
|
|
274
|
-
this.broadcast('ElTreeNode', 'tree-node-expand', node);
|
|
275
|
-
this.$emit('node-expand', nodeData, node, instance);
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
updateKeyChildren(key, data) {
|
|
279
|
-
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in updateKeyChild');
|
|
280
|
-
this.store.updateChildren(key, data);
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
initTabIndex() {
|
|
284
|
-
this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
|
|
285
|
-
this.checkboxItems = this.$el.querySelectorAll('input[type=checkbox]');
|
|
286
|
-
const checkedItem = this.$el.querySelectorAll('.is-checked[role=treeitem]');
|
|
287
|
-
if (checkedItem.length) {
|
|
288
|
-
checkedItem[0].setAttribute('tabindex', 0);
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
this.treeItems[0] && this.treeItems[0].setAttribute('tabindex', 0);
|
|
292
|
-
},
|
|
293
|
-
|
|
294
|
-
handleKeydown(ev) {
|
|
295
|
-
const currentItem = ev.target;
|
|
296
|
-
if (currentItem.className.indexOf('el-tree-node') === -1) return;
|
|
297
|
-
const keyCode = ev.keyCode;
|
|
298
|
-
this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
|
|
299
|
-
const currentIndex = this.treeItemArray.indexOf(currentItem);
|
|
300
|
-
let nextIndex;
|
|
301
|
-
if ([38, 40].indexOf(keyCode) > -1) { // up、down
|
|
302
|
-
ev.preventDefault();
|
|
303
|
-
if (keyCode === 38) { // up
|
|
304
|
-
nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0;
|
|
305
|
-
} else {
|
|
306
|
-
nextIndex = (currentIndex < this.treeItemArray.length - 1) ? currentIndex + 1 : 0;
|
|
307
|
-
}
|
|
308
|
-
this.treeItemArray[nextIndex].focus(); // 选中
|
|
309
|
-
}
|
|
310
|
-
if ([37, 39].indexOf(keyCode) > -1) { // left、right 展开
|
|
311
|
-
ev.preventDefault();
|
|
312
|
-
currentItem.click(); // 选中
|
|
313
|
-
}
|
|
314
|
-
const hasInput = currentItem.querySelector('[type="checkbox"]');
|
|
315
|
-
if ([13, 32].indexOf(keyCode) > -1 && hasInput) { // space enter选中checkbox
|
|
316
|
-
ev.preventDefault();
|
|
317
|
-
hasInput.click();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
|
|
322
|
-
created() {
|
|
323
|
-
this.isTree = true;
|
|
324
|
-
|
|
325
|
-
this.store = new TreeStore({
|
|
326
|
-
key: this.nodeKey,
|
|
327
|
-
data: this.data,
|
|
328
|
-
lazy: this.lazy,
|
|
329
|
-
props: this.props,
|
|
330
|
-
load: this.load,
|
|
331
|
-
currentNodeKey: this.currentNodeKey,
|
|
332
|
-
checkStrictly: this.checkStrictly,
|
|
333
|
-
checkDescendants: this.checkDescendants,
|
|
334
|
-
defaultCheckedKeys: this.defaultCheckedKeys,
|
|
335
|
-
defaultExpandedKeys: this.defaultExpandedKeys,
|
|
336
|
-
autoExpandParent: this.autoExpandParent,
|
|
337
|
-
defaultExpandAll: this.defaultExpandAll,
|
|
338
|
-
filterNodeMethod: this.filterNodeMethod
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
this.root = this.store.root;
|
|
342
|
-
|
|
343
|
-
let dragState = this.dragState;
|
|
344
|
-
this.$on('tree-node-drag-start', (event, treeNode) => {
|
|
345
|
-
if (typeof this.allowDrag === 'function' && !this.allowDrag(treeNode.node)) {
|
|
346
|
-
event.preventDefault();
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
event.dataTransfer.effectAllowed = 'move';
|
|
350
|
-
|
|
351
|
-
// wrap in try catch to address IE's error when first param is 'text/plain'
|
|
352
|
-
try {
|
|
353
|
-
// setData is required for draggable to work in FireFox
|
|
354
|
-
// the content has to be '' so dragging a node out of the tree won't open a new tab in FireFox
|
|
355
|
-
event.dataTransfer.setData('text/plain', '');
|
|
356
|
-
} catch (e) {}
|
|
357
|
-
dragState.draggingNode = treeNode;
|
|
358
|
-
this.$emit('node-drag-start', treeNode.node, event);
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
this.$on('tree-node-drag-over', (event, treeNode) => {
|
|
362
|
-
const dropNode = findNearestComponent(event.target, 'ElTreeNode');
|
|
363
|
-
const oldDropNode = dragState.dropNode;
|
|
364
|
-
if (oldDropNode && oldDropNode !== dropNode) {
|
|
365
|
-
removeClass(oldDropNode.$el, 'is-drop-inner');
|
|
366
|
-
}
|
|
367
|
-
const draggingNode = dragState.draggingNode;
|
|
368
|
-
if (!draggingNode || !dropNode) return;
|
|
369
|
-
|
|
370
|
-
let dropPrev = true;
|
|
371
|
-
let dropInner = true;
|
|
372
|
-
let dropNext = true;
|
|
373
|
-
let userAllowDropInner = true;
|
|
374
|
-
if (typeof this.allowDrop === 'function') {
|
|
375
|
-
dropPrev = this.allowDrop(draggingNode.node, dropNode.node, 'prev');
|
|
376
|
-
userAllowDropInner = dropInner = this.allowDrop(draggingNode.node, dropNode.node, 'inner');
|
|
377
|
-
dropNext = this.allowDrop(draggingNode.node, dropNode.node, 'next');
|
|
378
|
-
}
|
|
379
|
-
event.dataTransfer.dropEffect = dropInner ? 'move' : 'none';
|
|
380
|
-
if ((dropPrev || dropInner || dropNext) && oldDropNode !== dropNode) {
|
|
381
|
-
if (oldDropNode) {
|
|
382
|
-
this.$emit('node-drag-leave', draggingNode.node, oldDropNode.node, event);
|
|
383
|
-
}
|
|
384
|
-
this.$emit('node-drag-enter', draggingNode.node, dropNode.node, event);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (dropPrev || dropInner || dropNext) {
|
|
388
|
-
dragState.dropNode = dropNode;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (dropNode.node.nextSibling === draggingNode.node) {
|
|
392
|
-
dropNext = false;
|
|
393
|
-
}
|
|
394
|
-
if (dropNode.node.previousSibling === draggingNode.node) {
|
|
395
|
-
dropPrev = false;
|
|
396
|
-
}
|
|
397
|
-
if (dropNode.node.contains(draggingNode.node, false)) {
|
|
398
|
-
dropInner = false;
|
|
399
|
-
}
|
|
400
|
-
if (draggingNode.node === dropNode.node || draggingNode.node.contains(dropNode.node)) {
|
|
401
|
-
dropPrev = false;
|
|
402
|
-
dropInner = false;
|
|
403
|
-
dropNext = false;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
const targetPosition = dropNode.$el.getBoundingClientRect();
|
|
407
|
-
const treePosition = this.$el.getBoundingClientRect();
|
|
408
|
-
|
|
409
|
-
let dropType;
|
|
410
|
-
const prevPercent = dropPrev ? (dropInner ? 0.25 : (dropNext ? 0.45 : 1)) : -1;
|
|
411
|
-
const nextPercent = dropNext ? (dropInner ? 0.75 : (dropPrev ? 0.55 : 0)) : 1;
|
|
412
|
-
|
|
413
|
-
let indicatorTop = -9999;
|
|
414
|
-
const distance = event.clientY - targetPosition.top;
|
|
415
|
-
if (distance < targetPosition.height * prevPercent) {
|
|
416
|
-
dropType = 'before';
|
|
417
|
-
} else if (distance > targetPosition.height * nextPercent) {
|
|
418
|
-
dropType = 'after';
|
|
419
|
-
} else if (dropInner) {
|
|
420
|
-
dropType = 'inner';
|
|
421
|
-
} else {
|
|
422
|
-
dropType = 'none';
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
const iconPosition = dropNode.$el.querySelector('.el-tree-node__expand-icon').getBoundingClientRect();
|
|
426
|
-
const dropIndicator = this.$refs.dropIndicator;
|
|
427
|
-
if (dropType === 'before') {
|
|
428
|
-
indicatorTop = iconPosition.top - treePosition.top;
|
|
429
|
-
} else if (dropType === 'after') {
|
|
430
|
-
indicatorTop = iconPosition.bottom - treePosition.top;
|
|
431
|
-
}
|
|
432
|
-
dropIndicator.style.top = indicatorTop + 'px';
|
|
433
|
-
dropIndicator.style.left = (iconPosition.right - treePosition.left) + 'px';
|
|
434
|
-
|
|
435
|
-
if (dropType === 'inner') {
|
|
436
|
-
addClass(dropNode.$el, 'is-drop-inner');
|
|
437
|
-
} else {
|
|
438
|
-
removeClass(dropNode.$el, 'is-drop-inner');
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
dragState.showDropIndicator = dropType === 'before' || dropType === 'after';
|
|
442
|
-
dragState.allowDrop = dragState.showDropIndicator || userAllowDropInner;
|
|
443
|
-
dragState.dropType = dropType;
|
|
444
|
-
this.$emit('node-drag-over', draggingNode.node, dropNode.node, event);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
this.$on('tree-node-drag-end', (event) => {
|
|
448
|
-
const { draggingNode, dropType, dropNode } = dragState;
|
|
449
|
-
event.preventDefault();
|
|
450
|
-
event.dataTransfer.dropEffect = 'move';
|
|
451
|
-
|
|
452
|
-
if (draggingNode && dropNode) {
|
|
453
|
-
const draggingNodeCopy = { data: draggingNode.node.data };
|
|
454
|
-
if (dropType !== 'none') {
|
|
455
|
-
draggingNode.node.remove();
|
|
456
|
-
}
|
|
457
|
-
if (dropType === 'before') {
|
|
458
|
-
dropNode.node.parent.insertBefore(draggingNodeCopy, dropNode.node);
|
|
459
|
-
} else if (dropType === 'after') {
|
|
460
|
-
dropNode.node.parent.insertAfter(draggingNodeCopy, dropNode.node);
|
|
461
|
-
} else if (dropType === 'inner') {
|
|
462
|
-
dropNode.node.insertChild(draggingNodeCopy);
|
|
463
|
-
}
|
|
464
|
-
if (dropType !== 'none') {
|
|
465
|
-
this.store.registerNode(draggingNodeCopy);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
removeClass(dropNode.$el, 'is-drop-inner');
|
|
469
|
-
|
|
470
|
-
this.$emit('node-drag-end', draggingNode.node, dropNode.node, dropType, event);
|
|
471
|
-
if (dropType !== 'none') {
|
|
472
|
-
this.$emit('node-drop', draggingNode.node, dropNode.node, dropType, event);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
if (draggingNode && !dropNode) {
|
|
476
|
-
this.$emit('node-drag-end', draggingNode.node, null, dropType, event);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
dragState.showDropIndicator = false;
|
|
480
|
-
dragState.draggingNode = null;
|
|
481
|
-
dragState.dropNode = null;
|
|
482
|
-
dragState.allowDrop = true;
|
|
483
|
-
});
|
|
484
|
-
},
|
|
485
|
-
|
|
486
|
-
mounted() {
|
|
487
|
-
this.initTabIndex();
|
|
488
|
-
this.$el.addEventListener('keydown', this.handleKeydown);
|
|
489
|
-
},
|
|
490
|
-
|
|
491
|
-
updated() {
|
|
492
|
-
this.treeItems = this.$el.querySelectorAll('[role=treeitem]');
|
|
493
|
-
this.checkboxItems = this.$el.querySelectorAll('input[type=checkbox]');
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="el-tree"
|
|
4
|
+
:class="{
|
|
5
|
+
'el-tree--highlight-current': highlightCurrent,
|
|
6
|
+
'is-dragging': !!dragState.draggingNode,
|
|
7
|
+
'is-drop-not-allow': !dragState.allowDrop,
|
|
8
|
+
'is-drop-inner': dragState.dropType === 'inner'
|
|
9
|
+
}"
|
|
10
|
+
role="tree"
|
|
11
|
+
>
|
|
12
|
+
<el-tree-node
|
|
13
|
+
v-for="child in root.childNodes"
|
|
14
|
+
:node="child"
|
|
15
|
+
:props="props"
|
|
16
|
+
:render-after-expand="renderAfterExpand"
|
|
17
|
+
:show-checkbox="showCheckbox"
|
|
18
|
+
:key="getNodeKey(child)"
|
|
19
|
+
:render-content="renderContent"
|
|
20
|
+
@node-expand="handleNodeExpand">
|
|
21
|
+
</el-tree-node>
|
|
22
|
+
<div class="el-tree__empty-block" v-if="isEmpty">
|
|
23
|
+
<span class="el-tree__empty-text">{{ emptyText }}</span>
|
|
24
|
+
</div>
|
|
25
|
+
<div
|
|
26
|
+
v-show="dragState.showDropIndicator"
|
|
27
|
+
class="el-tree__drop-indicator"
|
|
28
|
+
ref="dropIndicator">
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script>
|
|
34
|
+
import TreeStore from './model/tree-store';
|
|
35
|
+
import { getNodeKey, findNearestComponent } from './model/util';
|
|
36
|
+
import ElTreeNode from './tree-node.vue';
|
|
37
|
+
import {t} from 'iov-design/src/locale';
|
|
38
|
+
import emitter from 'iov-design/src/mixins/emitter';
|
|
39
|
+
import { addClass, removeClass } from 'iov-design/src/utils/dom';
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
name: 'ElTree',
|
|
43
|
+
|
|
44
|
+
mixins: [emitter],
|
|
45
|
+
|
|
46
|
+
components: {
|
|
47
|
+
ElTreeNode
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
data() {
|
|
51
|
+
return {
|
|
52
|
+
store: null,
|
|
53
|
+
root: null,
|
|
54
|
+
currentNode: null,
|
|
55
|
+
treeItems: null,
|
|
56
|
+
checkboxItems: [],
|
|
57
|
+
dragState: {
|
|
58
|
+
showDropIndicator: false,
|
|
59
|
+
draggingNode: null,
|
|
60
|
+
dropNode: null,
|
|
61
|
+
allowDrop: true
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
props: {
|
|
67
|
+
data: {
|
|
68
|
+
type: Array
|
|
69
|
+
},
|
|
70
|
+
emptyText: {
|
|
71
|
+
type: String,
|
|
72
|
+
default() {
|
|
73
|
+
return t('el.tree.emptyText');
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
renderAfterExpand: {
|
|
77
|
+
type: Boolean,
|
|
78
|
+
default: true
|
|
79
|
+
},
|
|
80
|
+
nodeKey: String,
|
|
81
|
+
checkStrictly: Boolean,
|
|
82
|
+
defaultExpandAll: Boolean,
|
|
83
|
+
expandOnClickNode: {
|
|
84
|
+
type: Boolean,
|
|
85
|
+
default: true
|
|
86
|
+
},
|
|
87
|
+
checkOnClickNode: Boolean,
|
|
88
|
+
checkDescendants: {
|
|
89
|
+
type: Boolean,
|
|
90
|
+
default: false
|
|
91
|
+
},
|
|
92
|
+
autoExpandParent: {
|
|
93
|
+
type: Boolean,
|
|
94
|
+
default: true
|
|
95
|
+
},
|
|
96
|
+
defaultCheckedKeys: Array,
|
|
97
|
+
defaultExpandedKeys: Array,
|
|
98
|
+
currentNodeKey: [String, Number],
|
|
99
|
+
renderContent: Function,
|
|
100
|
+
showCheckbox: {
|
|
101
|
+
type: Boolean,
|
|
102
|
+
default: false
|
|
103
|
+
},
|
|
104
|
+
draggable: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
default: false
|
|
107
|
+
},
|
|
108
|
+
allowDrag: Function,
|
|
109
|
+
allowDrop: Function,
|
|
110
|
+
props: {
|
|
111
|
+
default() {
|
|
112
|
+
return {
|
|
113
|
+
children: 'children',
|
|
114
|
+
label: 'label',
|
|
115
|
+
disabled: 'disabled'
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
lazy: {
|
|
120
|
+
type: Boolean,
|
|
121
|
+
default: false
|
|
122
|
+
},
|
|
123
|
+
highlightCurrent: Boolean,
|
|
124
|
+
load: Function,
|
|
125
|
+
filterNodeMethod: Function,
|
|
126
|
+
accordion: Boolean,
|
|
127
|
+
indent: {
|
|
128
|
+
type: Number,
|
|
129
|
+
default: 18
|
|
130
|
+
},
|
|
131
|
+
iconClass: String
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
computed: {
|
|
135
|
+
children: {
|
|
136
|
+
set(value) {
|
|
137
|
+
this.data = value;
|
|
138
|
+
},
|
|
139
|
+
get() {
|
|
140
|
+
return this.data;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
treeItemArray() {
|
|
145
|
+
return Array.prototype.slice.call(this.treeItems);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
isEmpty() {
|
|
149
|
+
const { childNodes } = this.root;
|
|
150
|
+
return !childNodes || childNodes.length === 0 || childNodes.every(({visible}) => !visible);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
watch: {
|
|
155
|
+
defaultCheckedKeys(newVal) {
|
|
156
|
+
this.store.setDefaultCheckedKey(newVal);
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
defaultExpandedKeys(newVal) {
|
|
160
|
+
this.store.defaultExpandedKeys = newVal;
|
|
161
|
+
this.store.setDefaultExpandedKeys(newVal);
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
data(newVal) {
|
|
165
|
+
this.store.setData(newVal);
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
checkboxItems(val) {
|
|
169
|
+
Array.prototype.forEach.call(val, (checkbox) => {
|
|
170
|
+
checkbox.setAttribute('tabindex', -1);
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
checkStrictly(newVal) {
|
|
175
|
+
this.store.checkStrictly = newVal;
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
methods: {
|
|
180
|
+
filter(value) {
|
|
181
|
+
if (!this.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter');
|
|
182
|
+
this.store.filter(value);
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
getNodeKey(node) {
|
|
186
|
+
return getNodeKey(this.nodeKey, node.data);
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
getNodePath(data) {
|
|
190
|
+
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in getNodePath');
|
|
191
|
+
const node = this.store.getNode(data);
|
|
192
|
+
if (!node) return [];
|
|
193
|
+
const path = [node.data];
|
|
194
|
+
let parent = node.parent;
|
|
195
|
+
while (parent && parent !== this.root) {
|
|
196
|
+
path.push(parent.data);
|
|
197
|
+
parent = parent.parent;
|
|
198
|
+
}
|
|
199
|
+
return path.reverse();
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
getCheckedNodes(leafOnly, includeHalfChecked) {
|
|
203
|
+
return this.store.getCheckedNodes(leafOnly, includeHalfChecked);
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
getCheckedKeys(leafOnly) {
|
|
207
|
+
return this.store.getCheckedKeys(leafOnly);
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
getCurrentNode() {
|
|
211
|
+
const currentNode = this.store.getCurrentNode();
|
|
212
|
+
return currentNode ? currentNode.data : null;
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
getCurrentKey() {
|
|
216
|
+
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in getCurrentKey');
|
|
217
|
+
const currentNode = this.getCurrentNode();
|
|
218
|
+
return currentNode ? currentNode[this.nodeKey] : null;
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
setCheckedNodes(nodes, leafOnly) {
|
|
222
|
+
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
|
|
223
|
+
this.store.setCheckedNodes(nodes, leafOnly);
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
setCheckedKeys(keys, leafOnly) {
|
|
227
|
+
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedKeys');
|
|
228
|
+
this.store.setCheckedKeys(keys, leafOnly);
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
setChecked(data, checked, deep) {
|
|
232
|
+
this.store.setChecked(data, checked, deep);
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
getHalfCheckedNodes() {
|
|
236
|
+
return this.store.getHalfCheckedNodes();
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
getHalfCheckedKeys() {
|
|
240
|
+
return this.store.getHalfCheckedKeys();
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
setCurrentNode(node) {
|
|
244
|
+
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentNode');
|
|
245
|
+
this.store.setUserCurrentNode(node);
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
setCurrentKey(key) {
|
|
249
|
+
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentKey');
|
|
250
|
+
this.store.setCurrentNodeKey(key);
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
getNode(data) {
|
|
254
|
+
return this.store.getNode(data);
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
remove(data) {
|
|
258
|
+
this.store.remove(data);
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
append(data, parentNode) {
|
|
262
|
+
this.store.append(data, parentNode);
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
insertBefore(data, refNode) {
|
|
266
|
+
this.store.insertBefore(data, refNode);
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
insertAfter(data, refNode) {
|
|
270
|
+
this.store.insertAfter(data, refNode);
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
handleNodeExpand(nodeData, node, instance) {
|
|
274
|
+
this.broadcast('ElTreeNode', 'tree-node-expand', node);
|
|
275
|
+
this.$emit('node-expand', nodeData, node, instance);
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
updateKeyChildren(key, data) {
|
|
279
|
+
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in updateKeyChild');
|
|
280
|
+
this.store.updateChildren(key, data);
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
initTabIndex() {
|
|
284
|
+
this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
|
|
285
|
+
this.checkboxItems = this.$el.querySelectorAll('input[type=checkbox]');
|
|
286
|
+
const checkedItem = this.$el.querySelectorAll('.is-checked[role=treeitem]');
|
|
287
|
+
if (checkedItem.length) {
|
|
288
|
+
checkedItem[0].setAttribute('tabindex', 0);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
this.treeItems[0] && this.treeItems[0].setAttribute('tabindex', 0);
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
handleKeydown(ev) {
|
|
295
|
+
const currentItem = ev.target;
|
|
296
|
+
if (currentItem.className.indexOf('el-tree-node') === -1) return;
|
|
297
|
+
const keyCode = ev.keyCode;
|
|
298
|
+
this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
|
|
299
|
+
const currentIndex = this.treeItemArray.indexOf(currentItem);
|
|
300
|
+
let nextIndex;
|
|
301
|
+
if ([38, 40].indexOf(keyCode) > -1) { // up、down
|
|
302
|
+
ev.preventDefault();
|
|
303
|
+
if (keyCode === 38) { // up
|
|
304
|
+
nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0;
|
|
305
|
+
} else {
|
|
306
|
+
nextIndex = (currentIndex < this.treeItemArray.length - 1) ? currentIndex + 1 : 0;
|
|
307
|
+
}
|
|
308
|
+
this.treeItemArray[nextIndex].focus(); // 选中
|
|
309
|
+
}
|
|
310
|
+
if ([37, 39].indexOf(keyCode) > -1) { // left、right 展开
|
|
311
|
+
ev.preventDefault();
|
|
312
|
+
currentItem.click(); // 选中
|
|
313
|
+
}
|
|
314
|
+
const hasInput = currentItem.querySelector('[type="checkbox"]');
|
|
315
|
+
if ([13, 32].indexOf(keyCode) > -1 && hasInput) { // space enter选中checkbox
|
|
316
|
+
ev.preventDefault();
|
|
317
|
+
hasInput.click();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
created() {
|
|
323
|
+
this.isTree = true;
|
|
324
|
+
|
|
325
|
+
this.store = new TreeStore({
|
|
326
|
+
key: this.nodeKey,
|
|
327
|
+
data: this.data,
|
|
328
|
+
lazy: this.lazy,
|
|
329
|
+
props: this.props,
|
|
330
|
+
load: this.load,
|
|
331
|
+
currentNodeKey: this.currentNodeKey,
|
|
332
|
+
checkStrictly: this.checkStrictly,
|
|
333
|
+
checkDescendants: this.checkDescendants,
|
|
334
|
+
defaultCheckedKeys: this.defaultCheckedKeys,
|
|
335
|
+
defaultExpandedKeys: this.defaultExpandedKeys,
|
|
336
|
+
autoExpandParent: this.autoExpandParent,
|
|
337
|
+
defaultExpandAll: this.defaultExpandAll,
|
|
338
|
+
filterNodeMethod: this.filterNodeMethod
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
this.root = this.store.root;
|
|
342
|
+
|
|
343
|
+
let dragState = this.dragState;
|
|
344
|
+
this.$on('tree-node-drag-start', (event, treeNode) => {
|
|
345
|
+
if (typeof this.allowDrag === 'function' && !this.allowDrag(treeNode.node)) {
|
|
346
|
+
event.preventDefault();
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
350
|
+
|
|
351
|
+
// wrap in try catch to address IE's error when first param is 'text/plain'
|
|
352
|
+
try {
|
|
353
|
+
// setData is required for draggable to work in FireFox
|
|
354
|
+
// the content has to be '' so dragging a node out of the tree won't open a new tab in FireFox
|
|
355
|
+
event.dataTransfer.setData('text/plain', '');
|
|
356
|
+
} catch (e) {}
|
|
357
|
+
dragState.draggingNode = treeNode;
|
|
358
|
+
this.$emit('node-drag-start', treeNode.node, event);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
this.$on('tree-node-drag-over', (event, treeNode) => {
|
|
362
|
+
const dropNode = findNearestComponent(event.target, 'ElTreeNode');
|
|
363
|
+
const oldDropNode = dragState.dropNode;
|
|
364
|
+
if (oldDropNode && oldDropNode !== dropNode) {
|
|
365
|
+
removeClass(oldDropNode.$el, 'is-drop-inner');
|
|
366
|
+
}
|
|
367
|
+
const draggingNode = dragState.draggingNode;
|
|
368
|
+
if (!draggingNode || !dropNode) return;
|
|
369
|
+
|
|
370
|
+
let dropPrev = true;
|
|
371
|
+
let dropInner = true;
|
|
372
|
+
let dropNext = true;
|
|
373
|
+
let userAllowDropInner = true;
|
|
374
|
+
if (typeof this.allowDrop === 'function') {
|
|
375
|
+
dropPrev = this.allowDrop(draggingNode.node, dropNode.node, 'prev');
|
|
376
|
+
userAllowDropInner = dropInner = this.allowDrop(draggingNode.node, dropNode.node, 'inner');
|
|
377
|
+
dropNext = this.allowDrop(draggingNode.node, dropNode.node, 'next');
|
|
378
|
+
}
|
|
379
|
+
event.dataTransfer.dropEffect = dropInner ? 'move' : 'none';
|
|
380
|
+
if ((dropPrev || dropInner || dropNext) && oldDropNode !== dropNode) {
|
|
381
|
+
if (oldDropNode) {
|
|
382
|
+
this.$emit('node-drag-leave', draggingNode.node, oldDropNode.node, event);
|
|
383
|
+
}
|
|
384
|
+
this.$emit('node-drag-enter', draggingNode.node, dropNode.node, event);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (dropPrev || dropInner || dropNext) {
|
|
388
|
+
dragState.dropNode = dropNode;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (dropNode.node.nextSibling === draggingNode.node) {
|
|
392
|
+
dropNext = false;
|
|
393
|
+
}
|
|
394
|
+
if (dropNode.node.previousSibling === draggingNode.node) {
|
|
395
|
+
dropPrev = false;
|
|
396
|
+
}
|
|
397
|
+
if (dropNode.node.contains(draggingNode.node, false)) {
|
|
398
|
+
dropInner = false;
|
|
399
|
+
}
|
|
400
|
+
if (draggingNode.node === dropNode.node || draggingNode.node.contains(dropNode.node)) {
|
|
401
|
+
dropPrev = false;
|
|
402
|
+
dropInner = false;
|
|
403
|
+
dropNext = false;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const targetPosition = dropNode.$el.getBoundingClientRect();
|
|
407
|
+
const treePosition = this.$el.getBoundingClientRect();
|
|
408
|
+
|
|
409
|
+
let dropType;
|
|
410
|
+
const prevPercent = dropPrev ? (dropInner ? 0.25 : (dropNext ? 0.45 : 1)) : -1;
|
|
411
|
+
const nextPercent = dropNext ? (dropInner ? 0.75 : (dropPrev ? 0.55 : 0)) : 1;
|
|
412
|
+
|
|
413
|
+
let indicatorTop = -9999;
|
|
414
|
+
const distance = event.clientY - targetPosition.top;
|
|
415
|
+
if (distance < targetPosition.height * prevPercent) {
|
|
416
|
+
dropType = 'before';
|
|
417
|
+
} else if (distance > targetPosition.height * nextPercent) {
|
|
418
|
+
dropType = 'after';
|
|
419
|
+
} else if (dropInner) {
|
|
420
|
+
dropType = 'inner';
|
|
421
|
+
} else {
|
|
422
|
+
dropType = 'none';
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const iconPosition = dropNode.$el.querySelector('.el-tree-node__expand-icon').getBoundingClientRect();
|
|
426
|
+
const dropIndicator = this.$refs.dropIndicator;
|
|
427
|
+
if (dropType === 'before') {
|
|
428
|
+
indicatorTop = iconPosition.top - treePosition.top;
|
|
429
|
+
} else if (dropType === 'after') {
|
|
430
|
+
indicatorTop = iconPosition.bottom - treePosition.top;
|
|
431
|
+
}
|
|
432
|
+
dropIndicator.style.top = indicatorTop + 'px';
|
|
433
|
+
dropIndicator.style.left = (iconPosition.right - treePosition.left) + 'px';
|
|
434
|
+
|
|
435
|
+
if (dropType === 'inner') {
|
|
436
|
+
addClass(dropNode.$el, 'is-drop-inner');
|
|
437
|
+
} else {
|
|
438
|
+
removeClass(dropNode.$el, 'is-drop-inner');
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
dragState.showDropIndicator = dropType === 'before' || dropType === 'after';
|
|
442
|
+
dragState.allowDrop = dragState.showDropIndicator || userAllowDropInner;
|
|
443
|
+
dragState.dropType = dropType;
|
|
444
|
+
this.$emit('node-drag-over', draggingNode.node, dropNode.node, event);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
this.$on('tree-node-drag-end', (event) => {
|
|
448
|
+
const { draggingNode, dropType, dropNode } = dragState;
|
|
449
|
+
event.preventDefault();
|
|
450
|
+
event.dataTransfer.dropEffect = 'move';
|
|
451
|
+
|
|
452
|
+
if (draggingNode && dropNode) {
|
|
453
|
+
const draggingNodeCopy = { data: draggingNode.node.data };
|
|
454
|
+
if (dropType !== 'none') {
|
|
455
|
+
draggingNode.node.remove();
|
|
456
|
+
}
|
|
457
|
+
if (dropType === 'before') {
|
|
458
|
+
dropNode.node.parent.insertBefore(draggingNodeCopy, dropNode.node);
|
|
459
|
+
} else if (dropType === 'after') {
|
|
460
|
+
dropNode.node.parent.insertAfter(draggingNodeCopy, dropNode.node);
|
|
461
|
+
} else if (dropType === 'inner') {
|
|
462
|
+
dropNode.node.insertChild(draggingNodeCopy);
|
|
463
|
+
}
|
|
464
|
+
if (dropType !== 'none') {
|
|
465
|
+
this.store.registerNode(draggingNodeCopy);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
removeClass(dropNode.$el, 'is-drop-inner');
|
|
469
|
+
|
|
470
|
+
this.$emit('node-drag-end', draggingNode.node, dropNode.node, dropType, event);
|
|
471
|
+
if (dropType !== 'none') {
|
|
472
|
+
this.$emit('node-drop', draggingNode.node, dropNode.node, dropType, event);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
if (draggingNode && !dropNode) {
|
|
476
|
+
this.$emit('node-drag-end', draggingNode.node, null, dropType, event);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
dragState.showDropIndicator = false;
|
|
480
|
+
dragState.draggingNode = null;
|
|
481
|
+
dragState.dropNode = null;
|
|
482
|
+
dragState.allowDrop = true;
|
|
483
|
+
});
|
|
484
|
+
},
|
|
485
|
+
|
|
486
|
+
mounted() {
|
|
487
|
+
this.initTabIndex();
|
|
488
|
+
this.$el.addEventListener('keydown', this.handleKeydown);
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
updated() {
|
|
492
|
+
this.treeItems = this.$el.querySelectorAll('[role=treeitem]');
|
|
493
|
+
this.checkboxItems = this.$el.querySelectorAll('input[type=checkbox]');
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
</script>
|