@ddwl/ddwl-ui 1.2.2 → 1.2.3-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.
Files changed (139) hide show
  1. package/dist/index.html +1 -0
  2. package/dist/js/app.js +1 -0
  3. package/dist/js/chunk-vendors.js +17 -0
  4. package/dist/static/css/app.2ec4a629.css +1 -0
  5. package/package.json +4 -5
  6. package/src/lib/install/index.js +0 -14
  7. package/src/lib/slots/buttonGroup.vue +0 -113
  8. package/src/lib/slots/dict.vue +0 -46
  9. package/src/lib/slots/file.vue +0 -36
  10. package/src/lib/slots/icon.vue +0 -74
  11. package/src/lib/slots/index.js +0 -11
  12. package/src/lib/theme/alert.css +0 -1
  13. package/src/lib/theme/aside.css +0 -1
  14. package/src/lib/theme/autocomplete.css +0 -1
  15. package/src/lib/theme/avatar.css +0 -1
  16. package/src/lib/theme/backtop.css +0 -1
  17. package/src/lib/theme/badge.css +0 -1
  18. package/src/lib/theme/base.css +0 -1
  19. package/src/lib/theme/breadcrumb-item.css +0 -0
  20. package/src/lib/theme/breadcrumb.css +0 -1
  21. package/src/lib/theme/button-group.css +0 -0
  22. package/src/lib/theme/button.css +0 -1
  23. package/src/lib/theme/calendar.css +0 -1
  24. package/src/lib/theme/card.css +0 -1
  25. package/src/lib/theme/carousel-item.css +0 -1
  26. package/src/lib/theme/carousel.css +0 -1
  27. package/src/lib/theme/cascader-panel.css +0 -1
  28. package/src/lib/theme/cascader.css +0 -1
  29. package/src/lib/theme/checkbox-button.css +0 -0
  30. package/src/lib/theme/checkbox-group.css +0 -0
  31. package/src/lib/theme/checkbox.css +0 -1
  32. package/src/lib/theme/col.css +0 -1
  33. package/src/lib/theme/collapse-item.css +0 -0
  34. package/src/lib/theme/collapse.css +0 -1
  35. package/src/lib/theme/color-picker.css +0 -1
  36. package/src/lib/theme/container.css +0 -1
  37. package/src/lib/theme/date-picker.css +0 -1
  38. package/src/lib/theme/descriptions-item.css +0 -1
  39. package/src/lib/theme/descriptions.css +0 -1
  40. package/src/lib/theme/dialog.css +0 -1
  41. package/src/lib/theme/display.css +0 -1
  42. package/src/lib/theme/divider.css +0 -1
  43. package/src/lib/theme/drawer.css +0 -1
  44. package/src/lib/theme/dropdown-item.css +0 -0
  45. package/src/lib/theme/dropdown-menu.css +0 -0
  46. package/src/lib/theme/dropdown.css +0 -1
  47. package/src/lib/theme/empty.css +0 -1
  48. package/src/lib/theme/footer.css +0 -1
  49. package/src/lib/theme/form-item.css +0 -0
  50. package/src/lib/theme/form.css +0 -1
  51. package/src/lib/theme/header.css +0 -1
  52. package/src/lib/theme/icon.css +0 -1
  53. package/src/lib/theme/image.css +0 -1
  54. package/src/lib/theme/index.css +0 -1
  55. package/src/lib/theme/infinite-scroll.css +0 -0
  56. package/src/lib/theme/infiniteScroll.css +0 -0
  57. package/src/lib/theme/input-number.css +0 -1
  58. package/src/lib/theme/input.css +0 -1
  59. package/src/lib/theme/link.css +0 -1
  60. package/src/lib/theme/loading.css +0 -1
  61. package/src/lib/theme/main.css +0 -1
  62. package/src/lib/theme/menu-item-group.css +0 -0
  63. package/src/lib/theme/menu-item.css +0 -0
  64. package/src/lib/theme/menu.css +0 -1
  65. package/src/lib/theme/message-box.css +0 -1
  66. package/src/lib/theme/message.css +0 -1
  67. package/src/lib/theme/notification.css +0 -1
  68. package/src/lib/theme/option-group.css +0 -1
  69. package/src/lib/theme/option.css +0 -1
  70. package/src/lib/theme/page-header.css +0 -1
  71. package/src/lib/theme/pagination.css +0 -1
  72. package/src/lib/theme/popconfirm.css +0 -1
  73. package/src/lib/theme/popover.css +0 -1
  74. package/src/lib/theme/popper.css +0 -1
  75. package/src/lib/theme/progress.css +0 -1
  76. package/src/lib/theme/radio-button.css +0 -1
  77. package/src/lib/theme/radio-group.css +0 -1
  78. package/src/lib/theme/radio.css +0 -1
  79. package/src/lib/theme/rate.css +0 -1
  80. package/src/lib/theme/reset.css +0 -1
  81. package/src/lib/theme/result.css +0 -1
  82. package/src/lib/theme/row.css +0 -1
  83. package/src/lib/theme/scrollbar.css +0 -1
  84. package/src/lib/theme/select-dropdown.css +0 -1
  85. package/src/lib/theme/select.css +0 -1
  86. package/src/lib/theme/skeleton-item.css +0 -1
  87. package/src/lib/theme/skeleton.css +0 -1
  88. package/src/lib/theme/slider.css +0 -1
  89. package/src/lib/theme/spinner.css +0 -1
  90. package/src/lib/theme/step.css +0 -1
  91. package/src/lib/theme/steps.css +0 -1
  92. package/src/lib/theme/submenu.css +0 -0
  93. package/src/lib/theme/switch.css +0 -1
  94. package/src/lib/theme/tab-pane.css +0 -0
  95. package/src/lib/theme/table-column.css +0 -1
  96. package/src/lib/theme/table.css +0 -1
  97. package/src/lib/theme/tabs.css +0 -1
  98. package/src/lib/theme/tag.css +0 -1
  99. package/src/lib/theme/time-picker.css +0 -1
  100. package/src/lib/theme/time-select.css +0 -1
  101. package/src/lib/theme/timeline-item.css +0 -1
  102. package/src/lib/theme/timeline.css +0 -1
  103. package/src/lib/theme/tooltip.css +0 -1
  104. package/src/lib/theme/transfer.css +0 -1
  105. package/src/lib/theme/tree.css +0 -1
  106. package/src/lib/theme/upload.css +0 -1
  107. package/src/main.js +0 -70
  108. package/src/packages/button/index.vue +0 -36
  109. package/src/packages/checkbox-group/index.vue +0 -57
  110. package/src/packages/descriptions/index.vue +0 -124
  111. package/src/packages/dialog/index.vue +0 -172
  112. package/src/packages/dialog-confirm/index.vue +0 -99
  113. package/src/packages/drawer/index.vue +0 -136
  114. package/src/packages/file-preview/index.vue +0 -275
  115. package/src/packages/file-preview/static/audio.png +0 -0
  116. package/src/packages/file-preview/static/video.png +0 -0
  117. package/src/packages/filter-tree/index.vue +0 -292
  118. package/src/packages/form/index.vue +0 -149
  119. package/src/packages/form-item/index.vue +0 -199
  120. package/src/packages/import-file/index.vue +0 -173
  121. package/src/packages/menu/index.vue +0 -66
  122. package/src/packages/menu/menuItem.vue +0 -90
  123. package/src/packages/popconfirm/index.vue +0 -39
  124. package/src/packages/radio-group/index.vue +0 -57
  125. package/src/packages/render/index.vue +0 -14
  126. package/src/packages/search-form/index.vue +0 -257
  127. package/src/packages/search-input/index.vue +0 -68
  128. package/src/packages/search-table/index.vue +0 -93
  129. package/src/packages/select/index.vue +0 -74
  130. package/src/packages/svg-icon/index.vue +0 -43
  131. package/src/packages/table/drag.png +0 -0
  132. package/src/packages/table/index.vue +0 -453
  133. package/src/packages/upload/index.vue +0 -350
  134. package/src/utils/constant.js +0 -4
  135. package/src/utils/index.js +0 -77
  136. package/src/utils/treeLib.js +0 -190
  137. /package/{src/lib/theme/fonts/element-icons.ttf → dist/static/fonts/element-icons.f1a45d74.ttf} +0 -0
  138. /package/{src/lib/theme/fonts/element-icons.woff → dist/static/fonts/element-icons.ff18efd1.woff} +0 -0
  139. /package/{src/assets/video-play.jpeg → dist/static/img/video-play.49e933ba.jpeg} +0 -0
@@ -1,350 +0,0 @@
1
- <!-- 上传组件 -->
2
- <template>
3
- <div>
4
- <div
5
- v-show="imgOrVideoList.length || !readonly"
6
- ref="imgList"
7
- class="img-list el-upload-list el-upload-list--picture-card"
8
- >
9
- <div
10
- v-for="(file, index) in imgOrVideoList"
11
- v-show="imgOrVideoList.length"
12
- :key="file.uid"
13
- class="img-part el-upload-list__item is-success"
14
- >
15
- <el-image
16
- v-if="_hasFileType(imgExts, file)"
17
- class="el-upload-list__item-thumbnail"
18
- :src="file.fileUrl"
19
- />
20
- <el-image
21
- v-if="_hasFileType(videoExts, file)"
22
- class="el-upload-list__item-thumbnail"
23
- :src="videoBg"
24
- />
25
- <span class="el-upload-list__item-actions">
26
- <span
27
- v-if="_hasFileType(imgExts, file)"
28
- class="el-upload-list__item-preview"
29
- @click="picturePreview(index)"
30
- >
31
- <i class="el-icon-zoom-in" />
32
- </span>
33
- <span
34
- v-if="_hasFileType(videoExts, file)"
35
- class="el-upload-list__item-preview"
36
- @click="picturePreview(index)"
37
- >
38
- <i class="el-icon-video-play" />
39
- </span>
40
- <span
41
- v-show="!readonly"
42
- class="el-upload-list__item-delete"
43
- @click="uploadRemove(file)"
44
- >
45
- <i class="el-icon-delete" />
46
- </span>
47
- </span>
48
- </div>
49
- <div
50
- v-show="!readonly && value.length < limit"
51
- class="img-part el-upload-list__item is-success"
52
- style="border: none"
53
- >
54
- <el-upload
55
- ref="fileUpload"
56
- class="custom-upload-files"
57
- :class="
58
- showFileList && list.length >= limit && 'custom-upload-files-limit'
59
- "
60
- v-bind="$attrs"
61
- :show-file-list="false"
62
- action="#"
63
- :file-list="list"
64
- list-type="picture-card"
65
- :http-request="uploadRequest"
66
- :before-upload="beforeUpload"
67
- :on-success="uploadSuccess"
68
- :on-error="uploadError"
69
- v-on="$listeners"
70
- >
71
- <div
72
- slot="default"
73
- class="custom-upload-files-content"
74
- >
75
- <i class="el-icon-plus" />
76
- </div>
77
- </el-upload>
78
- </div>
79
- </div>
80
- <div class="file-list">
81
- <div
82
- v-for="file in restFileList"
83
- :key="file.uid"
84
- class="el-upload-list__item is-success"
85
- style="width: 100%; height: auto"
86
- >
87
- <a
88
- class="el-upload-list__item-name"
89
- :href="file.fileUrl"
90
- :download="file.name || file.fileName"
91
- >
92
- <i class="el-icon-document" />
93
- {{ file.name || file.fileName }}
94
- </a>
95
- <label class="el-upload-list__item-status-label">
96
- <i
97
- v-show="!readonly"
98
- class="el-icon-upload-success el-icon-circle-check"
99
- />
100
- </label>
101
- <i
102
- v-show="!readonly"
103
- class="el-icon-close"
104
- @click="uploadRemove(file)"
105
- />
106
- </div>
107
- </div>
108
- <div
109
- v-show="!readonly"
110
- slot="tip"
111
- class="el-upload__tip"
112
- >
113
- 文件大小不超过 {{ limitSizeText }} , 支持扩展名: {{ (_calcLimitType(limitType) || []).join(' ') }}
114
- </div>
115
- <file-preview
116
- v-if="previewVisible"
117
- :default-index="preveiwIndex"
118
- :list="imgOrVideoList.map(i=> i.fileUrl)"
119
- @close="previewVisible = false"
120
- />
121
- </div>
122
- </template>
123
-
124
- <script>
125
- import { get } from 'lodash'
126
- import videoBg from '../../assets/video-play.jpeg'
127
- import { convertBytesToSize } from '@/utils'
128
- import FilePreview from '../file-preview/index.vue'
129
- import {imgExts, videoExts, fileExts} from '../../utils/constant'
130
- export default {
131
- name: 'DUpload',
132
- components: { FilePreview },
133
- model: {
134
- prop: 'modelValue',
135
- event: 'change'
136
- },
137
- props: {
138
- readonly: {
139
- default: false,
140
- type: Boolean
141
- },
142
- limit: {
143
- default: 5,
144
- type: Number
145
- },
146
- limitSize: {
147
- default: 5,
148
- type: Number
149
- },
150
- imgExts: {
151
- type: Array,
152
- default: () => imgExts
153
- },
154
- fileExts: {
155
- type: Array,
156
- default: () => fileExts
157
- },
158
- videoExts: {
159
- type: Array,
160
- default: () => videoExts
161
- },
162
- limitType: {
163
- default: () => [...imgExts, ...fileExts, ...videoExts],
164
- type: [Array, String] // 兼容自定义表单配置
165
- },
166
- showFileList: {
167
- default: true,
168
- type: Boolean
169
- },
170
- modelValue: {
171
- default: () => [],
172
- type: Array
173
- },
174
- onSuccess: {
175
- default: () => [], // 外部传入上传成功处理函数,备用
176
- type: Function
177
- }
178
- },
179
- data () {
180
- return {
181
- list: [],
182
- dialogVisible: false,
183
- dialogImageUrl: '',
184
- videoBg,
185
- preveiwIndex: 0,
186
- previewVisible: false
187
- }
188
- },
189
- computed: {
190
- value: {
191
- get () {
192
- if (this.modelValue && this.modelValue.length && this.modelValue.some(v => typeof v === 'string')) {
193
- return this.modelValue.filter(url => url).map(url => this._urlToObj(url))
194
- } else {
195
- return this.modelValue || []
196
- }
197
- },
198
- set (value) {
199
- this.$emit('change', value)
200
- }
201
- },
202
- imgOrVideoList () {
203
- return this.value.filter(
204
- (item) => this._hasFileType(imgExts.concat(videoExts), item)
205
- )
206
- },
207
- restFileList () {
208
- return this.value.filter((item) => !this._hasFileType(imgExts.concat(videoExts), item))
209
- },
210
- limitSizeText () {
211
- return convertBytesToSize(Number(this.limitSize || 5) * 1024 * 1024)
212
- }
213
- },
214
- mounted () {
215
- },
216
- methods: {
217
- _hasFileType (files, item) {
218
- if (!item.fileExt) {
219
- return false
220
- }
221
- return files.includes(item.fileExt.toLowerCase())
222
- },
223
- _calcLimitType (limitType) {
224
- if (typeof limitType === 'string') return limitType.split(',').map(l => l.trim())
225
- return limitType
226
- },
227
- _urlToObj (url) {
228
- if (typeof url !== 'string') return url
229
- const name = url.substring(url.lastIndexOf('/') + 1, url.length) // 最后的文件名截取出来
230
- const fileExt = url.substring(url.lastIndexOf('.') + 1)
231
- return {
232
- name,
233
- fileExt,
234
- url,
235
- fileUrl: url
236
- }
237
- },
238
- async uploadRequest (data) {
239
- const formData = new FormData()
240
- formData.append('file', data.file)
241
- const res = await this.$DDWL.upload(formData)
242
- return res
243
- },
244
- beforeUpload (file) {
245
- const isLimit = file.size / 1024 / 1024 < this.limitSize
246
- const limitType = this._calcLimitType(this.limitType)
247
- const isType = limitType.includes(
248
- file.name.substr(file.name.lastIndexOf('.') + 1)
249
- )
250
-
251
- if (!isType) {
252
- this.$message.error(
253
- `请上传正确的文件格式(${limitType.join('、')})`
254
- )
255
- return false
256
- }
257
- if (!isLimit) {
258
- this.$message.error(`上传文件大小不能超过${this.limitSize}MB`)
259
- return false
260
- }
261
- },
262
- uploadSuccess (res, file) {
263
- if (res.code === 200) {
264
- this.value = this.value.concat({
265
- ...file,
266
- ...get(file, 'response.data'),
267
- fileUrl: get(file, 'response.data.filePath'),
268
- filePath: get(file, 'response.data.filePath')
269
- })
270
- this.$parent.$emit('el.form.change')
271
- } else {
272
- this.$message.error(res.message)
273
- }
274
- },
275
- uploadError (res) {
276
- console.log('upload error', res)
277
- },
278
- uploadRemove (file) {
279
- this.value = this.value.filter(item => item.fileUrl !== file.fileUrl)
280
- this.$parent.$emit('el.form.change')
281
- },
282
- picturePreview (index) {
283
- this.preveiwIndex = index
284
- this.previewVisible = true
285
- }
286
- }
287
- }
288
- </script>
289
-
290
- <style lang='scss' scoped>
291
- .custom-upload-files-content {
292
- display: inline-block;
293
- width: 80px;
294
- height: 80px;
295
- text-align: center;
296
- & > span {
297
- line-height: 16px;
298
- margin-top: 4px;
299
- color: #999;
300
- font-size: 12px;
301
- }
302
- i {
303
- text-align: center;
304
- }
305
- }
306
- .custom-upload-files {
307
- display: inline-block;
308
- }
309
- .custom-upload-files-limit {
310
- :deep(.el-upload--picture-card) {
311
- display: none;
312
- }
313
- }
314
- .img-list {
315
- padding-left: 3px;
316
- display: block;
317
- line-height: 1;
318
- .img-part {
319
- width: 80px;
320
- height: 80px;
321
- }
322
- }
323
- .file-list {
324
- :deep(.el-upload-list__item:first-child) {
325
- margin-top: -5px;
326
- }
327
- }
328
- :deep(.upload-preview-dialog) {
329
- margin-top: 0vh !important;
330
- max-height: 90vh;
331
- max-width: 80%;
332
- min-width: 150px;
333
- min-height: 150px;
334
- width: inherit;
335
- display: flex;
336
- flex-direction: column;
337
- .el-dialog__body {
338
- flex: 1;
339
- overflow: auto;
340
- text-align: center;
341
- img{
342
- max-height: 65vh;
343
- }
344
- }
345
- }
346
- .el-upload__tip {
347
- line-height: 20px;
348
- margin-top: 0;
349
- }
350
- </style>
@@ -1,4 +0,0 @@
1
- export const imgExts = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg']
2
- export const videoExts = ['mp4']
3
- export const audioExts = ['mp3', 'wav', 'ogg']
4
- export const fileExts = ['doc', 'docx', 'pdf']
@@ -1,77 +0,0 @@
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,190 +0,0 @@
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
- }