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