wedux-ui 0.1.0
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/LICENSE +21 -0
- package/README.md +184 -0
- package/miniprogram_dist/behaviors/formField.js +35 -0
- package/miniprogram_dist/components/avatar/avatar.js +70 -0
- package/miniprogram_dist/components/avatar/avatar.json +4 -0
- package/miniprogram_dist/components/avatar/avatar.scss +68 -0
- package/miniprogram_dist/components/avatar/avatar.wxml +15 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.js +45 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.json +7 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.scss +4 -0
- package/miniprogram_dist/components/avatar-group/avatar-group.wxml +3 -0
- package/miniprogram_dist/components/back-top/back-top.js +68 -0
- package/miniprogram_dist/components/back-top/back-top.json +4 -0
- package/miniprogram_dist/components/back-top/back-top.scss +43 -0
- package/miniprogram_dist/components/back-top/back-top.wxml +10 -0
- package/miniprogram_dist/components/badge/badge.js +100 -0
- package/miniprogram_dist/components/badge/badge.json +4 -0
- package/miniprogram_dist/components/badge/badge.scss +98 -0
- package/miniprogram_dist/components/badge/badge.wxml +11 -0
- package/miniprogram_dist/components/button/button.js +152 -0
- package/miniprogram_dist/components/button/button.json +4 -0
- package/miniprogram_dist/components/button/button.scss +499 -0
- package/miniprogram_dist/components/button/button.wxml +21 -0
- package/miniprogram_dist/components/button-group/button-group.js +51 -0
- package/miniprogram_dist/components/button-group/button-group.json +4 -0
- package/miniprogram_dist/components/button-group/button-group.scss +8 -0
- package/miniprogram_dist/components/button-group/button-group.wxml +3 -0
- package/miniprogram_dist/components/calendar/calendar.js +308 -0
- package/miniprogram_dist/components/calendar/calendar.json +4 -0
- package/miniprogram_dist/components/calendar/calendar.scss +141 -0
- package/miniprogram_dist/components/calendar/calendar.wxml +47 -0
- package/miniprogram_dist/components/card/card.js +44 -0
- package/miniprogram_dist/components/card/card.json +4 -0
- package/miniprogram_dist/components/card/card.scss +143 -0
- package/miniprogram_dist/components/card/card.wxml +31 -0
- package/miniprogram_dist/components/checkbox/checkbox.js +43 -0
- package/miniprogram_dist/components/checkbox/checkbox.json +4 -0
- package/miniprogram_dist/components/checkbox/checkbox.scss +77 -0
- package/miniprogram_dist/components/checkbox/checkbox.wxml +13 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.js +43 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.json +4 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.scss +39 -0
- package/miniprogram_dist/components/checkbox-button/checkbox-button.wxml +8 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.js +84 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.json +4 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.scss +9 -0
- package/miniprogram_dist/components/checkbox-group/checkbox-group.wxml +3 -0
- package/miniprogram_dist/components/color-picker/color-picker.js +348 -0
- package/miniprogram_dist/components/color-picker/color-picker.json +7 -0
- package/miniprogram_dist/components/color-picker/color-picker.scss +383 -0
- package/miniprogram_dist/components/color-picker/color-picker.wxml +232 -0
- package/miniprogram_dist/components/date-picker/date-picker.js +1289 -0
- package/miniprogram_dist/components/date-picker/date-picker.json +7 -0
- package/miniprogram_dist/components/date-picker/date-picker.scss +468 -0
- package/miniprogram_dist/components/date-picker/date-picker.wxml +214 -0
- package/miniprogram_dist/components/divider/divider.js +34 -0
- package/miniprogram_dist/components/divider/divider.json +4 -0
- package/miniprogram_dist/components/divider/divider.scss +75 -0
- package/miniprogram_dist/components/divider/divider.wxml +8 -0
- package/miniprogram_dist/components/drawer/drawer.js +104 -0
- package/miniprogram_dist/components/drawer/drawer.json +4 -0
- package/miniprogram_dist/components/drawer/drawer.scss +171 -0
- package/miniprogram_dist/components/drawer/drawer.wxml +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.js +38 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.json +4 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.scss +22 -0
- package/miniprogram_dist/components/ellipsis/ellipsis.wxml +7 -0
- package/miniprogram_dist/components/flex/flex.js +81 -0
- package/miniprogram_dist/components/flex/flex.json +4 -0
- package/miniprogram_dist/components/flex/flex.scss +4 -0
- package/miniprogram_dist/components/flex/flex.wxml +3 -0
- package/miniprogram_dist/components/float-button/float-button.js +78 -0
- package/miniprogram_dist/components/float-button/float-button.json +4 -0
- package/miniprogram_dist/components/float-button/float-button.scss +54 -0
- package/miniprogram_dist/components/float-button/float-button.wxml +9 -0
- package/miniprogram_dist/components/form/form.js +142 -0
- package/miniprogram_dist/components/form/form.json +4 -0
- package/miniprogram_dist/components/form/form.scss +11 -0
- package/miniprogram_dist/components/form/form.wxml +3 -0
- package/miniprogram_dist/components/form/validator.js +220 -0
- package/miniprogram_dist/components/form-item/form-item.js +240 -0
- package/miniprogram_dist/components/form-item/form-item.json +4 -0
- package/miniprogram_dist/components/form-item/form-item.scss +59 -0
- package/miniprogram_dist/components/form-item/form-item.wxml +33 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.js +54 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.json +4 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.scss +7 -0
- package/miniprogram_dist/components/gradient-text/gradient-text.wxml +1 -0
- package/miniprogram_dist/components/h/h.js +60 -0
- package/miniprogram_dist/components/h/h.json +4 -0
- package/miniprogram_dist/components/h/h.scss +53 -0
- package/miniprogram_dist/components/h/h.wxml +1 -0
- package/miniprogram_dist/components/highlight/highlight.js +77 -0
- package/miniprogram_dist/components/highlight/highlight.json +4 -0
- package/miniprogram_dist/components/highlight/highlight.scss +8 -0
- package/miniprogram_dist/components/highlight/highlight.wxml +12 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.js +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.json +4 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.scss +31 -0
- package/miniprogram_dist/components/infinite-scroll/infinite-scroll.wxml +12 -0
- package/miniprogram_dist/components/input/input.js +59 -0
- package/miniprogram_dist/components/input/input.json +4 -0
- package/miniprogram_dist/components/input/input.scss +96 -0
- package/miniprogram_dist/components/input/input.wxml +34 -0
- package/miniprogram_dist/components/input-otp/input-otp.js +106 -0
- package/miniprogram_dist/components/input-otp/input-otp.json +4 -0
- package/miniprogram_dist/components/input-otp/input-otp.scss +122 -0
- package/miniprogram_dist/components/input-otp/input-otp.wxml +38 -0
- package/miniprogram_dist/components/layout/layout.js +50 -0
- package/miniprogram_dist/components/layout/layout.json +4 -0
- package/miniprogram_dist/components/layout/layout.scss +10 -0
- package/miniprogram_dist/components/layout/layout.wxml +3 -0
- package/miniprogram_dist/components/layout-content/layout-content.js +47 -0
- package/miniprogram_dist/components/layout-content/layout-content.json +4 -0
- package/miniprogram_dist/components/layout-content/layout-content.scss +5 -0
- package/miniprogram_dist/components/layout-content/layout-content.wxml +13 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.js +59 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.json +4 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.scss +23 -0
- package/miniprogram_dist/components/layout-footer/layout-footer.wxml +16 -0
- package/miniprogram_dist/components/layout-header/layout-header.js +59 -0
- package/miniprogram_dist/components/layout-header/layout-header.json +4 -0
- package/miniprogram_dist/components/layout-header/layout-header.scss +23 -0
- package/miniprogram_dist/components/layout-header/layout-header.wxml +16 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.js +48 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.json +4 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.scss +13 -0
- package/miniprogram_dist/components/layout-sider/layout-sider.wxml +5 -0
- package/miniprogram_dist/components/list/list.js +55 -0
- package/miniprogram_dist/components/list/list.json +4 -0
- package/miniprogram_dist/components/list/list.scss +51 -0
- package/miniprogram_dist/components/list/list.wxml +9 -0
- package/miniprogram_dist/components/list-item/list-item.js +24 -0
- package/miniprogram_dist/components/list-item/list-item.json +4 -0
- package/miniprogram_dist/components/list-item/list-item.scss +51 -0
- package/miniprogram_dist/components/list-item/list-item.wxml +14 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.js +77 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.json +4 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.scss +63 -0
- package/miniprogram_dist/components/navigation-bar/navigation-bar.wxml +35 -0
- package/miniprogram_dist/components/number-animation/number-animation.js +124 -0
- package/miniprogram_dist/components/number-animation/number-animation.json +4 -0
- package/miniprogram_dist/components/number-animation/number-animation.scss +3 -0
- package/miniprogram_dist/components/number-animation/number-animation.wxml +1 -0
- package/miniprogram_dist/components/popover/popover.js +183 -0
- package/miniprogram_dist/components/popover/popover.json +4 -0
- package/miniprogram_dist/components/popover/popover.scss +69 -0
- package/miniprogram_dist/components/popover/popover.wxml +19 -0
- package/miniprogram_dist/components/qr-code/qr-code.js +216 -0
- package/miniprogram_dist/components/qr-code/qr-code.json +4 -0
- package/miniprogram_dist/components/qr-code/qr-code.scss +8 -0
- package/miniprogram_dist/components/qr-code/qr-code.wxml +16 -0
- package/miniprogram_dist/components/radio/radio.js +38 -0
- package/miniprogram_dist/components/radio/radio.json +4 -0
- package/miniprogram_dist/components/radio/radio.scss +50 -0
- package/miniprogram_dist/components/radio/radio.wxml +12 -0
- package/miniprogram_dist/components/radio-button/radio-button.js +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.json +4 -0
- package/miniprogram_dist/components/radio-button/radio-button.scss +39 -0
- package/miniprogram_dist/components/radio-button/radio-button.wxml +8 -0
- package/miniprogram_dist/components/radio-group/radio-group.js +72 -0
- package/miniprogram_dist/components/radio-group/radio-group.json +4 -0
- package/miniprogram_dist/components/radio-group/radio-group.scss +9 -0
- package/miniprogram_dist/components/radio-group/radio-group.wxml +3 -0
- package/miniprogram_dist/components/rate/rate.js +90 -0
- package/miniprogram_dist/components/rate/rate.json +4 -0
- package/miniprogram_dist/components/rate/rate.scss +59 -0
- package/miniprogram_dist/components/rate/rate.wxml +16 -0
- package/miniprogram_dist/components/select/select.js +201 -0
- package/miniprogram_dist/components/select/select.json +7 -0
- package/miniprogram_dist/components/select/select.scss +235 -0
- package/miniprogram_dist/components/select/select.wxml +79 -0
- package/miniprogram_dist/components/stepper/stepper.js +113 -0
- package/miniprogram_dist/components/stepper/stepper.json +4 -0
- package/miniprogram_dist/components/stepper/stepper.scss +73 -0
- package/miniprogram_dist/components/stepper/stepper.wxml +23 -0
- package/miniprogram_dist/components/switch/switch.js +42 -0
- package/miniprogram_dist/components/switch/switch.json +4 -0
- package/miniprogram_dist/components/switch/switch.scss +77 -0
- package/miniprogram_dist/components/switch/switch.wxml +10 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.js +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.json +4 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.scss +53 -0
- package/miniprogram_dist/components/tab-bar/tab-bar.wxml +12 -0
- package/miniprogram_dist/components/tag/tag.js +87 -0
- package/miniprogram_dist/components/tag/tag.json +4 -0
- package/miniprogram_dist/components/tag/tag.scss +138 -0
- package/miniprogram_dist/components/tag/tag.wxml +12 -0
- package/miniprogram_dist/components/textarea/textarea.js +46 -0
- package/miniprogram_dist/components/textarea/textarea.json +4 -0
- package/miniprogram_dist/components/textarea/textarea.scss +51 -0
- package/miniprogram_dist/components/textarea/textarea.wxml +20 -0
- package/miniprogram_dist/components/theme-provider/presets.js +101 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.js +34 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.json +4 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.scss +3 -0
- package/miniprogram_dist/components/theme-provider/theme-provider.wxml +3 -0
- package/miniprogram_dist/components/time-picker/time-picker.js +136 -0
- package/miniprogram_dist/components/time-picker/time-picker.json +7 -0
- package/miniprogram_dist/components/time-picker/time-picker.scss +135 -0
- package/miniprogram_dist/components/time-picker/time-picker.wxml +47 -0
- package/miniprogram_dist/components/tooltip/tooltip.js +179 -0
- package/miniprogram_dist/components/tooltip/tooltip.json +4 -0
- package/miniprogram_dist/components/tooltip/tooltip.scss +66 -0
- package/miniprogram_dist/components/tooltip/tooltip.wxml +17 -0
- package/miniprogram_dist/components/tree/tree.js +647 -0
- package/miniprogram_dist/components/tree/tree.json +4 -0
- package/miniprogram_dist/components/tree/tree.scss +178 -0
- package/miniprogram_dist/components/tree/tree.wxml +59 -0
- package/miniprogram_dist/components/tree-select/tree-select.js +260 -0
- package/miniprogram_dist/components/tree-select/tree-select.json +8 -0
- package/miniprogram_dist/components/tree-select/tree-select.scss +250 -0
- package/miniprogram_dist/components/tree-select/tree-select.wxml +118 -0
- package/miniprogram_dist/components/upload/upload.js +387 -0
- package/miniprogram_dist/components/upload/upload.json +4 -0
- package/miniprogram_dist/components/upload/upload.scss +258 -0
- package/miniprogram_dist/components/upload/upload.wxml +142 -0
- package/miniprogram_dist/components/watermark/watermark.js +260 -0
- package/miniprogram_dist/components/watermark/watermark.json +4 -0
- package/miniprogram_dist/components/watermark/watermark.scss +35 -0
- package/miniprogram_dist/components/watermark/watermark.wxml +13 -0
- package/miniprogram_dist/libs/qrcodegen.js +714 -0
- package/miniprogram_dist/libs/seemly.min.js +547 -0
- package/miniprogram_dist/libs/tempo_1_0_0.js +1264 -0
- package/miniprogram_dist/libs/validator_13_56_26.min.js +5282 -0
- package/miniprogram_dist/styles/demo.scss +96 -0
- package/miniprogram_dist/styles/iconfont.scss +91 -0
- package/miniprogram_dist/styles/theme.scss +126 -0
- package/miniprogram_dist/styles/tokens.scss +292 -0
- package/miniprogram_dist/utils/relations.js +21 -0
- package/package.json +25 -0
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
Component({
|
|
2
|
+
options: {
|
|
3
|
+
multipleSlots: true,
|
|
4
|
+
},
|
|
5
|
+
|
|
6
|
+
relations: {
|
|
7
|
+
'../tree-select/tree-select': {
|
|
8
|
+
type: 'ancestor',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
properties: {
|
|
13
|
+
data: { type: Array, value: [] },
|
|
14
|
+
checkedKeys: { type: Array, value: [] },
|
|
15
|
+
selectedKeys: { type: Array, value: [] },
|
|
16
|
+
expandedKeys: { type: Array, value: [] },
|
|
17
|
+
defaultExpandAll: { type: Boolean, value: false },
|
|
18
|
+
checkable: { type: Boolean, value: false },
|
|
19
|
+
selectable: { type: Boolean, value: true },
|
|
20
|
+
multiple: { type: Boolean, value: false },
|
|
21
|
+
cascade: { type: Boolean, value: true },
|
|
22
|
+
checkStrategy: { type: String, value: 'all' },
|
|
23
|
+
disabled: { type: Boolean, value: false },
|
|
24
|
+
pattern: { type: String, value: '' },
|
|
25
|
+
filterMode: { type: String, value: 'filter' },
|
|
26
|
+
accordion: { type: Boolean, value: false },
|
|
27
|
+
indent: { type: Number, value: 40 },
|
|
28
|
+
showLine: { type: Boolean, value: false },
|
|
29
|
+
keyField: { type: String, value: 'key' },
|
|
30
|
+
labelField: { type: String, value: 'label' },
|
|
31
|
+
childrenField: { type: String, value: 'children' },
|
|
32
|
+
checkOnClick: { type: Boolean, value: false },
|
|
33
|
+
expandOnClick: { type: Boolean, value: false },
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
data: {
|
|
37
|
+
_visibleNodes: [],
|
|
38
|
+
_checkedKeySet: {},
|
|
39
|
+
_selectedKeySet: {},
|
|
40
|
+
_expandedKeySet: {},
|
|
41
|
+
_indeterminateKeySet: {},
|
|
42
|
+
_loadingKeys: {},
|
|
43
|
+
_highlightPattern: '',
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
lifetimes: {
|
|
47
|
+
created() {
|
|
48
|
+
this._nodeMap = {};
|
|
49
|
+
this._flatNodes = [];
|
|
50
|
+
this._filterFn = null;
|
|
51
|
+
this._initialized = false;
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
observers: {
|
|
56
|
+
'data, keyField, labelField, childrenField'() {
|
|
57
|
+
this._buildTree();
|
|
58
|
+
},
|
|
59
|
+
checkedKeys(val) {
|
|
60
|
+
if (!this._initialized) return;
|
|
61
|
+
this._setCheckedKeys(val);
|
|
62
|
+
},
|
|
63
|
+
selectedKeys(val) {
|
|
64
|
+
if (!this._initialized) return;
|
|
65
|
+
const map = {};
|
|
66
|
+
val.forEach((k) => {
|
|
67
|
+
map[k] = true;
|
|
68
|
+
});
|
|
69
|
+
this.setData({ _selectedKeySet: map });
|
|
70
|
+
this._updateVisibleNodes();
|
|
71
|
+
},
|
|
72
|
+
expandedKeys(val) {
|
|
73
|
+
if (!this._initialized) return;
|
|
74
|
+
const map = {};
|
|
75
|
+
val.forEach((k) => {
|
|
76
|
+
map[k] = true;
|
|
77
|
+
});
|
|
78
|
+
this.setData({ _expandedKeySet: map });
|
|
79
|
+
this._updateVisibleNodes();
|
|
80
|
+
},
|
|
81
|
+
'pattern, filterMode'() {
|
|
82
|
+
this._applyFilter();
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
methods: {
|
|
87
|
+
// ===== Public Methods =====
|
|
88
|
+
|
|
89
|
+
setFilter(fn) {
|
|
90
|
+
this._filterFn = fn;
|
|
91
|
+
this._applyFilter();
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
loadChildren(key, children) {
|
|
95
|
+
const node = this._nodeMap[key];
|
|
96
|
+
if (!node) return;
|
|
97
|
+
|
|
98
|
+
const { keyField, labelField, childrenField } = this.data;
|
|
99
|
+
const newNodes = this._normalizeNodes(
|
|
100
|
+
children,
|
|
101
|
+
node.level + 1,
|
|
102
|
+
key,
|
|
103
|
+
keyField,
|
|
104
|
+
labelField,
|
|
105
|
+
childrenField,
|
|
106
|
+
);
|
|
107
|
+
node.childrenKeys = children.map((c) => String(c[keyField]));
|
|
108
|
+
node.isLeaf = newNodes.length === 0;
|
|
109
|
+
|
|
110
|
+
newNodes.forEach((n) => {
|
|
111
|
+
this._nodeMap[n.key] = n;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Insert into _flatNodes after parent
|
|
115
|
+
const parentIdx = this._flatNodes.findIndex((n) => n.key === key);
|
|
116
|
+
if (parentIdx !== -1) {
|
|
117
|
+
this._flatNodes.splice(parentIdx + 1, 0, ...newNodes);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const loading = { ...this.data._loadingKeys };
|
|
121
|
+
delete loading[key];
|
|
122
|
+
|
|
123
|
+
const expanded = { ...this.data._expandedKeySet, [key]: true };
|
|
124
|
+
this.setData({ _loadingKeys: loading, _expandedKeySet: expanded });
|
|
125
|
+
this._updateVisibleNodes();
|
|
126
|
+
this._emitExpandedKeys();
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
getCheckedNodes() {
|
|
130
|
+
const keys = this._getOutputCheckedKeys();
|
|
131
|
+
return keys.map((k) => this._nodeMap[k]?.raw).filter(Boolean);
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
getSelectedNodes() {
|
|
135
|
+
return Object.keys(this.data._selectedKeySet)
|
|
136
|
+
.filter((k) => this.data._selectedKeySet[k])
|
|
137
|
+
.map((k) => this._nodeMap[k]?.raw)
|
|
138
|
+
.filter(Boolean);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
expandAll() {
|
|
142
|
+
const map = {};
|
|
143
|
+
this._flatNodes.forEach((n) => {
|
|
144
|
+
if (!n.isLeaf) map[n.key] = true;
|
|
145
|
+
});
|
|
146
|
+
this.setData({ _expandedKeySet: map });
|
|
147
|
+
this._updateVisibleNodes();
|
|
148
|
+
this._emitExpandedKeys();
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
collapseAll() {
|
|
152
|
+
this.setData({ _expandedKeySet: {} });
|
|
153
|
+
this._updateVisibleNodes();
|
|
154
|
+
this._emitExpandedKeys();
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
// ===== Tree Building =====
|
|
158
|
+
|
|
159
|
+
_buildTree() {
|
|
160
|
+
const {
|
|
161
|
+
data,
|
|
162
|
+
keyField,
|
|
163
|
+
labelField,
|
|
164
|
+
childrenField,
|
|
165
|
+
defaultExpandAll,
|
|
166
|
+
checkedKeys,
|
|
167
|
+
selectedKeys,
|
|
168
|
+
expandedKeys,
|
|
169
|
+
} = this.data;
|
|
170
|
+
this._nodeMap = {};
|
|
171
|
+
this._flatNodes = this._normalizeNodes(data, 0, null, keyField, labelField, childrenField);
|
|
172
|
+
|
|
173
|
+
this._flatNodes.forEach((n) => {
|
|
174
|
+
this._nodeMap[n.key] = n;
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Initialize state sets
|
|
178
|
+
const expandedMap = {};
|
|
179
|
+
if (defaultExpandAll && !this._initialized) {
|
|
180
|
+
this._flatNodes.forEach((n) => {
|
|
181
|
+
if (!n.isLeaf) expandedMap[n.key] = true;
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
expandedKeys.forEach((k) => {
|
|
185
|
+
expandedMap[k] = true;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const selectedMap = {};
|
|
190
|
+
selectedKeys.forEach((k) => {
|
|
191
|
+
selectedMap[k] = true;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
this.setData({
|
|
195
|
+
_expandedKeySet: expandedMap,
|
|
196
|
+
_selectedKeySet: selectedMap,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
this._setCheckedKeys(checkedKeys);
|
|
200
|
+
this._initialized = true;
|
|
201
|
+
this._updateVisibleNodes();
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
_normalizeNodes(nodes, level, parentKey, keyField, labelField, childrenField) {
|
|
205
|
+
const result = [];
|
|
206
|
+
if (!nodes || !nodes.length) return result;
|
|
207
|
+
|
|
208
|
+
nodes.forEach((raw, index) => {
|
|
209
|
+
const key = String(raw[keyField]);
|
|
210
|
+
const children = raw[childrenField];
|
|
211
|
+
const hasChildren = Array.isArray(children) && children.length > 0;
|
|
212
|
+
const isLeaf = raw.isLeaf !== undefined ? raw.isLeaf : !hasChildren;
|
|
213
|
+
|
|
214
|
+
const node = {
|
|
215
|
+
key,
|
|
216
|
+
label: raw[labelField] || '',
|
|
217
|
+
level,
|
|
218
|
+
parentKey,
|
|
219
|
+
icon: raw.icon || '',
|
|
220
|
+
prefixIcon: raw.prefixIcon || '',
|
|
221
|
+
suffixText: raw.suffixText || '',
|
|
222
|
+
disabled: raw.disabled || false,
|
|
223
|
+
isLeaf,
|
|
224
|
+
isLast: index === nodes.length - 1,
|
|
225
|
+
childrenKeys: [],
|
|
226
|
+
raw,
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
result.push(node);
|
|
230
|
+
|
|
231
|
+
if (hasChildren) {
|
|
232
|
+
const childNodes = this._normalizeNodes(
|
|
233
|
+
children,
|
|
234
|
+
level + 1,
|
|
235
|
+
key,
|
|
236
|
+
keyField,
|
|
237
|
+
labelField,
|
|
238
|
+
childrenField,
|
|
239
|
+
);
|
|
240
|
+
node.childrenKeys = children.map((c) => String(c[keyField]));
|
|
241
|
+
result.push(...childNodes);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
return result;
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
// ===== Visible Nodes =====
|
|
249
|
+
|
|
250
|
+
_updateVisibleNodes() {
|
|
251
|
+
const {
|
|
252
|
+
_expandedKeySet,
|
|
253
|
+
_loadingKeys,
|
|
254
|
+
_checkedKeySet,
|
|
255
|
+
_selectedKeySet,
|
|
256
|
+
_indeterminateKeySet,
|
|
257
|
+
_highlightPattern,
|
|
258
|
+
} = this.data;
|
|
259
|
+
const { indent } = this.data;
|
|
260
|
+
const visible = [];
|
|
261
|
+
const hiddenParents = new Set();
|
|
262
|
+
|
|
263
|
+
this._flatNodes.forEach((node) => {
|
|
264
|
+
// Skip if any ancestor is collapsed
|
|
265
|
+
if (node.parentKey !== null && hiddenParents.has(node.parentKey)) {
|
|
266
|
+
hiddenParents.add(node.key);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (node.parentKey !== null && !_expandedKeySet[node.parentKey]) {
|
|
271
|
+
hiddenParents.add(node.key);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Apply filter (filter mode)
|
|
276
|
+
if (this._filteredKeySet && !this._filteredKeySet[node.key]) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const paddingLeft = node.level * indent;
|
|
281
|
+
const isExpanded = !!_expandedKeySet[node.key];
|
|
282
|
+
const isChecked = !!_checkedKeySet[node.key];
|
|
283
|
+
const isSelected = !!_selectedKeySet[node.key];
|
|
284
|
+
const isIndeterminate = !!_indeterminateKeySet[node.key];
|
|
285
|
+
const isLoading = !!_loadingKeys[node.key];
|
|
286
|
+
|
|
287
|
+
// Highlight matching
|
|
288
|
+
let labelParts = null;
|
|
289
|
+
if (_highlightPattern && node.label) {
|
|
290
|
+
const idx = node.label.toLowerCase().indexOf(_highlightPattern.toLowerCase());
|
|
291
|
+
if (idx !== -1) {
|
|
292
|
+
labelParts = [
|
|
293
|
+
node.label.slice(0, idx),
|
|
294
|
+
node.label.slice(idx, idx + _highlightPattern.length),
|
|
295
|
+
node.label.slice(idx + _highlightPattern.length),
|
|
296
|
+
];
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
visible.push({
|
|
301
|
+
key: node.key,
|
|
302
|
+
label: node.label,
|
|
303
|
+
level: node.level,
|
|
304
|
+
icon: node.icon,
|
|
305
|
+
prefixIcon: node.prefixIcon,
|
|
306
|
+
suffixText: node.suffixText,
|
|
307
|
+
disabled: node.disabled,
|
|
308
|
+
isLeaf: node.isLeaf,
|
|
309
|
+
isLast: node.isLast,
|
|
310
|
+
paddingLeft,
|
|
311
|
+
isExpanded,
|
|
312
|
+
isChecked,
|
|
313
|
+
isSelected,
|
|
314
|
+
isIndeterminate,
|
|
315
|
+
isLoading,
|
|
316
|
+
labelParts,
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
this.setData({ _visibleNodes: visible });
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
// ===== Check Logic =====
|
|
324
|
+
|
|
325
|
+
_setCheckedKeys(keys) {
|
|
326
|
+
const checkedMap = {};
|
|
327
|
+
keys.forEach((k) => {
|
|
328
|
+
checkedMap[k] = true;
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
if (this.data.cascade && this.data.checkable) {
|
|
332
|
+
const indeterminateMap = {};
|
|
333
|
+
this._flatNodes.forEach((node) => {
|
|
334
|
+
if (node.isLeaf || !node.childrenKeys.length) return;
|
|
335
|
+
const allDescendants = this._getAllDescendantKeys(node.key);
|
|
336
|
+
const checkedCount = allDescendants.filter((k) => checkedMap[k]).length;
|
|
337
|
+
if (checkedCount > 0 && checkedCount < allDescendants.length) {
|
|
338
|
+
indeterminateMap[node.key] = true;
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
this.setData({ _checkedKeySet: checkedMap, _indeterminateKeySet: indeterminateMap });
|
|
342
|
+
} else {
|
|
343
|
+
this.setData({ _checkedKeySet: checkedMap, _indeterminateKeySet: {} });
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
this._updateVisibleNodes();
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
_handleCheck(key) {
|
|
350
|
+
const node = this._nodeMap[key];
|
|
351
|
+
if (!node || node.disabled || this.data.disabled) return;
|
|
352
|
+
|
|
353
|
+
const isChecked = !!this.data._checkedKeySet[key];
|
|
354
|
+
const newChecked = { ...this.data._checkedKeySet };
|
|
355
|
+
const newIndeterminate = { ...this.data._indeterminateKeySet };
|
|
356
|
+
|
|
357
|
+
if (this.data.cascade) {
|
|
358
|
+
const descendants = this._getAllDescendantKeys(key).filter(
|
|
359
|
+
(k) => !this._nodeMap[k]?.disabled,
|
|
360
|
+
);
|
|
361
|
+
if (isChecked) {
|
|
362
|
+
delete newChecked[key];
|
|
363
|
+
descendants.forEach((k) => {
|
|
364
|
+
delete newChecked[k];
|
|
365
|
+
});
|
|
366
|
+
} else {
|
|
367
|
+
newChecked[key] = true;
|
|
368
|
+
descendants.forEach((k) => {
|
|
369
|
+
newChecked[k] = true;
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
this._updateAncestorCheckState(key, newChecked, newIndeterminate);
|
|
373
|
+
} else {
|
|
374
|
+
if (isChecked) {
|
|
375
|
+
delete newChecked[key];
|
|
376
|
+
} else {
|
|
377
|
+
newChecked[key] = true;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
this.setData({ _checkedKeySet: newChecked, _indeterminateKeySet: newIndeterminate });
|
|
382
|
+
this._updateVisibleNodes();
|
|
383
|
+
this._emitCheckedKeys();
|
|
384
|
+
},
|
|
385
|
+
|
|
386
|
+
_updateAncestorCheckState(key, checkedMap, indeterminateMap) {
|
|
387
|
+
let current = this._nodeMap[key];
|
|
388
|
+
while (current && current.parentKey !== null) {
|
|
389
|
+
const parent = this._nodeMap[current.parentKey];
|
|
390
|
+
if (!parent) break;
|
|
391
|
+
|
|
392
|
+
const childKeys = parent.childrenKeys;
|
|
393
|
+
const allLeafKeys = [];
|
|
394
|
+
childKeys.forEach((ck) => {
|
|
395
|
+
allLeafKeys.push(...this._getAllDescendantKeys(ck), ck);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
const nonDisabledKeys = allLeafKeys.filter((k) => !this._nodeMap[k]?.disabled);
|
|
399
|
+
const checkedCount = nonDisabledKeys.filter((k) => checkedMap[k]).length;
|
|
400
|
+
|
|
401
|
+
delete checkedMap[parent.key];
|
|
402
|
+
delete indeterminateMap[parent.key];
|
|
403
|
+
|
|
404
|
+
if (checkedCount === 0) {
|
|
405
|
+
// nothing
|
|
406
|
+
} else if (checkedCount === nonDisabledKeys.length) {
|
|
407
|
+
checkedMap[parent.key] = true;
|
|
408
|
+
} else {
|
|
409
|
+
indeterminateMap[parent.key] = true;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
current = parent;
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
_getAllDescendantKeys(key) {
|
|
417
|
+
const node = this._nodeMap[key];
|
|
418
|
+
if (!node || !node.childrenKeys.length) return [];
|
|
419
|
+
const result = [];
|
|
420
|
+
const stack = [...node.childrenKeys];
|
|
421
|
+
while (stack.length) {
|
|
422
|
+
const k = stack.pop();
|
|
423
|
+
result.push(k);
|
|
424
|
+
const child = this._nodeMap[k];
|
|
425
|
+
if (child && child.childrenKeys.length) {
|
|
426
|
+
stack.push(...child.childrenKeys);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return result;
|
|
430
|
+
},
|
|
431
|
+
|
|
432
|
+
_getOutputCheckedKeys() {
|
|
433
|
+
const { _checkedKeySet } = this.data;
|
|
434
|
+
const keys = Object.keys(_checkedKeySet).filter((k) => _checkedKeySet[k]);
|
|
435
|
+
const { checkStrategy } = this.data;
|
|
436
|
+
|
|
437
|
+
if (checkStrategy === 'parent') {
|
|
438
|
+
return keys
|
|
439
|
+
.filter((k) => {
|
|
440
|
+
const node = this._nodeMap[k];
|
|
441
|
+
if (!node || node.isLeaf) return true;
|
|
442
|
+
const desc = this._getAllDescendantKeys(k);
|
|
443
|
+
return desc.every((dk) => _checkedKeySet[dk]);
|
|
444
|
+
})
|
|
445
|
+
.filter((k) => {
|
|
446
|
+
const node = this._nodeMap[k];
|
|
447
|
+
if (!node || node.parentKey === null) return true;
|
|
448
|
+
const parent = this._nodeMap[node.parentKey];
|
|
449
|
+
if (!parent) return true;
|
|
450
|
+
const parentDesc = this._getAllDescendantKeys(parent.key);
|
|
451
|
+
return !parentDesc.every((dk) => _checkedKeySet[dk]);
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (checkStrategy === 'child') {
|
|
456
|
+
return keys.filter((k) => {
|
|
457
|
+
const node = this._nodeMap[k];
|
|
458
|
+
return node && node.isLeaf;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return keys;
|
|
463
|
+
},
|
|
464
|
+
|
|
465
|
+
// ===== Select Logic =====
|
|
466
|
+
|
|
467
|
+
_handleSelect(key) {
|
|
468
|
+
const node = this._nodeMap[key];
|
|
469
|
+
if (!node || node.disabled || this.data.disabled || !this.data.selectable) return;
|
|
470
|
+
|
|
471
|
+
const isSelected = !!this.data._selectedKeySet[key];
|
|
472
|
+
let newSelected;
|
|
473
|
+
|
|
474
|
+
if (this.data.multiple) {
|
|
475
|
+
newSelected = { ...this.data._selectedKeySet };
|
|
476
|
+
if (isSelected) {
|
|
477
|
+
delete newSelected[key];
|
|
478
|
+
} else {
|
|
479
|
+
newSelected[key] = true;
|
|
480
|
+
}
|
|
481
|
+
} else {
|
|
482
|
+
newSelected = isSelected ? {} : { [key]: true };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
this.setData({ _selectedKeySet: newSelected });
|
|
486
|
+
this._updateVisibleNodes();
|
|
487
|
+
this._emitSelectedKeys();
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
// ===== Expand Logic =====
|
|
491
|
+
|
|
492
|
+
_handleExpand(key) {
|
|
493
|
+
const node = this._nodeMap[key];
|
|
494
|
+
if (!node || node.isLeaf) return;
|
|
495
|
+
|
|
496
|
+
// Async loading
|
|
497
|
+
if (!node.childrenKeys.length && !node.isLeaf && !this.data._loadingKeys[key]) {
|
|
498
|
+
this.setData({ _loadingKeys: { ...this.data._loadingKeys, [key]: true } });
|
|
499
|
+
this._updateVisibleNodes();
|
|
500
|
+
this.triggerEvent('load', { node: node.raw });
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const isExpanded = !!this.data._expandedKeySet[key];
|
|
505
|
+
const newExpanded = { ...this.data._expandedKeySet };
|
|
506
|
+
|
|
507
|
+
if (isExpanded) {
|
|
508
|
+
delete newExpanded[key];
|
|
509
|
+
} else {
|
|
510
|
+
if (this.data.accordion) {
|
|
511
|
+
this._flatNodes.forEach((n) => {
|
|
512
|
+
if (n.parentKey === node.parentKey && n.key !== key && !n.isLeaf) {
|
|
513
|
+
delete newExpanded[n.key];
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
newExpanded[key] = true;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
this.setData({ _expandedKeySet: newExpanded });
|
|
521
|
+
this._updateVisibleNodes();
|
|
522
|
+
this._emitExpandedKeys();
|
|
523
|
+
},
|
|
524
|
+
|
|
525
|
+
// ===== Filter Logic =====
|
|
526
|
+
|
|
527
|
+
_applyFilter() {
|
|
528
|
+
const { pattern, filterMode } = this.data;
|
|
529
|
+
|
|
530
|
+
if (!pattern) {
|
|
531
|
+
this._filteredKeySet = null;
|
|
532
|
+
this.setData({ _highlightPattern: '' });
|
|
533
|
+
this._updateVisibleNodes();
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
const matchFn =
|
|
538
|
+
this._filterFn || ((pat, node) => node.label.toLowerCase().includes(pat.toLowerCase()));
|
|
539
|
+
|
|
540
|
+
if (filterMode === 'highlight') {
|
|
541
|
+
this._filteredKeySet = null;
|
|
542
|
+
this.setData({ _highlightPattern: pattern });
|
|
543
|
+
this._updateVisibleNodes();
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Filter mode: show only matching nodes + ancestors
|
|
548
|
+
const matchedKeys = new Set();
|
|
549
|
+
this._flatNodes.forEach((node) => {
|
|
550
|
+
if (matchFn(pattern, node)) {
|
|
551
|
+
matchedKeys.add(node.key);
|
|
552
|
+
let parentKey = node.parentKey;
|
|
553
|
+
while (parentKey !== null) {
|
|
554
|
+
matchedKeys.add(parentKey);
|
|
555
|
+
const parent = this._nodeMap[parentKey];
|
|
556
|
+
parentKey = parent ? parent.parentKey : null;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
this._filteredKeySet = {};
|
|
562
|
+
matchedKeys.forEach((k) => {
|
|
563
|
+
this._filteredKeySet[k] = true;
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
// Auto-expand ancestors of matched nodes
|
|
567
|
+
const newExpanded = { ...this.data._expandedKeySet };
|
|
568
|
+
matchedKeys.forEach((k) => {
|
|
569
|
+
const node = this._nodeMap[k];
|
|
570
|
+
if (node && !node.isLeaf) {
|
|
571
|
+
newExpanded[k] = true;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
this.setData({ _expandedKeySet: newExpanded, _highlightPattern: pattern });
|
|
576
|
+
this._updateVisibleNodes();
|
|
577
|
+
},
|
|
578
|
+
|
|
579
|
+
// ===== Event Emission =====
|
|
580
|
+
|
|
581
|
+
_emitCheckedKeys() {
|
|
582
|
+
const keys = this._getOutputCheckedKeys();
|
|
583
|
+
const nodes = keys.map((k) => this._nodeMap[k]?.raw).filter(Boolean);
|
|
584
|
+
this.triggerEvent('update:checked-keys', { keys, nodes });
|
|
585
|
+
},
|
|
586
|
+
|
|
587
|
+
_emitSelectedKeys() {
|
|
588
|
+
const keys = Object.keys(this.data._selectedKeySet).filter(
|
|
589
|
+
(k) => this.data._selectedKeySet[k],
|
|
590
|
+
);
|
|
591
|
+
const nodes = keys.map((k) => this._nodeMap[k]?.raw).filter(Boolean);
|
|
592
|
+
this.triggerEvent('update:selected-keys', { keys, nodes });
|
|
593
|
+
},
|
|
594
|
+
|
|
595
|
+
_emitExpandedKeys() {
|
|
596
|
+
const keys = Object.keys(this.data._expandedKeySet).filter(
|
|
597
|
+
(k) => this.data._expandedKeySet[k],
|
|
598
|
+
);
|
|
599
|
+
const nodes = keys.map((k) => this._nodeMap[k]?.raw).filter(Boolean);
|
|
600
|
+
this.triggerEvent('update:expanded-keys', { keys, nodes });
|
|
601
|
+
},
|
|
602
|
+
|
|
603
|
+
// ===== Event Handlers =====
|
|
604
|
+
|
|
605
|
+
handleNodeTap(e) {
|
|
606
|
+
const { key } = e.currentTarget.dataset;
|
|
607
|
+
const node = this._nodeMap[key];
|
|
608
|
+
if (!node || node.disabled || this.data.disabled) return;
|
|
609
|
+
|
|
610
|
+
this.triggerEvent('node-tap', { node: node.raw });
|
|
611
|
+
|
|
612
|
+
if (this.data.checkOnClick && this.data.checkable) {
|
|
613
|
+
this._handleCheck(key);
|
|
614
|
+
} else if (this.data.expandOnClick && !node.isLeaf) {
|
|
615
|
+
this._handleExpand(key);
|
|
616
|
+
} else if (this.data.selectable) {
|
|
617
|
+
this._handleSelect(key);
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
|
|
621
|
+
handleSwitcherTap(e) {
|
|
622
|
+
const { key } = e.currentTarget.dataset;
|
|
623
|
+
this._handleExpand(key);
|
|
624
|
+
},
|
|
625
|
+
|
|
626
|
+
handleCheckTap(e) {
|
|
627
|
+
const { key } = e.currentTarget.dataset;
|
|
628
|
+
this._handleCheck(key);
|
|
629
|
+
},
|
|
630
|
+
|
|
631
|
+
// ===== Helpers for tree-select =====
|
|
632
|
+
|
|
633
|
+
_getNodeByKey(key) {
|
|
634
|
+
return this._nodeMap[key];
|
|
635
|
+
},
|
|
636
|
+
|
|
637
|
+
_getNodePath(key) {
|
|
638
|
+
const path = [];
|
|
639
|
+
let current = this._nodeMap[key];
|
|
640
|
+
while (current) {
|
|
641
|
+
path.unshift(current.label);
|
|
642
|
+
current = current.parentKey !== null ? this._nodeMap[current.parentKey] : null;
|
|
643
|
+
}
|
|
644
|
+
return path;
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
});
|