@94ai/nf-variable-select 8.3.11 → 8.3.13
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/lib/index.d.ts +78 -0
- package/lib/nf-variable-select.cjs.js +75 -1
- package/lib/nf-variable-select.esm-bundler.js +75 -1
- package/lib/nf-variable-select.vue.d.ts +15 -0
- package/lib/types.d.ts +5 -0
- package/package/nf-variable-select.vue +74 -3
- package/package/types.ts +6 -0
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -75,6 +75,18 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
75
75
|
type: import("vue-demi").PropType<"small" | "mini" | "medium">;
|
|
76
76
|
default: string;
|
|
77
77
|
};
|
|
78
|
+
groupable: {
|
|
79
|
+
type: import("vue-demi").PropType<boolean>;
|
|
80
|
+
default: boolean;
|
|
81
|
+
};
|
|
82
|
+
groupKey: {
|
|
83
|
+
type: import("vue-demi").PropType<string>;
|
|
84
|
+
default: string;
|
|
85
|
+
};
|
|
86
|
+
groupLabels: {
|
|
87
|
+
type: import("vue-demi").PropType<Record<string, string>>;
|
|
88
|
+
default: () => {};
|
|
89
|
+
};
|
|
78
90
|
}>>, Readonly<import("vue-demi").ExtractPropTypes<{
|
|
79
91
|
offset: {
|
|
80
92
|
type: import("vue-demi").PropType<number>;
|
|
@@ -151,6 +163,18 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
151
163
|
type: import("vue-demi").PropType<"small" | "mini" | "medium">;
|
|
152
164
|
default: string;
|
|
153
165
|
};
|
|
166
|
+
groupable: {
|
|
167
|
+
type: import("vue-demi").PropType<boolean>;
|
|
168
|
+
default: boolean;
|
|
169
|
+
};
|
|
170
|
+
groupKey: {
|
|
171
|
+
type: import("vue-demi").PropType<string>;
|
|
172
|
+
default: string;
|
|
173
|
+
};
|
|
174
|
+
groupLabels: {
|
|
175
|
+
type: import("vue-demi").PropType<Record<string, string>>;
|
|
176
|
+
default: () => {};
|
|
177
|
+
};
|
|
154
178
|
}>>, {
|
|
155
179
|
"variate-click": (event: import("./types").VariableItem) => void;
|
|
156
180
|
hidden: () => void;
|
|
@@ -176,6 +200,9 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
176
200
|
closeDelay: number;
|
|
177
201
|
tabindex: number;
|
|
178
202
|
size: "small" | "mini" | "medium";
|
|
203
|
+
groupable: boolean;
|
|
204
|
+
groupKey: string;
|
|
205
|
+
groupLabels: Record<string, string>;
|
|
179
206
|
}, true, import("vue/types/v3-component-options").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, any>> & Readonly<Readonly<import("vue-demi").ExtractPropTypes<{
|
|
180
207
|
offset: {
|
|
181
208
|
type: import("vue-demi").PropType<number>;
|
|
@@ -252,6 +279,18 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
252
279
|
type: import("vue-demi").PropType<"small" | "mini" | "medium">;
|
|
253
280
|
default: string;
|
|
254
281
|
};
|
|
282
|
+
groupable: {
|
|
283
|
+
type: import("vue-demi").PropType<boolean>;
|
|
284
|
+
default: boolean;
|
|
285
|
+
};
|
|
286
|
+
groupKey: {
|
|
287
|
+
type: import("vue-demi").PropType<string>;
|
|
288
|
+
default: string;
|
|
289
|
+
};
|
|
290
|
+
groupLabels: {
|
|
291
|
+
type: import("vue-demi").PropType<Record<string, string>>;
|
|
292
|
+
default: () => {};
|
|
293
|
+
};
|
|
255
294
|
}>>> & import("vue-demi").ShallowUnwrapRef<{}> & import("vue/types/v3-component-options").ExtractComputedReturns<{}> & import("vue-demi").ComponentCustomProperties & Readonly<import("vue-demi").ExtractPropTypes<{
|
|
256
295
|
offset: {
|
|
257
296
|
type: import("vue-demi").PropType<number>;
|
|
@@ -328,6 +367,18 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
328
367
|
type: import("vue-demi").PropType<"small" | "mini" | "medium">;
|
|
329
368
|
default: string;
|
|
330
369
|
};
|
|
370
|
+
groupable: {
|
|
371
|
+
type: import("vue-demi").PropType<boolean>;
|
|
372
|
+
default: boolean;
|
|
373
|
+
};
|
|
374
|
+
groupKey: {
|
|
375
|
+
type: import("vue-demi").PropType<string>;
|
|
376
|
+
default: string;
|
|
377
|
+
};
|
|
378
|
+
groupLabels: {
|
|
379
|
+
type: import("vue-demi").PropType<Record<string, string>>;
|
|
380
|
+
default: () => {};
|
|
381
|
+
};
|
|
331
382
|
}>>, any, any, any, import("vue-demi").ComponentComputedOptions, import("vue-demi").ComponentMethodOptions> & import("vue/types/v3-component-options").ComponentOptionsBase<Readonly<import("vue-demi").ExtractPropTypes<{
|
|
332
383
|
offset: {
|
|
333
384
|
type: import("vue-demi").PropType<number>;
|
|
@@ -404,6 +455,18 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
404
455
|
type: import("vue-demi").PropType<"small" | "mini" | "medium">;
|
|
405
456
|
default: string;
|
|
406
457
|
};
|
|
458
|
+
groupable: {
|
|
459
|
+
type: import("vue-demi").PropType<boolean>;
|
|
460
|
+
default: boolean;
|
|
461
|
+
};
|
|
462
|
+
groupKey: {
|
|
463
|
+
type: import("vue-demi").PropType<string>;
|
|
464
|
+
default: string;
|
|
465
|
+
};
|
|
466
|
+
groupLabels: {
|
|
467
|
+
type: import("vue-demi").PropType<Record<string, string>>;
|
|
468
|
+
default: () => {};
|
|
469
|
+
};
|
|
407
470
|
}>>, {}, {}, {}, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {
|
|
408
471
|
"variate-click": (event: import("./types").VariableItem) => void;
|
|
409
472
|
hidden: () => void;
|
|
@@ -429,6 +492,9 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
429
492
|
closeDelay: number;
|
|
430
493
|
tabindex: number;
|
|
431
494
|
size: "small" | "mini" | "medium";
|
|
495
|
+
groupable: boolean;
|
|
496
|
+
groupKey: string;
|
|
497
|
+
groupLabels: Record<string, string>;
|
|
432
498
|
}> & {
|
|
433
499
|
props: {
|
|
434
500
|
offset: {
|
|
@@ -506,6 +572,18 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
506
572
|
type: import("vue-demi").PropType<"small" | "mini" | "medium">;
|
|
507
573
|
default: string;
|
|
508
574
|
};
|
|
575
|
+
groupable: {
|
|
576
|
+
type: import("vue-demi").PropType<boolean>;
|
|
577
|
+
default: boolean;
|
|
578
|
+
};
|
|
579
|
+
groupKey: {
|
|
580
|
+
type: import("vue-demi").PropType<string>;
|
|
581
|
+
default: string;
|
|
582
|
+
};
|
|
583
|
+
groupLabels: {
|
|
584
|
+
type: import("vue-demi").PropType<Record<string, string>>;
|
|
585
|
+
default: () => {};
|
|
586
|
+
};
|
|
509
587
|
};
|
|
510
588
|
} & (new () => {
|
|
511
589
|
$scopedSlots: {
|
|
@@ -117,6 +117,24 @@ __sfc_main.props = {
|
|
|
117
117
|
required: false,
|
|
118
118
|
type: String,
|
|
119
119
|
default: "mini"
|
|
120
|
+
},
|
|
121
|
+
groupable: {
|
|
122
|
+
key: "groupable",
|
|
123
|
+
required: false,
|
|
124
|
+
type: Boolean,
|
|
125
|
+
default: false
|
|
126
|
+
},
|
|
127
|
+
groupKey: {
|
|
128
|
+
key: "groupKey",
|
|
129
|
+
required: false,
|
|
130
|
+
type: String,
|
|
131
|
+
default: ""
|
|
132
|
+
},
|
|
133
|
+
groupLabels: {
|
|
134
|
+
key: "groupLabels",
|
|
135
|
+
required: false,
|
|
136
|
+
type: Object,
|
|
137
|
+
default: () => ({})
|
|
120
138
|
}
|
|
121
139
|
};
|
|
122
140
|
__sfc_main.setup = (__props, __ctx) => {
|
|
@@ -144,6 +162,33 @@ __sfc_main.setup = (__props, __ctx) => {
|
|
|
144
162
|
return item;
|
|
145
163
|
});
|
|
146
164
|
});
|
|
165
|
+
const groupedList = vueDemi.computed(() => {
|
|
166
|
+
const filteredList = keyword.value ? allList.value.filter((item) => item[props.valueAlias].includes(keyword.value)) : allList.value;
|
|
167
|
+
const items = filteredList.map((item) => {
|
|
168
|
+
if (!item[props.keyAlias]) {
|
|
169
|
+
item[props.keyAlias] = commonUtils.generateUUID();
|
|
170
|
+
}
|
|
171
|
+
return item;
|
|
172
|
+
});
|
|
173
|
+
const groupMap = /* @__PURE__ */ new Map();
|
|
174
|
+
items.forEach((item) => {
|
|
175
|
+
const groupValue = String(item[props.groupKey] ?? "default");
|
|
176
|
+
const list2 = groupMap.get(groupValue);
|
|
177
|
+
list2 ? list2.push(item) : groupMap.set(groupValue, [item]);
|
|
178
|
+
});
|
|
179
|
+
const result = [];
|
|
180
|
+
groupMap.forEach((groupItems, groupValue) => {
|
|
181
|
+
result.push({
|
|
182
|
+
type: groupValue,
|
|
183
|
+
label: props.groupLabels[groupValue] ?? groupValue,
|
|
184
|
+
list: groupItems
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
return result;
|
|
188
|
+
});
|
|
189
|
+
const hasGroupData = vueDemi.computed(() => {
|
|
190
|
+
return groupedList.value.some((group) => group.list && group.list.length > 0);
|
|
191
|
+
});
|
|
147
192
|
vueDemi.watch(() => {
|
|
148
193
|
return props.data;
|
|
149
194
|
}, () => {
|
|
@@ -166,6 +211,8 @@ __sfc_main.setup = (__props, __ctx) => {
|
|
|
166
211
|
return {
|
|
167
212
|
keyword,
|
|
168
213
|
list,
|
|
214
|
+
groupedList,
|
|
215
|
+
hasGroupData,
|
|
169
216
|
handleItem,
|
|
170
217
|
popHideHandle
|
|
171
218
|
};
|
|
@@ -224,7 +271,34 @@ var _sfc_render = function render() {
|
|
|
224
271
|
},
|
|
225
272
|
expression: "keyword"
|
|
226
273
|
}
|
|
227
|
-
})], 1), _c("div", {
|
|
274
|
+
})], 1), _vm.groupable ? _c("div", {
|
|
275
|
+
staticClass: "nf-variable-select-variate"
|
|
276
|
+
}, [_vm.hasGroupData ? _vm._l(_vm.groupedList, function(group) {
|
|
277
|
+
return _c("div", {
|
|
278
|
+
key: group.type,
|
|
279
|
+
staticClass: "nf-variable-select-group"
|
|
280
|
+
}, [_c("div", {
|
|
281
|
+
staticClass: "nf-variable-select-group-header"
|
|
282
|
+
}, [_c("span", {
|
|
283
|
+
staticClass: "nf-variable-select-group-indicator"
|
|
284
|
+
}), _c("span", {
|
|
285
|
+
staticClass: "nf-variable-select-group-label"
|
|
286
|
+
}, [_vm._v(_vm._s(group.label))])]), _c("div", {
|
|
287
|
+
staticClass: "nf-variable-select-group-content"
|
|
288
|
+
}, _vm._l(group.list, function(item) {
|
|
289
|
+
return _c("div", {
|
|
290
|
+
key: item[_vm.keyAlias],
|
|
291
|
+
staticClass: "nf-variable-select-variate-item",
|
|
292
|
+
on: {
|
|
293
|
+
"click": function($event) {
|
|
294
|
+
return _vm.handleItem(item);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}, [_vm._v(_vm._s(item[_vm.valueAlias]))]);
|
|
298
|
+
}), 0)]);
|
|
299
|
+
}) : _c("div", {
|
|
300
|
+
staticClass: "nf-variable-select-nothing"
|
|
301
|
+
}, [_vm._v(_vm._s(_vm.noMatchDesc))])], 2) : _c("div", {
|
|
228
302
|
staticClass: "nf-variable-select-variate"
|
|
229
303
|
}, [_vm._l(_vm.list, function(item) {
|
|
230
304
|
return _c("div", {
|
|
@@ -115,6 +115,24 @@ __sfc_main.props = {
|
|
|
115
115
|
required: false,
|
|
116
116
|
type: String,
|
|
117
117
|
default: "mini"
|
|
118
|
+
},
|
|
119
|
+
groupable: {
|
|
120
|
+
key: "groupable",
|
|
121
|
+
required: false,
|
|
122
|
+
type: Boolean,
|
|
123
|
+
default: false
|
|
124
|
+
},
|
|
125
|
+
groupKey: {
|
|
126
|
+
key: "groupKey",
|
|
127
|
+
required: false,
|
|
128
|
+
type: String,
|
|
129
|
+
default: ""
|
|
130
|
+
},
|
|
131
|
+
groupLabels: {
|
|
132
|
+
key: "groupLabels",
|
|
133
|
+
required: false,
|
|
134
|
+
type: Object,
|
|
135
|
+
default: () => ({})
|
|
118
136
|
}
|
|
119
137
|
};
|
|
120
138
|
__sfc_main.setup = (__props, __ctx) => {
|
|
@@ -142,6 +160,33 @@ __sfc_main.setup = (__props, __ctx) => {
|
|
|
142
160
|
return item;
|
|
143
161
|
});
|
|
144
162
|
});
|
|
163
|
+
const groupedList = computed(() => {
|
|
164
|
+
const filteredList = keyword.value ? allList.value.filter((item) => item[props.valueAlias].includes(keyword.value)) : allList.value;
|
|
165
|
+
const items = filteredList.map((item) => {
|
|
166
|
+
if (!item[props.keyAlias]) {
|
|
167
|
+
item[props.keyAlias] = generateUUID();
|
|
168
|
+
}
|
|
169
|
+
return item;
|
|
170
|
+
});
|
|
171
|
+
const groupMap = /* @__PURE__ */ new Map();
|
|
172
|
+
items.forEach((item) => {
|
|
173
|
+
const groupValue = String(item[props.groupKey] ?? "default");
|
|
174
|
+
const list2 = groupMap.get(groupValue);
|
|
175
|
+
list2 ? list2.push(item) : groupMap.set(groupValue, [item]);
|
|
176
|
+
});
|
|
177
|
+
const result = [];
|
|
178
|
+
groupMap.forEach((groupItems, groupValue) => {
|
|
179
|
+
result.push({
|
|
180
|
+
type: groupValue,
|
|
181
|
+
label: props.groupLabels[groupValue] ?? groupValue,
|
|
182
|
+
list: groupItems
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
return result;
|
|
186
|
+
});
|
|
187
|
+
const hasGroupData = computed(() => {
|
|
188
|
+
return groupedList.value.some((group) => group.list && group.list.length > 0);
|
|
189
|
+
});
|
|
145
190
|
watch(() => {
|
|
146
191
|
return props.data;
|
|
147
192
|
}, () => {
|
|
@@ -164,6 +209,8 @@ __sfc_main.setup = (__props, __ctx) => {
|
|
|
164
209
|
return {
|
|
165
210
|
keyword,
|
|
166
211
|
list,
|
|
212
|
+
groupedList,
|
|
213
|
+
hasGroupData,
|
|
167
214
|
handleItem,
|
|
168
215
|
popHideHandle
|
|
169
216
|
};
|
|
@@ -222,7 +269,34 @@ var _sfc_render = function render() {
|
|
|
222
269
|
},
|
|
223
270
|
expression: "keyword"
|
|
224
271
|
}
|
|
225
|
-
})], 1), _c("div", {
|
|
272
|
+
})], 1), _vm.groupable ? _c("div", {
|
|
273
|
+
staticClass: "nf-variable-select-variate"
|
|
274
|
+
}, [_vm.hasGroupData ? _vm._l(_vm.groupedList, function(group) {
|
|
275
|
+
return _c("div", {
|
|
276
|
+
key: group.type,
|
|
277
|
+
staticClass: "nf-variable-select-group"
|
|
278
|
+
}, [_c("div", {
|
|
279
|
+
staticClass: "nf-variable-select-group-header"
|
|
280
|
+
}, [_c("span", {
|
|
281
|
+
staticClass: "nf-variable-select-group-indicator"
|
|
282
|
+
}), _c("span", {
|
|
283
|
+
staticClass: "nf-variable-select-group-label"
|
|
284
|
+
}, [_vm._v(_vm._s(group.label))])]), _c("div", {
|
|
285
|
+
staticClass: "nf-variable-select-group-content"
|
|
286
|
+
}, _vm._l(group.list, function(item) {
|
|
287
|
+
return _c("div", {
|
|
288
|
+
key: item[_vm.keyAlias],
|
|
289
|
+
staticClass: "nf-variable-select-variate-item",
|
|
290
|
+
on: {
|
|
291
|
+
"click": function($event) {
|
|
292
|
+
return _vm.handleItem(item);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}, [_vm._v(_vm._s(item[_vm.valueAlias]))]);
|
|
296
|
+
}), 0)]);
|
|
297
|
+
}) : _c("div", {
|
|
298
|
+
staticClass: "nf-variable-select-nothing"
|
|
299
|
+
}, [_vm._v(_vm._s(_vm.noMatchDesc))])], 2) : _c("div", {
|
|
226
300
|
staticClass: "nf-variable-select-variate"
|
|
227
301
|
}, [_vm._l(_vm.list, function(item) {
|
|
228
302
|
return _c("div", {
|
|
@@ -18,6 +18,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
|
|
|
18
18
|
closeDelay?: number | undefined;
|
|
19
19
|
tabindex?: number | undefined;
|
|
20
20
|
size?: "small" | "mini" | "medium" | undefined;
|
|
21
|
+
groupable?: boolean | undefined;
|
|
22
|
+
groupKey?: string | undefined;
|
|
23
|
+
groupLabels?: Record<string, string> | undefined;
|
|
21
24
|
}>, {
|
|
22
25
|
noMatchDesc: string;
|
|
23
26
|
placeholder: string;
|
|
@@ -40,6 +43,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
|
|
|
40
43
|
closeDelay: number;
|
|
41
44
|
tabindex: number;
|
|
42
45
|
size: string;
|
|
46
|
+
groupable: boolean;
|
|
47
|
+
groupKey: string;
|
|
48
|
+
groupLabels: () => {};
|
|
43
49
|
}>, {}, {}, {}, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {
|
|
44
50
|
"variate-click": (event: VariableItem) => void;
|
|
45
51
|
hidden: () => void;
|
|
@@ -65,6 +71,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
|
|
|
65
71
|
closeDelay?: number | undefined;
|
|
66
72
|
tabindex?: number | undefined;
|
|
67
73
|
size?: "small" | "mini" | "medium" | undefined;
|
|
74
|
+
groupable?: boolean | undefined;
|
|
75
|
+
groupKey?: string | undefined;
|
|
76
|
+
groupLabels?: Record<string, string> | undefined;
|
|
68
77
|
}>, {
|
|
69
78
|
noMatchDesc: string;
|
|
70
79
|
placeholder: string;
|
|
@@ -87,6 +96,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
|
|
|
87
96
|
closeDelay: number;
|
|
88
97
|
tabindex: number;
|
|
89
98
|
size: string;
|
|
99
|
+
groupable: boolean;
|
|
100
|
+
groupKey: string;
|
|
101
|
+
groupLabels: () => {};
|
|
90
102
|
}>>>, {
|
|
91
103
|
offset: number;
|
|
92
104
|
transition: string;
|
|
@@ -106,6 +118,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
|
|
|
106
118
|
closeDelay: number;
|
|
107
119
|
tabindex: number;
|
|
108
120
|
size: "mini" | "medium" | "small";
|
|
121
|
+
groupable: boolean;
|
|
122
|
+
groupKey: string;
|
|
123
|
+
groupLabels: Record<string, string>;
|
|
109
124
|
}>, {
|
|
110
125
|
default?(_: {}): any;
|
|
111
126
|
}>;
|
package/lib/types.d.ts
CHANGED
|
@@ -25,7 +25,30 @@
|
|
|
25
25
|
<div class="nf-variable-select-search">
|
|
26
26
|
<el-input v-model="keyword" prefix-icon="el-icon-search" :placeholder="placeholder" :size="size"/>
|
|
27
27
|
</div>
|
|
28
|
-
<div class="nf-variable-select-variate">
|
|
28
|
+
<div v-if="groupable" class="nf-variable-select-variate">
|
|
29
|
+
<template v-if="hasGroupData">
|
|
30
|
+
<div
|
|
31
|
+
v-for="group in groupedList"
|
|
32
|
+
:key="group.type"
|
|
33
|
+
class="nf-variable-select-group"
|
|
34
|
+
>
|
|
35
|
+
<div class="nf-variable-select-group-header">
|
|
36
|
+
<span class="nf-variable-select-group-indicator" />
|
|
37
|
+
<span class="nf-variable-select-group-label">{{ group.label }}</span>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="nf-variable-select-group-content">
|
|
40
|
+
<div
|
|
41
|
+
v-for="item in group.list"
|
|
42
|
+
:key="item[keyAlias]"
|
|
43
|
+
class="nf-variable-select-variate-item"
|
|
44
|
+
@click="handleItem(item)"
|
|
45
|
+
>{{ item[valueAlias] }}</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</template>
|
|
49
|
+
<div v-else class="nf-variable-select-nothing">{{ noMatchDesc }}</div>
|
|
50
|
+
</div>
|
|
51
|
+
<div v-else class="nf-variable-select-variate">
|
|
29
52
|
<div v-for="item in list" :key="item[keyAlias]" class="nf-variable-select-variate-item" @click="handleItem(item)">{{ item[valueAlias] }}</div>
|
|
30
53
|
<div v-if="!list || !list.length" class="nf-variable-select-nothing">{{ noMatchDesc }}</div>
|
|
31
54
|
</div>
|
|
@@ -48,7 +71,7 @@ import {
|
|
|
48
71
|
ref,
|
|
49
72
|
watch
|
|
50
73
|
} from 'vue-demi'
|
|
51
|
-
import { VariableItem } from './types'
|
|
74
|
+
import { VariableItem, GroupItem } from './types'
|
|
52
75
|
import {
|
|
53
76
|
generateUUID
|
|
54
77
|
} from '@94ai/common-utils'
|
|
@@ -72,6 +95,9 @@ const props = withDefaults(defineProps<{
|
|
|
72
95
|
closeDelay?: number
|
|
73
96
|
tabindex?: number
|
|
74
97
|
size?: "mini" | "medium" | "small"
|
|
98
|
+
groupable?: boolean
|
|
99
|
+
groupKey?: string
|
|
100
|
+
groupLabels?: Record<string, string>
|
|
75
101
|
}>(), {
|
|
76
102
|
noMatchDesc: '无匹配数据',
|
|
77
103
|
placeholder: '输入变量名搜索',
|
|
@@ -90,7 +116,10 @@ const props = withDefaults(defineProps<{
|
|
|
90
116
|
openDelay: undefined,
|
|
91
117
|
closeDelay: 200,
|
|
92
118
|
tabindex: 0,
|
|
93
|
-
size: 'mini'
|
|
119
|
+
size: 'mini',
|
|
120
|
+
groupable: false,
|
|
121
|
+
groupKey: '',
|
|
122
|
+
groupLabels: () => ({})
|
|
94
123
|
})
|
|
95
124
|
const emit = defineEmits<{
|
|
96
125
|
(e: 'variate-click', event: VariableItem): void
|
|
@@ -124,6 +153,48 @@ const list = computed(() => {
|
|
|
124
153
|
})
|
|
125
154
|
})
|
|
126
155
|
|
|
156
|
+
const groupedList = computed<GroupItem[]>(() => {
|
|
157
|
+
// 根据搜索关键词过滤,无关键词则展示全部
|
|
158
|
+
const filteredList = keyword.value
|
|
159
|
+
? allList.value.filter(item => item[props.valueAlias].includes(keyword.value))
|
|
160
|
+
: allList.value
|
|
161
|
+
|
|
162
|
+
// 确保每条数据都有唯一标识(keyAlias),缺失则自动生成 UUID
|
|
163
|
+
const items = filteredList.map(item => {
|
|
164
|
+
if (!item[props.keyAlias]) {
|
|
165
|
+
item[props.keyAlias] = generateUUID()
|
|
166
|
+
}
|
|
167
|
+
return item
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
// 按 groupKey 字段值进行分组,值相同的归入同一组
|
|
171
|
+
// 创建分组映射表:键为分组字段值,值为该组下的所有数据项
|
|
172
|
+
const groupMap = new Map<string, VariableItem[]>()
|
|
173
|
+
items.forEach(item => {
|
|
174
|
+
// 取出当前项的分组字段值,若该字段不存在则归入 'default' 组
|
|
175
|
+
const groupValue = String(item[props.groupKey] ?? 'default')
|
|
176
|
+
// 若该组已存在,直接将当前项追加到该组列表中
|
|
177
|
+
// 若该组不存在,先初始化该组并将当前项作为第一个元素
|
|
178
|
+
const list = groupMap.get(groupValue)
|
|
179
|
+
list ? list.push(item) : groupMap.set(groupValue, [item])
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
// 将分组 Map 转换为 GroupItem 数组,组名优先取 groupLabels 映射,无映射则直接用字段值
|
|
183
|
+
const result: GroupItem[] = []
|
|
184
|
+
groupMap.forEach((groupItems, groupValue) => {
|
|
185
|
+
result.push({
|
|
186
|
+
type: groupValue,
|
|
187
|
+
label: props.groupLabels[groupValue] ?? groupValue,
|
|
188
|
+
list: groupItems
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
return result
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const hasGroupData = computed(() => {
|
|
195
|
+
return groupedList.value.some(group => group.list && group.list.length > 0)
|
|
196
|
+
})
|
|
197
|
+
|
|
127
198
|
watch(() => {
|
|
128
199
|
return props.data
|
|
129
200
|
}, () => {
|
package/package/types.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@94ai/nf-variable-select",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.13",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "zoujiahe <zoujiahe@94ai.com>",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"url": "http://94ai.gitlab.com/ui/common-ui.git"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@94ai/common-utils": "^8.3.
|
|
18
|
-
"@94ai/nf-theme-chalk": "^8.3.
|
|
17
|
+
"@94ai/common-utils": "^8.3.13",
|
|
18
|
+
"@94ai/nf-theme-chalk": "^8.3.13",
|
|
19
19
|
"vue-demi": "^0.14.5"
|
|
20
20
|
},
|
|
21
21
|
"peerDependenciesMeta": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"types": "lib/index.d.ts",
|
|
32
32
|
"main": "lib/nf-variable-select.cjs.js",
|
|
33
33
|
"module": "lib/nf-variable-select.esm-bundler.js",
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "1011ddd40b3a78915c088c232b66540b9ea486dc"
|
|
35
35
|
}
|