@elementplus-kit/uikit 1.0.4 → 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.
|
@@ -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: {
|
|
@@ -15,8 +22,8 @@ export default defineComponent({
|
|
|
15
22
|
type: Array,
|
|
16
23
|
default: () => [],
|
|
17
24
|
},
|
|
18
|
-
//
|
|
19
|
-
|
|
25
|
+
// 权限验证函数
|
|
26
|
+
permit: {
|
|
20
27
|
type: Function,
|
|
21
28
|
},
|
|
22
29
|
size: {
|
|
@@ -35,6 +42,16 @@ export default defineComponent({
|
|
|
35
42
|
type: Boolean,
|
|
36
43
|
default: undefined,
|
|
37
44
|
},
|
|
45
|
+
// 折叠
|
|
46
|
+
fold: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: false,
|
|
49
|
+
},
|
|
50
|
+
// 折叠数量
|
|
51
|
+
foldNum: {
|
|
52
|
+
type: Number,
|
|
53
|
+
default: 0,
|
|
54
|
+
},
|
|
38
55
|
// // 权限函数
|
|
39
56
|
// hasRole: {
|
|
40
57
|
// type: Function,
|
|
@@ -46,31 +63,27 @@ export default defineComponent({
|
|
|
46
63
|
// console.log('slots', slots);
|
|
47
64
|
// console.log('attrs', attrs);
|
|
48
65
|
|
|
49
|
-
//
|
|
66
|
+
// 解析按钮属性
|
|
50
67
|
const getAttrs = (item) => {
|
|
51
68
|
let defaultAttrs = {
|
|
52
69
|
size: props.size,
|
|
53
70
|
plain: props.plain,
|
|
54
71
|
text: props.text,
|
|
55
72
|
link: props.link,
|
|
56
|
-
class: `c-alias-${item.alias || ""}`,
|
|
73
|
+
class: `c-btn-alias-${item.alias || ""}`,
|
|
57
74
|
};
|
|
58
75
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
76
|
+
// 默认按钮类型 用样式控制?
|
|
77
|
+
// if (item?.alias && typeActiveMap[item.alias]) {
|
|
78
|
+
// defaultAttrs = {
|
|
79
|
+
// ...typeActiveMap[item.alias],
|
|
80
|
+
// ...defaultAttrs,
|
|
81
|
+
// };
|
|
82
|
+
// }
|
|
65
83
|
|
|
66
84
|
// 过滤掉非elbutton属性
|
|
67
|
-
const filterAttrsList = [
|
|
68
|
-
|
|
69
|
-
"alias",
|
|
70
|
-
"permission",
|
|
71
|
-
"vIf",
|
|
72
|
-
"disable",
|
|
73
|
-
];
|
|
85
|
+
const filterAttrsList = ["label", "alias", "permit", "vIf", "disable"];
|
|
86
|
+
|
|
74
87
|
Object.keys(item).map((key) => {
|
|
75
88
|
if (!filterAttrsList.includes(key)) {
|
|
76
89
|
defaultAttrs[key] = item[key];
|
|
@@ -81,30 +94,55 @@ export default defineComponent({
|
|
|
81
94
|
if (isBoolean(item.disable)) {
|
|
82
95
|
defaultAttrs.disabled = item.disable;
|
|
83
96
|
}
|
|
84
|
-
if (
|
|
97
|
+
if (
|
|
98
|
+
isFunction(item.disable) &&
|
|
99
|
+
item.disable(props.params) !== undefined
|
|
100
|
+
) {
|
|
85
101
|
defaultAttrs.disabled = item.disable(props.params);
|
|
86
102
|
}
|
|
87
103
|
return defaultAttrs;
|
|
88
104
|
};
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
105
|
+
// 解析下拉菜单属性
|
|
106
|
+
const getDropdownAttrs = (item) => {
|
|
107
|
+
const obj = getAttrs(item);
|
|
108
|
+
const defaultAttrs = {
|
|
109
|
+
splitButton: true,
|
|
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
|
+
});
|
|
126
|
+
return defaultAttrs;
|
|
127
|
+
};
|
|
128
|
+
// 过滤权限与 vIf
|
|
129
|
+
const filterOptions = () => {
|
|
130
|
+
const list = [];
|
|
92
131
|
// 过滤权限
|
|
93
132
|
props.btnOptions.map((item) => {
|
|
94
133
|
if (
|
|
95
|
-
isArray(item.
|
|
96
|
-
item.
|
|
97
|
-
isFunction(props.
|
|
134
|
+
isArray(item.permit) &&
|
|
135
|
+
item.permit.length > 0 &&
|
|
136
|
+
isFunction(props.permit)
|
|
98
137
|
) {
|
|
99
|
-
if (props.
|
|
138
|
+
if (props.permit(item.permit)) {
|
|
100
139
|
list.push(item);
|
|
101
140
|
}
|
|
102
141
|
} else {
|
|
103
142
|
list.push(item);
|
|
104
143
|
}
|
|
105
144
|
});
|
|
106
|
-
|
|
107
|
-
const listR = [];
|
|
145
|
+
const list2 = [];
|
|
108
146
|
// 过滤 vIf
|
|
109
147
|
list.map((item) => {
|
|
110
148
|
if (
|
|
@@ -113,27 +151,113 @@ export default defineComponent({
|
|
|
113
151
|
item.vIf(props.params) !== undefined
|
|
114
152
|
) {
|
|
115
153
|
if (item.vIf(props.params)) {
|
|
116
|
-
|
|
154
|
+
list2.push(item);
|
|
117
155
|
}
|
|
118
156
|
} else {
|
|
119
|
-
|
|
157
|
+
list2.push(item);
|
|
120
158
|
}
|
|
121
159
|
});
|
|
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 = []; // 折叠的按钮
|
|
122
182
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
+
}
|
|
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,
|
|
126
213
|
{
|
|
127
|
-
...
|
|
214
|
+
...getDropdownAttrs(dropdownMain[0]),
|
|
215
|
+
class: "c-btn-dropdown",
|
|
216
|
+
buttonProps: getAttrs(dropdownMain[0]),
|
|
217
|
+
splitButton: true,
|
|
218
|
+
// splitButton: dropdownItemList.length > 0,
|
|
128
219
|
onClick: () => {
|
|
129
|
-
emit("btnAction",
|
|
220
|
+
emit("btnAction", dropdownMain[0].alias, props.params);
|
|
221
|
+
},
|
|
222
|
+
onCommand: (command: string) => {
|
|
223
|
+
emit("btnAction", command, props.params);
|
|
130
224
|
},
|
|
131
225
|
},
|
|
132
226
|
{
|
|
133
|
-
default: () =>
|
|
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
|
+
},
|
|
134
243
|
}
|
|
135
244
|
);
|
|
136
|
-
|
|
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
|
+
}
|
|
137
261
|
};
|
|
138
262
|
return () => render();
|
|
139
263
|
},
|
|
@@ -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: () => ({}) },
|
|
@@ -60,7 +60,7 @@ export default defineComponent({
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
// 解构props
|
|
63
|
-
const { model, formOptions, readonly, gutter, col} = toRefs(props);
|
|
63
|
+
const { model, formOptions, readonly, gutter, col } = toRefs(props);
|
|
64
64
|
|
|
65
65
|
// 暴露elForm组件上的方法
|
|
66
66
|
const vm = getCurrentInstance(); // 获取虚拟DOM实例
|
|
@@ -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 = () => {
|
|
@@ -170,7 +170,7 @@ export default defineComponent({
|
|
|
170
170
|
|
|
171
171
|
// 渲染表单
|
|
172
172
|
const renderForm = () => {
|
|
173
|
-
console.log(
|
|
173
|
+
console.log("$attrs", $attrs);
|
|
174
174
|
return h(
|
|
175
175
|
ElConfigProvider,
|
|
176
176
|
{
|
|
@@ -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
|
}
|