@qin-ui/element-plus-pro 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-CONTEXT.md +227 -23
- package/LICENSE +9 -0
- package/api.json +44 -27
- package/bin/init-ai.mjs +214 -52
- package/es/component-provider/{index-Bmx9Q9Q-.js → index-BGGIWSkO.js} +2 -1
- package/es/component-provider/index-BGGIWSkO.js.map +1 -0
- package/es/component-provider/index.js +2 -1
- package/es/component-provider/index.js.map +1 -0
- package/es/components/component-provider/components/index.vue.d.ts +27 -0
- package/es/components/component-provider/components/index.vue.d.ts.map +1 -0
- package/es/components/component-provider/constants/index.d.ts +16 -0
- package/es/components/component-provider/constants/index.d.ts.map +1 -0
- package/es/components/component-provider/index.d.ts +4 -0
- package/es/components/component-provider/index.d.ts.map +1 -0
- package/es/components/component-provider/types/index.d.ts +35 -0
- package/es/components/component-provider/types/index.d.ts.map +1 -0
- package/es/components/form/components/BaseField/index.vue.d.ts +13 -0
- package/es/components/form/components/BaseField/index.vue.d.ts.map +1 -0
- package/es/components/form/components/BaseField/utils/index.d.ts +3 -0
- package/es/components/form/components/BaseField/utils/index.d.ts.map +1 -0
- package/es/components/form/components/BaseFormItem/index.vue.d.ts +9 -0
- package/es/components/form/components/BaseFormItem/index.vue.d.ts.map +1 -0
- package/es/components/form/components/ContainerFragment/index.vue.d.ts +23 -0
- package/es/components/form/components/ContainerFragment/index.vue.d.ts.map +1 -0
- package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts +31 -0
- package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts.map +1 -0
- package/es/components/form/components/PathProvider/index.vue.d.ts +24 -0
- package/es/components/form/components/PathProvider/index.vue.d.ts.map +1 -0
- package/es/components/form/components/ProForm/index.vue.d.ts +36 -0
- package/es/components/form/components/ProForm/index.vue.d.ts.map +1 -0
- package/es/components/form/components/SlotComponent/index.vue.d.ts +7 -0
- package/es/components/form/components/SlotComponent/index.vue.d.ts.map +1 -0
- package/es/components/form/components/index.d.ts +12 -0
- package/es/components/form/components/index.d.ts.map +1 -0
- package/es/components/form/constants/index.d.ts +67 -0
- package/es/components/form/constants/index.d.ts.map +1 -0
- package/es/components/form/hooks/index.d.ts +5 -0
- package/es/components/form/hooks/index.d.ts.map +1 -0
- package/es/components/form/hooks/useFields.d.ts +57 -0
- package/es/components/form/hooks/useFields.d.ts.map +1 -0
- package/es/components/form/hooks/useForm.d.ts +93 -0
- package/es/components/form/hooks/useForm.d.ts.map +1 -0
- package/es/components/form/hooks/useFormRef.d.ts +30 -0
- package/es/components/form/hooks/useFormRef.d.ts.map +1 -0
- package/es/components/form/index.d.ts +7 -0
- package/es/components/form/index.d.ts.map +1 -0
- package/es/components/form/types/index.d.ts +234 -0
- package/es/components/form/types/index.d.ts.map +1 -0
- package/es/components/table/components/ColumnControl.vue.d.ts +9 -0
- package/es/components/table/components/ColumnControl.vue.d.ts.map +1 -0
- package/es/components/table/components/DefaultSearchFormContainer.vue.d.ts +18 -0
- package/es/components/table/components/DefaultSearchFormContainer.vue.d.ts.map +1 -0
- package/es/components/table/components/DefaultTableContainer.vue.d.ts +18 -0
- package/es/components/table/components/DefaultTableContainer.vue.d.ts.map +1 -0
- package/es/components/table/components/ProTable.vue.d.ts +47 -0
- package/es/components/table/components/ProTable.vue.d.ts.map +1 -0
- package/es/components/table/components/SearchForm.vue.d.ts +48 -0
- package/es/components/table/components/SearchForm.vue.d.ts.map +1 -0
- package/es/components/table/components/SizeControl.vue.d.ts +12 -0
- package/es/components/table/components/SizeControl.vue.d.ts.map +1 -0
- package/es/components/table/components/TableColumnRenderer.vue.d.ts +17 -0
- package/es/components/table/components/TableColumnRenderer.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/ColumnHeightOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/ColumnHeightOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/DownOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/DownOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/icons/FilterOutlined.vue.d.ts +3 -0
- package/es/components/table/components/icons/FilterOutlined.vue.d.ts.map +1 -0
- package/es/components/table/components/index.d.ts +5 -0
- package/es/components/table/components/index.d.ts.map +1 -0
- package/es/components/table/index.d.ts +33 -0
- package/es/components/table/index.d.ts.map +1 -0
- package/es/components/table/types/index.d.ts +67 -0
- package/es/components/table/types/index.d.ts.map +1 -0
- package/es/components/table/useTable.d.ts +111 -0
- package/es/components/table/useTable.d.ts.map +1 -0
- package/es/element-plus-pro.css +10 -10
- package/es/form/{index-D8btGgqa.js → index-oI6LGSpA.js} +13 -7
- package/es/form/index-oI6LGSpA.js.map +1 -0
- package/es/form/index.js +4 -3
- package/es/form/index.js.map +1 -0
- package/es/index.d.ts +76 -1472
- package/es/index.d.ts.map +1 -0
- package/es/index.js +14 -23
- package/es/index.js.map +1 -0
- package/es/shared/core/index.d.ts +6 -0
- package/es/shared/core/index.d.ts.map +1 -0
- package/es/shared/ui/index.d.ts +12 -0
- package/es/shared/ui/index.d.ts.map +1 -0
- package/es/table/index.js +10 -10
- package/es/table/index.js.map +1 -0
- package/package.json +10 -11
- package/src/components/component-provider/components/index.vue +67 -0
- package/src/components/component-provider/constants/index.ts +209 -0
- package/src/components/component-provider/index.ts +6 -0
- package/src/components/component-provider/types/index.ts +64 -0
- package/src/components/form/components/BaseField/index.vue +181 -0
- package/src/components/form/components/BaseField/utils/index.ts +15 -0
- package/src/components/form/components/BaseFormItem/index.vue +170 -0
- package/src/components/form/components/ContainerFragment/index.vue +24 -0
- package/src/components/form/components/GroupedFieldAttrs/index.vue +115 -0
- package/src/components/form/components/PathProvider/index.vue +19 -0
- package/src/components/form/components/ProForm/index.vue +106 -0
- package/src/components/form/components/SlotComponent/index.vue +26 -0
- package/src/components/form/components/index.ts +15 -0
- package/src/components/form/constants/index.ts +116 -0
- package/src/components/form/hooks/index.ts +5 -0
- package/src/components/form/hooks/useFields.ts +67 -0
- package/src/components/form/hooks/useForm.ts +110 -0
- package/src/components/form/hooks/useFormRef.ts +35 -0
- package/src/components/form/index.ts +29 -0
- package/src/components/form/types/index.ts +300 -0
- package/src/components/table/components/ColumnControl.vue +136 -0
- package/src/components/table/components/DefaultSearchFormContainer.vue +14 -0
- package/src/components/table/components/DefaultTableContainer.vue +14 -0
- package/src/components/table/components/ProTable.vue +420 -0
- package/src/components/table/components/SearchForm.vue +302 -0
- package/src/components/table/components/SizeControl.vue +55 -0
- package/src/components/table/components/TableColumnRenderer.vue +71 -0
- package/src/components/table/components/icons/ColumnHeightOutlined.vue +4 -0
- package/src/components/table/components/icons/DownOutlined.vue +4 -0
- package/src/components/table/components/icons/FilterOutlined.vue +4 -0
- package/src/components/table/components/index.ts +4 -0
- package/src/components/table/index.ts +38 -0
- package/src/components/table/types/index.ts +77 -0
- package/src/components/table/useTable.ts +144 -0
- package/src/index.ts +81 -0
- package/src/shared/core/index.ts +38 -0
- package/src/shared/ui/index.ts +106 -0
- package/es/core/index-C0Pbv44C.js +0 -360
- package/es/vendor/utils/lodash-es-p6jau26B.js +0 -1120
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FormItemProps,
|
|
3
|
+
GridProps,
|
|
4
|
+
GridItemProps,
|
|
5
|
+
FormInstance,
|
|
6
|
+
} from '../../../shared/ui';
|
|
7
|
+
import { FormItem } from '../../../shared/ui';
|
|
8
|
+
import type {
|
|
9
|
+
ComponentProps,
|
|
10
|
+
ComponentSlots,
|
|
11
|
+
} from 'vue-component-type-helpers';
|
|
12
|
+
import {
|
|
13
|
+
type CSSProperties,
|
|
14
|
+
type Component,
|
|
15
|
+
type Raw,
|
|
16
|
+
type MaybeRef,
|
|
17
|
+
type ComputedRef,
|
|
18
|
+
VNode,
|
|
19
|
+
VNodeProps,
|
|
20
|
+
} from 'vue';
|
|
21
|
+
import type { Data, Path } from '../../../shared/core';
|
|
22
|
+
import { ComponentName, GetComponentType } from '../constants';
|
|
23
|
+
|
|
24
|
+
export type { FormInstance };
|
|
25
|
+
|
|
26
|
+
export type PathProps = { path?: string } & Data;
|
|
27
|
+
|
|
28
|
+
export type VModelProps<T = any> = {
|
|
29
|
+
modelValue?: T;
|
|
30
|
+
'onUpdate:modelValue'?: (val: T) => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type ValueFormatter =
|
|
34
|
+
| { (val: any, oldVal: any): any }
|
|
35
|
+
| { get?: (val: any) => any; set?: (val: any, oldVal: any) => any };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description 自定义组件
|
|
39
|
+
* @example (p, ctx) => h('div', ctx.attrs)
|
|
40
|
+
*/
|
|
41
|
+
export type RenderComponentType = Component<VModelProps & PathProps>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @description 插槽组件类型
|
|
45
|
+
*/
|
|
46
|
+
export type SlotComponentType =
|
|
47
|
+
| Component<PathProps>
|
|
48
|
+
| VNode
|
|
49
|
+
| string
|
|
50
|
+
| number
|
|
51
|
+
| boolean
|
|
52
|
+
| null
|
|
53
|
+
| undefined
|
|
54
|
+
| ((...args: any[]) => SlotComponentType);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @description 容器组件类型
|
|
58
|
+
*/
|
|
59
|
+
export type ContainerComponent = Component<PathProps>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @description 插槽对象类型
|
|
63
|
+
*/
|
|
64
|
+
export type Slots = {
|
|
65
|
+
[name: string]: SlotComponentType;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type Option = { label: string; value: any; [x: string]: any };
|
|
69
|
+
export type Options = Array<Option>;
|
|
70
|
+
|
|
71
|
+
export type Grid = boolean | (GridProps & {});
|
|
72
|
+
|
|
73
|
+
type BaseCommon<D extends Data = Data> = {
|
|
74
|
+
/**
|
|
75
|
+
* @description 字段标识namePath, 同prop
|
|
76
|
+
* @example 'name' | 'age' | 'sex' | ...
|
|
77
|
+
*/
|
|
78
|
+
path?: Path<D>;
|
|
79
|
+
/**
|
|
80
|
+
* @description 字段是否隐藏
|
|
81
|
+
*/
|
|
82
|
+
hidden?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* @description 字段是否禁用
|
|
85
|
+
*/
|
|
86
|
+
disabled?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* @description 字段中文名称,支持字符串或组件
|
|
89
|
+
* @example '姓名' | '年龄' | '性别' | () => h('span', '自定义标签')
|
|
90
|
+
*/
|
|
91
|
+
label?: SlotComponentType;
|
|
92
|
+
/**
|
|
93
|
+
* @description 字段插槽配置,可包含formItem插槽和component插槽
|
|
94
|
+
* @example
|
|
95
|
+
* ```js
|
|
96
|
+
* slots: {
|
|
97
|
+
* label: () => h('div', { style: { fontSize: '12px' } }, '年龄'),
|
|
98
|
+
* addonAfter: '岁',
|
|
99
|
+
* suffix: () => h('span', '元')
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
slots?: Partial<ComponentSlots<typeof FormItem>>;
|
|
104
|
+
/**
|
|
105
|
+
* @description 字段formItem样式属性
|
|
106
|
+
* @example { marginBottom: '8px', padding: '12px' }
|
|
107
|
+
*/
|
|
108
|
+
formItemStyle?: CSSProperties;
|
|
109
|
+
/**
|
|
110
|
+
* @description 字段formItem样式类名
|
|
111
|
+
* @example 'custom-form-item' | 'required-field'
|
|
112
|
+
*/
|
|
113
|
+
formItemClass?: string;
|
|
114
|
+
/**
|
|
115
|
+
* @description 字段formItem容器包裹组件
|
|
116
|
+
* @example (props, ctx) => h('div', { class: 'custom-container' }, ctx.slots.default?.())
|
|
117
|
+
*/
|
|
118
|
+
formItemContainer?: ContainerComponent;
|
|
119
|
+
/**
|
|
120
|
+
* @description 将属性附加到 FormItem 的 DOM 节点
|
|
121
|
+
* @example { 'data-form-item-test': 'test-value', 'aria-label': 'name' }
|
|
122
|
+
*/
|
|
123
|
+
formItemDataAttrs?: Record<string, string>;
|
|
124
|
+
/**
|
|
125
|
+
* @description 额外的自定义属性,不会被当作组件参数,仅用做给字段添加标识属性等功能
|
|
126
|
+
* @example { group: 'group-1' }
|
|
127
|
+
*/
|
|
128
|
+
extraProps?: Record<string, any>;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
type BaseWithFields<D extends Data = Data> = BaseCommon<D> & {
|
|
132
|
+
/**
|
|
133
|
+
* @description 嵌套子字段配置
|
|
134
|
+
* @example [{ key: 'firstName', label: '名' }, { key: 'lastName', label: '姓' }]
|
|
135
|
+
*/
|
|
136
|
+
fields: Fields<D>;
|
|
137
|
+
/**
|
|
138
|
+
* @description 网格布局属性,true表示使用默认网格布局,针对具有嵌套字段的字段
|
|
139
|
+
* @example boolean | { gutter: 24 }
|
|
140
|
+
*/
|
|
141
|
+
grid?: Grid;
|
|
142
|
+
component?: never;
|
|
143
|
+
/**
|
|
144
|
+
* @description 字段component样式属性
|
|
145
|
+
* @example { width: '100%', borderColor: '#d9d9d9' }
|
|
146
|
+
*/
|
|
147
|
+
componentStyle?: never;
|
|
148
|
+
/**
|
|
149
|
+
* @description 字段component样式类名
|
|
150
|
+
* @example 'custom-input' | 'error-input'
|
|
151
|
+
*/
|
|
152
|
+
componentClass?: never;
|
|
153
|
+
/**
|
|
154
|
+
* @description 字段component容器包裹组件
|
|
155
|
+
* @example (props, ctx) => h('div', { class: 'input-wrapper' }, ctx.slots.default?.())
|
|
156
|
+
*/
|
|
157
|
+
componentContainer?: never;
|
|
158
|
+
/**
|
|
159
|
+
* @description 将属性附加到表单组件的 DOM 节点
|
|
160
|
+
* @example { 'data-test': 'input-value', 'aria-label': 'name' }
|
|
161
|
+
*/
|
|
162
|
+
componentDataAttrs?: never;
|
|
163
|
+
/**
|
|
164
|
+
* @description 字段值处理函数,在onUpdateValue前执行,函数返回值将作为更新值,也可设置get和set函数,用于处理字段值
|
|
165
|
+
* @example (val) => val?.trim()
|
|
166
|
+
*/
|
|
167
|
+
valueFormatter?: never;
|
|
168
|
+
/**
|
|
169
|
+
* @description 组件v-model双向绑定更新属性名,默认'modelValue'
|
|
170
|
+
*/
|
|
171
|
+
modelProp?: never;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
type BaseWithoutFields<D extends Data = Data> = BaseCommon<D> & {
|
|
175
|
+
fields?: undefined;
|
|
176
|
+
grid?: never;
|
|
177
|
+
/**
|
|
178
|
+
* @description 字段component样式属性
|
|
179
|
+
* @example { width: '100%', borderColor: '#d9d9d9' }
|
|
180
|
+
*/
|
|
181
|
+
componentStyle?: CSSProperties;
|
|
182
|
+
/**
|
|
183
|
+
* @description 字段component样式类名
|
|
184
|
+
* @example 'custom-input' | 'error-input'
|
|
185
|
+
*/
|
|
186
|
+
componentClass?: string;
|
|
187
|
+
/**
|
|
188
|
+
* @description 字段component容器包裹组件
|
|
189
|
+
* @example (props, ctx) => h('div', { class: 'input-wrapper' }, ctx.slots.default?.())
|
|
190
|
+
*/
|
|
191
|
+
componentContainer?: ContainerComponent;
|
|
192
|
+
/**
|
|
193
|
+
* @description 将属性附加到表单组件的 DOM 节点
|
|
194
|
+
* @example { 'data-test': 'input-value', 'aria-label': 'name' }
|
|
195
|
+
*/
|
|
196
|
+
componentDataAttrs?: Record<string, string>;
|
|
197
|
+
/**
|
|
198
|
+
* @description 字段值处理函数,在onUpdateValue前执行,函数返回值将作为更新值,也可设置get和set函数,用于处理字段值
|
|
199
|
+
* @example (val) => val?.trim()
|
|
200
|
+
*/
|
|
201
|
+
valueFormatter?: ValueFormatter;
|
|
202
|
+
/**
|
|
203
|
+
* @description 组件v-model双向绑定更新属性名,默认'modelValue'
|
|
204
|
+
*/
|
|
205
|
+
modelProp?: string;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @type {Object} Base - 基础公共字段类型
|
|
210
|
+
*/
|
|
211
|
+
export type Base<D extends Data = Data> =
|
|
212
|
+
| BaseWithFields<D>
|
|
213
|
+
| BaseWithoutFields<D>;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @type {FieldTypeMap} 字段类型集合
|
|
217
|
+
*/
|
|
218
|
+
export type FieldTypeMap<D extends Data = Data> = {
|
|
219
|
+
[K in ComponentName]: K extends 'custom'
|
|
220
|
+
? WithCommon<{ slots?: Slots; [x: string]: any }, D> & {
|
|
221
|
+
component?: RenderComponentType | Raw<RenderComponentType>;
|
|
222
|
+
}
|
|
223
|
+
: WithComponent<GetComponentType<K>, D> & { component?: K };
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @description 不支持响应式的属性名
|
|
228
|
+
*/
|
|
229
|
+
type NotSupportedRefOrGetterProps =
|
|
230
|
+
| 'component'
|
|
231
|
+
| 'formItemContainer'
|
|
232
|
+
| 'componentContainer'
|
|
233
|
+
| 'valueFormatter'
|
|
234
|
+
| 'fields'
|
|
235
|
+
| 'slots'
|
|
236
|
+
| 'modelProp';
|
|
237
|
+
|
|
238
|
+
type MaybeRefOrComputedRef<T = any> = MaybeRef<T> | ComputedRef<T>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @description 为对象属性添加响应式支持的类型
|
|
242
|
+
* @template T - 原始类型
|
|
243
|
+
*/
|
|
244
|
+
export type WithRef<T> = {
|
|
245
|
+
[P in keyof T]: P extends NotSupportedRefOrGetterProps
|
|
246
|
+
? T[P]
|
|
247
|
+
: T[P] extends (...args: any[]) => any
|
|
248
|
+
? T[P]
|
|
249
|
+
: MaybeRefOrComputedRef<T[P]>;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
type WithCommonBase<T = unknown> = T &
|
|
253
|
+
Omit<FormItemProps, 'label'> &
|
|
254
|
+
GridItemProps;
|
|
255
|
+
|
|
256
|
+
type WithCommon<T, D extends Data = Data> = WithRef<
|
|
257
|
+
WithCommonBase<T> & BaseWithoutFields<D>
|
|
258
|
+
>;
|
|
259
|
+
|
|
260
|
+
type WithFields<D extends Data = Data> = WithRef<
|
|
261
|
+
WithCommonBase & BaseWithFields<D>
|
|
262
|
+
>;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @description 自动从 Vue 组件提取 Props 和 Slots,并加上公共表单字段属性
|
|
266
|
+
* @template T - Vue 组件类型
|
|
267
|
+
* @template D - 数据对象类型
|
|
268
|
+
*/
|
|
269
|
+
type WithComponent<
|
|
270
|
+
T extends abstract new (...args: any) => any,
|
|
271
|
+
D extends Data = Data,
|
|
272
|
+
> = WithCommon<
|
|
273
|
+
{ slots?: Partial<ComponentSlots<T>> } & Partial<
|
|
274
|
+
Omit<ComponentProps<T>, keyof VNodeProps>
|
|
275
|
+
>,
|
|
276
|
+
D
|
|
277
|
+
>;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @description 字段配置类型,包含所有字段属性和响应式支持
|
|
281
|
+
* @template D - 数据对象类型
|
|
282
|
+
|
|
283
|
+
* @public
|
|
284
|
+
*/
|
|
285
|
+
export type Field<
|
|
286
|
+
C extends ComponentName = ComponentName,
|
|
287
|
+
D extends Data = Data,
|
|
288
|
+
> =
|
|
289
|
+
| (FieldTypeMap<D>[C] & {
|
|
290
|
+
component?: C extends 'custom' ? FieldTypeMap<D>[C]['component'] : C;
|
|
291
|
+
})
|
|
292
|
+
| WithFields<D>;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @description 字段数组类型
|
|
296
|
+
* @template D - 数据对象类型
|
|
297
|
+
|
|
298
|
+
* @public
|
|
299
|
+
*/
|
|
300
|
+
export type Fields<D extends Data = Data> = Array<Field<ComponentName, D>>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
Dropdown,
|
|
5
|
+
DropdownMenu,
|
|
6
|
+
DropdownItem,
|
|
7
|
+
Checkbox,
|
|
8
|
+
} from '../../../shared/ui';
|
|
9
|
+
import { computed, ref, watch } from 'vue';
|
|
10
|
+
import type { Column, Columns } from '../types';
|
|
11
|
+
import { type Table } from '../useTable';
|
|
12
|
+
import FilterOutlined from './icons/FilterOutlined.vue';
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
columns: Columns;
|
|
16
|
+
table?: Table;
|
|
17
|
+
};
|
|
18
|
+
const { columns, table = undefined } = defineProps<Props>();
|
|
19
|
+
|
|
20
|
+
const open = ref(false);
|
|
21
|
+
const checkAll = ref(false);
|
|
22
|
+
const indeterminate = ref(false);
|
|
23
|
+
|
|
24
|
+
const getColumnKey = (column: Column, index: number) => {
|
|
25
|
+
const key = column.key ?? column.prop;
|
|
26
|
+
if (key === undefined || key === null) return `__idx_${index}`;
|
|
27
|
+
return Array.isArray(key) ? key.join('.') : String(key);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const checkedColumnsOptions = computed<
|
|
31
|
+
Array<{ label: string; value: string; checked: boolean; column: Column }>
|
|
32
|
+
>(() =>
|
|
33
|
+
columns.map((item, index) => ({
|
|
34
|
+
label: String(item.label ?? item.prop ?? `列${index + 1}`),
|
|
35
|
+
value: getColumnKey(item, index),
|
|
36
|
+
checked: !item.hidden,
|
|
37
|
+
column: item,
|
|
38
|
+
}))
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const checkedColumnKeys = computed({
|
|
42
|
+
get() {
|
|
43
|
+
return checkedColumnsOptions.value.flatMap(item =>
|
|
44
|
+
item.checked ? item.value : []
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
set(val: string[]) {
|
|
48
|
+
checkedColumnsOptions.value.forEach(item => {
|
|
49
|
+
table?.setColumn(item.value as any, {
|
|
50
|
+
hidden: !val.includes(item.value),
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const onCheckAllChange = (value: any) => {
|
|
57
|
+
const checked = !!(value?.target?.checked ?? value);
|
|
58
|
+
checkedColumnKeys.value = checked
|
|
59
|
+
? checkedColumnsOptions.value.map(item => item.value)
|
|
60
|
+
: [];
|
|
61
|
+
indeterminate.value = false;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const toggleColumnsItem = (val: string) => {
|
|
65
|
+
if (checkedColumnKeys.value.includes(val)) {
|
|
66
|
+
checkedColumnKeys.value = checkedColumnKeys.value.filter(
|
|
67
|
+
item => item !== val
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
checkedColumnKeys.value = [...checkedColumnKeys.value, val];
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
watch(
|
|
75
|
+
checkedColumnKeys,
|
|
76
|
+
val => {
|
|
77
|
+
indeterminate.value =
|
|
78
|
+
!!val.length && val.length < checkedColumnsOptions.value.length;
|
|
79
|
+
checkAll.value =
|
|
80
|
+
val.length > 0 && val.length === checkedColumnsOptions.value.length;
|
|
81
|
+
},
|
|
82
|
+
{ immediate: true }
|
|
83
|
+
);
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
<template>
|
|
87
|
+
<Dropdown
|
|
88
|
+
trigger="click"
|
|
89
|
+
:hide-on-click="false"
|
|
90
|
+
:visible="open"
|
|
91
|
+
@visible-change="val => (open = val)"
|
|
92
|
+
>
|
|
93
|
+
<Button text class="pro-table_column-control_button">
|
|
94
|
+
<FilterOutlined />
|
|
95
|
+
</Button>
|
|
96
|
+
<template #dropdown>
|
|
97
|
+
<DropdownMenu>
|
|
98
|
+
<DropdownItem :disabled="true" :divided="false">
|
|
99
|
+
<Checkbox
|
|
100
|
+
:model-value="checkAll"
|
|
101
|
+
:indeterminate="indeterminate"
|
|
102
|
+
@change="onCheckAllChange"
|
|
103
|
+
>
|
|
104
|
+
全选
|
|
105
|
+
</Checkbox>
|
|
106
|
+
</DropdownItem>
|
|
107
|
+
<DropdownItem
|
|
108
|
+
v-for="item in checkedColumnsOptions"
|
|
109
|
+
:key="item.value"
|
|
110
|
+
:command="item.value"
|
|
111
|
+
@click.stop="toggleColumnsItem(item.value)"
|
|
112
|
+
>
|
|
113
|
+
<Checkbox
|
|
114
|
+
:model-value="item.checked"
|
|
115
|
+
@change="() => toggleColumnsItem(item.value)"
|
|
116
|
+
>
|
|
117
|
+
{{ item.label }}
|
|
118
|
+
</Checkbox>
|
|
119
|
+
</DropdownItem>
|
|
120
|
+
</DropdownMenu>
|
|
121
|
+
</template>
|
|
122
|
+
</Dropdown>
|
|
123
|
+
</template>
|
|
124
|
+
|
|
125
|
+
<style scoped lang="less">
|
|
126
|
+
.pro-table_column-control_button {
|
|
127
|
+
display: flex;
|
|
128
|
+
align-items: center;
|
|
129
|
+
padding-right: 12px;
|
|
130
|
+
padding-left: 12px;
|
|
131
|
+
|
|
132
|
+
:deep(svg) {
|
|
133
|
+
transform: scale(1.2, 1.4);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="pro-table_search-form-container">
|
|
3
|
+
<slot />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<style scoped lang="less">
|
|
8
|
+
.pro-table_search-form-container {
|
|
9
|
+
margin-bottom: 24px;
|
|
10
|
+
padding: 24px;
|
|
11
|
+
background-color: var(--el-bg-color, #fff);
|
|
12
|
+
border-radius: 4px;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="pro-table_table-container">
|
|
3
|
+
<slot />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<style scoped lang="less">
|
|
8
|
+
.pro-table_table-container {
|
|
9
|
+
flex: 1;
|
|
10
|
+
padding: 24px 24px 0;
|
|
11
|
+
background-color: var(--el-bg-color, #fff);
|
|
12
|
+
border-radius: 4px;
|
|
13
|
+
}
|
|
14
|
+
</style>
|