@elementplus-kit/uikit 1.0.3 → 1.0.4
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 +84 -35
- package/components/form/src/FormItem.ts +7 -44
- package/components/form/src/index.ts +4 -2
- package/package.json +1 -1
- package/vite.config.ts +26 -0
package/build.log
ADDED
|
Binary file
|
|
@@ -11,18 +11,29 @@ export default defineComponent({
|
|
|
11
11
|
type: Object,
|
|
12
12
|
default: () => ({}),
|
|
13
13
|
},
|
|
14
|
-
|
|
15
|
-
// type: Object,
|
|
16
|
-
// default: {}
|
|
17
|
-
// },
|
|
18
|
-
buttonOptions: {
|
|
14
|
+
btnOptions: {
|
|
19
15
|
type: Array,
|
|
20
16
|
default: () => [],
|
|
21
17
|
},
|
|
22
18
|
// 权限函数
|
|
23
19
|
hasPermission: {
|
|
24
20
|
type: Function,
|
|
25
|
-
|
|
21
|
+
},
|
|
22
|
+
size: {
|
|
23
|
+
type: String as PropType<"large" | "default" | "small">,
|
|
24
|
+
default: undefined,
|
|
25
|
+
},
|
|
26
|
+
plain: {
|
|
27
|
+
type: Boolean,
|
|
28
|
+
default: undefined,
|
|
29
|
+
},
|
|
30
|
+
text: {
|
|
31
|
+
type: Boolean,
|
|
32
|
+
default: undefined,
|
|
33
|
+
},
|
|
34
|
+
link: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
default: undefined,
|
|
26
37
|
},
|
|
27
38
|
// // 权限函数
|
|
28
39
|
// hasRole: {
|
|
@@ -30,33 +41,62 @@ export default defineComponent({
|
|
|
30
41
|
// default: () => true
|
|
31
42
|
// },
|
|
32
43
|
},
|
|
33
|
-
|
|
44
|
+
emits: ["btnAction"],
|
|
34
45
|
setup(props, { emit, slots, attrs, expose }) {
|
|
35
|
-
// const slotsList = ["active", "btn-left", "btn-right"];
|
|
36
46
|
// console.log('slots', slots);
|
|
37
47
|
// console.log('attrs', attrs);
|
|
38
48
|
|
|
39
|
-
//
|
|
49
|
+
// 解析属性
|
|
40
50
|
const getAttrs = (item) => {
|
|
41
|
-
let defaultAttrs = {
|
|
42
|
-
|
|
51
|
+
let defaultAttrs = {
|
|
52
|
+
size: props.size,
|
|
53
|
+
plain: props.plain,
|
|
54
|
+
text: props.text,
|
|
55
|
+
link: props.link,
|
|
56
|
+
class: `c-alias-${item.alias || ""}`,
|
|
57
|
+
};
|
|
58
|
+
|
|
43
59
|
if (item?.alias && typeActiveMap[item.alias]) {
|
|
44
|
-
defaultAttrs =
|
|
60
|
+
defaultAttrs = {
|
|
61
|
+
...typeActiveMap[item.alias],
|
|
62
|
+
...defaultAttrs,
|
|
63
|
+
};
|
|
45
64
|
}
|
|
65
|
+
|
|
46
66
|
// 过滤掉非elbutton属性
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
67
|
+
const filterAttrsList = [
|
|
68
|
+
"label",
|
|
69
|
+
"alias",
|
|
70
|
+
"permission",
|
|
71
|
+
"vIf",
|
|
72
|
+
"disable",
|
|
73
|
+
];
|
|
74
|
+
Object.keys(item).map((key) => {
|
|
75
|
+
if (!filterAttrsList.includes(key)) {
|
|
76
|
+
defaultAttrs[key] = item[key];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// 处理禁用
|
|
81
|
+
if (isBoolean(item.disable)) {
|
|
82
|
+
defaultAttrs.disabled = item.disable;
|
|
83
|
+
}
|
|
84
|
+
if (isFunction(item.disable) && item.disable(props.params)) {
|
|
85
|
+
defaultAttrs.disabled = item.disable(props.params);
|
|
86
|
+
}
|
|
51
87
|
return defaultAttrs;
|
|
52
88
|
};
|
|
89
|
+
|
|
53
90
|
const render = () => {
|
|
54
|
-
console.log("render 执行");
|
|
55
|
-
// 过滤权限
|
|
56
91
|
let list = [];
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
92
|
+
// 过滤权限
|
|
93
|
+
props.btnOptions.map((item) => {
|
|
94
|
+
if (
|
|
95
|
+
isArray(item.permission) &&
|
|
96
|
+
item.permission.length > 0 &&
|
|
97
|
+
isFunction(props.hasPermission)
|
|
98
|
+
) {
|
|
99
|
+
if (props.hasPermission(item.permission)) {
|
|
60
100
|
list.push(item);
|
|
61
101
|
}
|
|
62
102
|
} else {
|
|
@@ -65,25 +105,34 @@ export default defineComponent({
|
|
|
65
105
|
});
|
|
66
106
|
|
|
67
107
|
const listR = [];
|
|
108
|
+
// 过滤 vIf
|
|
68
109
|
list.map((item) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} else {
|
|
110
|
+
if (
|
|
111
|
+
has(item, "vIf") &&
|
|
112
|
+
isFunction(item.vIf) &&
|
|
113
|
+
item.vIf(props.params) !== undefined
|
|
114
|
+
) {
|
|
115
|
+
if (item.vIf(props.params)) {
|
|
76
116
|
listR.push(item);
|
|
77
117
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
118
|
+
} else {
|
|
119
|
+
listR.push(item);
|
|
120
|
+
}
|
|
81
121
|
});
|
|
82
|
-
|
|
122
|
+
|
|
83
123
|
return listR.map((item) => {
|
|
84
|
-
return h(
|
|
85
|
-
|
|
86
|
-
|
|
124
|
+
return h(
|
|
125
|
+
ElButton,
|
|
126
|
+
{
|
|
127
|
+
...getAttrs(item),
|
|
128
|
+
onClick: () => {
|
|
129
|
+
emit("btnAction", item.alias, props.params);
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
default: () => item?.label,
|
|
134
|
+
}
|
|
135
|
+
);
|
|
87
136
|
});
|
|
88
137
|
};
|
|
89
138
|
return () => render();
|
|
@@ -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
|
};
|
|
@@ -60,7 +60,7 @@ export default defineComponent({
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
// 解构props
|
|
63
|
-
const { model, formOptions, readonly, gutter, col
|
|
63
|
+
const { model, formOptions, readonly, gutter, col} = toRefs(props);
|
|
64
64
|
|
|
65
65
|
// 暴露elForm组件上的方法
|
|
66
66
|
const vm = getCurrentInstance(); // 获取虚拟DOM实例
|
|
@@ -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
|
{
|
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
|
+
})
|