@qin-ui/antd-vue-pro 2.4.4 → 2.5.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/AI-CONTEXT.md +26 -2
- package/README.md +44 -37
- package/api.json +24 -9
- package/es/antd-vue-pro.css +15 -15
- package/es/components/component-provider/components/index.vue.d.ts +3 -3
- package/es/components/component-provider/components/index.vue.d.ts.map +1 -1
- package/es/components/component-provider/constants/index.d.ts +20 -4
- package/es/components/component-provider/constants/index.d.ts.map +1 -1
- package/es/components/component-provider/types/index.d.ts +8 -4
- package/es/components/component-provider/types/index.d.ts.map +1 -1
- package/es/components/form/components/BaseField/index.vue.d.ts +7 -1
- package/es/components/form/components/BaseField/index.vue.d.ts.map +1 -1
- package/es/components/form/components/BaseField/utils/index.d.ts +18 -0
- package/es/components/form/components/BaseField/utils/index.d.ts.map +1 -1
- package/es/components/form/components/BaseFormItem/index.vue.d.ts +3 -0
- package/es/components/form/components/BaseFormItem/index.vue.d.ts.map +1 -1
- package/es/components/form/components/ContainerFragment/index.vue.d.ts +1 -0
- package/es/components/form/components/ContainerFragment/index.vue.d.ts.map +1 -1
- package/es/components/form/components/ProForm/index.vue.d.ts.map +1 -1
- package/es/components/form/components/SlotComponent/index.vue.d.ts +1 -0
- package/es/components/form/components/SlotComponent/index.vue.d.ts.map +1 -1
- package/es/components/form/components/index.d.ts +4 -0
- package/es/components/form/components/index.d.ts.map +1 -1
- package/es/components/form/constants/index.d.ts.map +1 -1
- package/es/components/form/hooks/useFields.d.ts +2 -0
- package/es/components/form/hooks/useFields.d.ts.map +1 -1
- package/es/components/form/hooks/useGroupFieldAttrs.d.ts +10 -0
- package/es/components/form/hooks/useGroupFieldAttrs.d.ts.map +1 -1
- package/es/components/form/index.d.ts +2 -2
- package/es/components/form/index.d.ts.map +1 -1
- package/es/components/form/types/index.d.ts +75 -44
- package/es/components/form/types/index.d.ts.map +1 -1
- package/es/components/form/utils/fieldKey.d.ts +13 -0
- package/es/components/form/utils/fieldKey.d.ts.map +1 -0
- package/es/components/table/components/ColumnControl.vue.d.ts +3 -0
- package/es/components/table/components/ColumnControl.vue.d.ts.map +1 -1
- package/es/components/table/components/DefaultSearchFormContainer.vue.d.ts.map +1 -1
- package/es/components/table/components/DefaultTableContainer.vue.d.ts.map +1 -1
- package/es/components/table/components/ProTable.vue.d.ts +8 -1
- package/es/components/table/components/ProTable.vue.d.ts.map +1 -1
- package/es/components/table/components/SearchForm.vue.d.ts +10 -2
- package/es/components/table/components/SearchForm.vue.d.ts.map +1 -1
- package/es/components/table/components/SizeControl.vue.d.ts +7 -2
- package/es/components/table/components/SizeControl.vue.d.ts.map +1 -1
- package/es/components/table/hooks/useTable.d.ts.map +1 -1
- package/es/components/table/index.d.ts +4 -1
- package/es/components/table/index.d.ts.map +1 -1
- package/es/components/table/types/index.d.ts +14 -6
- package/es/components/table/types/index.d.ts.map +1 -1
- package/es/index.d.ts +8 -4
- package/es/index.d.ts.map +1 -1
- package/es/index.js +528 -343
- package/es/index.js.map +1 -1
- package/es/locale/index.d.ts +2 -0
- package/es/locale/index.d.ts.map +1 -1
- package/es/shared/core/index.d.ts +1 -1
- package/es/shared/core/index.d.ts.map +1 -1
- package/es/shared/ui/index.d.ts +15 -3
- package/es/shared/ui/index.d.ts.map +1 -1
- package/package.json +7 -4
- package/src/components/component-provider/components/index.vue +26 -12
- package/src/components/component-provider/constants/index.ts +33 -6
- package/src/components/component-provider/types/index.ts +17 -9
- package/src/components/form/components/BaseField/index.vue +48 -16
- package/src/components/form/components/BaseField/utils/index.ts +19 -1
- package/src/components/form/components/BaseFormItem/index.vue +65 -17
- package/src/components/form/components/ContainerFragment/index.vue +3 -1
- package/src/components/form/components/ProForm/index.vue +30 -18
- package/src/components/form/components/SlotComponent/index.vue +14 -4
- package/src/components/form/components/index.ts +8 -1
- package/src/components/form/constants/index.ts +3 -4
- package/src/components/form/hooks/useFields.ts +3 -1
- package/src/components/form/hooks/useGroupFieldAttrs.ts +34 -27
- package/src/components/form/index.ts +1 -3
- package/src/components/form/types/index.ts +79 -46
- package/src/components/form/utils/fieldKey.ts +27 -0
- package/src/components/table/components/ColumnControl.vue +21 -5
- package/src/components/table/components/DefaultSearchFormContainer.vue +5 -0
- package/src/components/table/components/DefaultTableContainer.vue +5 -0
- package/src/components/table/components/ProTable.vue +239 -66
- package/src/components/table/components/SearchForm.vue +58 -21
- package/src/components/table/components/SizeControl.vue +21 -1
- package/src/components/table/hooks/useTable.ts +1 -1
- package/src/components/table/index.ts +8 -3
- package/src/components/table/types/index.ts +15 -7
- package/src/index.ts +12 -5
- package/src/locale/index.ts +2 -0
- package/src/shared/core/index.ts +11 -0
- package/src/shared/ui/index.ts +22 -4
- package/tsconfig.json +22 -0
|
@@ -4,27 +4,31 @@ import type {
|
|
|
4
4
|
FormInstance,
|
|
5
5
|
FormItemProps,
|
|
6
6
|
} from '../../../shared/ui';
|
|
7
|
-
import { FormItem } from '../../../shared/ui';
|
|
7
|
+
import type { FormItem } from '../../../shared/ui';
|
|
8
8
|
import type {
|
|
9
9
|
ComponentProps,
|
|
10
10
|
ComponentSlots,
|
|
11
11
|
} from 'vue-component-type-helpers';
|
|
12
|
+
import type { VNode, VNodeProps } from 'vue';
|
|
12
13
|
import {
|
|
13
|
-
type
|
|
14
|
+
type ClassValue,
|
|
14
15
|
type Component,
|
|
15
16
|
type Raw,
|
|
16
17
|
type MaybeRef,
|
|
17
18
|
type ComputedRef,
|
|
18
|
-
|
|
19
|
-
VNodeProps,
|
|
19
|
+
type StyleValue,
|
|
20
20
|
} from 'vue';
|
|
21
|
-
import { ComponentName, GetComponentType } from '../constants';
|
|
21
|
+
import type { ComponentName, GetComponentType } from '../constants';
|
|
22
22
|
import type { Data, Path } from '../../../shared/core';
|
|
23
|
+
import type { AdditionalMethods } from '../../../shared/core';
|
|
24
|
+
import type { FormItemInstance } from '../../../shared/ui';
|
|
23
25
|
|
|
24
26
|
export type { FormInstance };
|
|
25
27
|
|
|
28
|
+
/** 带 `path` 的组件属性:容器与插槽组件按该路径关联字段 */
|
|
26
29
|
export type PathProps = { path?: string } & Data;
|
|
27
30
|
|
|
31
|
+
/** `value` / `onUpdate:value` 形态的 v-model 属性 */
|
|
28
32
|
export type VModelProps<T = any> = {
|
|
29
33
|
value?: T;
|
|
30
34
|
'onUpdate:value'?: (val: T) => void;
|
|
@@ -59,13 +63,14 @@ export type ValueFormatter =
|
|
|
59
63
|
| { get?: (val: any) => any; set?: (val: any, oldVal?: any) => any };
|
|
60
64
|
|
|
61
65
|
/**
|
|
62
|
-
*
|
|
66
|
+
* 自定义组件
|
|
67
|
+
*
|
|
63
68
|
* @example (p, ctx) => h('div', ctx.attrs)
|
|
64
69
|
*/
|
|
65
70
|
export type RenderComponentType = Component<VModelProps & PathProps>;
|
|
66
71
|
|
|
67
72
|
/**
|
|
68
|
-
*
|
|
73
|
+
* 插槽组件类型
|
|
69
74
|
*/
|
|
70
75
|
export type SlotComponentType =
|
|
71
76
|
| Component<PathProps>
|
|
@@ -78,45 +83,55 @@ export type SlotComponentType =
|
|
|
78
83
|
| ((...args: any[]) => SlotComponentType);
|
|
79
84
|
|
|
80
85
|
/**
|
|
81
|
-
*
|
|
86
|
+
* 容器组件类型
|
|
82
87
|
*/
|
|
83
88
|
export type ContainerComponent = Component<PathProps>;
|
|
84
89
|
|
|
85
90
|
/**
|
|
86
|
-
*
|
|
91
|
+
* 插槽对象类型
|
|
87
92
|
*/
|
|
88
93
|
export type Slots = {
|
|
89
94
|
[name: string]: SlotComponentType;
|
|
90
95
|
};
|
|
91
96
|
|
|
97
|
+
/** 选项项:`label` 展示文案与 `value` 取值,其余键透传控件 */
|
|
92
98
|
export type Option = { label: string; value: any; [x: string]: any };
|
|
99
|
+
/** 选项数组 */
|
|
93
100
|
export type Options = Array<Option>;
|
|
94
101
|
|
|
102
|
+
/** 表单栅格开关:`true` 启用默认栅格,或传 `GridProps` 自定义 */
|
|
95
103
|
export type Grid = boolean | (GridProps & {});
|
|
96
104
|
|
|
105
|
+
/** FormItem 自身的插槽集合(label / extra / help / tooltip 等) */
|
|
97
106
|
export type FormItemSlots = ComponentSlots<typeof FormItem>;
|
|
98
107
|
|
|
99
108
|
type BaseCommon<D extends Data = Data> = {
|
|
100
109
|
/**
|
|
101
|
-
*
|
|
110
|
+
* 字段标识namePath, 同name
|
|
111
|
+
*
|
|
112
|
+
* 字段标识按 `name`、`path` 的顺序取首个非 `null` / `undefined` 的值(`name` 优先),
|
|
113
|
+
* 结果经 `normalizePathKey` 归一化,供渲染标识与 core 字段查找 API(`getField` / `setField` 等)共用;
|
|
114
|
+
* `name` 仅参与标识解析,不落入控件属性透传。与 `element-plus-pro` 口径不同(该包宿主标识键为 `prop`,`name` 仅透传控件)。
|
|
115
|
+
* 嵌套字段的 `path` 使用各自独立的完整路径(不与父级路径拼接),重复路径需自行保证唯一。
|
|
116
|
+
*
|
|
102
117
|
* @example 'name' | 'age' | 'sex' | ...
|
|
103
118
|
*/
|
|
104
119
|
path?: Path<D>;
|
|
105
|
-
/**
|
|
106
|
-
* @description 字段是否隐藏
|
|
107
|
-
*/
|
|
120
|
+
/** 字段是否隐藏;支持布尔、Ref 与 ComputedRef 形式,渲染期统一按 `toValue` 取值 */
|
|
108
121
|
hidden?: boolean;
|
|
109
122
|
/**
|
|
110
|
-
*
|
|
123
|
+
* 字段是否禁用;字段级取值优先,未显式指定时继承上层(表单或宿主 Provider)的禁用上下文。
|
|
111
124
|
*/
|
|
112
125
|
disabled?: boolean;
|
|
113
126
|
/**
|
|
114
|
-
*
|
|
127
|
+
* 字段中文名称,支持字符串或组件
|
|
128
|
+
*
|
|
115
129
|
* @example '姓名' | '年龄' | '性别' | () => h('span', '自定义标签')
|
|
116
130
|
*/
|
|
117
131
|
label?: SlotComponentType;
|
|
118
132
|
/**
|
|
119
|
-
*
|
|
133
|
+
* 字段插槽配置,可包含formItem插槽和component插槽
|
|
134
|
+
*
|
|
120
135
|
* @example
|
|
121
136
|
* ```js
|
|
122
137
|
* slots: {
|
|
@@ -128,27 +143,32 @@ type BaseCommon<D extends Data = Data> = {
|
|
|
128
143
|
*/
|
|
129
144
|
slots?: Partial<FormItemSlots>;
|
|
130
145
|
/**
|
|
131
|
-
*
|
|
146
|
+
* 字段formItem样式属性
|
|
147
|
+
*
|
|
132
148
|
* @example { marginBottom: '8px', padding: '12px' }
|
|
133
149
|
*/
|
|
134
|
-
formItemStyle?:
|
|
150
|
+
formItemStyle?: StyleValue;
|
|
135
151
|
/**
|
|
136
|
-
*
|
|
152
|
+
* 字段formItem样式类名
|
|
153
|
+
*
|
|
137
154
|
* @example 'custom-form-item' | 'required-field'
|
|
138
155
|
*/
|
|
139
|
-
formItemClass?:
|
|
156
|
+
formItemClass?: ClassValue;
|
|
140
157
|
/**
|
|
141
|
-
*
|
|
158
|
+
* 字段formItem容器包裹组件
|
|
159
|
+
*
|
|
142
160
|
* @example (props, ctx) => h('div', { class: 'custom-container' }, ctx.slots.default?.())
|
|
143
161
|
*/
|
|
144
162
|
formItemContainer?: ContainerComponent;
|
|
145
163
|
/**
|
|
146
|
-
*
|
|
164
|
+
* 将属性附加到 FormItem 的 DOM 节点
|
|
165
|
+
*
|
|
147
166
|
* @example { 'data-form-item-test': 'test-value', 'aria-label': 'name' }
|
|
148
167
|
*/
|
|
149
168
|
formItemDataAttrs?: Record<string, string>;
|
|
150
169
|
/**
|
|
151
|
-
*
|
|
170
|
+
* 额外的自定义属性,不会被当作组件参数,仅用做给字段添加标识属性等功能
|
|
171
|
+
*
|
|
152
172
|
* @example { group: 'group-1' }
|
|
153
173
|
*/
|
|
154
174
|
extraProps?: Record<string, any>;
|
|
@@ -156,12 +176,14 @@ type BaseCommon<D extends Data = Data> = {
|
|
|
156
176
|
|
|
157
177
|
type BaseWithFields<D extends Data = Data> = BaseCommon<D> & {
|
|
158
178
|
/**
|
|
159
|
-
*
|
|
179
|
+
* 嵌套子字段配置
|
|
180
|
+
*
|
|
160
181
|
* @example [{ key: 'firstName', label: '名' }, { key: 'lastName', label: '姓' }]
|
|
161
182
|
*/
|
|
162
183
|
fields: Fields<D>;
|
|
163
184
|
/**
|
|
164
|
-
*
|
|
185
|
+
* 网格布局属性,true表示使用默认网格布局,针对具有嵌套字段的字段
|
|
186
|
+
*
|
|
165
187
|
* @example boolean | { gutter: 24 }
|
|
166
188
|
*/
|
|
167
189
|
grid?: Grid;
|
|
@@ -178,46 +200,47 @@ type BaseWithoutFields<D extends Data = Data> = BaseCommon<D> & {
|
|
|
178
200
|
fields?: undefined;
|
|
179
201
|
grid?: never;
|
|
180
202
|
/**
|
|
181
|
-
*
|
|
203
|
+
* 字段component样式属性
|
|
204
|
+
*
|
|
182
205
|
* @example { width: '100%', borderColor: '#d9d9d9' }
|
|
183
206
|
*/
|
|
184
|
-
componentStyle?:
|
|
207
|
+
componentStyle?: StyleValue;
|
|
185
208
|
/**
|
|
186
|
-
*
|
|
209
|
+
* 字段component样式类名
|
|
210
|
+
*
|
|
187
211
|
* @example 'custom-input' | 'error-input'
|
|
188
212
|
*/
|
|
189
|
-
componentClass?:
|
|
213
|
+
componentClass?: ClassValue;
|
|
190
214
|
/**
|
|
191
|
-
*
|
|
215
|
+
* 字段component容器包裹组件
|
|
216
|
+
*
|
|
192
217
|
* @example (props, ctx) => h('div', { class: 'input-wrapper' }, ctx.slots.default?.())
|
|
193
218
|
*/
|
|
194
219
|
componentContainer?: ContainerComponent;
|
|
195
220
|
/**
|
|
196
|
-
*
|
|
221
|
+
* 字段值处理函数,在onUpdateValue前执行,函数返回值将作为更新值,也可设置get和set函数,用于处理字段值
|
|
222
|
+
*
|
|
197
223
|
* @example (val) => val?.trim()
|
|
198
224
|
*/
|
|
199
225
|
valueFormatter?: ValueFormatter;
|
|
200
226
|
/**
|
|
201
|
-
*
|
|
227
|
+
* 组件v-model双向绑定更新属性名,默认'value'
|
|
202
228
|
*/
|
|
203
229
|
modelProp?: string;
|
|
204
230
|
/**
|
|
205
|
-
*
|
|
231
|
+
* 将属性附加到表单组件的 DOM 节点
|
|
232
|
+
*
|
|
206
233
|
* @example { 'data-test': 'input-value', 'aria-label': 'name' }
|
|
207
234
|
*/
|
|
208
235
|
componentDataAttrs?: Record<string, string>;
|
|
209
236
|
};
|
|
210
237
|
|
|
211
|
-
/**
|
|
212
|
-
* @type {Object} Base - 基础公共字段类型
|
|
213
|
-
*/
|
|
238
|
+
/** 基础公共字段类型 */
|
|
214
239
|
export type Base<D extends Data = Data> =
|
|
215
240
|
| BaseWithFields<D>
|
|
216
241
|
| BaseWithoutFields<D>;
|
|
217
242
|
|
|
218
|
-
/**
|
|
219
|
-
* @type {FieldTypeMap} 字段类型集合
|
|
220
|
-
*/
|
|
243
|
+
/** 字段类型集合 */
|
|
221
244
|
export type FieldTypeMap<D extends Data = Data> = {
|
|
222
245
|
[K in ComponentName]: K extends 'custom'
|
|
223
246
|
? WithCommon<{ slots?: Slots; [x: string]: any }, D> & {
|
|
@@ -227,7 +250,7 @@ export type FieldTypeMap<D extends Data = Data> = {
|
|
|
227
250
|
};
|
|
228
251
|
|
|
229
252
|
/**
|
|
230
|
-
*
|
|
253
|
+
* 不支持响应式的属性名
|
|
231
254
|
*/
|
|
232
255
|
type NotSupportedRefOrGetterProps =
|
|
233
256
|
| 'component'
|
|
@@ -241,7 +264,8 @@ type NotSupportedRefOrGetterProps =
|
|
|
241
264
|
type MaybeRefOrComputedRef<T = any> = MaybeRef<T> | ComputedRef<T>;
|
|
242
265
|
|
|
243
266
|
/**
|
|
244
|
-
*
|
|
267
|
+
* 为对象属性添加响应式支持的类型
|
|
268
|
+
*
|
|
245
269
|
* @template T - 原始类型
|
|
246
270
|
*/
|
|
247
271
|
export type WithRef<T> = {
|
|
@@ -252,6 +276,12 @@ export type WithRef<T> = {
|
|
|
252
276
|
: MaybeRefOrComputedRef<T[P]>;
|
|
253
277
|
};
|
|
254
278
|
|
|
279
|
+
/**
|
|
280
|
+
* 公共字段属性集合:FormItem 透传属性与 GridItem 栅格属性
|
|
281
|
+
*
|
|
282
|
+
* 栅格行为边界:字段显式指定 `span` 时整体接管栅格,不再叠加 Provider 注入的响应式断点;
|
|
283
|
+
* 未指定 `span` 时使用注入的断点配置。
|
|
284
|
+
*/
|
|
255
285
|
type WithCommonBase<T = unknown> = T &
|
|
256
286
|
Omit<FormItemProps, 'label'> &
|
|
257
287
|
GridItemProps;
|
|
@@ -265,7 +295,7 @@ type WithFields<D extends Data = Data> = WithRef<
|
|
|
265
295
|
>;
|
|
266
296
|
|
|
267
297
|
/**
|
|
268
|
-
*
|
|
298
|
+
* 合并 FormItem 插槽与组件插槽
|
|
269
299
|
*/
|
|
270
300
|
export type MergeSlots<T, CS = ComponentSlots<T>> = Partial<{
|
|
271
301
|
[K in keyof FormItemSlots | keyof CS]: K extends keyof FormItemSlots
|
|
@@ -276,7 +306,8 @@ export type MergeSlots<T, CS = ComponentSlots<T>> = Partial<{
|
|
|
276
306
|
}>;
|
|
277
307
|
|
|
278
308
|
/**
|
|
279
|
-
*
|
|
309
|
+
* 自动从 Vue 组件提取 Props 和 Slots,并加上公共表单字段属性
|
|
310
|
+
*
|
|
280
311
|
* @template T - Vue 组件类型
|
|
281
312
|
* @template D - 数据对象类型
|
|
282
313
|
*/
|
|
@@ -288,17 +319,19 @@ type WithComponent<T, D extends Data = Data> = Omit<
|
|
|
288
319
|
};
|
|
289
320
|
|
|
290
321
|
/**
|
|
291
|
-
*
|
|
322
|
+
* 字段配置类型,包含所有字段属性和响应式支持
|
|
323
|
+
*
|
|
292
324
|
* @template D - 数据对象类型
|
|
293
325
|
* @public
|
|
294
326
|
*/
|
|
295
327
|
export type Field<
|
|
296
328
|
C extends ComponentName = ComponentName,
|
|
297
329
|
D extends Data = Data,
|
|
298
|
-
> = FieldTypeMap<D>[C] | WithFields<D>;
|
|
330
|
+
> = (FieldTypeMap<D>[C] | WithFields<D>) & AdditionalMethods<FormItemInstance>;
|
|
299
331
|
|
|
300
332
|
/**
|
|
301
|
-
*
|
|
333
|
+
* 字段数组类型
|
|
334
|
+
*
|
|
302
335
|
* @template D - 数据对象类型
|
|
303
336
|
* @public
|
|
304
337
|
*/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { toRaw } from 'vue';
|
|
2
|
+
|
|
3
|
+
const fieldKeyMap = new WeakMap<object, number>();
|
|
4
|
+
let fieldKeySeed = 0;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 字段渲染 key
|
|
8
|
+
*
|
|
9
|
+
* @description 以 `toRaw(field)` 为键在模块级 WeakMap 中缓存自增编号,同一字段对象恒得同一 key:
|
|
10
|
+
* key 与字段在数组中的位置解耦,字段插入 / 删除 / 重排 / 过滤后仍与对象绑定;同 `path` 的兄弟字段各得其唯一 key。
|
|
11
|
+
* 非对象项无对象身份,按字面量生成稳定 key;渲染路径传入的字段项已由调用方过滤为非 null 对象,
|
|
12
|
+
* 该分支供本模块的直接调用者使用
|
|
13
|
+
*
|
|
14
|
+
* @param field - 字段配置项
|
|
15
|
+
* @returns 字段渲染 key
|
|
16
|
+
*/
|
|
17
|
+
export const getFieldKey = (field: unknown): string | number => {
|
|
18
|
+
if (field === null || typeof field !== 'object')
|
|
19
|
+
return `raw_${String(field)}`;
|
|
20
|
+
const raw = toRaw(field);
|
|
21
|
+
let key = fieldKeyMap.get(raw);
|
|
22
|
+
if (key === undefined) {
|
|
23
|
+
key = ++fieldKeySeed;
|
|
24
|
+
fieldKeyMap.set(raw, key);
|
|
25
|
+
}
|
|
26
|
+
return key;
|
|
27
|
+
};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
+
/**
|
|
3
|
+
* 列显隐控制控件,以下拉菜单列出可控列并支持全选/取消全选
|
|
4
|
+
*
|
|
5
|
+
* @component ColumnControl
|
|
6
|
+
*
|
|
7
|
+
* @param {Columns} columns - 参与控制的列配置(由 ProTable 下发)
|
|
8
|
+
* @param {Table} [table] - 表格实例,勾选结果经其 `setColumn` 写回列 `hidden`
|
|
9
|
+
* @param {ColumnControlConfig} [columnControl] - 控制项配置:labels / excludedKeys / disabledKeys / disableCheckAll
|
|
10
|
+
*/
|
|
2
11
|
import {
|
|
3
12
|
Button,
|
|
4
13
|
MenuDivider,
|
|
@@ -7,15 +16,19 @@ import {
|
|
|
7
16
|
MenuItem,
|
|
8
17
|
Checkbox,
|
|
9
18
|
} from '../../../shared/ui';
|
|
10
|
-
import { computed, ref, watch } from 'vue';
|
|
19
|
+
import { computed, ref, toValue, watch } from 'vue';
|
|
20
|
+
import { isObjectItem } from '../../../shared/core';
|
|
11
21
|
import type { Columns, ColumnControlConfig } from '../types';
|
|
12
22
|
import { type Table } from '../hooks/useTable';
|
|
13
23
|
import FilterOutlined from './icons/FilterOutlined.vue';
|
|
14
24
|
import { useLocale } from '../../../locale';
|
|
15
25
|
|
|
16
26
|
type Props = {
|
|
27
|
+
/** 参与控制的列配置(由 ProTable 下发) */
|
|
17
28
|
columns: Columns;
|
|
29
|
+
/** 表格实例,勾选结果经其 `setColumn` 写回列 `hidden` */
|
|
18
30
|
table?: Table;
|
|
31
|
+
/** 控制项配置:labels / excludedKeys / disabledKeys / disableCheckAll */
|
|
19
32
|
columnControl?: ColumnControlConfig;
|
|
20
33
|
};
|
|
21
34
|
const props = withDefaults(defineProps<Props>(), {
|
|
@@ -30,6 +43,7 @@ const open = ref(false);
|
|
|
30
43
|
const checkAll = ref(false);
|
|
31
44
|
const indeterminate = ref(false);
|
|
32
45
|
|
|
46
|
+
/** 下拉项:逐列解析出 key、显示名、勾选态与是否禁用 */
|
|
33
47
|
const checkedColumnsOptions = computed<
|
|
34
48
|
Array<{
|
|
35
49
|
label: string;
|
|
@@ -38,7 +52,7 @@ const checkedColumnsOptions = computed<
|
|
|
38
52
|
disabled: boolean;
|
|
39
53
|
}>
|
|
40
54
|
>(() =>
|
|
41
|
-
props.columns.flatMap(item => {
|
|
55
|
+
props.columns.filter(isObjectItem).flatMap(item => {
|
|
42
56
|
const rawKey =
|
|
43
57
|
item.key ??
|
|
44
58
|
(Array.isArray(item.dataIndex)
|
|
@@ -62,7 +76,7 @@ const checkedColumnsOptions = computed<
|
|
|
62
76
|
return {
|
|
63
77
|
label,
|
|
64
78
|
value: key,
|
|
65
|
-
checked: !item.hidden || disabled,
|
|
79
|
+
checked: !toValue(item.hidden) || disabled,
|
|
66
80
|
disabled,
|
|
67
81
|
};
|
|
68
82
|
})
|
|
@@ -80,10 +94,12 @@ const checkedColumnKeys = computed({
|
|
|
80
94
|
);
|
|
81
95
|
},
|
|
82
96
|
set(val) {
|
|
97
|
+
// 仅写 hidden 发生翻转的列
|
|
98
|
+
const checkedSet = new Set(val);
|
|
83
99
|
checkedColumnsOptions.value.forEach(item => {
|
|
84
|
-
if (item.disabled) return;
|
|
100
|
+
if (item.disabled || item.checked === checkedSet.has(item.value)) return;
|
|
85
101
|
props.table?.setColumn?.(item.value, {
|
|
86
|
-
hidden: !
|
|
102
|
+
hidden: !checkedSet.has(item.value),
|
|
87
103
|
});
|
|
88
104
|
});
|
|
89
105
|
},
|