@elementplus-kit/uikit 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/components/button/index.ts +2 -0
  2. package/components/button/src/constants.ts +50 -0
  3. package/components/button/src/index.ts +269 -0
  4. package/components/button/src/type.ts +15 -0
  5. package/components/button/style/index.scss +3 -0
  6. package/components/config.ts +4 -0
  7. package/components/dialog/index.ts +2 -0
  8. package/components/dialog/src/constants.ts +3 -0
  9. package/components/dialog/src/index.ts +54 -0
  10. package/components/dialog/src/type.ts +1 -0
  11. package/components/dialog/style/index.scss +18 -0
  12. package/components/dictLabel/index.ts +4 -0
  13. package/components/dictLabel/src/index.vue +21 -0
  14. package/components/dictLabel/src/type.ts +1 -0
  15. package/components/drawer/index.ts +2 -0
  16. package/components/drawer/src/constants.ts +3 -0
  17. package/components/drawer/src/index.ts +53 -0
  18. package/components/drawer/src/type.ts +1 -0
  19. package/components/drawer/style/index.scss +18 -0
  20. package/components/form/index.ts +2 -0
  21. package/components/form/src/FormItem.ts +406 -0
  22. package/components/form/src/constants.ts +161 -0
  23. package/components/form/src/index.ts +198 -0
  24. package/components/form/src/type.ts +68 -0
  25. package/components/form/src/utils.ts +4 -0
  26. package/components/form/style/index.scss +5 -0
  27. package/components/importText/index.ts +2 -0
  28. package/components/importText/src/index.ts +1 -0
  29. package/components/importText/src/type.ts +3 -0
  30. package/components/index.ts +10 -31
  31. package/components/pagination/index.ts +2 -0
  32. package/components/pagination/src/constants.ts +5 -0
  33. package/components/pagination/src/index.ts +50 -0
  34. package/components/pagination/src/type.ts +1 -0
  35. package/components/search/index.ts +2 -0
  36. package/components/search/src/index.tsx +306 -0
  37. package/components/search/src/type.ts +2 -0
  38. package/components/search/style/index.scss +104 -0
  39. package/components/table/index.ts +2 -0
  40. package/components/table/src/TableColumn.ts +116 -0
  41. package/components/table/src/constants.ts +42 -0
  42. package/components/table/src/index.ts +251 -0
  43. package/components/table/src/tableDictLabel.vue +21 -0
  44. package/components/table/src/type.ts +19 -0
  45. package/components/table/type/index.scss +0 -0
  46. package/components/table2/index.ts +4 -0
  47. package/components/table2/src/config.ts +5 -0
  48. package/components/table2/src/index.ts +12 -0
  49. package/components/table2/src/render.ts +136 -0
  50. package/components/table2/src/types.ts +39 -0
  51. package/components/table2/style/index.scss +0 -0
  52. package/components//346/250/241/346/235/277/index.tsx +57 -0
  53. package/components//346/250/241/346/235/277/ttt.ts +66 -0
  54. package/components//346/250/241/346/235/277/ttt.vue +18 -0
  55. package/index.ts +2 -0
  56. package/package.json +1 -4
  57. package/vite.config.ts +30 -0
  58. package//345/205/266/344/273/226/core/dialog/elementPlus/dialogWarp.vue +151 -0
  59. package//345/205/266/344/273/226/core/dialog/index.ts +10 -0
  60. package//345/205/266/344/273/226/core/form/elementPlus/elementWarp.ts +15 -0
  61. package//345/205/266/344/273/226/core/form/elementPlus/elementWarp.vue +16 -0
  62. package//345/205/266/344/273/226/core/form/elementPlus/formRender.ts +55 -0
  63. package//345/205/266/344/273/226/core/form/index.ts +10 -0
  64. package//345/205/266/344/273/226/core/table/config.ts +5 -0
  65. package//345/205/266/344/273/226/core/table/render.ts +91 -0
  66. package//345/205/266/344/273/226/core/table/warp.ts +11 -0
  67. package//345/205/266/344/273/226/core/utils/fetch.ts +58 -0
  68. package//345/205/266/344/273/226/useMessage.ts +95 -0
@@ -0,0 +1,406 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ toRefs,
5
+ inject,
6
+ type PropType,
7
+ type ExtractPropTypes,
8
+ } from "vue";
9
+ import {
10
+ ElFormItem,
11
+ ElInput,
12
+ ElInputNumber,
13
+ ElSelect,
14
+ ElOption,
15
+ ElSelectV2,
16
+ ElCascader,
17
+ ElTreeSelect,
18
+ ElRate,
19
+ ElCheckboxGroup,
20
+ ElCheckbox,
21
+ ElTimeSelect,
22
+ ElTimePicker,
23
+ ElDatePicker,
24
+ ElRadioGroup,
25
+ ElRadio,
26
+ ElRadioButton,
27
+ ElColorPicker,
28
+ ElSlider,
29
+ ElSwitch,
30
+ ElText,
31
+ } from "element-plus";
32
+ import { type FormItemProps } from "element-plus";
33
+ import { isFunction, isBoolean } from "lodash-es";
34
+ import { formTypeCfg } from "./constants";
35
+ import { formatEventName } from "./utils";
36
+
37
+ const formItemAttrs = {
38
+ model: { type: Object, default: () => {} },
39
+ // 表单名称
40
+ label: { type: String, default: "" },
41
+ // 表单类型
42
+ type: { type: String, default: "" },
43
+ // 表单key
44
+ prop: { type: String, default: "" },
45
+ // 必填
46
+ required: { type: Boolean, default: false },
47
+ // 全部只读
48
+ // allReadonly: { type: Boolean<PropType<Boolean | Object>>, default: false },
49
+ allReadonly: { type: Object, default: null }, // todo 上面传的类型是null报警告
50
+ // formItem 属性
51
+ formItem: { type: Object as PropType<FormItemProps>, default: () => {} },
52
+ // 表单类型属性
53
+ attrs: { type: Object, default: () => {} },
54
+ // 字典
55
+ dictType: { type: String, default: undefined },
56
+ // 字典选项
57
+ options: { type: Array, default: () => [] },
58
+ // 字典选项
59
+ optionsRef: { type: Object, default: () => {} },
60
+ mergeParams: { type: Object, default: () => {} },
61
+ };
62
+ export type FormItemAttrs = ExtractPropTypes<typeof formItemAttrs>;
63
+
64
+ export default defineComponent({
65
+ props: formItemAttrs,
66
+ setup(props: FormItemAttrs, { attrs: $attrs, emit, slots, expose }) {
67
+ // 事件插槽透传
68
+ const { formSlots, events } = inject("formContext");
69
+
70
+ // 解构props
71
+ const {
72
+ model,
73
+ type,
74
+ label,
75
+ prop,
76
+ required,
77
+ allReadonly,
78
+ formItem,
79
+ attrs,
80
+ dictType,
81
+ options,
82
+ } = toRefs(props);
83
+
84
+ // 处理组件自带插槽
85
+ const handleSlots = () => {
86
+ const compSlots = {};
87
+ // 遍历传进来的所有插槽匹配约定名称 例如:input.prefix
88
+ const formTypeSlots = formTypeCfg[type.value]?.slots;
89
+ formTypeSlots?.forEach((name) => {
90
+ const slotName = `${prop.value}.${name}`;
91
+ // 根据父组件插槽名称生成子组件插槽
92
+ Object.keys(formSlots).map((key) => {
93
+ if (key === slotName) {
94
+ compSlots[name] = formSlots[key];
95
+ }
96
+ });
97
+ });
98
+ return compSlots;
99
+ };
100
+
101
+ // 处理事件 只有自定义事件才能被vue组件捕获进$attrs中 所有不能实现根据父组件事件动态按需注册子组件事件
102
+ const handleEvents = () => {
103
+ const compEvents = {};
104
+ const formTypeEvents = formTypeCfg[type.value]?.events;
105
+ // 当前类型的事件
106
+ formTypeEvents?.forEach((event) => {
107
+ const eventName = `on${formatEventName(event)}`; // 字符串转大驼峰, 转成 h 函数需要格式
108
+ // events 第一个参数是事件名称,是h函数的写法规则,父组件provide events 中的e是第二个参数
109
+ compEvents[eventName] = (...arg: any) =>
110
+ events(event, prop.value, ...arg);
111
+ });
112
+ return compEvents;
113
+ };
114
+
115
+ // 获取禁用状态
116
+ const getDisabled = () => {
117
+ let disabled = false;
118
+ if (isFunction(attrs.value?.disabled)) {
119
+ disabled = attrs.value.disabled(props.mergeParams);
120
+ }
121
+ if (isBoolean(attrs.value?.disabled)) {
122
+ // 在 attrs 后面结构, 也要处理直接赋值的情况,不然会覆盖
123
+ disabled = attrs.value.disabled;
124
+ }
125
+ // 全部只读
126
+ if (allReadonly.value) {
127
+ disabled = true;
128
+ }
129
+ return { disabled };
130
+ };
131
+ // 处理属性 v-model绑定
132
+ const handleAttrs = () => {
133
+ // 获取默认属性
134
+ const defaultAttrs = formTypeCfg[type.value]?.defaultAttrs || {};
135
+ const typeAttrs = {
136
+ ref: (vEl) => setElRef(vEl, prop.value),
137
+ // modelValue: model.value[prop.value],
138
+ // 'onUpdate:modelValue': (val) => (model.value[prop.value] = val),
139
+ ...defaultAttrs,
140
+ ...attrs.value,
141
+ ...getDisabled(),
142
+ };
143
+
144
+ // 数据双向绑定,并过滤不需要双向绑定的组件
145
+ if (!["html"].includes(type.value)) {
146
+ typeAttrs.modelValue = model.value[prop.value];
147
+ typeAttrs["onUpdate:modelValue"] = (val) =>
148
+ (model.value[prop.value] = val);
149
+ }
150
+ return typeAttrs;
151
+ };
152
+
153
+ // 设置元素 Ref
154
+ const setElRef = (vEl: any, value: string) => {
155
+ props.optionsRef[`${value}Ref`] = vEl;
156
+ };
157
+
158
+ const getFormType = {
159
+ input: () => {
160
+ return h(
161
+ ElInput,
162
+ {
163
+ clearable: true,
164
+ ...handleAttrs(),
165
+ ...handleEvents(),
166
+ },
167
+ { ...handleSlots() },
168
+ );
169
+ },
170
+ textarea: () => {
171
+ return h(ElInput, {
172
+ ...handleAttrs(),
173
+ ...handleEvents(),
174
+ type: "textarea",
175
+ });
176
+ },
177
+ "input-number": () => {
178
+ return h(
179
+ ElInputNumber,
180
+ {
181
+ ...handleAttrs(),
182
+ ...handleEvents(),
183
+ },
184
+ { ...handleSlots() },
185
+ );
186
+ },
187
+ select: () => {
188
+ return h(
189
+ ElSelect,
190
+ {
191
+ clearable: true,
192
+ ...handleAttrs(),
193
+ ...handleEvents(),
194
+ },
195
+ () => {
196
+ return options?.value?.map((item) => {
197
+ return h(ElOption, {
198
+ ...item,
199
+ label: item.label,
200
+ value: item.value,
201
+ key: item.value,
202
+ });
203
+ });
204
+ },
205
+ );
206
+ },
207
+ "select-v2": () => {
208
+ return h(ElSelectV2, {
209
+ options: options.value,
210
+ clearable: true,
211
+ ...handleAttrs(),
212
+ ...handleEvents(),
213
+ });
214
+ },
215
+ cascader: () => {
216
+ return h(
217
+ ElCascader,
218
+ {
219
+ options: options.value,
220
+ clearable: true,
221
+ ...handleAttrs(),
222
+ ...handleEvents(),
223
+ },
224
+ { ...handleSlots() },
225
+ );
226
+ },
227
+ "tree-select": () => {
228
+ return h(
229
+ ElTreeSelect,
230
+ {
231
+ data: options.value,
232
+ clearable: true,
233
+ ...handleAttrs(),
234
+ ...handleEvents(),
235
+ },
236
+ { ...handleSlots() },
237
+ );
238
+ },
239
+ radio: () => {
240
+ return h(
241
+ ElRadioGroup,
242
+ {
243
+ ...handleAttrs(),
244
+ ...handleEvents(),
245
+ },
246
+ {
247
+ default: () => {
248
+ const v = options?.value?.map((item) => {
249
+ return h(item.radioButton ? ElRadioButton : ElRadio, {
250
+ ...item,
251
+ label: item.label,
252
+ value: item.value,
253
+ key: item.value,
254
+ });
255
+ });
256
+ return v;
257
+ },
258
+ },
259
+ );
260
+ },
261
+ checkbox: () => {
262
+ return h(
263
+ ElCheckboxGroup,
264
+ {
265
+ ...handleAttrs(),
266
+ ...handleEvents(),
267
+ },
268
+ {
269
+ default: () => {
270
+ const v = options?.value?.map((item) => {
271
+ return h(ElCheckbox, {
272
+ ...item,
273
+ label: item.label,
274
+ value: item.value,
275
+ key: item.value,
276
+ });
277
+ });
278
+ return v;
279
+ },
280
+ },
281
+ );
282
+ },
283
+ "time-select": () => {
284
+ return h(ElTimeSelect, {
285
+ ...handleAttrs(),
286
+ ...handleEvents(),
287
+ });
288
+ },
289
+ "date-picker": () => {
290
+ const type = attrs.value?.type || "date";
291
+ const valueFormatMap = {
292
+ year: "YYYY",
293
+ month: "YYYY-MM",
294
+ date: "YYYY-MM-DD",
295
+ };
296
+ const valueFormat = valueFormatMap[type];
297
+ return h(
298
+ ElDatePicker,
299
+ {
300
+ type,
301
+ valueFormat: valueFormat,
302
+ ...handleAttrs(),
303
+ ...handleEvents(),
304
+ },
305
+ { ...handleSlots() },
306
+ );
307
+ },
308
+ "time-picker": () => {
309
+ return h(ElTimePicker, {
310
+ valueFormat: "HH:mm:ss",
311
+ ...handleAttrs(),
312
+ ...handleEvents(),
313
+ });
314
+ },
315
+ rate: () => {
316
+ return h(ElRate, {
317
+ ...handleAttrs(),
318
+ ...handleEvents(),
319
+ });
320
+ },
321
+ "color-picker": () => {
322
+ return h(ElColorPicker, {
323
+ ...handleAttrs(),
324
+ ...handleEvents(),
325
+ });
326
+ },
327
+ slider: () => {
328
+ return h(ElSlider, {
329
+ ...handleAttrs(),
330
+ ...handleEvents(),
331
+ });
332
+ },
333
+ switch: () => {
334
+ return h(
335
+ ElSwitch,
336
+ {
337
+ ...handleAttrs(),
338
+ ...handleEvents(),
339
+ },
340
+ { ...handleSlots() },
341
+ );
342
+ },
343
+ text: () => {
344
+ return h(ElText, {
345
+ ...handleAttrs(),
346
+ });
347
+ },
348
+ html: () => {
349
+ return h("div", {
350
+ innerHTML: model.value[prop.value],
351
+ ...handleAttrs(),
352
+ });
353
+ },
354
+ slot: () => {
355
+ return formSlots[prop.value]?.(model.value);
356
+ },
357
+ };
358
+
359
+ const renderType = () => {
360
+ // 自动启动插槽
361
+ if (formSlots[prop.value]) {
362
+ return getFormType["slot"]();
363
+ } else {
364
+ // solt类型未定义插槽时提示
365
+ if (type.value === "slot") {
366
+ return `表单属性 ${prop.value} 插槽模板未定义`;
367
+ }
368
+ }
369
+
370
+ // 判断非插槽且不支持的类型
371
+ if (!getFormType[type.value]) {
372
+ console.error(`不支持的表单类型 ${type.value}`);
373
+ return `不支持的表单类型 ${type.value}`;
374
+ }
375
+
376
+ // 非插槽类型
377
+ return getFormType[type.value]();
378
+ };
379
+
380
+ const render = () => {
381
+ const renderTypeVdom = renderType();
382
+ return h(
383
+ ElFormItem,
384
+ {
385
+ label: label.value,
386
+ prop: prop.value,
387
+ rules: required.value
388
+ ? [
389
+ {
390
+ required: true,
391
+ message: `${label.value} 必填`,
392
+ trigger: "blur",
393
+ },
394
+ ]
395
+ : undefined,
396
+ ...formItem.value,
397
+ },
398
+ {
399
+ default: () => renderTypeVdom,
400
+ },
401
+ );
402
+ };
403
+ // 返回表单类型
404
+ return () => render();
405
+ },
406
+ });
@@ -0,0 +1,161 @@
1
+ export const formTypeCfg = {
2
+ input: {
3
+ elName: 'input',
4
+ defaultAttrs: {},
5
+ events: [
6
+ 'blur',
7
+ 'focus',
8
+ 'change',
9
+ 'input',
10
+ 'clear',
11
+ 'keydown',
12
+ 'mouseleave',
13
+ 'mouseenter',
14
+ 'compositionstart',
15
+ 'compositionupdate',
16
+ 'compositionend',
17
+ ],
18
+ slots: ['prefix', 'suffix', 'prepend', 'append'],
19
+ },
20
+ textarea: {
21
+ elName: 'textarea',
22
+ defaultAttrs: {},
23
+ events: ['blur', 'focus', 'change', 'input'],
24
+ },
25
+
26
+ 'input-number': {
27
+ elName: 'input-number',
28
+ defaultAttrs: {},
29
+ events: ['change', 'Function', 'blur', 'focus'],
30
+ slots: ['decrease-icon', 'increase-icon', 'prefix', 'suffix'],
31
+ },
32
+ select: {
33
+ elName: 'select',
34
+ defaultAttrs: {},
35
+ events: ['change', 'visible-change', 'remove-tag', 'clear', 'blur', 'focus', 'popup-scroll'],
36
+ slots: ['default', 'header', 'footer', 'prefix', 'empty', 'tag', 'loading', 'label'],
37
+ },
38
+ 'select-v2': {
39
+ elName: 'select-v2',
40
+ defaultAttrs: {},
41
+ events: ['focus', 'blur', 'selectedLabel'],
42
+ slots: ['default', 'header', 'footer', 'prefix', 'empty', 'tag', 'loading', 'label'],
43
+ },
44
+ cascader: {
45
+ elName: 'cascader',
46
+ defaultAttrs: {},
47
+ events: ['change', 'expand-change', 'blur', 'focus', 'clear', 'visible-change', 'remove-tag'],
48
+ slots: ['default', 'empty', 'prefix', 'suggestion-item', 'tag'],
49
+ },
50
+ 'tree-select': {
51
+ elName: 'tree-select',
52
+ defaultAttrs: {},
53
+ events: ['change', 'clear', 'blur', 'focus'],
54
+ slots: ['default'],
55
+ },
56
+ radio: {
57
+ elName: 'radio',
58
+ defaultAttrs: {},
59
+ events: ['change'],
60
+ // slots: ['default'],
61
+ },
62
+ checkbox: {
63
+ elName: 'checkbox',
64
+ defaultAttrs: {},
65
+ events: ['change'],
66
+ // slots: ['default'],
67
+ },
68
+ 'time-select': {
69
+ elName: 'time-select',
70
+ defaultAttrs: {},
71
+ events: ['change', 'blur', 'focus', 'clear'],
72
+ },
73
+ 'date-picker': {
74
+ elName: 'date-picker',
75
+ defaultAttrs: {},
76
+ events: [
77
+ 'change',
78
+ 'blur',
79
+ 'focus',
80
+ 'clear',
81
+ 'calendar-change',
82
+ 'panel-change',
83
+ 'visible-change',
84
+ ],
85
+ slots: ['default', 'range-separator', 'prev-month', 'next-month', 'prev-year', 'next-year'],
86
+ },
87
+ 'time-picker': {
88
+ elName: 'time-picker',
89
+ defaultAttrs: {},
90
+ events: ['change', 'blur', 'focus', 'clear', 'visible-change'],
91
+ slots: [],
92
+ },
93
+ rate: {
94
+ elName: 'rate',
95
+ defaultAttrs: {},
96
+ events: ['change'],
97
+ },
98
+ 'color-picker': {
99
+ elName: 'color-picker',
100
+ defaultAttrs: {},
101
+ events: ['change', 'active-change', 'focus', 'blur'],
102
+ },
103
+ slider: {
104
+ elName: 'slider',
105
+ defaultAttrs: {},
106
+ events: ['change', 'input'],
107
+ },
108
+ switch: {
109
+ elName: 'switch',
110
+ defaultAttrs: {},
111
+ events: ['change'],
112
+ slots: ['active-action', 'inactive-action'],
113
+ },
114
+ text: {
115
+ elName: 'text',
116
+ defaultAttrs: {},
117
+ slots: ['default'],
118
+ },
119
+ html: {},
120
+ slot: {},
121
+ }
122
+
123
+ enum formItemType2 {
124
+ input = 'input', // 文本
125
+ textarea = 'textarea', // 文本域
126
+ inputNumber = 'inputNumber', // 数字
127
+
128
+ select = 'select', // 下拉
129
+ selectV2 = 'selectV2', // 虚拟下拉
130
+ cascader = 'cascader', // 联级选择器
131
+ treeSelect = 'treeSelect', // 下拉树
132
+
133
+ radio = 'radio', // 单选
134
+ checkbox = 'checkbox', // 多选
135
+
136
+ datePicker = 'datePicker', // 日期选择器
137
+ dateTimePicker = 'dateTimePicker', // 日期时间选择器
138
+ timePicker = 'timePicker', // 联级时间选择
139
+ timeSelect = 'timeSelect', // 下拉时间选择
140
+
141
+ colorPicker = 'colorPicker', // 颜色选择器
142
+ switch = 'switch', // 开关
143
+ rate = 'rate', // 评分
144
+ slider = 'slider', // 滑块
145
+
146
+ html = 'html', // html
147
+ slot = 'slot', // slot插槽
148
+ }
149
+
150
+ // 获取所有的事件
151
+ export const getEmits = () => {
152
+ let emits = []
153
+ Object.keys(formTypeCfg).map((key) => {
154
+ const events = formTypeCfg[key]?.events
155
+ if (events?.length > 0) {
156
+ emits.push(...events)
157
+ }
158
+ })
159
+ emits = [...new Set(emits)]
160
+ return emits
161
+ }