@archbiz/element-ui 0.0.0-stage → 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.
Files changed (79) hide show
  1. package/dist/element-ui.cjs +12 -0
  2. package/dist/element-ui.js +5522 -0
  3. package/dist/style.css +1 -0
  4. package/package.json +49 -3
  5. package/src/components/ab-checkbox.vue +51 -0
  6. package/src/components/ab-color-picker.vue +39 -0
  7. package/src/components/ab-detail/ab-detail.vue +285 -0
  8. package/src/components/ab-detail/index.js +1 -0
  9. package/src/components/ab-drawer/ab-drawer.vue +50 -0
  10. package/src/components/ab-drawer/index.js +3 -0
  11. package/src/components/ab-icon/ab-icon.vue +90 -0
  12. package/src/components/ab-icon/index.js +1 -0
  13. package/src/components/ab-input-number.vue +49 -0
  14. package/src/components/ab-input-range.vue +90 -0
  15. package/src/components/ab-radio.vue +51 -0
  16. package/src/components/ab-router-link.vue +46 -0
  17. package/src/components/ab-search/ab-search.vue +168 -0
  18. package/src/components/ab-search/index.js +4 -0
  19. package/src/components/ab-select.vue +107 -0
  20. package/src/components/ab-table/ab-table-column.vue +131 -0
  21. package/src/components/ab-table/ab-table-columns.vue +62 -0
  22. package/src/components/ab-table/ab-table-operate.vue +160 -0
  23. package/src/components/ab-table/ab-table.vue +316 -0
  24. package/src/components/ab-table/columns.js +90 -0
  25. package/src/components/ab-table/footer.js +77 -0
  26. package/src/components/ab-table/formatter.js +2 -0
  27. package/src/components/ab-table/index.js +8 -0
  28. package/src/components/ab-table/utils.js +36 -0
  29. package/src/components/ab-time-period.vue +116 -0
  30. package/src/components/ab-time-picker.vue +38 -0
  31. package/src/components/ab-toolbar/ab-toolbar.vue +99 -0
  32. package/src/components/ab-toolbar/index.js +1 -0
  33. package/src/components/ab-tree-select.vue +456 -0
  34. package/src/components/ab-upload-file.vue +277 -0
  35. package/src/components/index.js +27 -0
  36. package/src/core/ab-form.js +25 -0
  37. package/src/core/alias.js +36 -0
  38. package/src/core/config.js +65 -0
  39. package/src/core/form-render.js +260 -0
  40. package/src/core/options.js +25 -0
  41. package/src/hooks/use-cache.js +75 -0
  42. package/src/index.js +39 -0
  43. package/src/makers/datePicker.js +8 -0
  44. package/src/makers/frame.js +23 -0
  45. package/src/makers/index.js +23 -0
  46. package/src/makers/input.js +12 -0
  47. package/src/makers/select.js +8 -0
  48. package/src/makers/slider.js +7 -0
  49. package/src/makers/timePicker.js +8 -0
  50. package/src/makers/tree.js +10 -0
  51. package/src/makers/upload.js +20 -0
  52. package/src/parsers/checkbox.js +5 -0
  53. package/src/parsers/colorPicker.js +29 -0
  54. package/src/parsers/datePicker.js +24 -0
  55. package/src/parsers/frame.js +17 -0
  56. package/src/parsers/hidden.js +11 -0
  57. package/src/parsers/index.js +36 -0
  58. package/src/parsers/input.js +15 -0
  59. package/src/parsers/number.js +29 -0
  60. package/src/parsers/radio.js +5 -0
  61. package/src/parsers/select.js +15 -0
  62. package/src/parsers/slider.js +21 -0
  63. package/src/parsers/switch.js +11 -0
  64. package/src/parsers/text.js +25 -0
  65. package/src/parsers/timePicker.js +12 -0
  66. package/src/parsers/tree.js +37 -0
  67. package/src/parsers/upload.js +35 -0
  68. package/src/plugins/ab-detail.js +7 -0
  69. package/src/plugins/ab-drawer.js +7 -0
  70. package/src/plugins/ab-form.js +14 -0
  71. package/src/plugins/ab-search.js +7 -0
  72. package/src/plugins/ab-table.js +15 -0
  73. package/src/plugins/ab-toolbar.js +7 -0
  74. package/src/rule/defaults.js +187 -0
  75. package/src/rule/formatter.js +218 -0
  76. package/src/style/index.css +356 -0
  77. package/src/utils/formatter.js +188 -0
  78. package/src/utils/router-link.js +59 -0
  79. package/README.md +0 -3
@@ -0,0 +1,116 @@
1
+ <template>
2
+ <div class="ab-time-period w-full">
3
+ <div class="start-time">{{ period[0] || "--:--" }}</div>
4
+ <div v-if="isReadonly">~</div>
5
+ <el-slider
6
+ v-else
7
+ :class="{ 'is-empty': !period[0] && !period[1] }"
8
+ :value="sliderValue"
9
+ range
10
+ :step="30"
11
+ :min="bounds[0]"
12
+ :max="bounds[1]"
13
+ :format-tooltip="formatTime"
14
+ @input="updatePeriod"
15
+ @change="handleChange"
16
+ />
17
+ <div class="end-time">{{ period[1] || "--:--" }}</div>
18
+ </div>
19
+ </template>
20
+
21
+ <script>
22
+ function parseTime(value) {
23
+ const match = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(String(value || "").trim());
24
+ if (!match) return 0;
25
+ const hour = Number(match[1]);
26
+ const minute = Number(match[2]);
27
+ const second = match[3] ? Number(match[3]) : 0;
28
+ return hour * 3600 + minute * 60 + second;
29
+ }
30
+
31
+ function formatTime(value) {
32
+ const hour = Math.floor(value / 3600);
33
+ const minute = Math.floor((value % 3600) / 60);
34
+ const second = value % 60;
35
+ const time = `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
36
+ return second ? `${time}:${String(second).padStart(2, "0")}` : time;
37
+ }
38
+
39
+ export default {
40
+ name: "AbTimePeriod",
41
+ props: {
42
+ abFormInject: { type: Object, default: undefined },
43
+ value: { type: Array, default: () => [] },
44
+ startTime: { type: String, default: "08:00" },
45
+ endTime: { type: String, default: "18:00" },
46
+ readonly: Boolean,
47
+ },
48
+ computed: {
49
+ isReadonly() {
50
+ return this.readonly === true || Boolean(this.abFormInject && this.abFormInject.readonly === true);
51
+ },
52
+ bounds() {
53
+ const start = parseTime(this.startTime);
54
+ const end = parseTime(this.endTime);
55
+ return start < end ? [start, end] : [0, 86400];
56
+ },
57
+ period() {
58
+ const value = Array.isArray(this.value) ? this.value : [];
59
+ return [
60
+ value[0] === "" || value[0] === undefined ? null : value[0],
61
+ value[1] === "" || value[1] === undefined ? null : value[1],
62
+ ];
63
+ },
64
+ selected() {
65
+ const [min, max] = this.bounds;
66
+ const start = this.period[0] === null ? min : parseTime(this.period[0]);
67
+ const end = this.period[1] === null ? max : parseTime(this.period[1]);
68
+ return start <= end ? [start, end] : [min, max];
69
+ },
70
+ sliderValue() {
71
+ const clamp = (value) => Math.min(this.bounds[1], Math.max(this.bounds[0], value));
72
+ return [clamp(this.selected[0]), clamp(this.selected[1])];
73
+ },
74
+ },
75
+ methods: {
76
+ formatTime,
77
+ toPeriod(value) {
78
+ const next = Array.isArray(value) ? value : [];
79
+ return [
80
+ this.period[0] !== null && next[0] === this.sliderValue[0] ? this.period[0] : formatTime(next[0]),
81
+ this.period[1] !== null && next[1] === this.sliderValue[1] ? this.period[1] : formatTime(next[1]),
82
+ ];
83
+ },
84
+ updatePeriod(value) {
85
+ this.$emit("input", this.toPeriod(value));
86
+ },
87
+ handleChange(value) {
88
+ this.$emit("change", this.toPeriod(value));
89
+ },
90
+ },
91
+ };
92
+ </script>
93
+
94
+ <style>
95
+ .ab-time-period {
96
+ display: flex;
97
+ align-items: center;
98
+ justify-content: flex-start;
99
+ width: 100%;
100
+ }
101
+ .ab-time-period .el-slider {
102
+ flex: 1;
103
+ margin: 0 12px;
104
+ }
105
+ .ab-time-period .start-time,
106
+ .ab-time-period .end-time {
107
+ width: 78px;
108
+ height: 100%;
109
+ }
110
+ .ab-time-period .end-time {
111
+ text-align: right;
112
+ }
113
+ .ab-time-period .el-slider.is-empty .el-slider__bar {
114
+ visibility: hidden;
115
+ }
116
+ </style>
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <el-time-picker
3
+ ref="el"
4
+ v-bind="$attrs"
5
+ :value="value"
6
+ :size="currentSize"
7
+ @input="handleInput"
8
+ @change="handleChange"
9
+ />
10
+ </template>
11
+
12
+ <script>
13
+ import { useCache } from "../hooks/use-cache.js";
14
+
15
+ export default {
16
+ name: "AbTimePicker",
17
+ inheritAttrs: false,
18
+ props: {
19
+ value: { default: undefined },
20
+ abFormInject: { type: Object, default: undefined },
21
+ },
22
+ computed: {
23
+ currentSize() {
24
+ const { getCurrentSize } = useCache();
25
+ const size = getCurrentSize();
26
+ return size && size !== "default" && size !== "large" ? size : undefined;
27
+ },
28
+ },
29
+ methods: {
30
+ handleInput(value) {
31
+ this.$emit("input", value);
32
+ },
33
+ handleChange(value) {
34
+ this.$emit("change", value);
35
+ },
36
+ },
37
+ };
38
+ </script>
@@ -0,0 +1,99 @@
1
+ <script>
2
+ import { AbTableEnum, trans2VxeSize } from '../ab-table/utils.js';
3
+
4
+ const clone = (value) => (value === undefined ? value : JSON.parse(JSON.stringify(value)));
5
+
6
+ export default {
7
+ name: 'AbToolbar',
8
+ inject: {
9
+ abTableRef: { default: () => ({}) }
10
+ },
11
+ props: {
12
+ title: String,
13
+ permiPrefix: String,
14
+ rule: { type: [Object, Array], default: undefined },
15
+ queryHandler: Function,
16
+ refreshEnable: { type: Boolean, default: true },
17
+ exportEnable: { type: Boolean, default: false },
18
+ settingEnable: { type: Boolean, default: true },
19
+ btnTreeEnable: Boolean,
20
+ classNmae: String,
21
+ vertical: { type: Boolean, default: false }
22
+ },
23
+ data() {
24
+ return {
25
+ loading: false
26
+ };
27
+ },
28
+ computed: {
29
+ vxeCurrentSize() {
30
+ return trans2VxeSize('default');
31
+ },
32
+ currentRule() {
33
+ if (!this.rule || (Array.isArray(this.rule) && !this.rule.length)) return undefined;
34
+ const rule = clone(this.rule);
35
+ return Array.isArray(rule) ? { type: 'ElRow', children: [...rule] } : rule;
36
+ },
37
+ refreshHandler() {
38
+ if (this.queryHandler) return this.queryHandler;
39
+ const table = this.abTableRef && this.abTableRef.value;
40
+ if (table && typeof table.reload === 'function') return table.reload;
41
+ return undefined;
42
+ }
43
+ },
44
+ mounted() {
45
+ const table = this.abTableRef && this.abTableRef.value;
46
+ const toolbar = this.$refs.toolbar && (this.$refs.toolbar.$el ? this.$refs.toolbar : this.$refs.toolbar);
47
+ if (table && table.tableRef && toolbar && typeof table.tableRef.connect === 'function') {
48
+ table.tableRef.connect(toolbar);
49
+ }
50
+ },
51
+ methods: {
52
+ getTitle() {
53
+ return this.title;
54
+ },
55
+ renderButtons(h) {
56
+ if (this.title) {
57
+ return h('div', { class: 'ab-toolbar__title' }, [this.$slots.icon, this.title]);
58
+ }
59
+ if (this.$slots.buttons) return this.$slots.buttons;
60
+ return h('div', { class: 'ab-toolbar__title' }, [this.$route?.meta?.title || '']);
61
+ },
62
+ renderTools(h) {
63
+ const nodes = [...(this.$slots.tools || [])];
64
+ if (this.currentRule) {
65
+ nodes.push(
66
+ h('ab-table-operate', {
67
+ props: {
68
+ permiPrefix: this.permiPrefix,
69
+ rule: this.currentRule,
70
+ plain: true
71
+ }
72
+ })
73
+ );
74
+ }
75
+ return nodes;
76
+ }
77
+ },
78
+ render(h) {
79
+ return h('vxe-toolbar', {
80
+ class: 'ab-toolbar',
81
+ ref: 'toolbar',
82
+ props: {
83
+ className: this.classNmae,
84
+ size: this.vxeCurrentSize,
85
+ loading: this.loading,
86
+ export: this.exportEnable,
87
+ refresh: this.refreshEnable,
88
+ refreshOptions: this.refreshEnable && this.refreshHandler ? { queryMethod: this.refreshHandler } : undefined,
89
+ custom: !!this.settingEnable,
90
+ vertical: this.vertical
91
+ },
92
+ scopedSlots: {
93
+ buttons: () => this.renderButtons(h),
94
+ tools: () => this.renderTools(h)
95
+ }
96
+ });
97
+ }
98
+ };
99
+ </script>
@@ -0,0 +1 @@
1
+ export { default as AbToolbar } from './ab-toolbar.vue';
@@ -0,0 +1,456 @@
1
+ <template>
2
+ <el-popover
3
+ ref="popover"
4
+ placement="bottom-start"
5
+ v-model="visible"
6
+ width="320"
7
+ :disabled="disabled"
8
+ trigger="manual"
9
+ @show="onShow"
10
+ @hide="onHide"
11
+ popper-class="ab-tree-select__popper"
12
+ >
13
+ <div class="ab-tree-select__dropdown" @mouseenter="onDropdownEnter" @mouseleave="onDropdownLeave">
14
+ <div v-if="filterable" class="ab-tree-select__filter">
15
+ <el-input v-model="filterText" size="small" placeholder="搜索..." class="ab-tree-select__filter-input" @keydown.esc.stop @keydown.tab.stop @click.stop>
16
+ <template slot="prefix">
17
+ <i class="el-icon-search" />
18
+ </template>
19
+ <template slot="suffix" v-if="filterText">
20
+ <i class="el-icon-circle-close" @click.stop="filterText = ''" />
21
+ </template>
22
+ </el-input>
23
+ </div>
24
+ <el-tree
25
+ ref="tree"
26
+ :data="filteredData"
27
+ :props="treeProps"
28
+ :node-key="treeProps.value"
29
+ :default-expanded-keys="defaultExpandedKeysInternal"
30
+ :show-checkbox="multiple"
31
+ :check-strictly="checkStrictly"
32
+ :highlight-current="!multiple"
33
+ :default-checked-keys="getDefaultCheckedKeys()"
34
+ :filter-node-method="filterNodeMethod"
35
+ @node-click="handleNodeClick"
36
+ @check-change="handleCheckChange"
37
+ @current-change="handleCurrentChange"
38
+ style="max-height: 300px; overflow: auto"
39
+ />
40
+ <div v-if="filteredData.length === 0 && filterText" class="ab-tree-select__empty">无匹配数据</div>
41
+ </div>
42
+ <template slot="reference">
43
+ <div class="ab-tree-select__reference">
44
+ <!-- 单选/非多选:显示输入框 -->
45
+ <el-input
46
+ v-if="!multiple"
47
+ ref="input"
48
+ v-bind="$attrs"
49
+ :value="displayValue"
50
+ :size="currentSize"
51
+ :disabled="disabled"
52
+ :readonly="true"
53
+ :placeholder="placeholder"
54
+ @focus="handleFocus"
55
+ @blur="handleBlur"
56
+ class="ab-tree-select__input"
57
+ >
58
+ <template slot="suffix">
59
+ <i class="el-input__suffix-inner el-select__caret el-icon-arrow-down" :class="{ 'is-reverse': visible }" />
60
+ </template>
61
+ </el-input>
62
+ <!-- 多选:隐藏输入框只用于表单提交,显示标签区域作为点击容器 -->
63
+ <div v-else class="ab-tree-select__tags-wrapper" @click="handleClick">
64
+ <input type="hidden" ref="input" :name="$attrs.name" :value="Array.isArray(value) ? value.join(',') : value || ''" />
65
+ <div class="ab-tree-select__tags">
66
+ <el-tag v-if="displayLabels.length === 1" size="small" type="info" @close.stop="removeTag(displayLabels[0].value)" class="ab-tree-select__tag">
67
+ {{ displayLabels[0].label }}
68
+ </el-tag>
69
+ <span v-else-if="displayLabels.length > 1" class="ab-tree-select__tag-multiple">
70
+ <el-tag size="small" type="info" class="ab-tree-select__first-tag" @close.stop="removeTag(displayLabels[0].value)">
71
+ {{ displayLabels[0].label }}
72
+ </el-tag>
73
+ <el-tag size="small" type="info" class="ab-tree-select__count-tag"> +{{ displayLabels.length - 1 }} </el-tag>
74
+ </span>
75
+ <span v-else class="ab-tree-select__placeholder">{{ placeholder }}</span>
76
+ <i class="el-select__caret el-icon-arrow-down" :class="{ 'is-reverse': visible }" />
77
+ </div>
78
+ </div>
79
+ </div>
80
+ </template>
81
+ </el-popover>
82
+ </template>
83
+
84
+ <script>
85
+ export default {
86
+ name: "AbTreeSelect",
87
+ inheritAttrs: false,
88
+ props: {
89
+ value: {
90
+ type: [Array, String, Number, Boolean, Object],
91
+ default: undefined,
92
+ },
93
+ data: {
94
+ type: Array,
95
+ default: () => [],
96
+ },
97
+ props: {
98
+ type: Object,
99
+ default: () => ({}),
100
+ },
101
+ multiple: Boolean,
102
+ checkStrictly: Boolean,
103
+ filterable: Boolean,
104
+ disabled: Boolean,
105
+ placeholder: String,
106
+ size: String,
107
+ defaultExpandedKeys: Array,
108
+ showValue: Boolean,
109
+ showKey: Boolean,
110
+ showCode: Boolean,
111
+ abFormInject: Object,
112
+ },
113
+ data() {
114
+ return {
115
+ visible: false,
116
+ filterText: "",
117
+ dropdownHovering: false,
118
+ inputHovering: false,
119
+ currentNodeKey: null,
120
+ defaultExpandedKeysInternal: [],
121
+ };
122
+ },
123
+ computed: {
124
+ currentSize() {
125
+ return this.size || (this.$ELEMENT && this.$ELEMENT.size) || "default";
126
+ },
127
+ treeData() {
128
+ return this.data || (this.abFormInject && this.abFormInject.options) || [];
129
+ },
130
+ treeProps() {
131
+ const p = this.props || {};
132
+ return {
133
+ value: p.valueKey || p.nodeKey || "value",
134
+ label: p.label || "label",
135
+ children: p.children || "children",
136
+ disabled: p.disabled || "disabled",
137
+ leaf: p.leaf || "isLeaf",
138
+ ...p,
139
+ };
140
+ },
141
+ filteredData() {
142
+ if (!this.filterText) return this.treeData;
143
+ const filter = this.filterText.toLowerCase();
144
+ const filterNode = (nodes) => {
145
+ return nodes
146
+ .map((node) => {
147
+ const label = String(node[this.treeProps.label] || "").toLowerCase();
148
+ const match = label.includes(filter);
149
+ const children = node[this.treeProps.children];
150
+ const filteredChildren = children ? filterNode(children) : [];
151
+ if (match || filteredChildren.length) {
152
+ return { ...node, [this.treeProps.children]: filteredChildren };
153
+ }
154
+ return null;
155
+ })
156
+ .filter(Boolean);
157
+ };
158
+ return filterNode(this.treeData);
159
+ },
160
+ displayLabels() {
161
+ if (!this.multiple || !this.value || !Array.isArray(this.value) || !this.value.length) return [];
162
+ const valueKey = this.treeProps.value;
163
+ const labelKey = this.treeProps.label;
164
+ const findNode = (nodes, value) => {
165
+ for (const node of nodes || []) {
166
+ if (node[valueKey] === value) return node;
167
+ const found = findNode(node[this.treeProps.children], value);
168
+ if (found) return found;
169
+ }
170
+ return null;
171
+ };
172
+ return this.value.map((val) => {
173
+ const node = findNode(this.treeData, val);
174
+ return node ? { value: val, label: node[labelKey] } : { value: val, label: String(val) };
175
+ });
176
+ },
177
+ displayValue() {
178
+ if (this.value === undefined || this.value === null || this.value === "") return "";
179
+ const values = Array.isArray(this.value) ? this.value : [this.value];
180
+ const valueKey = this.treeProps.value;
181
+ const labelKey = this.treeProps.label;
182
+ const findLabel = (nodes, value) => {
183
+ for (const node of nodes || []) {
184
+ if (node[valueKey] === value) return node[labelKey];
185
+ const found = findLabel(node[this.treeProps.children], value);
186
+ if (found) return found;
187
+ }
188
+ return null;
189
+ };
190
+ const labels = values.map((val) => findLabel(this.treeData, val));
191
+ return labels.filter(Boolean).join(", ");
192
+ },
193
+ },
194
+ watch: {
195
+ visible(val) {
196
+ if (val) {
197
+ this.filterText = "";
198
+ this.$nextTick(() => {
199
+ if (this.$refs.tree) {
200
+ if (this.multiple && Array.isArray(this.value)) {
201
+ this.$refs.tree.setCheckedKeys(this.value);
202
+ } else if (!this.multiple && this.value !== undefined && this.value !== null) {
203
+ this.$refs.tree.setCurrentKey(this.value);
204
+ }
205
+ }
206
+ });
207
+ }
208
+ },
209
+ value(newVal) {
210
+ if (this.visible && this.$refs.tree) {
211
+ if (this.multiple && Array.isArray(newVal)) {
212
+ this.$refs.tree.setCheckedKeys(newVal);
213
+ } else if (!this.multiple && newVal !== undefined && newVal !== null) {
214
+ this.$refs.tree.setCurrentKey(newVal);
215
+ }
216
+ }
217
+ },
218
+ treeData(newVal) {
219
+ if (this.defaultExpandedKeys && this.defaultExpandedKeys.length) {
220
+ this.defaultExpandedKeysInternal = [...this.defaultExpandedKeys];
221
+ } else {
222
+ const keys = [];
223
+ const collectKeys = (nodes) => {
224
+ for (const node of nodes || []) {
225
+ if (node[this.treeProps.children] && node[this.treeProps.children].length) {
226
+ keys.push(node[this.treeProps.value]);
227
+ collectKeys(node[this.treeProps.children]);
228
+ }
229
+ }
230
+ };
231
+ collectKeys(newVal);
232
+ this.defaultExpandedKeysInternal = keys;
233
+ }
234
+ },
235
+ },
236
+ mounted() {
237
+ this.$emit("fc.el", this.$refs.input);
238
+ document.addEventListener("click", this.handleOutsideClick, true);
239
+ this.updateDefaultExpandedKeys();
240
+ },
241
+ beforeDestroy() {
242
+ document.removeEventListener("click", this.handleOutsideClick, true);
243
+ },
244
+ methods: {
245
+ filterNodeMethod(value, node) {
246
+ if (!this.filterText) return true;
247
+ return String(node[this.treeProps.label] || "")
248
+ .toLowerCase()
249
+ .includes(this.filterText.toLowerCase());
250
+ },
251
+ getDefaultCheckedKeys() {
252
+ if (!this.multiple) return [];
253
+ const valueKey = this.treeProps.value;
254
+ if (this.checkStrictly) {
255
+ return Array.isArray(this.value) ? this.value : this.value ? [this.value] : [];
256
+ }
257
+ const leafKeys = [];
258
+ const collectLeafKeys = (nodes) => {
259
+ for (const node of nodes || []) {
260
+ if (!node[this.treeProps.children] || !node[this.treeProps.children].length) {
261
+ leafKeys.push(node[valueKey]);
262
+ } else {
263
+ collectLeafKeys(node[this.treeProps.children]);
264
+ }
265
+ }
266
+ };
267
+ collectLeafKeys(this.treeData);
268
+ return leafKeys.filter((key) => (Array.isArray(this.value) ? this.value.includes(key) : this.value === key));
269
+ },
270
+ handleNodeClick(data, node, e) {
271
+ if (this.multiple) return;
272
+ const valueKey = this.treeProps.value;
273
+ const newValue = data[valueKey];
274
+ this.$emit("input", newValue);
275
+ this.$emit("change", newValue);
276
+ this.visible = false;
277
+ },
278
+ handleCheckChange(data, checked) {
279
+ if (!this.multiple) return;
280
+ const valueKey = this.treeProps.value;
281
+ const checkedKeys = this.$refs.tree.getCheckedKeys();
282
+ let value;
283
+ if (this.checkStrictly) {
284
+ value = checkedKeys;
285
+ } else {
286
+ const checkedNodes = this.$refs.tree.getCheckedNodes();
287
+ value = checkedNodes.filter((n) => n.isLeaf).map((n) => n[valueKey]);
288
+ }
289
+ this.$emit("input", value);
290
+ this.$emit("change", value);
291
+ },
292
+ handleCurrentChange(node) {
293
+ if (node) {
294
+ this.currentNodeKey = node[this.treeProps.value];
295
+ }
296
+ },
297
+ handleFocus() {
298
+ if (!this.disabled && !this.multiple) {
299
+ this.inputHovering = true;
300
+ }
301
+ },
302
+ handleBlur() {
303
+ if (!this.multiple) {
304
+ this.inputHovering = false;
305
+ setTimeout(() => {
306
+ if (!this.inputHovering && !this.dropdownHovering) {
307
+ this.visible = false;
308
+ }
309
+ }, 150);
310
+ }
311
+ },
312
+ handleClick(e) {
313
+ if (!this.disabled) {
314
+ // 防止点击标签关闭时触发 toggle
315
+ if (e.target.closest(".ab-tree-select__tag")) return;
316
+ this.visible = !this.visible;
317
+ }
318
+ },
319
+ onDropdownEnter() {
320
+ this.dropdownHovering = true;
321
+ },
322
+ onDropdownLeave() {
323
+ this.dropdownHovering = false;
324
+ setTimeout(() => {
325
+ if (!this.inputHovering && !this.dropdownHovering) {
326
+ this.visible = false;
327
+ }
328
+ }, 100);
329
+ },
330
+ onShow() {
331
+ this.$emit("visible-change", true);
332
+ },
333
+ onHide() {
334
+ this.$emit("visible-change", false);
335
+ },
336
+ handleOutsideClick(e) {
337
+ if (this.$refs.popover && this.$refs.popover.popperElm) {
338
+ const popperElm = this.$refs.popover.popperElm;
339
+ const referenceElm = this.$refs.popover.referenceElm || this.$el.querySelector(".ab-tree-select__reference");
340
+ if (!popperElm.contains(e.target) && (!referenceElm || !referenceElm.contains(e.target))) {
341
+ this.visible = false;
342
+ }
343
+ }
344
+ },
345
+ removeTag(item) {
346
+ if (this.disabled) return;
347
+ let newValue;
348
+ if (this.multiple && Array.isArray(this.value)) {
349
+ newValue = this.value.filter((v) => v !== item);
350
+ }
351
+ this.$emit("input", newValue);
352
+ this.$emit("change", newValue);
353
+ },
354
+ updateDefaultExpandedKeys() {
355
+ if (this.defaultExpandedKeys && this.defaultExpandedKeys.length) {
356
+ this.defaultExpandedKeysInternal = [...this.defaultExpandedKeys];
357
+ } else {
358
+ const keys = [];
359
+ const collectKeys = (nodes) => {
360
+ for (const node of nodes || []) {
361
+ if (node[this.treeProps.children] && node[this.treeProps.children].length) {
362
+ keys.push(node[this.treeProps.value]);
363
+ collectKeys(node[this.treeProps.children]);
364
+ }
365
+ }
366
+ };
367
+ collectKeys(this.treeData);
368
+ this.defaultExpandedKeysInternal = keys;
369
+ }
370
+ },
371
+ },
372
+ };
373
+ </script>
374
+
375
+ <style scoped>
376
+ .ab-tree-select__reference {
377
+ display: inline-block;
378
+ width: 100%;
379
+ }
380
+ .ab-tree-select__tags-wrapper {
381
+ width: 100%;
382
+ min-height: 38px;
383
+ cursor: pointer;
384
+ display: flex;
385
+ align-items: center;
386
+ justify-content: space-between;
387
+ padding: 0 8px;
388
+ background: #fff;
389
+ border: 1px solid #dcdfe6;
390
+ border-radius: 4px;
391
+ box-sizing: border-box;
392
+ transition: border-color 0.2s;
393
+ }
394
+ .ab-tree-select__tags-wrapper:hover {
395
+ border-color: #c0c4cc;
396
+ }
397
+ .ab-tree-select__tags {
398
+ width: 100%;
399
+ display: flex;
400
+ align-items: center;
401
+ justify-content: space-between;
402
+ flex-wrap: nowrap;
403
+ overflow: hidden;
404
+ flex: 1;
405
+ min-width: 0;
406
+ }
407
+ .ab-tree-select__input {
408
+ width: 100%;
409
+ }
410
+ .ab-tree-select__tag {
411
+ flex-shrink: 0;
412
+ white-space: nowrap;
413
+ overflow: hidden;
414
+ text-overflow: ellipsis;
415
+ max-width: 100%;
416
+ }
417
+ .ab-tree-select__first-tag {
418
+ flex-shrink: 0;
419
+ white-space: nowrap;
420
+ overflow: hidden;
421
+ text-overflow: ellipsis;
422
+ max-width: 180px;
423
+ }
424
+ .ab-tree-select__tag-multiple {
425
+ display: flex;
426
+ align-items: center;
427
+ gap: 4px;
428
+ }
429
+ .ab-tree-select__count-tag {
430
+ flex-shrink: 0;
431
+ cursor: default;
432
+ }
433
+ .ab-tree-select__placeholder {
434
+ color: #c0c4cc;
435
+ font-size: 14px;
436
+ }
437
+ .ab-tree-select__dropdown {
438
+ min-width: 300px;
439
+ }
440
+ .ab-tree-select__filter {
441
+ padding: 8px;
442
+ border-bottom: 1px solid #ebeef5;
443
+ }
444
+ .ab-tree-select__filter-input {
445
+ width: 100%;
446
+ }
447
+ .ab-tree-select__empty {
448
+ padding: 16px;
449
+ text-align: center;
450
+ color: #909399;
451
+ }
452
+ .el-select__caret.is-reverse {
453
+ transform: rotate(180deg);
454
+ transition: transform 0.2s;
455
+ }
456
+ </style>