@ddwl/ddwl-ui 1.1.3 → 1.1.5-beta.1
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/README.md +92 -92
- package/package.json +68 -68
- package/src/lib/install/index.js +13 -13
- package/src/lib/slots/buttonGroup.vue +113 -113
- package/src/lib/slots/dict.vue +46 -46
- package/src/lib/slots/file.vue +36 -36
- package/src/lib/slots/icon.vue +74 -74
- package/src/lib/slots/index.js +11 -11
- package/src/main.js +62 -62
- package/src/packages/button/index.vue +36 -36
- package/src/packages/descriptions/index.vue +124 -124
- package/src/packages/dialog/index.vue +172 -172
- package/src/packages/dialog-confirm/index.vue +99 -99
- package/src/packages/drawer/index.vue +136 -136
- package/src/packages/file-preview/index.vue +277 -276
- package/src/packages/filter-tree/index.vue +295 -295
- package/src/packages/form/index.vue +149 -149
- package/src/packages/form-item/index.vue +199 -199
- package/src/packages/import-file/index.vue +173 -173
- package/src/packages/menu/index.vue +66 -66
- package/src/packages/menu/menuItem.vue +90 -90
- package/src/packages/popconfirm/index.vue +39 -39
- package/src/packages/render/index.vue +14 -14
- package/src/packages/search-form/index.vue +257 -257
- package/src/packages/search-input/index.vue +68 -68
- package/src/packages/search-table/index.vue +93 -93
- package/src/packages/svg-icon/index.vue +43 -43
- package/src/packages/table/index.vue +458 -458
- package/src/packages/upload/index.vue +356 -356
- package/src/utils/index.js +77 -77
- package/src/utils/treeLib.js +190 -190
package/src/utils/index.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description: 文件大小转换
|
|
3
|
-
* @param {Number} bytes 字节大小
|
|
4
|
-
* @return {String} 转换后带单位的文件大小结果
|
|
5
|
-
*/
|
|
6
|
-
export const convertBytesToSize = (bytes) => {
|
|
7
|
-
const thresh = 1024
|
|
8
|
-
if (Math.abs(bytes) < thresh) {
|
|
9
|
-
return bytes + ' B'
|
|
10
|
-
}
|
|
11
|
-
const units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
12
|
-
let u = -1
|
|
13
|
-
do {
|
|
14
|
-
bytes /= thresh
|
|
15
|
-
++u
|
|
16
|
-
} while (Math.abs(bytes) >= thresh && u < units.length - 1)
|
|
17
|
-
return bytes.toFixed(0) + ' ' + units[u]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @description: 获取url参数
|
|
22
|
-
* @param {*} name 参数名称
|
|
23
|
-
* @return {string}
|
|
24
|
-
*/
|
|
25
|
-
export function getQueryString (name) {
|
|
26
|
-
const href = window.location.href
|
|
27
|
-
/*eslint-disable */
|
|
28
|
-
const reg = new RegExp(name + '=[^&|#|\/]*')
|
|
29
|
-
const res = href.match(reg)
|
|
30
|
-
return res ? href.match(reg)[0].split('=')[1] : ''
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @description: 移除url参数
|
|
35
|
-
* @param {*} name 参数名称
|
|
36
|
-
* @return {string}
|
|
37
|
-
*/
|
|
38
|
-
export const removeURLParam = (name) => {
|
|
39
|
-
let tempUrl = window.location.href
|
|
40
|
-
tempUrl = tempUrl.split("?")[0]
|
|
41
|
-
window.history.replaceState({}, "0", tempUrl)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @description: 复制内容到剪贴板
|
|
46
|
-
* @param {string} text 复制文本
|
|
47
|
-
* @return {string}
|
|
48
|
-
*/
|
|
49
|
-
export const copy = (text) => {
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
const input = document.createElement('input')
|
|
52
|
-
document.body.appendChild(input)
|
|
53
|
-
input.setAttribute('value', text)
|
|
54
|
-
input.select()
|
|
55
|
-
if (document.execCommand('copy')) {
|
|
56
|
-
document.execCommand('copy')
|
|
57
|
-
resolve()
|
|
58
|
-
} else {
|
|
59
|
-
reject()
|
|
60
|
-
}
|
|
61
|
-
document.body.removeChild(input)
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @description: 根据字符串长度生成*号字符串
|
|
67
|
-
* @param {*} text 字符串
|
|
68
|
-
* @return {string}
|
|
69
|
-
*/
|
|
70
|
-
export function generateAsterisksByString (text) {
|
|
71
|
-
const length = text.length
|
|
72
|
-
if (typeof length !== 'number' || length <= 0) {
|
|
73
|
-
return ''
|
|
74
|
-
}
|
|
75
|
-
return '*'.repeat(length)
|
|
76
|
-
}
|
|
77
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description: 文件大小转换
|
|
3
|
+
* @param {Number} bytes 字节大小
|
|
4
|
+
* @return {String} 转换后带单位的文件大小结果
|
|
5
|
+
*/
|
|
6
|
+
export const convertBytesToSize = (bytes) => {
|
|
7
|
+
const thresh = 1024
|
|
8
|
+
if (Math.abs(bytes) < thresh) {
|
|
9
|
+
return bytes + ' B'
|
|
10
|
+
}
|
|
11
|
+
const units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
12
|
+
let u = -1
|
|
13
|
+
do {
|
|
14
|
+
bytes /= thresh
|
|
15
|
+
++u
|
|
16
|
+
} while (Math.abs(bytes) >= thresh && u < units.length - 1)
|
|
17
|
+
return bytes.toFixed(0) + ' ' + units[u]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @description: 获取url参数
|
|
22
|
+
* @param {*} name 参数名称
|
|
23
|
+
* @return {string}
|
|
24
|
+
*/
|
|
25
|
+
export function getQueryString (name) {
|
|
26
|
+
const href = window.location.href
|
|
27
|
+
/*eslint-disable */
|
|
28
|
+
const reg = new RegExp(name + '=[^&|#|\/]*')
|
|
29
|
+
const res = href.match(reg)
|
|
30
|
+
return res ? href.match(reg)[0].split('=')[1] : ''
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @description: 移除url参数
|
|
35
|
+
* @param {*} name 参数名称
|
|
36
|
+
* @return {string}
|
|
37
|
+
*/
|
|
38
|
+
export const removeURLParam = (name) => {
|
|
39
|
+
let tempUrl = window.location.href
|
|
40
|
+
tempUrl = tempUrl.split("?")[0]
|
|
41
|
+
window.history.replaceState({}, "0", tempUrl)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @description: 复制内容到剪贴板
|
|
46
|
+
* @param {string} text 复制文本
|
|
47
|
+
* @return {string}
|
|
48
|
+
*/
|
|
49
|
+
export const copy = (text) => {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const input = document.createElement('input')
|
|
52
|
+
document.body.appendChild(input)
|
|
53
|
+
input.setAttribute('value', text)
|
|
54
|
+
input.select()
|
|
55
|
+
if (document.execCommand('copy')) {
|
|
56
|
+
document.execCommand('copy')
|
|
57
|
+
resolve()
|
|
58
|
+
} else {
|
|
59
|
+
reject()
|
|
60
|
+
}
|
|
61
|
+
document.body.removeChild(input)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @description: 根据字符串长度生成*号字符串
|
|
67
|
+
* @param {*} text 字符串
|
|
68
|
+
* @return {string}
|
|
69
|
+
*/
|
|
70
|
+
export function generateAsterisksByString (text) {
|
|
71
|
+
const length = text.length
|
|
72
|
+
if (typeof length !== 'number' || length <= 0) {
|
|
73
|
+
return ''
|
|
74
|
+
}
|
|
75
|
+
return '*'.repeat(length)
|
|
76
|
+
}
|
|
77
|
+
|
package/src/utils/treeLib.js
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
import { cloneDeep } from 'lodash'
|
|
2
|
-
|
|
3
|
-
// 默认的props传参
|
|
4
|
-
const defaultProps = {
|
|
5
|
-
key: 'id',
|
|
6
|
-
label: 'label',
|
|
7
|
-
children: 'children'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const _getProps = (props) => {
|
|
11
|
-
return { ...defaultProps, ...props }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @description: 获取树结构第一个匹配的节点数据
|
|
16
|
-
* @param {Array} tree
|
|
17
|
-
* * @param {String} matchs 匹配规则函数
|
|
18
|
-
* @return {Any}
|
|
19
|
-
*/
|
|
20
|
-
export const getFirstVaildNode = (tree, matchs, props = {}) => {
|
|
21
|
-
props = _getProps(props)
|
|
22
|
-
for (const node of tree) {
|
|
23
|
-
if (matchs(node)) {
|
|
24
|
-
return node
|
|
25
|
-
}
|
|
26
|
-
if (node[props.children] && node[props.children].length) {
|
|
27
|
-
const data = getFirstVaildNode(node[props.children], matchs, props)
|
|
28
|
-
if (data) return data
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @description: 根据key查找树中的匹配节点
|
|
35
|
-
* @param {Array} data
|
|
36
|
-
* @param {String | Number} value 匹配的值
|
|
37
|
-
* @return {Any}
|
|
38
|
-
*/
|
|
39
|
-
export const getNodeByKey = (data, value, props = {}) => {
|
|
40
|
-
props = _getProps(props)
|
|
41
|
-
const tree = cloneDeep(data)
|
|
42
|
-
const arr = Array.isArray(tree) ? tree : [tree]
|
|
43
|
-
let result = null
|
|
44
|
-
while (arr.length) {
|
|
45
|
-
const item = arr.pop()
|
|
46
|
-
if (item && item[props.key] === value) {
|
|
47
|
-
result = item
|
|
48
|
-
break
|
|
49
|
-
} else if (item && item[props.children] && item[props.children].length) {
|
|
50
|
-
arr.push(...item[props.children])
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return result
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @description: 根据key查找树中的匹配节点集合
|
|
58
|
-
* @param {Array} data
|
|
59
|
-
* @param {String | Number} value 匹配的值
|
|
60
|
-
* @return {Any}
|
|
61
|
-
*/
|
|
62
|
-
export const getNodeByKeys = (data, values, props = {}, arr = []) => {
|
|
63
|
-
props = _getProps(props)
|
|
64
|
-
let tree = cloneDeep(data)
|
|
65
|
-
tree = Array.isArray(tree) ? tree : [tree]
|
|
66
|
-
tree.forEach((node) => {
|
|
67
|
-
if (values.includes(node[props.key])) {
|
|
68
|
-
arr.push(node)
|
|
69
|
-
}
|
|
70
|
-
if (node[props.children] && node[props.children].length) {
|
|
71
|
-
arr = arr.concat(getNodeByKeys(node[props.children], values, props))
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
return arr
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @description: 获取树所有节点 --- 树扁平化
|
|
79
|
-
* @param {Array} data
|
|
80
|
-
* @return {Array}
|
|
81
|
-
*/
|
|
82
|
-
export const flatTree = (data, props = {}) => {
|
|
83
|
-
props = _getProps(props)
|
|
84
|
-
let arr = []
|
|
85
|
-
data.forEach((node) => {
|
|
86
|
-
arr.push(node)
|
|
87
|
-
if (node[props.children] && node[props.children].length) {
|
|
88
|
-
arr = arr.concat(flatTree(node[props.children], props))
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
return arr
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @description: 获取树所有没有子节点的节点 --- 树扁平化
|
|
96
|
-
* @param {Array} data
|
|
97
|
-
* @return {Array}
|
|
98
|
-
*/
|
|
99
|
-
export const flatTreeByLastNode = (data, props = {}) => {
|
|
100
|
-
props = _getProps(props)
|
|
101
|
-
let arr = []
|
|
102
|
-
data.forEach((node) => {
|
|
103
|
-
if (node[props.children] && node[props.children].length) {
|
|
104
|
-
arr = arr.concat(flatTreeByLastNode(node[props.children], props))
|
|
105
|
-
} else {
|
|
106
|
-
arr.push(node)
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
return arr
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @description: 删除树指定节点
|
|
114
|
-
* @param {Array} data
|
|
115
|
-
* @param {String} value 匹配的节点值
|
|
116
|
-
* @param {String} self true: 删除自身 false: 只删除子节点 默认true
|
|
117
|
-
* @return {Array}
|
|
118
|
-
*/
|
|
119
|
-
export const deleteNode = (data, value, self = true, props = {}) => {
|
|
120
|
-
props = _getProps(props)
|
|
121
|
-
data = cloneDeep(data)
|
|
122
|
-
let arr = []
|
|
123
|
-
if (self) {
|
|
124
|
-
arr = data.filter((node) => node[props.key] !== value)
|
|
125
|
-
if (arr.length === data.length) {
|
|
126
|
-
arr = arr.map((node) => {
|
|
127
|
-
if (node[props.children] && node[props.children].length) {
|
|
128
|
-
node[props.children] = deleteNode(
|
|
129
|
-
node[props.children],
|
|
130
|
-
value,
|
|
131
|
-
self,
|
|
132
|
-
props
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
return node
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
arr = data.map((node) => {
|
|
140
|
-
if (node[props.key] === value) {
|
|
141
|
-
delete node[props.children]
|
|
142
|
-
}
|
|
143
|
-
if (node[props.children] && node[props.children].length) {
|
|
144
|
-
node[props.children] = deleteNode(
|
|
145
|
-
node[props.children],
|
|
146
|
-
value,
|
|
147
|
-
self,
|
|
148
|
-
props
|
|
149
|
-
)
|
|
150
|
-
}
|
|
151
|
-
return node
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return arr
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @description: 根据key 精准/模糊搜索匹配到的所有节点
|
|
160
|
-
* @param {Array} data
|
|
161
|
-
* @param {Array} data 匹配的节点值
|
|
162
|
-
* @param {String} type fuzzy: 模糊搜索 precise: 精准搜索
|
|
163
|
-
* @return {Array}
|
|
164
|
-
*/
|
|
165
|
-
export const filterNodeMethod = (value, data = [], type = 'fuzzy', props = {}) => {
|
|
166
|
-
props = _getProps(props)
|
|
167
|
-
let newarr = []
|
|
168
|
-
data.forEach((node) => {
|
|
169
|
-
if (type === 'fuzzy' ? (node[props.key].indexOf(value) > -1) : node[props.key] === value) {
|
|
170
|
-
const ab = filterNodeMethod(value, node[props.children], type, props)
|
|
171
|
-
const obj = {
|
|
172
|
-
...node,
|
|
173
|
-
children: ab
|
|
174
|
-
}
|
|
175
|
-
newarr.push(obj)
|
|
176
|
-
} else {
|
|
177
|
-
if (node[props.children] && node[props.children].length > 0) {
|
|
178
|
-
const ab = filterNodeMethod(value, node[props.children], type, props)
|
|
179
|
-
const obj = {
|
|
180
|
-
...node,
|
|
181
|
-
children: ab
|
|
182
|
-
}
|
|
183
|
-
if (ab && ab.length > 0) {
|
|
184
|
-
newarr.push(obj)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
})
|
|
189
|
-
return newarr
|
|
190
|
-
}
|
|
1
|
+
import { cloneDeep } from 'lodash'
|
|
2
|
+
|
|
3
|
+
// 默认的props传参
|
|
4
|
+
const defaultProps = {
|
|
5
|
+
key: 'id',
|
|
6
|
+
label: 'label',
|
|
7
|
+
children: 'children'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const _getProps = (props) => {
|
|
11
|
+
return { ...defaultProps, ...props }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @description: 获取树结构第一个匹配的节点数据
|
|
16
|
+
* @param {Array} tree
|
|
17
|
+
* * @param {String} matchs 匹配规则函数
|
|
18
|
+
* @return {Any}
|
|
19
|
+
*/
|
|
20
|
+
export const getFirstVaildNode = (tree, matchs, props = {}) => {
|
|
21
|
+
props = _getProps(props)
|
|
22
|
+
for (const node of tree) {
|
|
23
|
+
if (matchs(node)) {
|
|
24
|
+
return node
|
|
25
|
+
}
|
|
26
|
+
if (node[props.children] && node[props.children].length) {
|
|
27
|
+
const data = getFirstVaildNode(node[props.children], matchs, props)
|
|
28
|
+
if (data) return data
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @description: 根据key查找树中的匹配节点
|
|
35
|
+
* @param {Array} data
|
|
36
|
+
* @param {String | Number} value 匹配的值
|
|
37
|
+
* @return {Any}
|
|
38
|
+
*/
|
|
39
|
+
export const getNodeByKey = (data, value, props = {}) => {
|
|
40
|
+
props = _getProps(props)
|
|
41
|
+
const tree = cloneDeep(data)
|
|
42
|
+
const arr = Array.isArray(tree) ? tree : [tree]
|
|
43
|
+
let result = null
|
|
44
|
+
while (arr.length) {
|
|
45
|
+
const item = arr.pop()
|
|
46
|
+
if (item && item[props.key] === value) {
|
|
47
|
+
result = item
|
|
48
|
+
break
|
|
49
|
+
} else if (item && item[props.children] && item[props.children].length) {
|
|
50
|
+
arr.push(...item[props.children])
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return result
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @description: 根据key查找树中的匹配节点集合
|
|
58
|
+
* @param {Array} data
|
|
59
|
+
* @param {String | Number} value 匹配的值
|
|
60
|
+
* @return {Any}
|
|
61
|
+
*/
|
|
62
|
+
export const getNodeByKeys = (data, values, props = {}, arr = []) => {
|
|
63
|
+
props = _getProps(props)
|
|
64
|
+
let tree = cloneDeep(data)
|
|
65
|
+
tree = Array.isArray(tree) ? tree : [tree]
|
|
66
|
+
tree.forEach((node) => {
|
|
67
|
+
if (values.includes(node[props.key])) {
|
|
68
|
+
arr.push(node)
|
|
69
|
+
}
|
|
70
|
+
if (node[props.children] && node[props.children].length) {
|
|
71
|
+
arr = arr.concat(getNodeByKeys(node[props.children], values, props))
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
return arr
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @description: 获取树所有节点 --- 树扁平化
|
|
79
|
+
* @param {Array} data
|
|
80
|
+
* @return {Array}
|
|
81
|
+
*/
|
|
82
|
+
export const flatTree = (data, props = {}) => {
|
|
83
|
+
props = _getProps(props)
|
|
84
|
+
let arr = []
|
|
85
|
+
data.forEach((node) => {
|
|
86
|
+
arr.push(node)
|
|
87
|
+
if (node[props.children] && node[props.children].length) {
|
|
88
|
+
arr = arr.concat(flatTree(node[props.children], props))
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
return arr
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @description: 获取树所有没有子节点的节点 --- 树扁平化
|
|
96
|
+
* @param {Array} data
|
|
97
|
+
* @return {Array}
|
|
98
|
+
*/
|
|
99
|
+
export const flatTreeByLastNode = (data, props = {}) => {
|
|
100
|
+
props = _getProps(props)
|
|
101
|
+
let arr = []
|
|
102
|
+
data.forEach((node) => {
|
|
103
|
+
if (node[props.children] && node[props.children].length) {
|
|
104
|
+
arr = arr.concat(flatTreeByLastNode(node[props.children], props))
|
|
105
|
+
} else {
|
|
106
|
+
arr.push(node)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
return arr
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @description: 删除树指定节点
|
|
114
|
+
* @param {Array} data
|
|
115
|
+
* @param {String} value 匹配的节点值
|
|
116
|
+
* @param {String} self true: 删除自身 false: 只删除子节点 默认true
|
|
117
|
+
* @return {Array}
|
|
118
|
+
*/
|
|
119
|
+
export const deleteNode = (data, value, self = true, props = {}) => {
|
|
120
|
+
props = _getProps(props)
|
|
121
|
+
data = cloneDeep(data)
|
|
122
|
+
let arr = []
|
|
123
|
+
if (self) {
|
|
124
|
+
arr = data.filter((node) => node[props.key] !== value)
|
|
125
|
+
if (arr.length === data.length) {
|
|
126
|
+
arr = arr.map((node) => {
|
|
127
|
+
if (node[props.children] && node[props.children].length) {
|
|
128
|
+
node[props.children] = deleteNode(
|
|
129
|
+
node[props.children],
|
|
130
|
+
value,
|
|
131
|
+
self,
|
|
132
|
+
props
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
return node
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
arr = data.map((node) => {
|
|
140
|
+
if (node[props.key] === value) {
|
|
141
|
+
delete node[props.children]
|
|
142
|
+
}
|
|
143
|
+
if (node[props.children] && node[props.children].length) {
|
|
144
|
+
node[props.children] = deleteNode(
|
|
145
|
+
node[props.children],
|
|
146
|
+
value,
|
|
147
|
+
self,
|
|
148
|
+
props
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
return node
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return arr
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @description: 根据key 精准/模糊搜索匹配到的所有节点
|
|
160
|
+
* @param {Array} data
|
|
161
|
+
* @param {Array} data 匹配的节点值
|
|
162
|
+
* @param {String} type fuzzy: 模糊搜索 precise: 精准搜索
|
|
163
|
+
* @return {Array}
|
|
164
|
+
*/
|
|
165
|
+
export const filterNodeMethod = (value, data = [], type = 'fuzzy', props = {}) => {
|
|
166
|
+
props = _getProps(props)
|
|
167
|
+
let newarr = []
|
|
168
|
+
data.forEach((node) => {
|
|
169
|
+
if (type === 'fuzzy' ? (node[props.key].indexOf(value) > -1) : node[props.key] === value) {
|
|
170
|
+
const ab = filterNodeMethod(value, node[props.children], type, props)
|
|
171
|
+
const obj = {
|
|
172
|
+
...node,
|
|
173
|
+
children: ab
|
|
174
|
+
}
|
|
175
|
+
newarr.push(obj)
|
|
176
|
+
} else {
|
|
177
|
+
if (node[props.children] && node[props.children].length > 0) {
|
|
178
|
+
const ab = filterNodeMethod(value, node[props.children], type, props)
|
|
179
|
+
const obj = {
|
|
180
|
+
...node,
|
|
181
|
+
children: ab
|
|
182
|
+
}
|
|
183
|
+
if (ab && ab.length > 0) {
|
|
184
|
+
newarr.push(obj)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
return newarr
|
|
190
|
+
}
|