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