@elementplus-kit/uikit 1.0.2 → 1.0.3

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.
@@ -0,0 +1,4 @@
1
+ import Button from "./src/index";
2
+ export * from "./src/index";
3
+ export { Button };
4
+ export default Button;
@@ -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,91 @@
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
+ // modelValue: {
15
+ // type: Object,
16
+ // default: {}
17
+ // },
18
+ buttonOptions: {
19
+ type: Array,
20
+ default: () => [],
21
+ },
22
+ // 权限函数
23
+ hasPermission: {
24
+ type: Function,
25
+ default: () => true,
26
+ },
27
+ // // 权限函数
28
+ // hasRole: {
29
+ // type: Function,
30
+ // default: () => true
31
+ // },
32
+ },
33
+
34
+ setup(props, { emit, slots, attrs, expose }) {
35
+ // const slotsList = ["active", "btn-left", "btn-right"];
36
+ // console.log('slots', slots);
37
+ // console.log('attrs', attrs);
38
+
39
+ // 解析插槽
40
+ const getAttrs = (item) => {
41
+ let defaultAttrs = {};
42
+ // const { alias, hasPermission, vIf, ...p } = item;
43
+ if (item?.alias && typeActiveMap[item.alias]) {
44
+ defaultAttrs = typeActiveMap[item.alias];
45
+ }
46
+ // 过滤掉非elbutton属性
47
+ defaultAttrs = {
48
+ ...defaultAttrs,
49
+ ...item,
50
+ };
51
+ return defaultAttrs;
52
+ };
53
+ const render = () => {
54
+ console.log("render 执行");
55
+ // 过滤权限
56
+ let list = [];
57
+ props.buttonOptions.map((item) => {
58
+ if (has(item, "permission") && isArray(item.permission)) {
59
+ if (props.hasPermission && props.hasPermission(item.permission)) {
60
+ list.push(item);
61
+ }
62
+ } else {
63
+ list.push(item);
64
+ }
65
+ });
66
+
67
+ const listR = [];
68
+ list.map((item) => {
69
+ // if (has(item, "vIf")) {
70
+ if (has(item, "vIf") && isFunction(item.vIf) && item.vIf(props.params) !== undefined) {
71
+ console.log('aaaaaaaaaa', item.vIf(props.params));
72
+ if (item.vIf(props.params)) {
73
+ listR.push(item);
74
+ }
75
+ } else {
76
+ listR.push(item);
77
+ }
78
+ // } else {
79
+ // listR.push(item);
80
+ // }
81
+ });
82
+ console.log("🚀 ~ render ~ listR:", listR);
83
+ return listR.map((item) => {
84
+ return h(ElButton, getAttrs(item), {
85
+ default: () => item?.name,
86
+ });
87
+ });
88
+ };
89
+ return () => render();
90
+ },
91
+ });
File without changes
@@ -0,0 +1,4 @@
1
+ import DictLabel from "./src/index.vue";
2
+ export * from "./src/index.vue";
3
+ export { DictLabel };
4
+ export default DictLabel;
@@ -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>
@@ -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>;
@@ -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: () => renderFormItem(),
97
+ default: () => formItemVdom,
95
98
  }
96
99
  );
97
100
  } else {
98
- return renderFormItem();
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
@@ -0,0 +1,5 @@
1
+ .c-form.el-form--inline {
2
+ .el-select {
3
+ --el-select-width: 220px;
4
+ }
5
+ }
@@ -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"; // 抽屉
@@ -47,7 +47,7 @@ const propsAttrs = {
47
47
  type: String,
48
48
  default: undefined,
49
49
  },
50
- // 字典
50
+ // 字典 暂不实现
51
51
  dictType: { type: String, default: undefined },
52
52
  // 字典选项
53
53
  options: { type: Array, default: () => [] },
@@ -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
- // tableRef,
66
- });
69
+ // expose({
70
+ // // tableRef,
71
+ // });
67
72
 
68
- // 属性处理
69
- const getAttrs = () => {
70
- const obj = {
71
- ...defaultAttrs, // 设置默认值
72
- };
73
- return obj;
74
- };
75
- // 事件处理
76
- const getEvents = () => {
77
- const obj = {
78
- ...defaultAttrs, // 设置默认值
79
- };
80
- return obj;
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
- console.log("adsadsd");
86
- // 递归处理数据
87
- const list = [];
88
+ // // 处理列数据-数组
89
+ // const getArrayColumn = () => {
90
+ // // 递归处理数据
91
+ // const list = [];
88
92
 
89
- const c = (columns, list) => {
90
- columns?.map((item) => {
91
- const { children, ...p } = item;
92
- // 递归处理子列
93
- if (isArray(item.children)) {
94
- item.children = c(item.children, list);
95
- }
96
- list.push(p);
97
- });
98
- };
99
- c(props.columns, list);
100
- console.log("🚀 ~ gggggggg:", list);
101
- return list;
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: 55,
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: 55,
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
- listSub.length
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
- listSub.length ? { default: () => listSub } : undefined
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: () => renderTableColumn(),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementplus-kit/uikit",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "./components/index.ts",
6
6
  "peerDependencies": {