@silver-formily/element-plus 4.0.1 → 4.0.2
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/esm/checkbox/index.d.ts +30 -30
- package/esm/color-picker/index.d.ts +6 -6
- package/esm/form-collapse/index.d.ts +3 -3
- package/esm/form-dialog/dialog-content.mjs +10 -12
- package/esm/form-dialog/dialog-content.mjs.map +1 -1
- package/esm/form-dialog/index.mjs +22 -26
- package/esm/form-dialog/index.mjs.map +1 -1
- package/esm/form-dialog/types.d.ts +0 -1
- package/esm/form-drawer/drawer-content.mjs +10 -12
- package/esm/form-drawer/drawer-content.mjs.map +1 -1
- package/esm/form-drawer/index.mjs +22 -26
- package/esm/form-drawer/index.mjs.map +1 -1
- package/esm/form-drawer/types.d.ts +0 -1
- package/esm/form-layout/form-layout.vue.d.ts +1 -1
- package/esm/radio/index.d.ts +33 -33
- package/esm/select/index.d.ts +14 -14
- package/esm/select-table/index.d.ts +1 -1
- package/esm/select-table/select-table.mjs +63 -29
- package/esm/select-table/select-table.mjs.map +1 -1
- package/esm/select-table/types.d.ts +1 -1
- package/esm/time-select/index.d.ts +16 -16
- package/esm/transfer/index.d.ts +21 -21
- package/package.json +4 -4
- package/esm/shared/url-change-listener.mjs +0 -50
- package/esm/shared/url-change-listener.mjs.map +0 -1
|
@@ -7,8 +7,8 @@ type __VLS_Slots = {} & {
|
|
|
7
7
|
default?: (props: typeof __VLS_11) => any;
|
|
8
8
|
};
|
|
9
9
|
declare const __VLS_base: _$vue.DefineComponent<IFormLayoutProps, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<IFormLayoutProps> & Readonly<{}>, {
|
|
10
|
-
size: "small" | "default" | "large";
|
|
11
10
|
layout: "vertical" | "horizontal" | "inline" | ("vertical" | "horizontal" | "inline")[];
|
|
11
|
+
size: "small" | "default" | "large";
|
|
12
12
|
tag: string;
|
|
13
13
|
colon: boolean;
|
|
14
14
|
labelWrap: boolean;
|
package/esm/radio/index.d.ts
CHANGED
|
@@ -248,18 +248,14 @@ declare const Radio: {
|
|
|
248
248
|
});
|
|
249
249
|
RadioGroup: {
|
|
250
250
|
new (...args: any[]): _$vue.CreateComponentPublicInstanceWithMixins<Readonly<_$vue.ExtractPropTypes<{
|
|
251
|
-
props: {
|
|
252
|
-
type: _$vue.PropType<_$element_plus0.radioOptionProp>;
|
|
253
|
-
default: () => Required<_$element_plus0.radioOptionProp>;
|
|
254
|
-
};
|
|
255
|
-
fill: {
|
|
256
|
-
type: _$vue.PropType<string>;
|
|
257
|
-
default: "";
|
|
258
|
-
};
|
|
259
251
|
modelValue: {
|
|
260
252
|
type: _$vue.PropType<string | number | boolean>;
|
|
261
253
|
default: undefined;
|
|
262
254
|
};
|
|
255
|
+
props: {
|
|
256
|
+
type: _$vue.PropType<_$element_plus0.radioOptionProp>;
|
|
257
|
+
default: () => Required<_$element_plus0.radioOptionProp>;
|
|
258
|
+
};
|
|
263
259
|
type: {
|
|
264
260
|
type: _$vue.PropType<"button" | "radio">;
|
|
265
261
|
default: "radio";
|
|
@@ -268,16 +264,20 @@ declare const Radio: {
|
|
|
268
264
|
type: _$vue.PropType<string>;
|
|
269
265
|
default: undefined;
|
|
270
266
|
};
|
|
267
|
+
fill: {
|
|
268
|
+
type: _$vue.PropType<string>;
|
|
269
|
+
default: "";
|
|
270
|
+
};
|
|
271
271
|
disabled: {
|
|
272
272
|
type: _$vue.PropType<boolean>;
|
|
273
273
|
default: undefined;
|
|
274
274
|
};
|
|
275
|
-
options: {
|
|
276
|
-
type: _$vue.PropType<_$element_plus0.radioOption[]>;
|
|
277
|
-
};
|
|
278
275
|
size: {
|
|
279
276
|
type: _$vue.PropType<"" | "default" | "small" | "large">;
|
|
280
277
|
};
|
|
278
|
+
options: {
|
|
279
|
+
type: _$vue.PropType<_$element_plus0.radioOption[]>;
|
|
280
|
+
};
|
|
281
281
|
validateEvent: {
|
|
282
282
|
type: _$vue.PropType<boolean>;
|
|
283
283
|
default: true;
|
|
@@ -317,18 +317,14 @@ declare const Radio: {
|
|
|
317
317
|
M: {};
|
|
318
318
|
Defaults: {};
|
|
319
319
|
}, Readonly<_$vue.ExtractPropTypes<{
|
|
320
|
-
props: {
|
|
321
|
-
type: _$vue.PropType<_$element_plus0.radioOptionProp>;
|
|
322
|
-
default: () => Required<_$element_plus0.radioOptionProp>;
|
|
323
|
-
};
|
|
324
|
-
fill: {
|
|
325
|
-
type: _$vue.PropType<string>;
|
|
326
|
-
default: "";
|
|
327
|
-
};
|
|
328
320
|
modelValue: {
|
|
329
321
|
type: _$vue.PropType<string | number | boolean>;
|
|
330
322
|
default: undefined;
|
|
331
323
|
};
|
|
324
|
+
props: {
|
|
325
|
+
type: _$vue.PropType<_$element_plus0.radioOptionProp>;
|
|
326
|
+
default: () => Required<_$element_plus0.radioOptionProp>;
|
|
327
|
+
};
|
|
332
328
|
type: {
|
|
333
329
|
type: _$vue.PropType<"button" | "radio">;
|
|
334
330
|
default: "radio";
|
|
@@ -337,16 +333,20 @@ declare const Radio: {
|
|
|
337
333
|
type: _$vue.PropType<string>;
|
|
338
334
|
default: undefined;
|
|
339
335
|
};
|
|
336
|
+
fill: {
|
|
337
|
+
type: _$vue.PropType<string>;
|
|
338
|
+
default: "";
|
|
339
|
+
};
|
|
340
340
|
disabled: {
|
|
341
341
|
type: _$vue.PropType<boolean>;
|
|
342
342
|
default: undefined;
|
|
343
343
|
};
|
|
344
|
-
options: {
|
|
345
|
-
type: _$vue.PropType<_$element_plus0.radioOption[]>;
|
|
346
|
-
};
|
|
347
344
|
size: {
|
|
348
345
|
type: _$vue.PropType<"" | "default" | "small" | "large">;
|
|
349
346
|
};
|
|
347
|
+
options: {
|
|
348
|
+
type: _$vue.PropType<_$element_plus0.radioOption[]>;
|
|
349
|
+
};
|
|
350
350
|
validateEvent: {
|
|
351
351
|
type: _$vue.PropType<boolean>;
|
|
352
352
|
default: true;
|
|
@@ -380,18 +380,14 @@ declare const Radio: {
|
|
|
380
380
|
__isTeleport?: never;
|
|
381
381
|
__isSuspense?: never;
|
|
382
382
|
} & _$vue.ComponentOptionsBase<Readonly<_$vue.ExtractPropTypes<{
|
|
383
|
-
props: {
|
|
384
|
-
type: _$vue.PropType<_$element_plus0.radioOptionProp>;
|
|
385
|
-
default: () => Required<_$element_plus0.radioOptionProp>;
|
|
386
|
-
};
|
|
387
|
-
fill: {
|
|
388
|
-
type: _$vue.PropType<string>;
|
|
389
|
-
default: "";
|
|
390
|
-
};
|
|
391
383
|
modelValue: {
|
|
392
384
|
type: _$vue.PropType<string | number | boolean>;
|
|
393
385
|
default: undefined;
|
|
394
386
|
};
|
|
387
|
+
props: {
|
|
388
|
+
type: _$vue.PropType<_$element_plus0.radioOptionProp>;
|
|
389
|
+
default: () => Required<_$element_plus0.radioOptionProp>;
|
|
390
|
+
};
|
|
395
391
|
type: {
|
|
396
392
|
type: _$vue.PropType<"button" | "radio">;
|
|
397
393
|
default: "radio";
|
|
@@ -400,16 +396,20 @@ declare const Radio: {
|
|
|
400
396
|
type: _$vue.PropType<string>;
|
|
401
397
|
default: undefined;
|
|
402
398
|
};
|
|
399
|
+
fill: {
|
|
400
|
+
type: _$vue.PropType<string>;
|
|
401
|
+
default: "";
|
|
402
|
+
};
|
|
403
403
|
disabled: {
|
|
404
404
|
type: _$vue.PropType<boolean>;
|
|
405
405
|
default: undefined;
|
|
406
406
|
};
|
|
407
|
-
options: {
|
|
408
|
-
type: _$vue.PropType<_$element_plus0.radioOption[]>;
|
|
409
|
-
};
|
|
410
407
|
size: {
|
|
411
408
|
type: _$vue.PropType<"" | "default" | "small" | "large">;
|
|
412
409
|
};
|
|
410
|
+
options: {
|
|
411
|
+
type: _$vue.PropType<_$element_plus0.radioOption[]>;
|
|
412
|
+
};
|
|
413
413
|
validateEvent: {
|
|
414
414
|
type: _$vue.PropType<boolean>;
|
|
415
415
|
default: true;
|
package/esm/select/index.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ declare const Select: {
|
|
|
8
8
|
disabled: boolean;
|
|
9
9
|
created: boolean;
|
|
10
10
|
}> & Omit<{
|
|
11
|
-
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
11
|
+
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(BooleanConstructor | ObjectConstructor | StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
12
12
|
readonly disabled: boolean;
|
|
13
13
|
readonly created: boolean;
|
|
14
|
-
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
14
|
+
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
15
15
|
} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps, "disabled" | "created">) | (Partial<{
|
|
16
16
|
disabled: boolean;
|
|
17
17
|
}> & Omit<{
|
|
@@ -22,10 +22,10 @@ declare const Select: {
|
|
|
22
22
|
disabled: boolean;
|
|
23
23
|
created: boolean;
|
|
24
24
|
}> & Omit<{
|
|
25
|
-
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
25
|
+
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(BooleanConstructor | ObjectConstructor | StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
26
26
|
readonly disabled: boolean;
|
|
27
27
|
readonly created: boolean;
|
|
28
|
-
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
28
|
+
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
29
29
|
} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps, "disabled" | "created">)[];
|
|
30
30
|
})>;
|
|
31
31
|
}> & Readonly<{}>, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, _$vue.PublicProps, {}, true, {}, {}, _$vue.GlobalComponents, _$vue.GlobalDirectives, string, {}, any, _$vue.ComponentProvideOptions, {
|
|
@@ -40,10 +40,10 @@ declare const Select: {
|
|
|
40
40
|
disabled: boolean;
|
|
41
41
|
created: boolean;
|
|
42
42
|
}> & Omit<{
|
|
43
|
-
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
43
|
+
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(BooleanConstructor | ObjectConstructor | StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
44
44
|
readonly disabled: boolean;
|
|
45
45
|
readonly created: boolean;
|
|
46
|
-
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
46
|
+
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
47
47
|
} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps, "disabled" | "created">) | (Partial<{
|
|
48
48
|
disabled: boolean;
|
|
49
49
|
}> & Omit<{
|
|
@@ -54,10 +54,10 @@ declare const Select: {
|
|
|
54
54
|
disabled: boolean;
|
|
55
55
|
created: boolean;
|
|
56
56
|
}> & Omit<{
|
|
57
|
-
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
57
|
+
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(BooleanConstructor | ObjectConstructor | StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
58
58
|
readonly disabled: boolean;
|
|
59
59
|
readonly created: boolean;
|
|
60
|
-
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
60
|
+
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
61
61
|
} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps, "disabled" | "created">)[];
|
|
62
62
|
})>;
|
|
63
63
|
}> & Readonly<{}>, {}, {}, {}, {}, {}>;
|
|
@@ -69,10 +69,10 @@ declare const Select: {
|
|
|
69
69
|
disabled: boolean;
|
|
70
70
|
created: boolean;
|
|
71
71
|
}> & Omit<{
|
|
72
|
-
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
72
|
+
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(BooleanConstructor | ObjectConstructor | StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
73
73
|
readonly disabled: boolean;
|
|
74
74
|
readonly created: boolean;
|
|
75
|
-
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
75
|
+
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
76
76
|
} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps, "disabled" | "created">) | (Partial<{
|
|
77
77
|
disabled: boolean;
|
|
78
78
|
}> & Omit<{
|
|
@@ -83,10 +83,10 @@ declare const Select: {
|
|
|
83
83
|
disabled: boolean;
|
|
84
84
|
created: boolean;
|
|
85
85
|
}> & Omit<{
|
|
86
|
-
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
86
|
+
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(BooleanConstructor | ObjectConstructor | StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
87
87
|
readonly disabled: boolean;
|
|
88
88
|
readonly created: boolean;
|
|
89
|
-
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
89
|
+
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
90
90
|
} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps, "disabled" | "created">)[];
|
|
91
91
|
})>;
|
|
92
92
|
}> & Readonly<{}>, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, {}, {}, string, {}, _$vue.GlobalComponents, _$vue.GlobalDirectives, string, _$vue.ComponentProvideOptions> & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps & (new () => {
|
|
@@ -96,10 +96,10 @@ declare const Select: {
|
|
|
96
96
|
disabled: boolean;
|
|
97
97
|
created: boolean;
|
|
98
98
|
}> & Omit<{
|
|
99
|
-
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
99
|
+
readonly value: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(BooleanConstructor | ObjectConstructor | StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
100
100
|
readonly disabled: boolean;
|
|
101
101
|
readonly created: boolean;
|
|
102
|
-
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(
|
|
102
|
+
readonly label?: _$element_plus_es_utils_index_mjs0.EpPropMergeType<(StringConstructor | NumberConstructor)[], unknown, unknown>;
|
|
103
103
|
} & _$vue.VNodeProps & _$vue.AllowedComponentProps & _$vue.ComponentCustomProps, "disabled" | "created">;
|
|
104
104
|
}) => any;
|
|
105
105
|
header?: () => any;
|
|
@@ -18,7 +18,7 @@ declare const SelectTable: {
|
|
|
18
18
|
clickRowToSelect: boolean;
|
|
19
19
|
showAlertToolbar: boolean;
|
|
20
20
|
ignoreSelectable: boolean;
|
|
21
|
-
},
|
|
21
|
+
}, false, {}, {}, _$vue.GlobalComponents, _$vue.GlobalDirectives, string, {}, any, _$vue.ComponentProvideOptions, {
|
|
22
22
|
P: {};
|
|
23
23
|
B: {};
|
|
24
24
|
D: {};
|
|
@@ -46,57 +46,90 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
46
46
|
const emit = __emit;
|
|
47
47
|
const elTableProps = useAttrs();
|
|
48
48
|
const field = useField();
|
|
49
|
+
const elTableRef = ref();
|
|
50
|
+
const radioSelectedKey = ref();
|
|
51
|
+
function requireRowKey() {
|
|
52
|
+
if (!props.rowKey) throw new Error("rowKey is required");
|
|
53
|
+
return props.rowKey;
|
|
54
|
+
}
|
|
55
|
+
function getRowValue(item) {
|
|
56
|
+
if (!props.rowKey || !item) return;
|
|
57
|
+
return item[props.rowKey];
|
|
58
|
+
}
|
|
59
|
+
function getSingleSelectedKey(value) {
|
|
60
|
+
if (!isValid(value)) return null;
|
|
61
|
+
return props.optionAsValue ? getRowValue(value) ?? null : value;
|
|
62
|
+
}
|
|
63
|
+
function getMultipleSelectedKeys(value) {
|
|
64
|
+
if (!Array.isArray(value)) return [];
|
|
65
|
+
return value.map((item) => props.optionAsValue ? getRowValue(item) : item).filter(isValid);
|
|
66
|
+
}
|
|
67
|
+
function syncRadioSelection(item) {
|
|
68
|
+
radioSelectedKey.value = getRowValue(item) ?? null;
|
|
69
|
+
elTableRef.value?.setCurrentRow(item);
|
|
70
|
+
}
|
|
49
71
|
function compatibleRadioValue(key) {
|
|
50
72
|
return lt(version, "2.6.0") ? { label: key } : { value: key };
|
|
51
73
|
}
|
|
52
|
-
const elTableRef = ref();
|
|
53
|
-
const rowKey = props.rowKey;
|
|
54
74
|
function getInitialSelectedList() {
|
|
55
|
-
if (props.
|
|
56
|
-
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
75
|
+
if (!isValid(props.modelValue)) return [];
|
|
76
|
+
if (props.mode === "multiple") {
|
|
77
|
+
if (!Array.isArray(props.modelValue)) return [];
|
|
78
|
+
return props.modelValue.map((item) => {
|
|
79
|
+
if (!props.optionAsValue) {
|
|
80
|
+
if (!props.rowKey) return null;
|
|
81
|
+
return { [props.rowKey]: item };
|
|
82
|
+
}
|
|
83
|
+
return item;
|
|
84
|
+
}).filter(isValid);
|
|
85
|
+
} else {
|
|
86
|
+
if (props.optionAsValue) return [props.modelValue];
|
|
87
|
+
if (!props.rowKey) return [];
|
|
88
|
+
return [{ [props.rowKey]: props.modelValue }];
|
|
89
|
+
}
|
|
60
90
|
}
|
|
61
91
|
const selectedFlatDataSource = ref(getInitialSelectedList());
|
|
62
92
|
let prevSelection = [];
|
|
63
|
-
const radioSelectedKey = ref();
|
|
64
93
|
const currentSelectLength = computed(() => {
|
|
65
94
|
if (props.mode === "multiple") return Array.isArray(props.modelValue) ? props.modelValue.length : 0;
|
|
66
95
|
else return isValid(radioSelectedKey.value) ? 1 : 0;
|
|
67
96
|
});
|
|
68
97
|
watch(() => props.dataSource, async () => {
|
|
69
|
-
const selectedKeys = uniq(selectedFlatDataSource.value.map((item) => item
|
|
98
|
+
const selectedKeys = uniq(selectedFlatDataSource.value.map((item) => getRowValue(item)).filter(isValid));
|
|
70
99
|
await nextTick();
|
|
71
100
|
for (const item of props.dataSource) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
onRadioClick(item);
|
|
76
|
-
}
|
|
101
|
+
const itemKey = getRowValue(item);
|
|
102
|
+
if (isValid(itemKey) && selectedKeys.includes(itemKey)) if (props.mode === "multiple") elTableRef.value?.toggleRowSelection(item, true, props.ignoreSelectable);
|
|
103
|
+
else syncRadioSelection(item);
|
|
77
104
|
await nextTick();
|
|
78
|
-
prevSelection = elTableRef.value?.getSelectionRows();
|
|
105
|
+
prevSelection = elTableRef.value?.getSelectionRows() ?? [];
|
|
79
106
|
}
|
|
80
107
|
}, { immediate: true });
|
|
81
108
|
watch(() => [props.modelValue, props.loading], async ([value, loading]) => {
|
|
82
109
|
if (loading) return;
|
|
83
|
-
if (props.mode === "single")
|
|
84
|
-
|
|
110
|
+
if (props.mode === "single") {
|
|
111
|
+
const selectedKey = getSingleSelectedKey(value);
|
|
112
|
+
radioSelectedKey.value = selectedKey;
|
|
113
|
+
const selectedItem = props.dataSource.find((item) => getRowValue(item) === selectedKey);
|
|
114
|
+
elTableRef.value?.setCurrentRow(selectedItem);
|
|
115
|
+
} else {
|
|
85
116
|
await nextTick();
|
|
86
|
-
const currentDisplayDataKeys = elTableRef.value?.getSelectionRows().map((item) => item[
|
|
87
|
-
const valueKeys =
|
|
88
|
-
selectedFlatDataSource.value = selectedFlatDataSource.value.filter((item) => valueKeys.includes(item
|
|
117
|
+
const currentDisplayDataKeys = elTableRef.value?.getSelectionRows().map((item) => getRowValue(item)).filter(isValid) ?? [];
|
|
118
|
+
const valueKeys = getMultipleSelectedKeys(value);
|
|
119
|
+
selectedFlatDataSource.value = selectedFlatDataSource.value.filter((item) => valueKeys.includes(getRowValue(item)));
|
|
89
120
|
if (isEqual(valueKeys, currentDisplayDataKeys)) return;
|
|
90
121
|
const diffItems = xor(valueKeys, currentDisplayDataKeys);
|
|
91
|
-
for (const tableItem of props.dataSource)
|
|
92
|
-
const
|
|
93
|
-
|
|
122
|
+
for (const tableItem of props.dataSource) {
|
|
123
|
+
const itemKey = getRowValue(tableItem);
|
|
124
|
+
if (isValid(itemKey) && diffItems.includes(itemKey)) {
|
|
125
|
+
const shouldSelect = valueKeys.includes(itemKey);
|
|
126
|
+
elTableRef.value?.toggleRowSelection(tableItem, shouldSelect, props.ignoreSelectable);
|
|
127
|
+
}
|
|
94
128
|
}
|
|
95
129
|
}
|
|
96
130
|
}, { immediate: true });
|
|
97
131
|
function onSelect(newSelection) {
|
|
98
|
-
|
|
99
|
-
if (!rowKey) throw new Error("rowKey is required");
|
|
132
|
+
const rowKey = requireRowKey();
|
|
100
133
|
const removedItemList = prevSelection.length > newSelection.length ? differenceWith(prevSelection, newSelection, (itemPrev, itemNext) => {
|
|
101
134
|
return itemPrev[rowKey] === itemNext[rowKey];
|
|
102
135
|
}) : [];
|
|
@@ -112,7 +145,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
112
145
|
else emit("update:modelValue", selectedFlatDataSource.value.map((item) => item[rowKey]));
|
|
113
146
|
}
|
|
114
147
|
function onRadioClick(item) {
|
|
115
|
-
|
|
148
|
+
const rowKey = requireRowKey();
|
|
149
|
+
syncRadioSelection(item);
|
|
116
150
|
if (props.optionAsValue) emit("update:modelValue", item);
|
|
117
151
|
else emit("update:modelValue", item[rowKey]);
|
|
118
152
|
}
|
|
@@ -131,7 +165,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
131
165
|
emit("update:modelValue", []);
|
|
132
166
|
selectedFlatDataSource.value = [];
|
|
133
167
|
} else {
|
|
134
|
-
|
|
168
|
+
syncRadioSelection(null);
|
|
135
169
|
emit("update:modelValue", null);
|
|
136
170
|
}
|
|
137
171
|
}
|
|
@@ -155,7 +189,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
155
189
|
ref_key: "elTableRef",
|
|
156
190
|
ref: elTableRef
|
|
157
191
|
}, unref(elTableProps), {
|
|
158
|
-
"row-key":
|
|
192
|
+
"row-key": __props.rowKey,
|
|
159
193
|
"row-class-name": props.clickRowToSelect ? `--click-row-select` : "",
|
|
160
194
|
data: props.dataSource,
|
|
161
195
|
"highlight-current-row": props.mode === "single",
|
|
@@ -176,7 +210,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
176
210
|
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => radioSelectedKey.value = $event),
|
|
177
211
|
style: { "width": "100%" }
|
|
178
212
|
}, {
|
|
179
|
-
default: withCtx(() => [createVNode(unref(ElRadio), mergeProps(compatibleRadioValue(row[
|
|
213
|
+
default: withCtx(() => [createVNode(unref(ElRadio), mergeProps(compatibleRadioValue(row[__props.rowKey]), { onChange: () => onRadioClick(row) }), {
|
|
180
214
|
default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode(" \xA0 ", -1)])]),
|
|
181
215
|
_: 1
|
|
182
216
|
}, 16, ["onChange"])]),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-table.mjs","names":[],"sources":["../../src/select-table/select-table.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport type { TableInstance } from 'element-plus'\nimport type { ISelectTableProps } from './types'\nimport { isEqual, isFn, isValid } from '@formily/shared'\nimport { useField } from '@silver-formily/vue'\nimport {\n ElLink,\n ElRadio,\n ElRadioGroup,\n ElTable,\n ElTableColumn,\n useAttrs,\n version,\n vLoading,\n} from 'element-plus'\nimport { differenceWith, remove, uniq, uniqWith, xor } from 'lodash-es'\nimport { computed, nextTick, ref, watch } from 'vue'\nimport { lt, stylePrefix } from '../__builtins__'\n\ndefineOptions({\n name: 'FSelectTable',\n inheritAttrs: false,\n})\n\nconst props = withDefaults(defineProps<ISelectTableProps>(), {\n columns: () => [],\n mode: 'multiple',\n dataSource: () => [],\n optionAsValue: false,\n valueType: 'all',\n loading: false,\n clickRowToSelect: true,\n showAlertToolbar: true,\n ignoreSelectable: true,\n})\n\nconst emit = defineEmits(['update:modelValue'])\n\nconst elTableProps = useAttrs()\nconst field = useField()\n\nfunction compatibleRadioValue(key: string) {\n return lt(version, '2.6.0') ? { label: key } : { value: key }\n}\n\nconst elTableRef = ref<TableInstance>()\nconst rowKey = props.rowKey\nfunction getInitialSelectedList() {\n if (props.mode === 'multiple') {\n return props.modelValue?.map((item) => {\n if (!props.optionAsValue) {\n return {\n [rowKey]: item,\n }\n }\n return item\n }) ?? []\n }\n else {\n return props.optionAsValue ? [props.modelValue] : [{ [rowKey]: props.modelValue }]\n }\n}\nconst initialSelectedList = getInitialSelectedList()\nconst selectedFlatDataSource = ref(initialSelectedList)\n// 为了获取移除的项而缓存的当前页面的前一次选择。由于element-plus没有获取移除项的方法,需要通过这种方式移除field中移除的项\nlet prevSelection = []\n\nconst radioSelectedKey = ref()\n\nconst currentSelectLength = computed(() => {\n if (props.mode === 'multiple') {\n return Array.isArray(props.modelValue) ? props.modelValue.length : 0\n }\n else {\n return isValid(radioSelectedKey.value) ? 1 : 0\n }\n})\n\nwatch(\n () => props.dataSource,\n async () => {\n const selectedKeys = uniq(\n selectedFlatDataSource.value.map(item => item[rowKey]),\n )\n await nextTick()\n for (const item of props.dataSource) {\n if (selectedKeys.includes(item[rowKey])) {\n if (props.mode === 'multiple') {\n elTableRef.value?.toggleRowSelection(item, true, props.ignoreSelectable)\n }\n else {\n elTableRef.value?.setCurrentRow(item)\n onRadioClick(item)\n }\n }\n await nextTick()\n prevSelection = elTableRef.value?.getSelectionRows()\n }\n },\n { immediate: true },\n)\n\nwatch(\n () => [props.modelValue, props.loading],\n async ([value, loading]) => {\n if (loading) {\n return\n }\n if (props.mode === 'single') {\n radioSelectedKey.value = props.optionAsValue ? value[rowKey] : value\n }\n else {\n await nextTick()\n const currentDisplayDataKeys = elTableRef.value\n ?.getSelectionRows()\n .map(item => item[rowKey])\n const valueKeys = props.optionAsValue\n ? value?.map(item => item[rowKey])\n : value ?? []\n selectedFlatDataSource.value = selectedFlatDataSource.value.filter(\n item => valueKeys.includes(item[rowKey]),\n )\n if (isEqual(valueKeys, currentDisplayDataKeys)) {\n return\n }\n const diffItems = xor(valueKeys, currentDisplayDataKeys)\n for (const tableItem of props.dataSource) {\n if (diffItems.includes(tableItem[rowKey])) {\n const shouldSelect = valueKeys.includes(tableItem[rowKey])\n elTableRef.value.toggleRowSelection(tableItem, shouldSelect, props.ignoreSelectable)\n }\n }\n }\n },\n {\n immediate: true,\n },\n)\n\nfunction onSelect(newSelection: Record<string, any>[]) {\n /* istanbul ignore if -- @preserve */\n if (!rowKey) {\n throw new Error('rowKey is required')\n }\n\n const removedItemList\n = prevSelection.length > newSelection.length\n ? differenceWith(\n prevSelection,\n newSelection,\n (itemPrev, itemNext) => {\n return itemPrev[rowKey] === itemNext[rowKey]\n },\n )\n : []\n prevSelection = [...newSelection]\n selectedFlatDataSource.value = uniqWith(\n [...selectedFlatDataSource.value, ...newSelection],\n (itemPrev, itemNext) => {\n return itemPrev[rowKey] === itemNext[rowKey]\n },\n )\n if (removedItemList.length > 0) {\n const removedKeys = uniq(removedItemList.map(item => item[rowKey]))\n remove(selectedFlatDataSource.value, item =>\n removedKeys.includes(item[rowKey]))\n }\n\n if (props.optionAsValue) {\n emit('update:modelValue', selectedFlatDataSource.value)\n }\n else {\n const selectedKeys = selectedFlatDataSource.value.map(\n item => item[rowKey],\n )\n emit('update:modelValue', selectedKeys)\n }\n}\n\nfunction onRadioClick(item) {\n radioSelectedKey.value = item[rowKey]\n if (props.optionAsValue) {\n emit('update:modelValue', item)\n }\n else {\n emit('update:modelValue', item[rowKey])\n }\n}\n\nfunction onRowClick(row: Record<string, any>, _, event: Event) {\n if (!props.clickRowToSelect)\n return\n\n if (props.mode === 'multiple') {\n const checkboxDOM = (event.target as Element)\n .closest('tr')\n .querySelector('input[type=\"checkbox\"]')\n if (checkboxDOM instanceof HTMLElement) {\n checkboxDOM.click()\n }\n }\n else {\n const radioDOM = (event.target as Element)\n .closest('tr')\n .querySelector('input[type=\"radio\"]')\n if (radioDOM instanceof HTMLElement) {\n radioDOM.click()\n }\n }\n}\n\nfunction onClearSelectionClick() {\n if (props.mode === 'multiple') {\n emit('update:modelValue', [])\n selectedFlatDataSource.value = []\n }\n else {\n radioSelectedKey.value = null\n emit('update:modelValue', null)\n }\n}\n\nfunction selectable(row: Record<string, any>, index: number) {\n if (props.selectable && isFn(props.selectable)) {\n return props.selectable(row, index, field.value)\n }\n return true\n}\n</script>\n\n<template>\n <div :class=\"`${stylePrefix}-select-table`\">\n <div\n v-if=\"currentSelectLength > 0 && props.showAlertToolbar\"\n :class=\"`${stylePrefix}-select-table-alert-container`\"\n >\n <span>已选择 {{ currentSelectLength }} 项</span>\n <ElLink\n type=\"primary\"\n :underline=\"lt(version, '2.9.9') ? false : 'never'\"\n style=\"margin-left: 8px;\"\n @click=\"onClearSelectionClick\"\n >\n 取消选择\n </ElLink>\n </div>\n <ElTable\n ref=\"elTableRef\"\n v-loading=\"props.loading\"\n v-bind=\"elTableProps\"\n :row-key=\"rowKey\"\n :row-class-name=\"props.clickRowToSelect ? `--click-row-select` : ''\"\n :data=\"props.dataSource\"\n :highlight-current-row=\"props.mode === 'single'\"\n @select=\"onSelect\"\n @select-all=\"onSelect\"\n @row-click=\"onRowClick\"\n >\n <ElTableColumn\n v-if=\"props.mode === 'multiple'\"\n type=\"selection\"\n :selectable=\"selectable\"\n />\n <ElTableColumn\n v-else\n width=\"46\"\n >\n <template #default=\"{ row }\">\n <ElRadioGroup v-model=\"radioSelectedKey\" style=\"width: 100%;\">\n <ElRadio\n v-bind=\"compatibleRadioValue(row[rowKey])\"\n @change=\"() => onRadioClick(row)\"\n >\n \n </ElRadio>\n </ElRadioGroup>\n </template>\n </ElTableColumn>\n <template v-if=\"props.columns.length === 0\">\n <slot />\n </template>\n <template v-else>\n <ElTableColumn\n v-for=\"colItem of props.columns\"\n v-bind=\"colItem\"\n :key=\"colItem.prop || colItem.type\"\n />\n </template>\n </ElTable>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwBA,MAAM,QAAQ;EAYd,MAAM,OAAO;EAEb,MAAM,eAAe,UAAS;EAC9B,MAAM,QAAQ,UAAS;EAEvB,SAAS,qBAAqB,KAAa;AACzC,UAAO,GAAG,SAAS,QAAQ,GAAG,EAAE,OAAO,KAAK,GAAG,EAAE,OAAO,KAAI;;EAG9D,MAAM,aAAa,KAAmB;EACtC,MAAM,SAAS,MAAM;EACrB,SAAS,yBAAyB;AAChC,OAAI,MAAM,SAAS,WACjB,QAAO,MAAM,YAAY,KAAK,SAAS;AACrC,QAAI,CAAC,MAAM,cACT,QAAO,GACJ,SAAS,MACZ;AAEF,WAAO;KACP,IAAI,EAAC;OAGP,QAAO,MAAM,gBAAgB,CAAC,MAAM,WAAW,GAAG,CAAC,GAAG,SAAS,MAAM,YAAY,CAAA;;EAIrF,MAAM,yBAAyB,IADH,wBAAuB,CACG;EAEtD,IAAI,gBAAgB,EAAC;EAErB,MAAM,mBAAmB,KAAI;EAE7B,MAAM,sBAAsB,eAAe;AACzC,OAAI,MAAM,SAAS,WACjB,QAAO,MAAM,QAAQ,MAAM,WAAW,GAAG,MAAM,WAAW,SAAS;OAGnE,QAAO,QAAQ,iBAAiB,MAAM,GAAG,IAAI;IAEhD;AAED,cACQ,MAAM,YACZ,YAAY;GACV,MAAM,eAAe,KACnB,uBAAuB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AA,WAAA,EAAA,KAAA,GAAA,CAAA,IAAA,UAAA,KAAA,EAGR,mBAIE,UAAA,EAAA,KAAA,GAAA,EAAA,WAHkB,MAAM,UAAjB,YAAO;yBADhB,YAIE,MAAA,cAAA,EAJF,WAIE,EAAA,SAAA,MAAA,EAFQ,SAAO,EACd,KAAK,QAAQ,QAAQ,QAAQ,MAAA,CAAA,EAAA,MAAA,GAAA;;;;;;;;2BArCvB,MAAM,QAAO,CAAA,CAAA,CAAA,EAAA,EAAA"}
|
|
1
|
+
{"version":3,"file":"select-table.mjs","names":[],"sources":["../../src/select-table/select-table.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport type { TableInstance } from 'element-plus'\nimport type { ISelectTableProps } from './types'\nimport { isEqual, isFn, isValid } from '@formily/shared'\nimport { useField } from '@silver-formily/vue'\nimport {\n ElLink,\n ElRadio,\n ElRadioGroup,\n ElTable,\n ElTableColumn,\n useAttrs,\n version,\n vLoading,\n} from 'element-plus'\nimport { differenceWith, remove, uniq, uniqWith, xor } from 'lodash-es'\nimport { computed, nextTick, ref, watch } from 'vue'\nimport { lt, stylePrefix } from '../__builtins__'\n\ndefineOptions({\n name: 'FSelectTable',\n inheritAttrs: false,\n})\n\nconst props = withDefaults(defineProps<ISelectTableProps>(), {\n columns: () => [],\n mode: 'multiple',\n dataSource: () => [],\n optionAsValue: false,\n valueType: 'all',\n loading: false,\n clickRowToSelect: true,\n showAlertToolbar: true,\n ignoreSelectable: true,\n})\n\nconst emit = defineEmits(['update:modelValue'])\n\nconst elTableProps = useAttrs()\nconst field = useField()\nconst elTableRef = ref<TableInstance>()\nconst radioSelectedKey = ref()\n\nfunction requireRowKey() {\n if (!props.rowKey) {\n throw new Error('rowKey is required')\n }\n return props.rowKey\n}\n\nfunction getRowValue(item?: Record<string, any> | null) {\n if (!props.rowKey || !item) {\n return undefined\n }\n return item[props.rowKey]\n}\n\nfunction getSingleSelectedKey(value: any) {\n if (!isValid(value)) {\n return null\n }\n return props.optionAsValue ? getRowValue(value) ?? null : value\n}\n\nfunction getMultipleSelectedKeys(value: any) {\n if (!Array.isArray(value)) {\n return []\n }\n return value\n .map(item => props.optionAsValue ? getRowValue(item) : item)\n .filter(isValid)\n}\n\nfunction syncRadioSelection(item?: Record<string, any> | null) {\n radioSelectedKey.value = getRowValue(item) ?? null\n elTableRef.value?.setCurrentRow(item)\n}\n\nfunction compatibleRadioValue(key: string) {\n return lt(version, '2.6.0') ? { label: key } : { value: key }\n}\n\nfunction getInitialSelectedList() {\n if (!isValid(props.modelValue)) {\n return []\n }\n\n if (props.mode === 'multiple') {\n if (!Array.isArray(props.modelValue)) {\n return []\n }\n\n return props.modelValue.map((item) => {\n if (!props.optionAsValue) {\n if (!props.rowKey) {\n return null\n }\n return {\n [props.rowKey]: item,\n }\n }\n return item\n }).filter(isValid)\n }\n else {\n if (props.optionAsValue) {\n return [props.modelValue]\n }\n if (!props.rowKey) {\n return []\n }\n return [{ [props.rowKey]: props.modelValue }]\n }\n}\nconst initialSelectedList = getInitialSelectedList()\nconst selectedFlatDataSource = ref(initialSelectedList)\n// 为了获取移除的项而缓存的当前页面的前一次选择。由于element-plus没有获取移除项的方法,需要通过这种方式移除field中移除的项\nlet prevSelection = []\n\nconst currentSelectLength = computed(() => {\n if (props.mode === 'multiple') {\n return Array.isArray(props.modelValue) ? props.modelValue.length : 0\n }\n else {\n return isValid(radioSelectedKey.value) ? 1 : 0\n }\n})\n\nwatch(\n () => props.dataSource,\n async () => {\n const selectedKeys = uniq(\n selectedFlatDataSource.value.map(item => getRowValue(item)).filter(isValid),\n )\n await nextTick()\n for (const item of props.dataSource) {\n const itemKey = getRowValue(item)\n if (isValid(itemKey) && selectedKeys.includes(itemKey)) {\n if (props.mode === 'multiple') {\n elTableRef.value?.toggleRowSelection(item, true, props.ignoreSelectable)\n }\n else {\n syncRadioSelection(item)\n }\n }\n await nextTick()\n prevSelection = elTableRef.value?.getSelectionRows() ?? []\n }\n },\n { immediate: true },\n)\n\nwatch(\n () => [props.modelValue, props.loading],\n async ([value, loading]) => {\n if (loading) {\n return\n }\n if (props.mode === 'single') {\n const selectedKey = getSingleSelectedKey(value)\n radioSelectedKey.value = selectedKey\n const selectedItem = props.dataSource.find(item => getRowValue(item) === selectedKey)\n elTableRef.value?.setCurrentRow(selectedItem)\n }\n else {\n await nextTick()\n const currentDisplayDataKeys = elTableRef.value\n ?.getSelectionRows()\n .map(item => getRowValue(item))\n .filter(isValid) ?? []\n const valueKeys = getMultipleSelectedKeys(value)\n selectedFlatDataSource.value = selectedFlatDataSource.value.filter(\n item => valueKeys.includes(getRowValue(item)),\n )\n if (isEqual(valueKeys, currentDisplayDataKeys)) {\n return\n }\n const diffItems = xor(valueKeys, currentDisplayDataKeys)\n for (const tableItem of props.dataSource) {\n const itemKey = getRowValue(tableItem)\n if (isValid(itemKey) && diffItems.includes(itemKey)) {\n const shouldSelect = valueKeys.includes(itemKey)\n elTableRef.value?.toggleRowSelection(tableItem, shouldSelect, props.ignoreSelectable)\n }\n }\n }\n },\n {\n immediate: true,\n },\n)\n\nfunction onSelect(newSelection: Record<string, any>[]) {\n const rowKey = requireRowKey()\n\n const removedItemList\n = prevSelection.length > newSelection.length\n ? differenceWith(\n prevSelection,\n newSelection,\n (itemPrev, itemNext) => {\n return itemPrev[rowKey] === itemNext[rowKey]\n },\n )\n : []\n prevSelection = [...newSelection]\n selectedFlatDataSource.value = uniqWith(\n [...selectedFlatDataSource.value, ...newSelection],\n (itemPrev, itemNext) => {\n return itemPrev[rowKey] === itemNext[rowKey]\n },\n )\n if (removedItemList.length > 0) {\n const removedKeys = uniq(removedItemList.map(item => item[rowKey]))\n remove(selectedFlatDataSource.value, item =>\n removedKeys.includes(item[rowKey]))\n }\n\n if (props.optionAsValue) {\n emit('update:modelValue', selectedFlatDataSource.value)\n }\n else {\n const selectedKeys = selectedFlatDataSource.value.map(\n item => item[rowKey],\n )\n emit('update:modelValue', selectedKeys)\n }\n}\n\nfunction onRadioClick(item) {\n const rowKey = requireRowKey()\n syncRadioSelection(item)\n if (props.optionAsValue) {\n emit('update:modelValue', item)\n }\n else {\n emit('update:modelValue', item[rowKey])\n }\n}\n\nfunction onRowClick(row: Record<string, any>, _, event: Event) {\n if (!props.clickRowToSelect)\n return\n\n if (props.mode === 'multiple') {\n const checkboxDOM = (event.target as Element)\n .closest('tr')\n .querySelector('input[type=\"checkbox\"]')\n if (checkboxDOM instanceof HTMLElement) {\n checkboxDOM.click()\n }\n }\n else {\n const radioDOM = (event.target as Element)\n .closest('tr')\n .querySelector('input[type=\"radio\"]')\n if (radioDOM instanceof HTMLElement) {\n radioDOM.click()\n }\n }\n}\n\nfunction onClearSelectionClick() {\n if (props.mode === 'multiple') {\n emit('update:modelValue', [])\n selectedFlatDataSource.value = []\n }\n else {\n syncRadioSelection(null)\n emit('update:modelValue', null)\n }\n}\n\nfunction selectable(row: Record<string, any>, index: number) {\n if (props.selectable && isFn(props.selectable)) {\n return props.selectable(row, index, field.value)\n }\n return true\n}\n</script>\n\n<template>\n <div :class=\"`${stylePrefix}-select-table`\">\n <div\n v-if=\"currentSelectLength > 0 && props.showAlertToolbar\"\n :class=\"`${stylePrefix}-select-table-alert-container`\"\n >\n <span>已选择 {{ currentSelectLength }} 项</span>\n <ElLink\n type=\"primary\"\n :underline=\"lt(version, '2.9.9') ? false : 'never'\"\n style=\"margin-left: 8px;\"\n @click=\"onClearSelectionClick\"\n >\n 取消选择\n </ElLink>\n </div>\n <ElTable\n ref=\"elTableRef\"\n v-loading=\"props.loading\"\n v-bind=\"elTableProps\"\n :row-key=\"rowKey\"\n :row-class-name=\"props.clickRowToSelect ? `--click-row-select` : ''\"\n :data=\"props.dataSource\"\n :highlight-current-row=\"props.mode === 'single'\"\n @select=\"onSelect\"\n @select-all=\"onSelect\"\n @row-click=\"onRowClick\"\n >\n <ElTableColumn\n v-if=\"props.mode === 'multiple'\"\n type=\"selection\"\n :selectable=\"selectable\"\n />\n <ElTableColumn\n v-else\n width=\"46\"\n >\n <template #default=\"{ row }\">\n <ElRadioGroup v-model=\"radioSelectedKey\" style=\"width: 100%;\">\n <ElRadio\n v-bind=\"compatibleRadioValue(row[rowKey])\"\n @change=\"() => onRadioClick(row)\"\n >\n \n </ElRadio>\n </ElRadioGroup>\n </template>\n </ElTableColumn>\n <template v-if=\"props.columns.length === 0\">\n <slot />\n </template>\n <template v-else>\n <ElTableColumn\n v-for=\"colItem of props.columns\"\n v-bind=\"colItem\"\n :key=\"colItem.prop || colItem.type\"\n />\n </template>\n </ElTable>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwBA,MAAM,QAAQ;EAYd,MAAM,OAAO;EAEb,MAAM,eAAe,UAAS;EAC9B,MAAM,QAAQ,UAAS;EACvB,MAAM,aAAa,KAAmB;EACtC,MAAM,mBAAmB,KAAI;EAE7B,SAAS,gBAAgB;AACvB,OAAI,CAAC,MAAM,OACT,OAAM,IAAI,MAAM,qBAAoB;AAEtC,UAAO,MAAM;;EAGf,SAAS,YAAY,MAAmC;AACtD,OAAI,CAAC,MAAM,UAAU,CAAC,KACpB;AAEF,UAAO,KAAK,MAAM;;EAGpB,SAAS,qBAAqB,OAAY;AACxC,OAAI,CAAC,QAAQ,MAAM,CACjB,QAAO;AAET,UAAO,MAAM,gBAAgB,YAAY,MAAM,IAAI,OAAO;;EAG5D,SAAS,wBAAwB,OAAY;AAC3C,OAAI,CAAC,MAAM,QAAQ,MAAM,CACvB,QAAO,EAAC;AAEV,UAAO,MACJ,KAAI,SAAQ,MAAM,gBAAgB,YAAY,KAAK,GAAG,KAAI,CAC1D,OAAO,QAAO;;EAGnB,SAAS,mBAAmB,MAAmC;AAC7D,oBAAiB,QAAQ,YAAY,KAAK,IAAI;AAC9C,cAAW,OAAO,cAAc,KAAI;;EAGtC,SAAS,qBAAqB,KAAa;AACzC,UAAO,GAAG,SAAS,QAAQ,GAAG,EAAE,OAAO,KAAK,GAAG,EAAE,OAAO,KAAI;;EAG9D,SA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,CAAA,CAAA,CAAA,EAAA,EAAA"}
|
|
@@ -14,6 +14,14 @@ declare const TimeSelect: _$element_plus_es_utils_index_mjs0.SFCWithInstall<_$vu
|
|
|
14
14
|
type: _$vue.PropType<boolean>;
|
|
15
15
|
default: undefined;
|
|
16
16
|
};
|
|
17
|
+
popperClass: {
|
|
18
|
+
type: _$vue.PropType<string>;
|
|
19
|
+
default: string;
|
|
20
|
+
};
|
|
21
|
+
popperStyle: {
|
|
22
|
+
type: _$vue.PropType<string | _$vue.CSSProperties>;
|
|
23
|
+
default: undefined;
|
|
24
|
+
};
|
|
17
25
|
size: {
|
|
18
26
|
type: _$vue.PropType<"" | "default" | "small" | "large">;
|
|
19
27
|
};
|
|
@@ -24,14 +32,6 @@ declare const TimeSelect: _$element_plus_es_utils_index_mjs0.SFCWithInstall<_$vu
|
|
|
24
32
|
placeholder: {
|
|
25
33
|
type: _$vue.PropType<string>;
|
|
26
34
|
};
|
|
27
|
-
popperClass: {
|
|
28
|
-
type: _$vue.PropType<string>;
|
|
29
|
-
default: string;
|
|
30
|
-
};
|
|
31
|
-
popperStyle: {
|
|
32
|
-
type: _$vue.PropType<string | _$vue.CSSProperties>;
|
|
33
|
-
default: undefined;
|
|
34
|
-
};
|
|
35
35
|
clearable: {
|
|
36
36
|
type: _$vue.PropType<boolean>;
|
|
37
37
|
default: boolean;
|
|
@@ -100,6 +100,14 @@ declare const TimeSelect: _$element_plus_es_utils_index_mjs0.SFCWithInstall<_$vu
|
|
|
100
100
|
type: _$vue.PropType<boolean>;
|
|
101
101
|
default: undefined;
|
|
102
102
|
};
|
|
103
|
+
popperClass: {
|
|
104
|
+
type: _$vue.PropType<string>;
|
|
105
|
+
default: string;
|
|
106
|
+
};
|
|
107
|
+
popperStyle: {
|
|
108
|
+
type: _$vue.PropType<string | _$vue.CSSProperties>;
|
|
109
|
+
default: undefined;
|
|
110
|
+
};
|
|
103
111
|
size: {
|
|
104
112
|
type: _$vue.PropType<"" | "default" | "small" | "large">;
|
|
105
113
|
};
|
|
@@ -110,14 +118,6 @@ declare const TimeSelect: _$element_plus_es_utils_index_mjs0.SFCWithInstall<_$vu
|
|
|
110
118
|
placeholder: {
|
|
111
119
|
type: _$vue.PropType<string>;
|
|
112
120
|
};
|
|
113
|
-
popperClass: {
|
|
114
|
-
type: _$vue.PropType<string>;
|
|
115
|
-
default: string;
|
|
116
|
-
};
|
|
117
|
-
popperStyle: {
|
|
118
|
-
type: _$vue.PropType<string | _$vue.CSSProperties>;
|
|
119
|
-
default: undefined;
|
|
120
|
-
};
|
|
121
121
|
clearable: {
|
|
122
122
|
type: _$vue.PropType<boolean>;
|
|
123
123
|
default: boolean;
|