el-plus-crud 0.0.78 → 0.0.80

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,148 +1,194 @@
1
- import { cloneDeep } from 'lodash'
2
- import { IColumnItem } from 'types'
3
-
4
- /**
5
- * 获取随机字符串
6
- * @returns {string}
7
- */
8
- export function getUID(): string {
9
- let str = ''
10
- const arr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
11
- for (let i = 0; i < 32; i++) {
12
- let index = Math.floor(arr.length * Math.random())
13
- if (index < 0) index = 0
14
- str += arr[index]
15
- }
16
- return str
17
- }
18
-
19
- // 判断类型
20
- export function is(val: any, type: any) {
21
- const typeArr = Array.isArray(type) ? type : [type]
22
- const valType = Object.prototype.toString.call(val)
23
- return typeArr.some((type) => `[object ${type}]` === valType)
24
- }
25
-
26
- /**
27
- * 判断是否是移动端
28
- */
29
- export function isMobile() {
30
- if (navigator.userAgent.match(/('phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone')/i)) {
31
- return true
32
- } else {
33
- return false
34
- }
35
- }
36
-
37
- /**
38
- * 处理按钮类型
39
- * @param item
40
- */
41
- export function handelBtnType(item: any): Object {
42
- switch (item.type) {
43
- case undefined:
44
- item.type = 'primary'
45
- break
46
- case 'add':
47
- item.type = 'primary'
48
- item.title = item.title || '新增'
49
- item.icon = 'ele-Plus'
50
- break
51
- case 'edit':
52
- item.type = 'primary'
53
- item.title = item.title || '编辑'
54
- item.icon = 'ele-EditPen'
55
- break
56
- case 'delete':
57
- case 'del':
58
- item.type = 'danger'
59
- item.title = item.title || '删除'
60
- item.icon = 'ele-Delete'
61
- break
62
- }
63
- return item
64
- }
65
-
66
- /**
67
- * 处理列表表头,list转Map
68
- */
69
- export function handelListColumn(columnList: Array<IColumnItem>, minWidth?: string): any[] {
70
- const tempColumnList = [] as any[]
71
- if (columnList && columnList.length > 0) {
72
- // 不影响原有的对象,这里进行拷贝
73
- cloneDeep(columnList).map((item: IColumnItem) => {
74
- // 处理下一个单元格显示多个数据
75
- if (item.nodes) {
76
- const tempList = (handelListColumn(item.nodes, minWidth) as any)[0].children
77
- item.nodes = tempList || item.nodes
78
- }
79
- // 检查type属性,没有type属性的自动补一个text类型
80
- if (!item.type) {
81
- item.type = 'text'
82
- }
83
- // 这里判断下type类型,然后进行一下表头和表格的对齐方式
84
- switch (item.type) {
85
- case 'image':
86
- item.width = item.width || '110px'
87
- item.align = item.align || 'left'
88
- item.headerAlign = item.headerAlign || 'left'
89
- break
90
- case 'btns':
91
- if (!item.minWidth && item.btns && item.btns.length >= 2) {
92
- let labelLength = 0
93
- item.btns.map((item: any) => (labelLength += typeof item.label === 'string' ? item.label.length : 4))
94
- item.width = item.width || labelLength * 20 + 'px'
95
- }
96
- item.align = item.align || 'left'
97
- item.headerAlign = item.headerAlign || 'left'
98
- item.text = true
99
- break
100
- }
101
- // item.minWidth = item.minWidth || 'auto'
102
- item.minWidth = item.minWidth || (item.label !== '操作' ? minWidth : 'auto')
103
-
104
- // 处理下‘操作’
105
- item.showOverflowTooltip = item.label !== '操作'
106
-
107
- if (item.parent) {
108
- let isExists = false
109
- tempColumnList.forEach((colum: any) => {
110
- if (colum.label === item.parent) {
111
- colum.children.push(item)
112
- isExists = true
113
- }
114
- })
115
- if (!isExists) {
116
- tempColumnList.push({ label: item.parent, children: [item] })
117
- }
118
- } else {
119
- tempColumnList.push(item)
120
- }
121
- })
122
- }
123
- return tempColumnList
124
- }
125
-
126
- /**
127
- * map转string
128
- * @param map
129
- * @param excludeList
130
- * @returns {string}
131
- */
132
- export const mapToUrlStr = (map: any, excludeList?: any) => {
133
- let queryStr = ''
134
- for (const key in map) {
135
- if (excludeList && Array.isArray(excludeList) && excludeList.length > 0) {
136
- if (excludeList.indexOf(key) >= 0) {
137
- continue
138
- }
139
- }
140
- if (map[key] !== undefined && map[key] !== null && map[key] !== '') {
141
- if (queryStr !== '') {
142
- queryStr += '&'
143
- }
144
- queryStr += key + '=' + map[key]
145
- }
146
- }
147
- return queryStr
148
- }
1
+ import { cloneDeep } from 'lodash'
2
+ import { ICRUDConfig, IColumnItem } from 'types'
3
+
4
+ /**
5
+ * 获取随机字符串
6
+ * @returns {string}
7
+ */
8
+ export function getUID(): string {
9
+ let str = ''
10
+ const arr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
11
+ for (let i = 0; i < 32; i++) {
12
+ let index = Math.floor(arr.length * Math.random())
13
+ if (index < 0) index = 0
14
+ str += arr[index]
15
+ }
16
+ return str
17
+ }
18
+
19
+ // 判断类型
20
+ export function is(val: any, type: any) {
21
+ const typeArr = Array.isArray(type) ? type : [type]
22
+ const valType = Object.prototype.toString.call(val)
23
+ return typeArr.some((type) => `[object ${type}]` === valType)
24
+ }
25
+
26
+ /**
27
+ * 判断是否是移动端
28
+ */
29
+ export function isMobile() {
30
+ if (navigator.userAgent.match(/('phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone')/i)) {
31
+ return true
32
+ } else {
33
+ return false
34
+ }
35
+ }
36
+
37
+ /**
38
+ * 处理按钮类型
39
+ * @param item
40
+ */
41
+ export function handelBtnType(item: any): Object {
42
+ switch (item.type) {
43
+ case undefined:
44
+ item.type = 'primary'
45
+ break
46
+ case 'add':
47
+ item.type = 'primary'
48
+ item.title = item.title || '新增'
49
+ item.icon = 'ele-Plus'
50
+ break
51
+ case 'edit':
52
+ item.type = 'primary'
53
+ item.title = item.title || '编辑'
54
+ item.icon = 'ele-EditPen'
55
+ break
56
+ case 'delete':
57
+ case 'del':
58
+ item.type = 'danger'
59
+ item.title = item.title || '删除'
60
+ item.icon = 'ele-Delete'
61
+ break
62
+ }
63
+ return item
64
+ }
65
+
66
+ /**
67
+ * 处理列表表头,list转Map
68
+ */
69
+ export function handelListColumn(columnList: Array<IColumnItem>, defaultConf: ICRUDConfig, tbName: string, headerAlign?: string, minWidth?: string): any[] {
70
+ const tempColumnList = [] as any[]
71
+ if (columnList && columnList.length > 0) {
72
+ // 不影响原有的对象,这里进行拷贝
73
+ cloneDeep(columnList).map((item: IColumnItem) => {
74
+ // 如果有子集
75
+ if (item.children) {
76
+ item.children = handelListColumn(item.children, defaultConf, tbName, headerAlign, minWidth)
77
+ }
78
+
79
+ // 处理下一个单元格显示多个数据
80
+ // if (item.nodes) {
81
+ // const tempList = (handelListColumn(item.nodes, minWidth) as any)[0].children
82
+ // item.nodes = tempList || item.nodes
83
+ // }
84
+ // 检查type属性,没有type属性的自动补一个text类型
85
+ if (!item.type) {
86
+ item.type = 'text'
87
+ }
88
+ // 这里判断下type类型,然后进行一下表头和表格的对齐方式
89
+ switch (item.type) {
90
+ case 'image':
91
+ item.width = item.width || '110px'
92
+ item.align = item.align || 'left'
93
+ item.headerAlign = item.headerAlign || headerAlign || 'left'
94
+ break
95
+ case 'btns':
96
+ if (!item.minWidth && item.btns && item.btns.length >= 2) {
97
+ let labelLength = 0
98
+ item.btns.map((item: any) => (labelLength += typeof item.label === 'string' ? item.label.length : 4))
99
+ item.width = item.width || labelLength * 20 + 'px'
100
+ }
101
+ item.align = item.align || 'left'
102
+ item.headerAlign = item.headerAlign || headerAlign || 'left'
103
+ item.text = true
104
+ break
105
+ }
106
+ // item.minWidth = item.minWidth || 'auto'
107
+ item.minWidth = item.minWidth || (item.label !== '操作' ? minWidth : 'auto')
108
+
109
+ // 处理下‘操作’
110
+ item.showOverflowTooltip = item.label !== '操作'
111
+
112
+ // 处理vif
113
+ handelVIf(item, defaultConf, tbName)
114
+
115
+ // 表头居中
116
+ if (item.children?.length) {
117
+ item.headerAlign = item.headerAlign || headerAlign || 'center'
118
+ }
119
+
120
+ tempColumnList.push(item)
121
+ })
122
+ }
123
+ return tempColumnList
124
+ }
125
+
126
+ /**
127
+ * 处理item的vif
128
+ * @param item
129
+ * @param defaultConf
130
+ * @param tbName
131
+ */
132
+ export function handelVIf(item: IColumnItem, defaultConf: ICRUDConfig, tbName: string) {
133
+ if (tbName) {
134
+ if (item.vif !== undefined && item.vif !== null) {
135
+ if (typeof item.vif === 'function') {
136
+ item._vif = item.vif(item)
137
+ } else {
138
+ item._vif = !!item.vif
139
+ }
140
+ } else {
141
+ item._vif = true
142
+ }
143
+ item.__vif = item.scShow && item._vif
144
+ } else {
145
+ // 这里初始化一下vif
146
+ if (item.vif !== undefined && item.vif !== null) {
147
+ if (typeof item.vif === 'function') {
148
+ item._vif = item.vif(item)
149
+ } else {
150
+ item._vif = !!item.vif
151
+ }
152
+ } else {
153
+ item._vif = true
154
+ }
155
+ // 这里最终处理一下auth权限问题
156
+ if (item.auth) {
157
+ if (!defaultConf.auth) {
158
+ console.warn('使用auth属性,请在crud注册时传入auth校验方法~')
159
+ } else {
160
+ item._vif = defaultConf.auth(item.auth)
161
+ }
162
+ }
163
+ item.__vif = item._vif
164
+ }
165
+
166
+ // 这里要判断下下级显示状态, 如果下级全部隐藏了,那么本级也应该隐藏
167
+ if (item.children && item.children.every((info) => !info.__vif)) {
168
+ item.__vif = false
169
+ }
170
+ }
171
+
172
+ /**
173
+ * map转string
174
+ * @param map
175
+ * @param excludeList
176
+ * @returns {string}
177
+ */
178
+ export const mapToUrlStr = (map: any, excludeList?: any) => {
179
+ let queryStr = ''
180
+ for (const key in map) {
181
+ if (excludeList && Array.isArray(excludeList) && excludeList.length > 0) {
182
+ if (excludeList.indexOf(key) >= 0) {
183
+ continue
184
+ }
185
+ }
186
+ if (map[key] !== undefined && map[key] !== null && map[key] !== '') {
187
+ if (queryStr !== '') {
188
+ queryStr += '&'
189
+ }
190
+ queryStr += key + '=' + map[key]
191
+ }
192
+ }
193
+ return queryStr
194
+ }
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "el-plus-crud",
3
- "version": "0.0.78",
3
+ "version": "0.0.80",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "el-plus-crud",
9
- "version": "0.0.78",
9
+ "version": "0.0.80",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@element-plus/icons-vue": "^2.1.0",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "el-plus-crud",
3
3
  "description": "采用Vue3 + TS,封装的element-plus数据驱动表单、列表组件",
4
4
  "author": "K.D.Jack",
5
- "version": "0.0.78",
5
+ "version": "0.0.80",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "main": "dist/el-plus-crud.mjs",