vue-devui 1.0.0-rc.3 → 1.0.0-rc.6
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 +144 -129
- package/auto-complete/index.es.js +45 -16
- package/auto-complete/index.umd.js +3 -3
- package/auto-complete/style.css +1 -1
- package/button/index.es.js +20 -13
- package/button/index.umd.js +1 -1
- package/button/style.css +1 -1
- package/comment/index.es.js +2 -1
- package/comment/index.umd.js +1 -1
- package/{tag-input → date-picker}/index.d.ts +0 -0
- package/date-picker/index.es.js +1145 -0
- package/date-picker/index.umd.js +1 -0
- package/date-picker/package.json +7 -0
- package/date-picker/style.css +1 -0
- package/drawer/index.d.ts +7 -0
- package/drawer/index.es.js +236 -0
- package/drawer/index.umd.js +1 -0
- package/{tag-input → drawer}/package.json +1 -1
- package/drawer/style.css +1 -0
- package/dropdown/index.d.ts +7 -0
- package/dropdown/index.es.js +718 -0
- package/dropdown/index.umd.js +1 -0
- package/dropdown/package.json +7 -0
- package/dropdown/style.css +1 -0
- package/form/index.d.ts +7 -0
- package/form/index.es.js +7881 -0
- package/form/index.umd.js +27 -0
- package/form/package.json +7 -0
- package/form/style.css +1 -0
- package/input/index.es.js +13 -19
- package/input/index.umd.js +1 -1
- package/input/style.css +1 -1
- package/input-number/index.d.ts +7 -0
- package/input-number/index.es.js +251 -0
- package/input-number/index.umd.js +1 -0
- package/input-number/package.json +7 -0
- package/input-number/style.css +1 -0
- package/layout/index.es.js +3 -1
- package/layout/index.umd.js +1 -1
- package/loading/index.es.js +20 -13
- package/loading/index.umd.js +1 -1
- package/modal/index.es.js +16 -4
- package/modal/index.umd.js +1 -1
- package/notification/index.es.js +100 -10
- package/notification/index.umd.js +1 -1
- package/notification/style.css +1 -1
- package/nuxt/components/Column.js +3 -0
- package/nuxt/components/DatePicker.js +3 -0
- package/nuxt/components/Drawer.js +3 -0
- package/nuxt/components/DrawerService.js +3 -0
- package/nuxt/components/Dropdown.js +3 -0
- package/nuxt/components/DropdownMenu.js +3 -0
- package/nuxt/components/Form.js +3 -0
- package/nuxt/components/FormControl.js +3 -0
- package/nuxt/components/FormItem.js +3 -0
- package/nuxt/components/FormLabel.js +3 -0
- package/nuxt/components/FormOperation.js +3 -0
- package/nuxt/components/InputNumber.js +3 -0
- package/nuxt/components/LoadingOptions.js +3 -0
- package/nuxt/components/Select.js +3 -0
- package/nuxt/components/StickSlider.js +3 -0
- package/nuxt/components/Tab.js +3 -0
- package/nuxt/components/Table.js +3 -0
- package/nuxt/components/Tabs.js +3 -0
- package/nuxt/components/Tooltip.js +3 -0
- package/nuxt/components/Tree.js +3 -0
- package/nuxt/components/dropdownMenuProps.js +3 -0
- package/nuxt/components/loadingProps.js +3 -0
- package/nuxt/components/modalProps.js +3 -0
- package/nuxt/components/sliderProps.js +3 -0
- package/nuxt/components/tabsProps.js +3 -0
- package/nuxt/components/tooltipProps.js +3 -0
- package/nuxt/components/treeProps.js +3 -0
- package/overlay/index.es.js +15 -3
- package/overlay/index.umd.js +1 -1
- package/package.json +2 -2
- package/popover/index.es.js +15 -3
- package/popover/index.umd.js +9 -9
- package/popover/style.css +1 -1
- package/rate/index.es.js +27 -34
- package/rate/index.umd.js +1 -1
- package/read-tip/index.es.js +32 -29
- package/read-tip/index.umd.js +1 -1
- package/read-tip/style.css +1 -1
- package/search/index.es.js +13 -19
- package/search/index.umd.js +12 -12
- package/search/style.css +1 -1
- package/select/index.d.ts +7 -0
- package/select/index.es.js +696 -0
- package/select/index.umd.js +1 -0
- package/select/package.json +7 -0
- package/select/style.css +1 -0
- package/skeleton/index.es.js +6 -6
- package/skeleton/index.umd.js +1 -1
- package/slider/index.es.js +19 -10
- package/slider/index.umd.js +1 -1
- package/splitter/index.es.js +15 -3
- package/splitter/index.umd.js +11 -11
- package/style.css +1 -1
- package/switch/index.es.js +1 -1
- package/switch/index.umd.js +1 -1
- package/switch/style.css +1 -1
- package/table/index.d.ts +7 -0
- package/table/index.es.js +2661 -0
- package/table/index.umd.js +1 -0
- package/table/package.json +7 -0
- package/table/style.css +1 -0
- package/tabs/index.d.ts +7 -0
- package/tabs/index.es.js +194 -0
- package/tabs/index.umd.js +1 -0
- package/tabs/package.json +7 -0
- package/tabs/style.css +1 -0
- package/timeline/index.es.js +2 -2
- package/timeline/index.umd.js +1 -1
- package/tooltip/index.d.ts +7 -0
- package/tooltip/index.es.js +5847 -0
- package/tooltip/index.umd.js +27 -0
- package/tooltip/package.json +7 -0
- package/tooltip/style.css +1 -0
- package/tree/index.d.ts +7 -0
- package/tree/index.es.js +1021 -0
- package/tree/index.umd.js +1 -0
- package/tree/package.json +7 -0
- package/tree/style.css +1 -0
- package/upload/index.es.js +100 -10
- package/upload/index.umd.js +1 -1
- package/upload/style.css +1 -1
- package/vue-devui.es.js +13211 -7394
- package/vue-devui.umd.js +24 -24
- package/nuxt/components/TagInput.js +0 -3
- package/nuxt/components/tagInputProps.js +0 -3
- package/tag-input/index.es.js +0 -328
- package/tag-input/index.umd.js +0 -1
- package/tag-input/style.css +0 -1
package/tree/index.es.js
ADDED
|
@@ -0,0 +1,1021 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { createVNode, defineComponent, toRefs, inject, computed, mergeProps, toRef, provide, renderSlot, useSlots, ref, watch } from "vue";
|
|
21
|
+
const USE_TREE_TOKEN = "use-tree-token";
|
|
22
|
+
const NODE_HEIGHT = 30;
|
|
23
|
+
const NODE_INDENT = 24;
|
|
24
|
+
const IconClose = () => createVNode("svg", {
|
|
25
|
+
"width": "16px",
|
|
26
|
+
"height": "16px",
|
|
27
|
+
"viewBox": "0 0 16 16",
|
|
28
|
+
"version": "1.1",
|
|
29
|
+
"xmlns": "http://www.w3.org/2000/svg",
|
|
30
|
+
"class": "svg-icon"
|
|
31
|
+
}, [createVNode("g", {
|
|
32
|
+
"stroke": "none",
|
|
33
|
+
"stroke-width": "1",
|
|
34
|
+
"fill": "none",
|
|
35
|
+
"fill-rule": "evenodd"
|
|
36
|
+
}, [createVNode("rect", {
|
|
37
|
+
"x": "0.5",
|
|
38
|
+
"y": "0.5",
|
|
39
|
+
"width": "15",
|
|
40
|
+
"height": "15",
|
|
41
|
+
"rx": "2",
|
|
42
|
+
"stroke": "#252b3a"
|
|
43
|
+
}, null), createVNode("path", {
|
|
44
|
+
"fill": "#252b3a",
|
|
45
|
+
"d": "M8.75,4 L8.75,7.25 L12,7.25 L12,8.75 L8.749,8.75 L8.75,12 L7.25,12 L7.249,8.75 L4,8.75 L4,7.25 L7.25,7.25 L7.25,4 L8.75,4 Z"
|
|
46
|
+
}, null)])]);
|
|
47
|
+
const IconOpen = () => createVNode("svg", {
|
|
48
|
+
"width": "16px",
|
|
49
|
+
"height": "16px",
|
|
50
|
+
"viewBox": "0 0 16 16",
|
|
51
|
+
"version": "1.1",
|
|
52
|
+
"xmlns": "http://www.w3.org/2000/svg",
|
|
53
|
+
"class": "svg-icon svg-icon-close"
|
|
54
|
+
}, [createVNode("g", {
|
|
55
|
+
"stroke-width": "1",
|
|
56
|
+
"fill": "none",
|
|
57
|
+
"fill-rule": "evenodd"
|
|
58
|
+
}, [createVNode("rect", {
|
|
59
|
+
"x": "0.5",
|
|
60
|
+
"y": "0.5",
|
|
61
|
+
"width": "15",
|
|
62
|
+
"height": "15",
|
|
63
|
+
"rx": "2",
|
|
64
|
+
"stroke": "#5e7ce0"
|
|
65
|
+
}, null), createVNode("rect", {
|
|
66
|
+
"x": "4",
|
|
67
|
+
"y": "7",
|
|
68
|
+
"width": "8",
|
|
69
|
+
"height": "2",
|
|
70
|
+
"fill": "#5e7ce0"
|
|
71
|
+
}, null)])]);
|
|
72
|
+
var DTreeNodeToggle = defineComponent({
|
|
73
|
+
name: "DTreeNodeToggle",
|
|
74
|
+
props: {
|
|
75
|
+
data: {
|
|
76
|
+
type: Object,
|
|
77
|
+
default: () => ({})
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
setup(props) {
|
|
81
|
+
const {
|
|
82
|
+
data
|
|
83
|
+
} = toRefs(props);
|
|
84
|
+
const {
|
|
85
|
+
toggleNode
|
|
86
|
+
} = inject(USE_TREE_TOKEN);
|
|
87
|
+
return () => {
|
|
88
|
+
var _a;
|
|
89
|
+
return createVNode("span", {
|
|
90
|
+
"class": ["devui-tree-node__folder", ((_a = data.value) == null ? void 0 : _a.disableToggle) && "toggle-disabled"],
|
|
91
|
+
"onClick": (event) => {
|
|
92
|
+
event.stopPropagation();
|
|
93
|
+
if (toggleNode) {
|
|
94
|
+
toggleNode(data.value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, [data.value.isLeaf ? createVNode("span", {
|
|
98
|
+
"class": "devui-tree-node__indent"
|
|
99
|
+
}, null) : data.value.expanded ? createVNode(IconOpen, {
|
|
100
|
+
"class": "mr-xs"
|
|
101
|
+
}, null) : createVNode(IconClose, {
|
|
102
|
+
"class": "mr-xs"
|
|
103
|
+
}, null)]);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
var checkbox = "";
|
|
108
|
+
const commonProps = {
|
|
109
|
+
name: {
|
|
110
|
+
type: String,
|
|
111
|
+
default: void 0
|
|
112
|
+
},
|
|
113
|
+
halfchecked: {
|
|
114
|
+
type: Boolean,
|
|
115
|
+
default: false
|
|
116
|
+
},
|
|
117
|
+
isShowTitle: {
|
|
118
|
+
type: Boolean,
|
|
119
|
+
default: true
|
|
120
|
+
},
|
|
121
|
+
title: {
|
|
122
|
+
type: String
|
|
123
|
+
},
|
|
124
|
+
color: {
|
|
125
|
+
type: String,
|
|
126
|
+
default: void 0
|
|
127
|
+
},
|
|
128
|
+
showAnimation: {
|
|
129
|
+
type: Boolean,
|
|
130
|
+
default: true
|
|
131
|
+
},
|
|
132
|
+
disabled: {
|
|
133
|
+
type: Boolean,
|
|
134
|
+
default: false
|
|
135
|
+
},
|
|
136
|
+
beforeChange: {
|
|
137
|
+
type: Function,
|
|
138
|
+
default: void 0
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const checkboxProps = __spreadProps(__spreadValues({}, commonProps), {
|
|
142
|
+
halfchecked: {
|
|
143
|
+
type: Boolean,
|
|
144
|
+
default: false
|
|
145
|
+
},
|
|
146
|
+
checked: {
|
|
147
|
+
type: Boolean,
|
|
148
|
+
default: false
|
|
149
|
+
},
|
|
150
|
+
value: {
|
|
151
|
+
type: String
|
|
152
|
+
},
|
|
153
|
+
label: {
|
|
154
|
+
type: String,
|
|
155
|
+
default: void 0
|
|
156
|
+
},
|
|
157
|
+
title: {
|
|
158
|
+
type: String,
|
|
159
|
+
default: void 0
|
|
160
|
+
},
|
|
161
|
+
"onUpdate:checked": {
|
|
162
|
+
type: Function,
|
|
163
|
+
default: void 0
|
|
164
|
+
},
|
|
165
|
+
onChange: {
|
|
166
|
+
type: Function,
|
|
167
|
+
default: void 0
|
|
168
|
+
},
|
|
169
|
+
modelValue: {
|
|
170
|
+
type: Boolean
|
|
171
|
+
},
|
|
172
|
+
"onUpdate:modelValue": {
|
|
173
|
+
type: Function
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const checkboxGroupProps = __spreadProps(__spreadValues({}, commonProps), {
|
|
177
|
+
modelValue: {
|
|
178
|
+
type: Array,
|
|
179
|
+
required: true
|
|
180
|
+
},
|
|
181
|
+
direction: {
|
|
182
|
+
type: String,
|
|
183
|
+
default: "column"
|
|
184
|
+
},
|
|
185
|
+
itemWidth: {
|
|
186
|
+
type: Number,
|
|
187
|
+
default: void 0
|
|
188
|
+
},
|
|
189
|
+
options: {
|
|
190
|
+
type: Array,
|
|
191
|
+
default: () => []
|
|
192
|
+
},
|
|
193
|
+
onChange: {
|
|
194
|
+
type: Function,
|
|
195
|
+
default: void 0
|
|
196
|
+
},
|
|
197
|
+
"onUpdate:modelValue": {
|
|
198
|
+
type: Function,
|
|
199
|
+
default: void 0
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const checkboxGroupInjectionKey = Symbol("d-checkbox-group");
|
|
203
|
+
var Checkbox = defineComponent({
|
|
204
|
+
name: "DCheckbox",
|
|
205
|
+
props: checkboxProps,
|
|
206
|
+
emits: ["change", "update:checked", "update:modelValue"],
|
|
207
|
+
setup(props, ctx) {
|
|
208
|
+
const checkboxGroupConf = inject(checkboxGroupInjectionKey, null);
|
|
209
|
+
const isChecked = computed(() => props.checked || props.modelValue);
|
|
210
|
+
const mergedDisabled = computed(() => {
|
|
211
|
+
return (checkboxGroupConf == null ? void 0 : checkboxGroupConf.disabled.value) || props.disabled;
|
|
212
|
+
});
|
|
213
|
+
const mergedChecked = computed(() => {
|
|
214
|
+
var _a, _b;
|
|
215
|
+
return (_b = (_a = checkboxGroupConf == null ? void 0 : checkboxGroupConf.isItemChecked) == null ? void 0 : _a.call(checkboxGroupConf, props.value)) != null ? _b : isChecked.value;
|
|
216
|
+
});
|
|
217
|
+
const mergedIsShowTitle = computed(() => {
|
|
218
|
+
var _a;
|
|
219
|
+
return (_a = checkboxGroupConf == null ? void 0 : checkboxGroupConf.isShowTitle.value) != null ? _a : props.isShowTitle;
|
|
220
|
+
});
|
|
221
|
+
const mergedShowAnimation = computed(() => {
|
|
222
|
+
var _a;
|
|
223
|
+
return (_a = checkboxGroupConf == null ? void 0 : checkboxGroupConf.showAnimation.value) != null ? _a : props.showAnimation;
|
|
224
|
+
});
|
|
225
|
+
const mergedColor = computed(() => {
|
|
226
|
+
var _a;
|
|
227
|
+
return (_a = checkboxGroupConf == null ? void 0 : checkboxGroupConf.color.value) != null ? _a : props.color;
|
|
228
|
+
});
|
|
229
|
+
const itemWidth = checkboxGroupConf == null ? void 0 : checkboxGroupConf.itemWidth.value;
|
|
230
|
+
const direction = checkboxGroupConf == null ? void 0 : checkboxGroupConf.direction.value;
|
|
231
|
+
const canChange = (checked, val) => {
|
|
232
|
+
var _a;
|
|
233
|
+
if (mergedDisabled.value) {
|
|
234
|
+
return Promise.resolve(false);
|
|
235
|
+
}
|
|
236
|
+
const beforeChange = (_a = props.beforeChange) != null ? _a : checkboxGroupConf == null ? void 0 : checkboxGroupConf.beforeChange;
|
|
237
|
+
if (beforeChange) {
|
|
238
|
+
const res = beforeChange(checked, val);
|
|
239
|
+
if (typeof res === "boolean") {
|
|
240
|
+
return Promise.resolve(res);
|
|
241
|
+
}
|
|
242
|
+
return res;
|
|
243
|
+
}
|
|
244
|
+
return Promise.resolve(true);
|
|
245
|
+
};
|
|
246
|
+
const toggle = () => {
|
|
247
|
+
const current = !isChecked.value;
|
|
248
|
+
checkboxGroupConf == null ? void 0 : checkboxGroupConf.toggleGroupVal(props.value);
|
|
249
|
+
ctx.emit("update:checked", current);
|
|
250
|
+
ctx.emit("update:modelValue", current);
|
|
251
|
+
ctx.emit("change", current);
|
|
252
|
+
};
|
|
253
|
+
const handleClick = () => {
|
|
254
|
+
canChange(!isChecked.value, props.label).then((res) => res && toggle());
|
|
255
|
+
};
|
|
256
|
+
return {
|
|
257
|
+
itemWidth,
|
|
258
|
+
direction,
|
|
259
|
+
mergedColor,
|
|
260
|
+
mergedDisabled,
|
|
261
|
+
mergedIsShowTitle,
|
|
262
|
+
mergedChecked,
|
|
263
|
+
mergedShowAnimation,
|
|
264
|
+
handleClick
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
render() {
|
|
268
|
+
var _a;
|
|
269
|
+
const {
|
|
270
|
+
itemWidth,
|
|
271
|
+
direction,
|
|
272
|
+
mergedChecked,
|
|
273
|
+
mergedDisabled,
|
|
274
|
+
mergedIsShowTitle,
|
|
275
|
+
mergedShowAnimation,
|
|
276
|
+
halfchecked,
|
|
277
|
+
title,
|
|
278
|
+
label,
|
|
279
|
+
handleClick,
|
|
280
|
+
name,
|
|
281
|
+
value,
|
|
282
|
+
mergedColor,
|
|
283
|
+
$slots
|
|
284
|
+
} = this;
|
|
285
|
+
const wrapperCls = {
|
|
286
|
+
"devui-checkbox-column-margin": direction === "column",
|
|
287
|
+
"devui-checkbox-wrap": typeof itemWidth !== "undefined"
|
|
288
|
+
};
|
|
289
|
+
const wrapperStyle = itemWidth ? [`width: ${itemWidth}px`] : [];
|
|
290
|
+
const checkboxCls = {
|
|
291
|
+
"devui-checkbox": true,
|
|
292
|
+
active: mergedChecked,
|
|
293
|
+
halfchecked,
|
|
294
|
+
disabled: mergedDisabled,
|
|
295
|
+
unchecked: !mergedChecked
|
|
296
|
+
};
|
|
297
|
+
const labelTitle = mergedIsShowTitle ? title || label : "";
|
|
298
|
+
const bgImgStyle = mergedColor && halfchecked || mergedColor ? `linear-gradient(${mergedColor}, ${mergedColor})` : "";
|
|
299
|
+
const spanStyle = [`border-color:${(mergedChecked || halfchecked) && mergedColor ? mergedColor : ""}`, `background-image:${bgImgStyle}`, `background-color:${mergedColor && halfchecked ? mergedColor : ""}`];
|
|
300
|
+
const spanCls = {
|
|
301
|
+
"devui-checkbox-material": true,
|
|
302
|
+
"custom-color": mergedColor,
|
|
303
|
+
"devui-checkbox-no-label": !label && !$slots.default,
|
|
304
|
+
"devui-no-animation": !mergedShowAnimation,
|
|
305
|
+
"devui-checkbox-default-background": !halfchecked
|
|
306
|
+
};
|
|
307
|
+
const polygonCls = {
|
|
308
|
+
"devui-tick": true,
|
|
309
|
+
"devui-no-animation": !mergedShowAnimation
|
|
310
|
+
};
|
|
311
|
+
const stopPropagation = ($event) => $event.stopPropagation();
|
|
312
|
+
const inputProps = {
|
|
313
|
+
indeterminate: halfchecked
|
|
314
|
+
};
|
|
315
|
+
return createVNode("div", {
|
|
316
|
+
"class": wrapperCls,
|
|
317
|
+
"style": wrapperStyle
|
|
318
|
+
}, [createVNode("div", {
|
|
319
|
+
"class": checkboxCls
|
|
320
|
+
}, [createVNode("label", {
|
|
321
|
+
"title": labelTitle,
|
|
322
|
+
"onClick": handleClick
|
|
323
|
+
}, [createVNode("input", mergeProps({
|
|
324
|
+
"name": name || value,
|
|
325
|
+
"class": "devui-checkbox-input",
|
|
326
|
+
"type": "checkbox"
|
|
327
|
+
}, inputProps, {
|
|
328
|
+
"checked": mergedChecked,
|
|
329
|
+
"disabled": mergedDisabled,
|
|
330
|
+
"onClick": stopPropagation,
|
|
331
|
+
"onChange": stopPropagation
|
|
332
|
+
}), null), createVNode("span", {
|
|
333
|
+
"style": spanStyle,
|
|
334
|
+
"class": spanCls
|
|
335
|
+
}, [createVNode("span", {
|
|
336
|
+
"class": "devui-checkbox-halfchecked-bg"
|
|
337
|
+
}, null), createVNode("svg", {
|
|
338
|
+
"viewBox": "0 0 16 16",
|
|
339
|
+
"version": "1.1",
|
|
340
|
+
"xmlns": "http://www.w3.org/2000/svg",
|
|
341
|
+
"class": "devui-checkbox-tick"
|
|
342
|
+
}, [createVNode("g", {
|
|
343
|
+
"stroke": "none",
|
|
344
|
+
"stroke-width": "1",
|
|
345
|
+
"fill": "none",
|
|
346
|
+
"fill-rule": "evenodd"
|
|
347
|
+
}, [createVNode("polygon", {
|
|
348
|
+
"fill-rule": "nonzero",
|
|
349
|
+
"points": "5.17391304 6.56521739 7.7173913 9.10869565 11.826087 5 13 6.17391304 7.7173913 11.4565217 4 7.73913043",
|
|
350
|
+
"class": polygonCls
|
|
351
|
+
}, null)])])]), label || ((_a = $slots.default) == null ? void 0 : _a.call($slots))])])]);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
var checkboxGroup = "";
|
|
355
|
+
defineComponent({
|
|
356
|
+
name: "DCheckboxGroup",
|
|
357
|
+
props: checkboxGroupProps,
|
|
358
|
+
emits: ["change", "update:modelValue"],
|
|
359
|
+
setup(props, ctx) {
|
|
360
|
+
const valList = toRef(props, "modelValue");
|
|
361
|
+
const defaultOpt = {
|
|
362
|
+
checked: false,
|
|
363
|
+
isShowTitle: true,
|
|
364
|
+
halfchecked: false,
|
|
365
|
+
showAnimation: true,
|
|
366
|
+
disabled: false
|
|
367
|
+
};
|
|
368
|
+
const toggleGroupVal = (val) => {
|
|
369
|
+
let index2 = -1;
|
|
370
|
+
if (typeof valList.value[0] === "string") {
|
|
371
|
+
index2 = valList.value.findIndex((item) => item === val);
|
|
372
|
+
} else if (typeof valList.value[0] === "object") {
|
|
373
|
+
index2 = valList.value.findIndex((item) => item.value === val);
|
|
374
|
+
}
|
|
375
|
+
if (index2 === -1) {
|
|
376
|
+
if (typeof props.options[0] === "object") {
|
|
377
|
+
const newOne = props.options.find((item) => item.value === val);
|
|
378
|
+
const res2 = [...valList.value, newOne];
|
|
379
|
+
ctx.emit("update:modelValue", res2);
|
|
380
|
+
ctx.emit("change", res2);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const res = [...valList.value, val];
|
|
384
|
+
ctx.emit("update:modelValue", res);
|
|
385
|
+
ctx.emit("change", res);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
valList.value.splice(index2, 1);
|
|
389
|
+
ctx.emit("update:modelValue", valList.value);
|
|
390
|
+
ctx.emit("change", valList.value);
|
|
391
|
+
};
|
|
392
|
+
const isItemChecked = (itemVal) => {
|
|
393
|
+
if (typeof valList.value[0] === "string") {
|
|
394
|
+
return valList.value.includes(itemVal);
|
|
395
|
+
} else if (typeof valList.value[0] === "object") {
|
|
396
|
+
return valList.value.some((item) => item.value === itemVal);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
provide(checkboxGroupInjectionKey, {
|
|
400
|
+
disabled: toRef(props, "disabled"),
|
|
401
|
+
isShowTitle: toRef(props, "isShowTitle"),
|
|
402
|
+
color: toRef(props, "color"),
|
|
403
|
+
showAnimation: toRef(props, "showAnimation"),
|
|
404
|
+
beforeChange: props.beforeChange,
|
|
405
|
+
isItemChecked,
|
|
406
|
+
toggleGroupVal,
|
|
407
|
+
itemWidth: toRef(props, "itemWidth"),
|
|
408
|
+
direction: toRef(props, "direction")
|
|
409
|
+
});
|
|
410
|
+
return {
|
|
411
|
+
defaultOpt
|
|
412
|
+
};
|
|
413
|
+
},
|
|
414
|
+
render() {
|
|
415
|
+
var _a;
|
|
416
|
+
const {
|
|
417
|
+
direction,
|
|
418
|
+
$slots,
|
|
419
|
+
defaultOpt,
|
|
420
|
+
options
|
|
421
|
+
} = this;
|
|
422
|
+
let children = (_a = $slots.default) == null ? void 0 : _a.call($slots);
|
|
423
|
+
if ((options == null ? void 0 : options.length) > 0) {
|
|
424
|
+
children = options.map((opt) => {
|
|
425
|
+
let mergedOpt = null;
|
|
426
|
+
if (typeof opt === "string") {
|
|
427
|
+
mergedOpt = Object.assign({}, defaultOpt, {
|
|
428
|
+
label: opt,
|
|
429
|
+
value: opt
|
|
430
|
+
});
|
|
431
|
+
} else if (typeof opt === "object") {
|
|
432
|
+
mergedOpt = Object.assign({}, defaultOpt, __spreadProps(__spreadValues({}, opt), {
|
|
433
|
+
label: opt.name
|
|
434
|
+
}));
|
|
435
|
+
}
|
|
436
|
+
return createVNode(Checkbox, mergedOpt, null);
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return createVNode("div", {
|
|
440
|
+
"class": "devui-checkbox-group"
|
|
441
|
+
}, [createVNode("div", {
|
|
442
|
+
"class": {
|
|
443
|
+
"devui-checkbox-list-inline": direction === "row"
|
|
444
|
+
}
|
|
445
|
+
}, [children])]);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
function useTreeNode(data) {
|
|
449
|
+
const { getChildren } = inject(USE_TREE_TOKEN);
|
|
450
|
+
const nodeClass = computed(() => {
|
|
451
|
+
var _a;
|
|
452
|
+
return [
|
|
453
|
+
"devui-tree-node",
|
|
454
|
+
((_a = data.value) == null ? void 0 : _a.expanded) && "devui-tree-node__open"
|
|
455
|
+
];
|
|
456
|
+
});
|
|
457
|
+
const nodeStyle = computed(() => {
|
|
458
|
+
var _a;
|
|
459
|
+
return { paddingLeft: `${NODE_INDENT * (((_a = data.value) == null ? void 0 : _a.level) - 1)}px` };
|
|
460
|
+
});
|
|
461
|
+
const nodeVLineClass = computed(() => {
|
|
462
|
+
var _a, _b;
|
|
463
|
+
return [
|
|
464
|
+
!((_a = data.value) == null ? void 0 : _a.isLeaf) && ((_b = data.value) == null ? void 0 : _b.expanded) && "devui-tree-node__vline"
|
|
465
|
+
];
|
|
466
|
+
});
|
|
467
|
+
const nodeVLineStyle = computed(() => {
|
|
468
|
+
var _a;
|
|
469
|
+
return {
|
|
470
|
+
height: `${NODE_HEIGHT * (getChildren(data.value, { expanded: true }).length - 1) + NODE_HEIGHT / 2 + 1}px`,
|
|
471
|
+
left: `${NODE_INDENT * (((_a = data.value) == null ? void 0 : _a.level) - 1) + 9}px`,
|
|
472
|
+
top: `${NODE_HEIGHT}px`
|
|
473
|
+
};
|
|
474
|
+
});
|
|
475
|
+
const nodeHLineClass = computed(() => {
|
|
476
|
+
var _a;
|
|
477
|
+
return [
|
|
478
|
+
((_a = data.value) == null ? void 0 : _a.level) !== 1 && "devui-tree-node__hline"
|
|
479
|
+
];
|
|
480
|
+
});
|
|
481
|
+
const nodeContentClass = computed(() => {
|
|
482
|
+
var _a;
|
|
483
|
+
return [
|
|
484
|
+
"devui-tree-node__content",
|
|
485
|
+
((_a = data.value) == null ? void 0 : _a.selected) && "active"
|
|
486
|
+
];
|
|
487
|
+
});
|
|
488
|
+
const nodeTitleClass = computed(() => {
|
|
489
|
+
var _a;
|
|
490
|
+
return [
|
|
491
|
+
"devui-tree-node__title",
|
|
492
|
+
((_a = data.value) == null ? void 0 : _a.disableSelect) && "select-disabled"
|
|
493
|
+
];
|
|
494
|
+
});
|
|
495
|
+
return {
|
|
496
|
+
nodeClass,
|
|
497
|
+
nodeStyle,
|
|
498
|
+
nodeContentClass,
|
|
499
|
+
nodeTitleClass,
|
|
500
|
+
nodeVLineClass,
|
|
501
|
+
nodeVLineStyle,
|
|
502
|
+
nodeHLineClass
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
var DTreeNodeContent = defineComponent({
|
|
506
|
+
name: "DTreeNodeContent",
|
|
507
|
+
props: {
|
|
508
|
+
data: {
|
|
509
|
+
type: Object,
|
|
510
|
+
default: () => ({})
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
setup(props) {
|
|
514
|
+
const {
|
|
515
|
+
data
|
|
516
|
+
} = toRefs(props);
|
|
517
|
+
const {
|
|
518
|
+
nodeTitleClass
|
|
519
|
+
} = useTreeNode(data);
|
|
520
|
+
return () => {
|
|
521
|
+
var _a;
|
|
522
|
+
return createVNode("span", {
|
|
523
|
+
"class": nodeTitleClass.value
|
|
524
|
+
}, [(_a = data.value) == null ? void 0 : _a.label]);
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
var DTreeNode = defineComponent({
|
|
529
|
+
name: "DTreeNode",
|
|
530
|
+
props: {
|
|
531
|
+
data: {
|
|
532
|
+
type: Object,
|
|
533
|
+
default: () => ({})
|
|
534
|
+
},
|
|
535
|
+
check: {
|
|
536
|
+
type: Boolean,
|
|
537
|
+
default: false
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
setup(props, {
|
|
541
|
+
slots
|
|
542
|
+
}) {
|
|
543
|
+
const {
|
|
544
|
+
data,
|
|
545
|
+
check
|
|
546
|
+
} = toRefs(props);
|
|
547
|
+
const {
|
|
548
|
+
toggleSelectNode,
|
|
549
|
+
toggleCheckNode,
|
|
550
|
+
toggleNode,
|
|
551
|
+
getChildren
|
|
552
|
+
} = inject(USE_TREE_TOKEN);
|
|
553
|
+
const {
|
|
554
|
+
nodeClass,
|
|
555
|
+
nodeStyle,
|
|
556
|
+
nodeContentClass,
|
|
557
|
+
nodeVLineClass,
|
|
558
|
+
nodeVLineStyle,
|
|
559
|
+
nodeHLineClass
|
|
560
|
+
} = useTreeNode(data);
|
|
561
|
+
const halfChecked = computed(() => {
|
|
562
|
+
const children = getChildren == null ? void 0 : getChildren(data.value);
|
|
563
|
+
const checkedChildren = children == null ? void 0 : children.filter((item) => item.checked);
|
|
564
|
+
if (["upward", "both"].includes(check.value)) {
|
|
565
|
+
return checkedChildren.length > 0 && checkedChildren.length < children.length;
|
|
566
|
+
} else {
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
return () => {
|
|
571
|
+
var _a, _b, _c;
|
|
572
|
+
const checkboxProps2 = {
|
|
573
|
+
key: (_a = data.value) == null ? void 0 : _a.id,
|
|
574
|
+
disabled: (_b = data.value) == null ? void 0 : _b.disableCheck,
|
|
575
|
+
halfchecked: halfChecked.value,
|
|
576
|
+
modelValue: (_c = data.value) == null ? void 0 : _c.checked,
|
|
577
|
+
"onUpdate:modelValue": () => {
|
|
578
|
+
toggleCheckNode(data.value);
|
|
579
|
+
},
|
|
580
|
+
onClick: (event) => {
|
|
581
|
+
event.stopPropagation();
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
return createVNode("div", {
|
|
585
|
+
"class": nodeClass.value,
|
|
586
|
+
"style": nodeStyle.value
|
|
587
|
+
}, [createVNode("span", {
|
|
588
|
+
"class": nodeVLineClass.value,
|
|
589
|
+
"style": nodeVLineStyle.value
|
|
590
|
+
}, null), createVNode("div", {
|
|
591
|
+
"class": nodeContentClass.value,
|
|
592
|
+
"onClick": () => {
|
|
593
|
+
toggleSelectNode(data.value);
|
|
594
|
+
}
|
|
595
|
+
}, [createVNode("span", {
|
|
596
|
+
"class": nodeHLineClass.value
|
|
597
|
+
}, null), slots.icon ? renderSlot(useSlots(), "icon", {
|
|
598
|
+
nodeData: data,
|
|
599
|
+
toggleNode
|
|
600
|
+
}) : createVNode(DTreeNodeToggle, {
|
|
601
|
+
"data": data.value
|
|
602
|
+
}, null), createVNode("div", {
|
|
603
|
+
"class": "devui-tree-node__content--value-wrapper",
|
|
604
|
+
"style": {
|
|
605
|
+
height: `${NODE_HEIGHT}px`
|
|
606
|
+
}
|
|
607
|
+
}, [check.value && createVNode(Checkbox, checkboxProps2, null), slots.default ? renderSlot(useSlots(), "default", {
|
|
608
|
+
nodeData: data
|
|
609
|
+
}) : createVNode(DTreeNodeContent, {
|
|
610
|
+
"data": data
|
|
611
|
+
}, null)])])]);
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
function useToggle() {
|
|
616
|
+
return function useToggle2(data, core) {
|
|
617
|
+
const { getNode, setNodeValue } = core;
|
|
618
|
+
const expandNode = (node) => {
|
|
619
|
+
if (node.disableToggle) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
setNodeValue(node, "expanded", true);
|
|
623
|
+
};
|
|
624
|
+
const collapseNode = (node) => {
|
|
625
|
+
if (node.disableToggle) {
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
setNodeValue(node, "expanded", false);
|
|
629
|
+
};
|
|
630
|
+
const toggleNode = (node) => {
|
|
631
|
+
if (node.disableToggle) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (getNode(node).expanded) {
|
|
635
|
+
setNodeValue(node, "expanded", false);
|
|
636
|
+
} else {
|
|
637
|
+
setNodeValue(node, "expanded", true);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
return {
|
|
641
|
+
expandNode,
|
|
642
|
+
collapseNode,
|
|
643
|
+
toggleNode
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
function randomId(n = 8) {
|
|
648
|
+
const str = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
649
|
+
let result = "";
|
|
650
|
+
for (let i = 0; i < n; i++) {
|
|
651
|
+
result += str[parseInt((Math.random() * str.length).toString())];
|
|
652
|
+
}
|
|
653
|
+
return result;
|
|
654
|
+
}
|
|
655
|
+
function omit(obj, ...keys) {
|
|
656
|
+
return Object.entries(obj).filter((item) => !keys.includes(item[0])).reduce((acc, item) => Object.assign({}, acc, { [item[0]]: item[1] }), {});
|
|
657
|
+
}
|
|
658
|
+
function generateInnerTree(tree2, key = "children", level = 0, path = []) {
|
|
659
|
+
level++;
|
|
660
|
+
return tree2.reduce((acc, item) => {
|
|
661
|
+
var _a, _b;
|
|
662
|
+
const newItem = Object.assign({}, item);
|
|
663
|
+
if (newItem.id === void 0) {
|
|
664
|
+
newItem.id = randomId();
|
|
665
|
+
newItem.idType = "random";
|
|
666
|
+
}
|
|
667
|
+
newItem.level = level;
|
|
668
|
+
if (path.length > 0 && ((_a = path[path.length - 1]) == null ? void 0 : _a.level) >= level) {
|
|
669
|
+
while (((_b = path[path.length - 1]) == null ? void 0 : _b.level) >= level) {
|
|
670
|
+
path.pop();
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
path.push(newItem);
|
|
674
|
+
const parentNode = path[path.length - 2];
|
|
675
|
+
if (parentNode) {
|
|
676
|
+
newItem.parentId = parentNode.id;
|
|
677
|
+
}
|
|
678
|
+
if (!newItem[key]) {
|
|
679
|
+
return acc.concat(__spreadProps(__spreadValues({}, newItem), { isLeaf: true }));
|
|
680
|
+
} else {
|
|
681
|
+
return acc.concat(omit(newItem, "children"), generateInnerTree(newItem[key], key, level, path));
|
|
682
|
+
}
|
|
683
|
+
}, []);
|
|
684
|
+
}
|
|
685
|
+
const DEFAULT_CONFIG = {
|
|
686
|
+
expanded: false,
|
|
687
|
+
recursive: true
|
|
688
|
+
};
|
|
689
|
+
function useCore() {
|
|
690
|
+
return function useCore2(data) {
|
|
691
|
+
const getLevel = (node) => {
|
|
692
|
+
return data.value.find((item) => item.id === node.id).level;
|
|
693
|
+
};
|
|
694
|
+
const getChildren = (node, userConfig = DEFAULT_CONFIG) => {
|
|
695
|
+
const getInnerExpendedTree = () => {
|
|
696
|
+
return computed(() => {
|
|
697
|
+
let excludeNodes = [];
|
|
698
|
+
const result2 = [];
|
|
699
|
+
for (let i = 0, len = data == null ? void 0 : data.value.length; i < len; i++) {
|
|
700
|
+
const item = data == null ? void 0 : data.value[i];
|
|
701
|
+
if (excludeNodes.map((innerNode) => innerNode.id).includes(item.id)) {
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
if (item.expanded !== true) {
|
|
705
|
+
excludeNodes = getChildren(item);
|
|
706
|
+
}
|
|
707
|
+
result2.push(item);
|
|
708
|
+
}
|
|
709
|
+
return result2;
|
|
710
|
+
});
|
|
711
|
+
};
|
|
712
|
+
const result = [];
|
|
713
|
+
const config = __spreadValues(__spreadValues({}, DEFAULT_CONFIG), userConfig);
|
|
714
|
+
const treeData = config.expanded ? getInnerExpendedTree() : data;
|
|
715
|
+
const startIndex = treeData.value.findIndex((item) => item.id === node.id);
|
|
716
|
+
for (let i = startIndex + 1; i < treeData.value.length && getLevel(node) < treeData.value[i].level; i++) {
|
|
717
|
+
if (config.recursive) {
|
|
718
|
+
result.push(treeData.value[i]);
|
|
719
|
+
} else if (getLevel(node) === treeData.value[i].level - 1) {
|
|
720
|
+
result.push(treeData.value[i]);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return result;
|
|
724
|
+
};
|
|
725
|
+
const getParent = (node) => {
|
|
726
|
+
return data.value.find((item) => item.id === node.parentId);
|
|
727
|
+
};
|
|
728
|
+
const getExpendedTree = () => {
|
|
729
|
+
return computed(() => {
|
|
730
|
+
let excludeNodes = [];
|
|
731
|
+
const result = [];
|
|
732
|
+
for (let i = 0, len = data == null ? void 0 : data.value.length; i < len; i++) {
|
|
733
|
+
const item = data == null ? void 0 : data.value[i];
|
|
734
|
+
if (excludeNodes.map((node) => node.id).includes(item.id)) {
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
if (item.expanded !== true) {
|
|
738
|
+
excludeNodes = getChildren(item);
|
|
739
|
+
}
|
|
740
|
+
result.push(item);
|
|
741
|
+
}
|
|
742
|
+
return result;
|
|
743
|
+
});
|
|
744
|
+
};
|
|
745
|
+
const getIndex = (node) => {
|
|
746
|
+
return data.value.findIndex((item) => item.id === node.id);
|
|
747
|
+
};
|
|
748
|
+
const getNode = (node) => {
|
|
749
|
+
return data.value.find((item) => item.id === node.id);
|
|
750
|
+
};
|
|
751
|
+
const setNodeValue = (node, key, value) => {
|
|
752
|
+
data.value[getIndex(node)][key] = value;
|
|
753
|
+
};
|
|
754
|
+
const setTree = (newTree) => {
|
|
755
|
+
data.value = generateInnerTree(newTree);
|
|
756
|
+
};
|
|
757
|
+
return {
|
|
758
|
+
getLevel,
|
|
759
|
+
getChildren,
|
|
760
|
+
getParent,
|
|
761
|
+
getExpendedTree,
|
|
762
|
+
getIndex,
|
|
763
|
+
getNode,
|
|
764
|
+
setNodeValue,
|
|
765
|
+
setTree
|
|
766
|
+
};
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
const DEFAULT_TREE_PLUGINS = [useCore(), useToggle()];
|
|
770
|
+
function useTree(tree2, plugins = []) {
|
|
771
|
+
const treeData = ref(generateInnerTree(tree2));
|
|
772
|
+
const core = useCore()(treeData);
|
|
773
|
+
const pluginMethods = DEFAULT_TREE_PLUGINS.concat(plugins).reduce((acc, plugin) => {
|
|
774
|
+
return __spreadValues(__spreadValues({}, acc), plugin(treeData, core));
|
|
775
|
+
}, {});
|
|
776
|
+
return __spreadValues({
|
|
777
|
+
treeData
|
|
778
|
+
}, pluginMethods);
|
|
779
|
+
}
|
|
780
|
+
function useCheck(options = ref({ checkStrategy: "both" })) {
|
|
781
|
+
return function useCheck2(data, core) {
|
|
782
|
+
const { setNodeValue, getNode, getChildren, getParent } = core;
|
|
783
|
+
const checkNode = (node) => {
|
|
784
|
+
setNodeValue(node, "checked", true);
|
|
785
|
+
};
|
|
786
|
+
const uncheckNode = (node) => {
|
|
787
|
+
setNodeValue(node, "checked", false);
|
|
788
|
+
};
|
|
789
|
+
const controlParentNodeChecked = (node) => {
|
|
790
|
+
const parentNode = getParent(node);
|
|
791
|
+
if (!parentNode) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
const siblingNodes = getChildren(parentNode, { recursive: false });
|
|
795
|
+
const checkedSiblingNodes = siblingNodes.filter((item) => item.checked);
|
|
796
|
+
const toggleParentChecked = () => {
|
|
797
|
+
if (checkedSiblingNodes.length === 0) {
|
|
798
|
+
setNodeValue(parentNode, "checked", false);
|
|
799
|
+
} else if (checkedSiblingNodes.length === siblingNodes.length) {
|
|
800
|
+
setNodeValue(parentNode, "checked", true);
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
if (parentNode.parentId) {
|
|
804
|
+
toggleParentChecked();
|
|
805
|
+
controlParentNodeChecked(parentNode);
|
|
806
|
+
} else {
|
|
807
|
+
toggleParentChecked();
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
const toggleCheckNode = (node) => {
|
|
811
|
+
if (getNode(node).checked) {
|
|
812
|
+
setNodeValue(node, "checked", false);
|
|
813
|
+
if (["downward", "both"].includes(options.value.checkStrategy)) {
|
|
814
|
+
getChildren(node).forEach((item) => setNodeValue(item, "checked", false));
|
|
815
|
+
}
|
|
816
|
+
} else {
|
|
817
|
+
setNodeValue(node, "checked", true);
|
|
818
|
+
if (["downward", "both"].includes(options.value.checkStrategy)) {
|
|
819
|
+
getChildren(node).forEach((item) => setNodeValue(item, "checked", true));
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
if (["upward", "both"].includes(options.value.checkStrategy)) {
|
|
823
|
+
controlParentNodeChecked(node);
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
return {
|
|
827
|
+
checkNode,
|
|
828
|
+
uncheckNode,
|
|
829
|
+
toggleCheckNode
|
|
830
|
+
};
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
function useSelect() {
|
|
834
|
+
return function useSelect2(data, core) {
|
|
835
|
+
const { setNodeValue } = core;
|
|
836
|
+
let prevActiveNode;
|
|
837
|
+
const selectNode = (node) => {
|
|
838
|
+
if (node.disableSelect) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
if (prevActiveNode) {
|
|
842
|
+
const prevActiveNodeIndex = data.value.findIndex((item) => item.id === prevActiveNode.id);
|
|
843
|
+
setNodeValue(data.value[prevActiveNodeIndex], "selected", false);
|
|
844
|
+
}
|
|
845
|
+
setNodeValue(node, "selected", true);
|
|
846
|
+
prevActiveNode = node;
|
|
847
|
+
};
|
|
848
|
+
const deselectNode = (node) => {
|
|
849
|
+
setNodeValue(node, "selected", false);
|
|
850
|
+
};
|
|
851
|
+
const toggleSelectNode = (node) => {
|
|
852
|
+
if (node.selected) {
|
|
853
|
+
deselectNode(node);
|
|
854
|
+
} else {
|
|
855
|
+
selectNode(node);
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
return {
|
|
859
|
+
selectNode,
|
|
860
|
+
deselectNode,
|
|
861
|
+
toggleSelectNode
|
|
862
|
+
};
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
function useOperate() {
|
|
866
|
+
return function useOperate2(data, core) {
|
|
867
|
+
const { setNodeValue, getChildren, getIndex, getLevel } = core;
|
|
868
|
+
const insertBefore = (parentNode, node, referenceNode) => {
|
|
869
|
+
const children = getChildren(parentNode);
|
|
870
|
+
const lastChild = children[children.length - 1];
|
|
871
|
+
let insertedIndex = getIndex(parentNode) + 1;
|
|
872
|
+
if (referenceNode) {
|
|
873
|
+
insertedIndex = getIndex(referenceNode);
|
|
874
|
+
} else if (lastChild) {
|
|
875
|
+
insertedIndex = getIndex(lastChild) + 1;
|
|
876
|
+
}
|
|
877
|
+
setNodeValue(parentNode, "expanded", true);
|
|
878
|
+
setNodeValue(parentNode, "isLeaf", false);
|
|
879
|
+
const currentNode = __spreadProps(__spreadValues({}, node), {
|
|
880
|
+
level: getLevel(parentNode) + 1,
|
|
881
|
+
parentId: parentNode.id,
|
|
882
|
+
isLeaf: true
|
|
883
|
+
});
|
|
884
|
+
data.value = data.value.slice(0, insertedIndex).concat(currentNode, data.value.slice(insertedIndex, data.value.length));
|
|
885
|
+
};
|
|
886
|
+
const removeNode = (node, config = { recursive: true }) => {
|
|
887
|
+
if (!config.recursive) {
|
|
888
|
+
getChildren(node).forEach((child) => {
|
|
889
|
+
setNodeValue(child, "level", getLevel(child) - 1);
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
data.value = data.value.filter((item) => {
|
|
893
|
+
if (config.recursive) {
|
|
894
|
+
return item.id !== node.id && !getChildren(node).map((nodeItem) => nodeItem.id).includes(item.id);
|
|
895
|
+
} else {
|
|
896
|
+
return item.id !== node.id;
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
};
|
|
900
|
+
const editNode = (node, label) => {
|
|
901
|
+
setNodeValue(node, "label", label);
|
|
902
|
+
};
|
|
903
|
+
return {
|
|
904
|
+
insertBefore,
|
|
905
|
+
removeNode,
|
|
906
|
+
editNode
|
|
907
|
+
};
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
function useMergeNodes() {
|
|
911
|
+
return function useMergeNodes2(data, core) {
|
|
912
|
+
const { setNodeValue, getChildren } = core;
|
|
913
|
+
const { removeNode } = useOperate()(data, core);
|
|
914
|
+
const mergeTreeNodes = () => {
|
|
915
|
+
const mergeToNode = (node) => {
|
|
916
|
+
var _a;
|
|
917
|
+
if (node.isLeaf) {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
const children = getChildren(node, { recursive: false });
|
|
921
|
+
if ((children == null ? void 0 : children.length) === 1) {
|
|
922
|
+
const subChildren = getChildren(children[0], { recursive: false });
|
|
923
|
+
if (subChildren.length !== 0) {
|
|
924
|
+
setNodeValue(node, "label", node.label + " / " + ((_a = children[0]) == null ? void 0 : _a.label));
|
|
925
|
+
removeNode(children[0], { recursive: false });
|
|
926
|
+
mergeToNode(node);
|
|
927
|
+
} else {
|
|
928
|
+
setNodeValue(children[0], "parentId", node.id);
|
|
929
|
+
}
|
|
930
|
+
} else {
|
|
931
|
+
children.forEach((item) => {
|
|
932
|
+
mergeToNode(item);
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
data.value.filter((item) => item.level === 1).forEach((item) => {
|
|
937
|
+
mergeToNode(item);
|
|
938
|
+
});
|
|
939
|
+
};
|
|
940
|
+
return {
|
|
941
|
+
mergeTreeNodes
|
|
942
|
+
};
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
const treeProps = {
|
|
946
|
+
data: {
|
|
947
|
+
type: Object,
|
|
948
|
+
default: []
|
|
949
|
+
},
|
|
950
|
+
check: {
|
|
951
|
+
type: [Boolean, String],
|
|
952
|
+
default: false
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
var tree = "";
|
|
956
|
+
var Tree = defineComponent({
|
|
957
|
+
name: "DTree",
|
|
958
|
+
props: treeProps,
|
|
959
|
+
setup(props, {
|
|
960
|
+
slots,
|
|
961
|
+
expose
|
|
962
|
+
}) {
|
|
963
|
+
const {
|
|
964
|
+
data,
|
|
965
|
+
check
|
|
966
|
+
} = toRefs(props);
|
|
967
|
+
const userPlugins = [useSelect(), useOperate(), useMergeNodes()];
|
|
968
|
+
const checkOptions = ref({
|
|
969
|
+
checkStrategy: check.value || "both"
|
|
970
|
+
});
|
|
971
|
+
watch(check, (newVal) => {
|
|
972
|
+
checkOptions.value.checkStrategy = newVal;
|
|
973
|
+
});
|
|
974
|
+
if (check.value) {
|
|
975
|
+
userPlugins.push(useCheck(checkOptions));
|
|
976
|
+
}
|
|
977
|
+
const treeFactory = useTree(data.value, userPlugins);
|
|
978
|
+
const {
|
|
979
|
+
setTree,
|
|
980
|
+
getExpendedTree,
|
|
981
|
+
toggleNode
|
|
982
|
+
} = treeFactory;
|
|
983
|
+
watch(data, setTree);
|
|
984
|
+
provide(USE_TREE_TOKEN, treeFactory);
|
|
985
|
+
expose({
|
|
986
|
+
treeFactory
|
|
987
|
+
});
|
|
988
|
+
return () => {
|
|
989
|
+
return createVNode("div", {
|
|
990
|
+
"class": "devui-tree"
|
|
991
|
+
}, [getExpendedTree == null ? void 0 : getExpendedTree().value.map((treeNode) => slots.default ? renderSlot(useSlots(), "default", {
|
|
992
|
+
treeFactory,
|
|
993
|
+
nodeData: treeNode
|
|
994
|
+
}) : createVNode(DTreeNode, {
|
|
995
|
+
"data": treeNode,
|
|
996
|
+
"check": check.value
|
|
997
|
+
}, {
|
|
998
|
+
default: () => slots.content ? renderSlot(useSlots(), "content", {
|
|
999
|
+
nodeData: treeNode
|
|
1000
|
+
}) : createVNode(DTreeNodeContent, {
|
|
1001
|
+
"data": treeNode
|
|
1002
|
+
}, null),
|
|
1003
|
+
icon: () => slots.icon ? renderSlot(useSlots(), "icon", {
|
|
1004
|
+
nodeData: treeNode,
|
|
1005
|
+
toggleNode
|
|
1006
|
+
}) : createVNode(DTreeNodeToggle, {
|
|
1007
|
+
"data": treeNode
|
|
1008
|
+
}, null)
|
|
1009
|
+
}))]);
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
var index = {
|
|
1014
|
+
title: "Tree \u6811",
|
|
1015
|
+
category: "\u6570\u636E\u5C55\u793A",
|
|
1016
|
+
status: "20%",
|
|
1017
|
+
install(app) {
|
|
1018
|
+
app.component(Tree.name, Tree);
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
export { Tree, index as default, treeProps };
|