@elementplus-kit/uikit 1.0.3 → 1.0.5
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/build.log +0 -0
- package/components/button/src/index.ts +219 -46
- package/components/button/style/index.scss +3 -0
- package/components/form/src/FormItem.ts +7 -44
- package/components/form/src/index.ts +12 -10
- package/components/table/src/index.ts +2 -2
- package/package.json +1 -1
- package/vite.config.ts +26 -0
package/build.log
ADDED
|
Binary file
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { defineComponent, h } from "vue";
|
|
2
|
-
import {
|
|
1
|
+
import { defineComponent, h, PropType } from "vue";
|
|
2
|
+
import {
|
|
3
|
+
ElButton,
|
|
4
|
+
ElDropdown,
|
|
5
|
+
ElDropdownMenu,
|
|
6
|
+
ElDropdownItem,
|
|
7
|
+
buttonProps,
|
|
8
|
+
} from "element-plus";
|
|
3
9
|
|
|
4
|
-
|
|
10
|
+
import "../style/index.scss";
|
|
5
11
|
import { typeActiveMap } from "./constants.ts";
|
|
6
12
|
import { has, isBoolean, isFunction, isArray } from "lodash-es";
|
|
13
|
+
import { tr } from "element-plus/es/locales.mjs";
|
|
7
14
|
export default defineComponent({
|
|
8
15
|
props: {
|
|
9
16
|
params: {
|
|
@@ -11,18 +18,39 @@ export default defineComponent({
|
|
|
11
18
|
type: Object,
|
|
12
19
|
default: () => ({}),
|
|
13
20
|
},
|
|
14
|
-
|
|
15
|
-
// type: Object,
|
|
16
|
-
// default: {}
|
|
17
|
-
// },
|
|
18
|
-
buttonOptions: {
|
|
21
|
+
btnOptions: {
|
|
19
22
|
type: Array,
|
|
20
23
|
default: () => [],
|
|
21
24
|
},
|
|
22
|
-
//
|
|
23
|
-
|
|
25
|
+
// 权限验证函数
|
|
26
|
+
permit: {
|
|
24
27
|
type: Function,
|
|
25
|
-
|
|
28
|
+
},
|
|
29
|
+
size: {
|
|
30
|
+
type: String as PropType<"large" | "default" | "small">,
|
|
31
|
+
default: undefined,
|
|
32
|
+
},
|
|
33
|
+
plain: {
|
|
34
|
+
type: Boolean,
|
|
35
|
+
default: undefined,
|
|
36
|
+
},
|
|
37
|
+
text: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
default: undefined,
|
|
40
|
+
},
|
|
41
|
+
link: {
|
|
42
|
+
type: Boolean,
|
|
43
|
+
default: undefined,
|
|
44
|
+
},
|
|
45
|
+
// 折叠
|
|
46
|
+
fold: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: false,
|
|
49
|
+
},
|
|
50
|
+
// 折叠数量
|
|
51
|
+
foldNum: {
|
|
52
|
+
type: Number,
|
|
53
|
+
default: 0,
|
|
26
54
|
},
|
|
27
55
|
// // 权限函数
|
|
28
56
|
// hasRole: {
|
|
@@ -30,61 +58,206 @@ export default defineComponent({
|
|
|
30
58
|
// default: () => true
|
|
31
59
|
// },
|
|
32
60
|
},
|
|
33
|
-
|
|
61
|
+
emits: ["btnAction"],
|
|
34
62
|
setup(props, { emit, slots, attrs, expose }) {
|
|
35
|
-
// const slotsList = ["active", "btn-left", "btn-right"];
|
|
36
63
|
// console.log('slots', slots);
|
|
37
64
|
// console.log('attrs', attrs);
|
|
38
65
|
|
|
39
|
-
//
|
|
66
|
+
// 解析按钮属性
|
|
40
67
|
const getAttrs = (item) => {
|
|
41
|
-
let defaultAttrs = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
let defaultAttrs = {
|
|
69
|
+
size: props.size,
|
|
70
|
+
plain: props.plain,
|
|
71
|
+
text: props.text,
|
|
72
|
+
link: props.link,
|
|
73
|
+
class: `c-btn-alias-${item.alias || ""}`,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// 默认按钮类型 用样式控制?
|
|
77
|
+
// if (item?.alias && typeActiveMap[item.alias]) {
|
|
78
|
+
// defaultAttrs = {
|
|
79
|
+
// ...typeActiveMap[item.alias],
|
|
80
|
+
// ...defaultAttrs,
|
|
81
|
+
// };
|
|
82
|
+
// }
|
|
83
|
+
|
|
46
84
|
// 过滤掉非elbutton属性
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
85
|
+
const filterAttrsList = ["label", "alias", "permit", "vIf", "disable"];
|
|
86
|
+
|
|
87
|
+
Object.keys(item).map((key) => {
|
|
88
|
+
if (!filterAttrsList.includes(key)) {
|
|
89
|
+
defaultAttrs[key] = item[key];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// 处理禁用
|
|
94
|
+
if (isBoolean(item.disable)) {
|
|
95
|
+
defaultAttrs.disabled = item.disable;
|
|
96
|
+
}
|
|
97
|
+
if (
|
|
98
|
+
isFunction(item.disable) &&
|
|
99
|
+
item.disable(props.params) !== undefined
|
|
100
|
+
) {
|
|
101
|
+
defaultAttrs.disabled = item.disable(props.params);
|
|
102
|
+
}
|
|
103
|
+
return defaultAttrs;
|
|
104
|
+
};
|
|
105
|
+
// 解析下拉菜单属性
|
|
106
|
+
const getDropdownAttrs = (item) => {
|
|
107
|
+
const obj = getAttrs(item);
|
|
108
|
+
const defaultAttrs = {
|
|
109
|
+
splitButton: true,
|
|
50
110
|
};
|
|
111
|
+
// 过滤下拉菜单属性
|
|
112
|
+
const l = [
|
|
113
|
+
"type",
|
|
114
|
+
"size",
|
|
115
|
+
"splitButton",
|
|
116
|
+
"disabled",
|
|
117
|
+
"placement",
|
|
118
|
+
"effect",
|
|
119
|
+
"trigger",
|
|
120
|
+
];
|
|
121
|
+
l.forEach((key) => {
|
|
122
|
+
if (obj[key] !== undefined) {
|
|
123
|
+
defaultAttrs[key] = obj[key];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
51
126
|
return defaultAttrs;
|
|
52
127
|
};
|
|
53
|
-
|
|
54
|
-
|
|
128
|
+
// 过滤权限与 vIf
|
|
129
|
+
const filterOptions = () => {
|
|
130
|
+
const list = [];
|
|
55
131
|
// 过滤权限
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
132
|
+
props.btnOptions.map((item) => {
|
|
133
|
+
if (
|
|
134
|
+
isArray(item.permit) &&
|
|
135
|
+
item.permit.length > 0 &&
|
|
136
|
+
isFunction(props.permit)
|
|
137
|
+
) {
|
|
138
|
+
if (props.permit(item.permit)) {
|
|
60
139
|
list.push(item);
|
|
61
140
|
}
|
|
62
141
|
} else {
|
|
63
142
|
list.push(item);
|
|
64
143
|
}
|
|
65
144
|
});
|
|
66
|
-
|
|
67
|
-
|
|
145
|
+
const list2 = [];
|
|
146
|
+
// 过滤 vIf
|
|
68
147
|
list.map((item) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
listR.push(item);
|
|
148
|
+
if (
|
|
149
|
+
has(item, "vIf") &&
|
|
150
|
+
isFunction(item.vIf) &&
|
|
151
|
+
item.vIf(props.params) !== undefined
|
|
152
|
+
) {
|
|
153
|
+
if (item.vIf(props.params)) {
|
|
154
|
+
list2.push(item);
|
|
77
155
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
156
|
+
} else {
|
|
157
|
+
list2.push(item);
|
|
158
|
+
}
|
|
81
159
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
160
|
+
return list2;
|
|
161
|
+
};
|
|
162
|
+
// 按钮单个生成函数
|
|
163
|
+
const createBtn = (item) => {
|
|
164
|
+
return h(
|
|
165
|
+
ElButton,
|
|
166
|
+
{
|
|
167
|
+
...getAttrs(item),
|
|
168
|
+
onClick: () => {
|
|
169
|
+
emit("btnAction", item.alias, props.params);
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
default: () => item?.label,
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
// 下拉菜单生成函数
|
|
178
|
+
const createDropdown = (finalList) => {
|
|
179
|
+
const dropdownList = []; // 不折叠的按钮
|
|
180
|
+
const dropdownMain = []; // 下拉占位
|
|
181
|
+
const dropdownItemList = []; // 折叠的按钮
|
|
182
|
+
|
|
183
|
+
finalList.map((itm, idx) => {
|
|
184
|
+
if (idx < props.foldNum) {
|
|
185
|
+
dropdownList.push(itm);
|
|
186
|
+
} else if (idx === props.foldNum) {
|
|
187
|
+
dropdownMain.push(itm);
|
|
188
|
+
} else {
|
|
189
|
+
dropdownItemList.push(itm);
|
|
190
|
+
}
|
|
87
191
|
});
|
|
192
|
+
// 处理只有一个下拉按钮的情况
|
|
193
|
+
if (dropdownMain.length > 0 && dropdownItemList.length === 0) {
|
|
194
|
+
dropdownList.push(dropdownMain[0]);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 最终渲染的vdom
|
|
198
|
+
let renderVdom = [];
|
|
199
|
+
// 展示按钮vdom
|
|
200
|
+
const butsVdom = dropdownList.map((item) => {
|
|
201
|
+
return createBtn(item);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// 合并参数
|
|
205
|
+
if (butsVdom.length > 0) {
|
|
206
|
+
renderVdom = renderVdom.concat(butsVdom);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (dropdownMain.length > 0 && dropdownItemList.length > 0) {
|
|
210
|
+
// 下拉菜单vdom
|
|
211
|
+
const dropdownVdom = h(
|
|
212
|
+
ElDropdown,
|
|
213
|
+
{
|
|
214
|
+
...getDropdownAttrs(dropdownMain[0]),
|
|
215
|
+
class: "c-btn-dropdown",
|
|
216
|
+
buttonProps: getAttrs(dropdownMain[0]),
|
|
217
|
+
splitButton: true,
|
|
218
|
+
// splitButton: dropdownItemList.length > 0,
|
|
219
|
+
onClick: () => {
|
|
220
|
+
emit("btnAction", dropdownMain[0].alias, props.params);
|
|
221
|
+
},
|
|
222
|
+
onCommand: (command: string) => {
|
|
223
|
+
emit("btnAction", command, props.params);
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
default: () => {
|
|
228
|
+
return dropdownMain[0].label;
|
|
229
|
+
},
|
|
230
|
+
dropdown: () => {
|
|
231
|
+
return dropdownItemList.map((item) => {
|
|
232
|
+
return h(
|
|
233
|
+
ElDropdownItem,
|
|
234
|
+
{
|
|
235
|
+
command: item.alias,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
default: () => item?.label,
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
renderVdom = renderVdom.concat(dropdownVdom);
|
|
246
|
+
}
|
|
247
|
+
return renderVdom;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const render = () => {
|
|
251
|
+
const finalList = filterOptions(); // 最终列表
|
|
252
|
+
// 是否折叠 折叠
|
|
253
|
+
if (props.fold) {
|
|
254
|
+
return createDropdown(finalList);
|
|
255
|
+
} else {
|
|
256
|
+
// 不折叠
|
|
257
|
+
return finalList.map((item) => {
|
|
258
|
+
return createBtn(item);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
88
261
|
};
|
|
89
262
|
return () => render();
|
|
90
263
|
},
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
ElText,
|
|
24
24
|
} from "element-plus";
|
|
25
25
|
|
|
26
|
-
import { isFunction,
|
|
26
|
+
import { isFunction, isBoolean } from "lodash-es";
|
|
27
27
|
import { formTypeCfg } from "./constants";
|
|
28
28
|
import { formatEventName } from "./utils";
|
|
29
29
|
|
|
@@ -106,9 +106,12 @@ export default defineComponent({
|
|
|
106
106
|
// 获取禁用状态
|
|
107
107
|
const getDisabled = () => {
|
|
108
108
|
let disabled = false;
|
|
109
|
-
if (
|
|
109
|
+
if (isFunction(attrs.value?.disabled)) {
|
|
110
110
|
disabled = attrs.value.disabled(model.value);
|
|
111
111
|
}
|
|
112
|
+
if (isBoolean(attrs.value?.disabled)) { // 在 attrs 后面结构, 也要处理直接赋值的情况,不然会覆盖
|
|
113
|
+
disabled = attrs.value.disabled;
|
|
114
|
+
}
|
|
112
115
|
// 全部只读
|
|
113
116
|
if (allReadonly.value) {
|
|
114
117
|
disabled = true;
|
|
@@ -137,14 +140,6 @@ export default defineComponent({
|
|
|
137
140
|
return typeAttrs;
|
|
138
141
|
};
|
|
139
142
|
|
|
140
|
-
// 获取事件和属性
|
|
141
|
-
const getEventsAndAttrs = () => {
|
|
142
|
-
return {
|
|
143
|
-
...handleEvents(),
|
|
144
|
-
...handleAttrs(),
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
|
|
148
143
|
// 设置元素 Ref
|
|
149
144
|
const setElRef = (vEl: any, value: string) => {
|
|
150
145
|
props.optionsRef[`${value}Ref`] = vEl;
|
|
@@ -353,31 +348,6 @@ export default defineComponent({
|
|
|
353
348
|
};
|
|
354
349
|
|
|
355
350
|
const renderType = () => {
|
|
356
|
-
// // 有下拉
|
|
357
|
-
// if (['cascader', 'select-v2', 'tree-select'].includes(type)) {
|
|
358
|
-
// defailtAttrs.options = options.value
|
|
359
|
-
// }
|
|
360
|
-
// if (['tree-select'].includes(type)) {
|
|
361
|
-
// defailtAttrs.data = options.value
|
|
362
|
-
// }
|
|
363
|
-
|
|
364
|
-
// // 只读转禁用
|
|
365
|
-
// if ([''].includes(type)) {
|
|
366
|
-
// }
|
|
367
|
-
// if (['condition'].includes(type)) {
|
|
368
|
-
// return getType(type.value)
|
|
369
|
-
// } else {
|
|
370
|
-
// return h(getType(type.value), {
|
|
371
|
-
// modelValue: model.value[prop.value],
|
|
372
|
-
// 'onUpdate:modelValue': (val) => (model.value[prop.value] = val),
|
|
373
|
-
// ...attrs.value,
|
|
374
|
-
// })
|
|
375
|
-
// }
|
|
376
|
-
// return h(ElInput, {
|
|
377
|
-
// vModel: model.value[prop.value],
|
|
378
|
-
// ...attrs,
|
|
379
|
-
// })
|
|
380
|
-
|
|
381
351
|
// 自动启动插槽
|
|
382
352
|
if (formSlots[prop.value]) {
|
|
383
353
|
return getFormType["slot"]();
|
|
@@ -397,16 +367,9 @@ export default defineComponent({
|
|
|
397
367
|
// 非插槽类型
|
|
398
368
|
return getFormType[type.value]();
|
|
399
369
|
};
|
|
400
|
-
// 处理事件
|
|
401
|
-
const getAttribute = () => {
|
|
402
|
-
return {};
|
|
403
|
-
};
|
|
404
|
-
// 处理属性
|
|
405
|
-
const getEvents = () => {
|
|
406
|
-
return {};
|
|
407
|
-
};
|
|
408
370
|
|
|
409
371
|
const render = () => {
|
|
372
|
+
const renderTypeVdom = renderType();
|
|
410
373
|
return h(
|
|
411
374
|
ElFormItem,
|
|
412
375
|
{
|
|
@@ -424,7 +387,7 @@ export default defineComponent({
|
|
|
424
387
|
...formItem.value,
|
|
425
388
|
},
|
|
426
389
|
{
|
|
427
|
-
default: () =>
|
|
390
|
+
default: () => renderTypeVdom,
|
|
428
391
|
}
|
|
429
392
|
);
|
|
430
393
|
};
|
|
@@ -14,7 +14,7 @@ import zhCn from "element-plus/es/locale/lang/zh-cn";
|
|
|
14
14
|
import CFormItem from "./FormItem.ts";
|
|
15
15
|
import { has, isArray, isBoolean, isFunction, isNumber } from "lodash-es";
|
|
16
16
|
import { getEmits } from "./constants"; // 获取所有的事件
|
|
17
|
-
import
|
|
17
|
+
import "../style/index.scss";
|
|
18
18
|
const propsAttrs = {
|
|
19
19
|
// 表单数据
|
|
20
20
|
model: { type: Object, default: () => ({}) },
|
|
@@ -105,18 +105,18 @@ export default defineComponent({
|
|
|
105
105
|
// 渲染表单项
|
|
106
106
|
const renderFormItem = () => {
|
|
107
107
|
// 过滤权限
|
|
108
|
-
const list = []
|
|
108
|
+
const list = [];
|
|
109
109
|
formOptions.value.map((item) => {
|
|
110
|
-
// 处理 vIf
|
|
111
|
-
if(
|
|
112
|
-
if (
|
|
113
|
-
list.push(item)
|
|
110
|
+
// 处理 vIf true 显示 false 隐藏
|
|
111
|
+
if (isFunction(item?.vIf) && item.vIf(props.model, props.params) !== undefined) {
|
|
112
|
+
if (item.vIf(props.model, props.params)) {
|
|
113
|
+
list.push(item);
|
|
114
114
|
}
|
|
115
115
|
} else {
|
|
116
|
-
list.push(item)
|
|
116
|
+
list.push(item);
|
|
117
117
|
}
|
|
118
|
-
})
|
|
119
|
-
return
|
|
118
|
+
});
|
|
119
|
+
return list.map((item) => {
|
|
120
120
|
// const { label, prop, type, required, col, formItem, attrs } = item
|
|
121
121
|
// const { label, prop, type, required, col, formItem, attrs, ...args } = item
|
|
122
122
|
const rFormItem = () => {
|
|
@@ -151,7 +151,7 @@ export default defineComponent({
|
|
|
151
151
|
{
|
|
152
152
|
class: "c-col",
|
|
153
153
|
span: has(item, "col")
|
|
154
|
-
? col
|
|
154
|
+
? item.col
|
|
155
155
|
: col?.value
|
|
156
156
|
? col?.value
|
|
157
157
|
: isLayout.value
|
|
@@ -170,6 +170,7 @@ export default defineComponent({
|
|
|
170
170
|
|
|
171
171
|
// 渲染表单
|
|
172
172
|
const renderForm = () => {
|
|
173
|
+
console.log("$attrs", $attrs);
|
|
173
174
|
return h(
|
|
174
175
|
ElConfigProvider,
|
|
175
176
|
{
|
|
@@ -182,6 +183,7 @@ export default defineComponent({
|
|
|
182
183
|
{
|
|
183
184
|
ref: cFormFnRef,
|
|
184
185
|
...$attrs,
|
|
186
|
+
model: model.value,
|
|
185
187
|
class: allReadonly.value ? "isReadonly c-form" : "c-form", // 放在 $attrs 后面可自动合并 放在 $attrs 前面会被 $attrs.class 覆盖, h函数渲染的是标签就会覆盖 是组件就会合并不用管顺序
|
|
186
188
|
},
|
|
187
189
|
{
|
|
@@ -132,11 +132,11 @@ export default defineComponent({
|
|
|
132
132
|
const rColumn = (columns, list) => {
|
|
133
133
|
columns.map((item) => {
|
|
134
134
|
const { children, ...p } = item;
|
|
135
|
-
// 处理 vIf
|
|
135
|
+
// 处理 vIf true 显示 false 隐藏
|
|
136
136
|
if (
|
|
137
137
|
isFunction(item.vIf) &&
|
|
138
138
|
item.vIf(props.params) !== undefined &&
|
|
139
|
-
item.vIf(props.params)
|
|
139
|
+
!item.vIf(props.params)
|
|
140
140
|
) {
|
|
141
141
|
return;
|
|
142
142
|
}
|
package/package.json
CHANGED
package/vite.config.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
4
|
+
import dts from 'vite-plugin-dts'
|
|
5
|
+
import { resolve } from 'path'
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [
|
|
9
|
+
vue(),
|
|
10
|
+
vueJsx(),
|
|
11
|
+
// dts({
|
|
12
|
+
// rollupTypes: false,
|
|
13
|
+
// tsconfigPath: './tsconfig.json',
|
|
14
|
+
// }),
|
|
15
|
+
],
|
|
16
|
+
build: {
|
|
17
|
+
lib: {
|
|
18
|
+
entry: 'components/index.ts',
|
|
19
|
+
name: 'ElementPlusKit',
|
|
20
|
+
fileName: 'index',
|
|
21
|
+
},
|
|
22
|
+
rollupOptions: {
|
|
23
|
+
external: ['vue', 'element-plus'],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
})
|