@elementplus-kit/uikit 1.0.2 → 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/index.ts +4 -0
- package/components/button/src/constants.ts +50 -0
- package/components/button/src/index.ts +140 -0
- package/components/button/style/index.scss +0 -0
- package/components/dictLabel/index.ts +4 -0
- package/components/dictLabel/src/index.vue +21 -0
- package/components/form/src/FormItem.ts +7 -44
- package/components/form/src/index.ts +22 -5
- package/components/form/style/index.scss +5 -0
- package/components/index.ts +7 -3
- package/components/table/src/TableColumn.ts +1 -1
- package/components/table/src/index.ts +88 -48
- package/components/table/src/tableDictLabel.vue +21 -0
- package/components//346/250/241/346/235/277/index.tsx +57 -0
- package/package.json +1 -1
- package/vite.config.ts +26 -0
package/build.log
ADDED
|
Binary file
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const typeActiveMap = {
|
|
2
|
+
reset: {
|
|
3
|
+
name: "重置",
|
|
4
|
+
type: "info",
|
|
5
|
+
},
|
|
6
|
+
search: {
|
|
7
|
+
name: "查询",
|
|
8
|
+
type: "primary",
|
|
9
|
+
},
|
|
10
|
+
submit: {
|
|
11
|
+
name: "提交",
|
|
12
|
+
type: "primary",
|
|
13
|
+
},
|
|
14
|
+
save: {
|
|
15
|
+
name: "保存",
|
|
16
|
+
type: "primary",
|
|
17
|
+
},
|
|
18
|
+
create: {
|
|
19
|
+
name: "新增",
|
|
20
|
+
type: "primary",
|
|
21
|
+
},
|
|
22
|
+
delete: {
|
|
23
|
+
name: "删除",
|
|
24
|
+
type: "danger",
|
|
25
|
+
},
|
|
26
|
+
edit: {
|
|
27
|
+
name: "编辑",
|
|
28
|
+
type: "primary",
|
|
29
|
+
},
|
|
30
|
+
view: {
|
|
31
|
+
name: "查看",
|
|
32
|
+
type: "primary",
|
|
33
|
+
},
|
|
34
|
+
publish: {
|
|
35
|
+
name: "发布",
|
|
36
|
+
type: "primary",
|
|
37
|
+
},
|
|
38
|
+
import: {
|
|
39
|
+
name: "导入",
|
|
40
|
+
type: "primary",
|
|
41
|
+
},
|
|
42
|
+
export: {
|
|
43
|
+
name: "导出",
|
|
44
|
+
type: "primary",
|
|
45
|
+
},
|
|
46
|
+
exportAll: {
|
|
47
|
+
name: "导出全部",
|
|
48
|
+
type: "primary",
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { defineComponent, h } from "vue";
|
|
2
|
+
import { ElButton } from "element-plus";
|
|
3
|
+
|
|
4
|
+
// import '../style/index.scss';
|
|
5
|
+
import { typeActiveMap } from "./constants.ts";
|
|
6
|
+
import { has, isBoolean, isFunction, isArray } from "lodash-es";
|
|
7
|
+
export default defineComponent({
|
|
8
|
+
props: {
|
|
9
|
+
params: {
|
|
10
|
+
// 用于验证自定义函数的外部数据
|
|
11
|
+
type: Object,
|
|
12
|
+
default: () => ({}),
|
|
13
|
+
},
|
|
14
|
+
btnOptions: {
|
|
15
|
+
type: Array,
|
|
16
|
+
default: () => [],
|
|
17
|
+
},
|
|
18
|
+
// 权限函数
|
|
19
|
+
hasPermission: {
|
|
20
|
+
type: Function,
|
|
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,
|
|
37
|
+
},
|
|
38
|
+
// // 权限函数
|
|
39
|
+
// hasRole: {
|
|
40
|
+
// type: Function,
|
|
41
|
+
// default: () => true
|
|
42
|
+
// },
|
|
43
|
+
},
|
|
44
|
+
emits: ["btnAction"],
|
|
45
|
+
setup(props, { emit, slots, attrs, expose }) {
|
|
46
|
+
// console.log('slots', slots);
|
|
47
|
+
// console.log('attrs', attrs);
|
|
48
|
+
|
|
49
|
+
// 解析属性
|
|
50
|
+
const getAttrs = (item) => {
|
|
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
|
+
|
|
59
|
+
if (item?.alias && typeActiveMap[item.alias]) {
|
|
60
|
+
defaultAttrs = {
|
|
61
|
+
...typeActiveMap[item.alias],
|
|
62
|
+
...defaultAttrs,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 过滤掉非elbutton属性
|
|
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
|
+
}
|
|
87
|
+
return defaultAttrs;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const render = () => {
|
|
91
|
+
let list = [];
|
|
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)) {
|
|
100
|
+
list.push(item);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
list.push(item);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const listR = [];
|
|
108
|
+
// 过滤 vIf
|
|
109
|
+
list.map((item) => {
|
|
110
|
+
if (
|
|
111
|
+
has(item, "vIf") &&
|
|
112
|
+
isFunction(item.vIf) &&
|
|
113
|
+
item.vIf(props.params) !== undefined
|
|
114
|
+
) {
|
|
115
|
+
if (item.vIf(props.params)) {
|
|
116
|
+
listR.push(item);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
listR.push(item);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return listR.map((item) => {
|
|
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
|
+
);
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
return () => render();
|
|
139
|
+
},
|
|
140
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
{{ label }}
|
|
3
|
+
</template>
|
|
4
|
+
<script setup lang="ts">
|
|
5
|
+
import { computed, PropType } from 'vue'
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
options: {
|
|
8
|
+
type: Array,
|
|
9
|
+
default: () => []
|
|
10
|
+
},
|
|
11
|
+
value: {
|
|
12
|
+
type: String as PropType<any>,
|
|
13
|
+
default: ''
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
const label = computed(() => {
|
|
17
|
+
// 处理value为数字的情况 后端字典都是字符串
|
|
18
|
+
const item = props.options?.find((item) => item.value == props.value.toString());
|
|
19
|
+
return item?.label || props.value;
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
@@ -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
|
-
|
|
17
|
+
import '../style/index.scss'
|
|
18
18
|
const propsAttrs = {
|
|
19
19
|
// 表单数据
|
|
20
20
|
model: { type: Object, default: () => ({}) },
|
|
@@ -30,6 +30,8 @@ const propsAttrs = {
|
|
|
30
30
|
},
|
|
31
31
|
// row 列数
|
|
32
32
|
col: { type: Number, default: undefined },
|
|
33
|
+
// 额外业务全局参数
|
|
34
|
+
params: { type: Object, default: () => ({}) },
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
export type PropsAttrs = ExtractPropTypes<typeof propsAttrs>;
|
|
@@ -58,7 +60,7 @@ export default defineComponent({
|
|
|
58
60
|
});
|
|
59
61
|
|
|
60
62
|
// 解构props
|
|
61
|
-
const { model, formOptions, readonly, gutter, col
|
|
63
|
+
const { model, formOptions, readonly, gutter, col} = toRefs(props);
|
|
62
64
|
|
|
63
65
|
// 暴露elForm组件上的方法
|
|
64
66
|
const vm = getCurrentInstance(); // 获取虚拟DOM实例
|
|
@@ -81,6 +83,7 @@ export default defineComponent({
|
|
|
81
83
|
|
|
82
84
|
// 渲染 row
|
|
83
85
|
const renderRow = () => {
|
|
86
|
+
const formItemVdom = renderFormItem();
|
|
84
87
|
if (isLayout.value) {
|
|
85
88
|
return h(
|
|
86
89
|
ElRow,
|
|
@@ -91,16 +94,28 @@ export default defineComponent({
|
|
|
91
94
|
...$attrs,
|
|
92
95
|
},
|
|
93
96
|
{
|
|
94
|
-
default: () =>
|
|
97
|
+
default: () => formItemVdom,
|
|
95
98
|
}
|
|
96
99
|
);
|
|
97
100
|
} else {
|
|
98
|
-
return
|
|
101
|
+
return formItemVdom;
|
|
99
102
|
}
|
|
100
103
|
};
|
|
101
104
|
|
|
102
105
|
// 渲染表单项
|
|
103
106
|
const renderFormItem = () => {
|
|
107
|
+
// 过滤权限
|
|
108
|
+
const list = []
|
|
109
|
+
formOptions.value.map((item) => {
|
|
110
|
+
// 处理 vIf 显示隐藏
|
|
111
|
+
if(has(item, 'vIf')) {
|
|
112
|
+
if (isFunction(item.vIf) && item.vIf(props.model, props.params)) {
|
|
113
|
+
list.push(item)
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
list.push(item)
|
|
117
|
+
}
|
|
118
|
+
})
|
|
104
119
|
return formOptions.value.map((item) => {
|
|
105
120
|
// const { label, prop, type, required, col, formItem, attrs } = item
|
|
106
121
|
// const { label, prop, type, required, col, formItem, attrs, ...args } = item
|
|
@@ -136,7 +151,7 @@ export default defineComponent({
|
|
|
136
151
|
{
|
|
137
152
|
class: "c-col",
|
|
138
153
|
span: has(item, "col")
|
|
139
|
-
? col
|
|
154
|
+
? item.col
|
|
140
155
|
: col?.value
|
|
141
156
|
? col?.value
|
|
142
157
|
: isLayout.value
|
|
@@ -155,6 +170,7 @@ export default defineComponent({
|
|
|
155
170
|
|
|
156
171
|
// 渲染表单
|
|
157
172
|
const renderForm = () => {
|
|
173
|
+
console.log('$attrs', $attrs);
|
|
158
174
|
return h(
|
|
159
175
|
ElConfigProvider,
|
|
160
176
|
{
|
|
@@ -167,6 +183,7 @@ export default defineComponent({
|
|
|
167
183
|
{
|
|
168
184
|
ref: cFormFnRef,
|
|
169
185
|
...$attrs,
|
|
186
|
+
model: model.value,
|
|
170
187
|
class: allReadonly.value ? "isReadonly c-form" : "c-form", // 放在 $attrs 后面可自动合并 放在 $attrs 前面会被 $attrs.class 覆盖, h函数渲染的是标签就会覆盖 是组件就会合并不用管顺序
|
|
171
188
|
},
|
|
172
189
|
{
|
package/components/index.ts
CHANGED
|
@@ -29,12 +29,16 @@ export * from "./drawer/index.ts";
|
|
|
29
29
|
export const CDrawer = Drawer;
|
|
30
30
|
|
|
31
31
|
// 搜索
|
|
32
|
-
// import Search from "./search/index.ts";
|
|
33
|
-
// export * from "./search/index.ts";
|
|
34
|
-
// export const CSearch = Search;
|
|
35
32
|
import Search from "./search/index.ts";
|
|
36
33
|
export * from "./search/index.ts";
|
|
37
34
|
export const CSearch = Search;
|
|
35
|
+
|
|
36
|
+
// 按钮
|
|
37
|
+
import Button from "./button/index.ts";
|
|
38
|
+
export * from "./button/index.ts";
|
|
39
|
+
export const CButton = Button;
|
|
40
|
+
|
|
41
|
+
|
|
38
42
|
// 测试单个引入-----------------------------
|
|
39
43
|
// export * from "./dialog/index.ts"; // 弹窗
|
|
40
44
|
// export * from "./drawer/index.ts"; // 抽屉
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type ExtractPropTypes,
|
|
6
6
|
} from "vue";
|
|
7
7
|
import { ElTable, ElTableColumn } from "element-plus";
|
|
8
|
+
import TableDictLabel from "./tableDictLabel.vue";
|
|
8
9
|
import {
|
|
9
10
|
defaultAttrs,
|
|
10
11
|
tableSlots,
|
|
@@ -12,10 +13,14 @@ import {
|
|
|
12
13
|
selectionColumn,
|
|
13
14
|
indexColumn,
|
|
14
15
|
} from "./constants.ts";
|
|
15
|
-
import { isArray, isObject } from "lodash-es";
|
|
16
|
+
import { isArray, isObject, isFunction } from "lodash-es";
|
|
16
17
|
const propsAttrs = {
|
|
17
18
|
module: {
|
|
18
|
-
|
|
19
|
+
type: Object,
|
|
20
|
+
default: () => {},
|
|
21
|
+
},
|
|
22
|
+
params: {
|
|
23
|
+
// 额外业务全局参数
|
|
19
24
|
type: Object,
|
|
20
25
|
default: () => {},
|
|
21
26
|
},
|
|
@@ -61,45 +66,43 @@ export default defineComponent({
|
|
|
61
66
|
};
|
|
62
67
|
|
|
63
68
|
// 暴露方法
|
|
64
|
-
expose({
|
|
65
|
-
|
|
66
|
-
});
|
|
69
|
+
// expose({
|
|
70
|
+
// // tableRef,
|
|
71
|
+
// });
|
|
67
72
|
|
|
68
|
-
// 属性处理
|
|
69
|
-
const getAttrs = () => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
// 事件处理
|
|
76
|
-
const getEvents = () => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
};
|
|
73
|
+
// // 属性处理
|
|
74
|
+
// const getAttrs = () => {
|
|
75
|
+
// const obj = {
|
|
76
|
+
// ...defaultAttrs, // 设置默认值
|
|
77
|
+
// };
|
|
78
|
+
// return obj;
|
|
79
|
+
// };
|
|
80
|
+
// // 事件处理
|
|
81
|
+
// const getEvents = () => {
|
|
82
|
+
// const obj = {
|
|
83
|
+
// ...defaultAttrs, // 设置默认值
|
|
84
|
+
// };
|
|
85
|
+
// return obj;
|
|
86
|
+
// };
|
|
82
87
|
|
|
83
|
-
// 处理列数据-数组
|
|
84
|
-
const getArrayColumn = () => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const list = [];
|
|
88
|
+
// // 处理列数据-数组
|
|
89
|
+
// const getArrayColumn = () => {
|
|
90
|
+
// // 递归处理数据
|
|
91
|
+
// const list = [];
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
93
|
+
// const columnsRecursion = (columns, list) => {
|
|
94
|
+
// columns?.map((item) => {
|
|
95
|
+
// const { children, ...p } = item;
|
|
96
|
+
// // 递归处理子列
|
|
97
|
+
// if (isArray(item.children)) {
|
|
98
|
+
// item.children = c(item.children, list);
|
|
99
|
+
// }
|
|
100
|
+
// list.push(p);
|
|
101
|
+
// });
|
|
102
|
+
// };
|
|
103
|
+
// columnsRecursion(props.columns, list);
|
|
104
|
+
// return list;
|
|
105
|
+
// };
|
|
103
106
|
|
|
104
107
|
// 渲染表格列
|
|
105
108
|
const renderTableColumn = () => {
|
|
@@ -109,7 +112,8 @@ export default defineComponent({
|
|
|
109
112
|
list.push(
|
|
110
113
|
h(ElTableColumn, {
|
|
111
114
|
type: "selection",
|
|
112
|
-
width:
|
|
115
|
+
width: 50,
|
|
116
|
+
align: "center",
|
|
113
117
|
})
|
|
114
118
|
);
|
|
115
119
|
}
|
|
@@ -118,7 +122,8 @@ export default defineComponent({
|
|
|
118
122
|
h(ElTableColumn, {
|
|
119
123
|
label: "序号",
|
|
120
124
|
type: "index",
|
|
121
|
-
width:
|
|
125
|
+
width: 60,
|
|
126
|
+
align: "center",
|
|
122
127
|
})
|
|
123
128
|
);
|
|
124
129
|
}
|
|
@@ -127,6 +132,14 @@ export default defineComponent({
|
|
|
127
132
|
const rColumn = (columns, list) => {
|
|
128
133
|
columns.map((item) => {
|
|
129
134
|
const { children, ...p } = item;
|
|
135
|
+
// 处理 vIf
|
|
136
|
+
if (
|
|
137
|
+
isFunction(item.vIf) &&
|
|
138
|
+
item.vIf(props.params) !== undefined &&
|
|
139
|
+
item.vIf(props.params)
|
|
140
|
+
) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
130
143
|
|
|
131
144
|
// 处理多级表头
|
|
132
145
|
const listSub = [];
|
|
@@ -147,25 +160,50 @@ export default defineComponent({
|
|
|
147
160
|
// column 列插槽
|
|
148
161
|
if (slots[item.prop]) {
|
|
149
162
|
itemSlot["default"] = slots[item.prop];
|
|
163
|
+
} else if (isFunction(item.render)) {
|
|
164
|
+
// column render 渲染函数
|
|
165
|
+
itemSlot["default"] = item.render;
|
|
166
|
+
} else if (isArray(item.options)) {
|
|
167
|
+
// column 字典数组
|
|
168
|
+
itemSlot["default"] = (scope: any) =>
|
|
169
|
+
h(TableDictLabel, {
|
|
170
|
+
options: item.options,
|
|
171
|
+
value: scope.row[item.prop],
|
|
172
|
+
});
|
|
150
173
|
}
|
|
151
174
|
|
|
152
|
-
// 赋值
|
|
175
|
+
// 赋值 有插槽
|
|
153
176
|
if (Object.keys(itemSlot).length) {
|
|
177
|
+
const getColumnContent = () => {
|
|
178
|
+
let content = undefined;
|
|
179
|
+
if (listSub.length) {
|
|
180
|
+
content = { ...itemSlot, default: () => listSub };
|
|
181
|
+
} else {
|
|
182
|
+
content = { ...itemSlot };
|
|
183
|
+
}
|
|
184
|
+
return content;
|
|
185
|
+
};
|
|
154
186
|
list.push(
|
|
155
187
|
h(
|
|
156
188
|
ElTableColumn,
|
|
157
189
|
{ ...p, class: "c-table-column" },
|
|
158
|
-
|
|
159
|
-
? { ...itemSlot, default: () => listSub }
|
|
160
|
-
: { ...itemSlot }
|
|
190
|
+
getColumnContent()
|
|
161
191
|
)
|
|
162
192
|
);
|
|
163
193
|
} else {
|
|
194
|
+
const getColumnContent = () => {
|
|
195
|
+
let content = undefined;
|
|
196
|
+
if (listSub.length) {
|
|
197
|
+
content = { default: () => listSub };
|
|
198
|
+
}
|
|
199
|
+
return content;
|
|
200
|
+
};
|
|
201
|
+
// 无插槽
|
|
164
202
|
list.push(
|
|
165
203
|
h(
|
|
166
204
|
ElTableColumn,
|
|
167
205
|
{ ...p, class: "c-table-column" },
|
|
168
|
-
|
|
206
|
+
getColumnContent()
|
|
169
207
|
)
|
|
170
208
|
);
|
|
171
209
|
}
|
|
@@ -188,8 +226,10 @@ export default defineComponent({
|
|
|
188
226
|
// 渲染表格组件
|
|
189
227
|
const renderTable = () => {
|
|
190
228
|
// getColumnList();
|
|
191
|
-
console.log("props", props);
|
|
192
|
-
console.log("attrs", attrs);
|
|
229
|
+
// console.log("props", props);
|
|
230
|
+
// console.log("attrs", attrs);
|
|
231
|
+
// 先拼接好子数据不然会重复执行多次
|
|
232
|
+
const columnList = renderTableColumn();
|
|
193
233
|
return h(
|
|
194
234
|
ElTable,
|
|
195
235
|
{
|
|
@@ -198,7 +238,7 @@ export default defineComponent({
|
|
|
198
238
|
class: "c-table",
|
|
199
239
|
},
|
|
200
240
|
{
|
|
201
|
-
default: () =>
|
|
241
|
+
default: () => columnList,
|
|
202
242
|
...getSlots(),
|
|
203
243
|
}
|
|
204
244
|
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
{{ label }}
|
|
3
|
+
</template>
|
|
4
|
+
<script setup lang="ts">
|
|
5
|
+
import { computed, PropType } from 'vue'
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
options: {
|
|
8
|
+
type: Array,
|
|
9
|
+
default: () => []
|
|
10
|
+
},
|
|
11
|
+
value: {
|
|
12
|
+
type: String as PropType<any>,
|
|
13
|
+
default: ''
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
const label = computed(() => {
|
|
17
|
+
// 处理value为数字的情况 后端字典都是字符串
|
|
18
|
+
const item = props.options?.find((item) => item.value == props.value.toString());
|
|
19
|
+
return item?.label || props.value;
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
computed,
|
|
4
|
+
defineComponent,
|
|
5
|
+
} from "vue";
|
|
6
|
+
|
|
7
|
+
// import { CForm, CDrawer } from "@elementplus-kit/uikit";
|
|
8
|
+
// import '../style/index.scss';
|
|
9
|
+
|
|
10
|
+
export default defineComponent({
|
|
11
|
+
props: {
|
|
12
|
+
// modelValue: {
|
|
13
|
+
// type: Object,
|
|
14
|
+
// default: {}
|
|
15
|
+
// },
|
|
16
|
+
// formOptions: {
|
|
17
|
+
// type: Array,
|
|
18
|
+
// default: () => []
|
|
19
|
+
// },
|
|
20
|
+
// isDrawer: {
|
|
21
|
+
// type: Boolean,
|
|
22
|
+
// default: false
|
|
23
|
+
// },
|
|
24
|
+
},
|
|
25
|
+
// emits: ['update:modelValue', 'search', 'reset', 'close'],
|
|
26
|
+
|
|
27
|
+
setup(props, { emit, slots, attrs, expose }) {
|
|
28
|
+
// 自己的 slot
|
|
29
|
+
// const slotsList = ["active", "btn-left", "btn-right"];
|
|
30
|
+
// console.log('slots', slots);
|
|
31
|
+
// console.log('attrs', attrs);
|
|
32
|
+
// 解析 attrs 中的事件
|
|
33
|
+
// const getEvent = () => {
|
|
34
|
+
// let formObj: any = {};
|
|
35
|
+
// Object.keys(attrs)?.forEach((name) => {
|
|
36
|
+
// if (name.indexOf("on") === 0) {
|
|
37
|
+
// formObj[name] = attrs[name];
|
|
38
|
+
// }
|
|
39
|
+
// })
|
|
40
|
+
// return formObj
|
|
41
|
+
// };
|
|
42
|
+
|
|
43
|
+
// 解析插槽
|
|
44
|
+
// const getSlot = () => {
|
|
45
|
+
// let formObj = {};
|
|
46
|
+
// Object.keys(slots).forEach((key) => {
|
|
47
|
+
// if (!slotsList.includes(key)) {
|
|
48
|
+
// formObj[key] = slots[key];
|
|
49
|
+
// }
|
|
50
|
+
// });
|
|
51
|
+
// return formObj
|
|
52
|
+
// };
|
|
53
|
+
return () => (
|
|
54
|
+
<div className="xxxxxxx">xxxxxxx</div>
|
|
55
|
+
)
|
|
56
|
+
},
|
|
57
|
+
})
|
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
|
+
})
|