kui-vue 3.4.5 → 3.4.7

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 (106) hide show
  1. package/components/_tool/clone.js +1 -1
  2. package/components/avatar/demo/base.md +13 -15
  3. package/components/avatar/demo/change.md +2 -2
  4. package/components/avatar/demo/index.vue +1 -8
  5. package/components/avatar/demo/types.md +2 -2
  6. package/components/badge/badge.jsx +1 -0
  7. package/components/badge/demo/base.md +5 -5
  8. package/components/badge/demo/dot.md +1 -12
  9. package/components/badge/demo/dynamic.md +0 -11
  10. package/components/badge/demo/index.vue +14 -2
  11. package/components/badge/demo/mark.md +3 -3
  12. package/components/badge/demo/max.md +0 -12
  13. package/components/badge/demo/status.md +0 -5
  14. package/components/badge/styles/index.less +29 -2
  15. package/components/base/input.jsx +53 -27
  16. package/components/base/pop.jsx +0 -1
  17. package/components/button/styles/index.less +4 -1
  18. package/components/checkbox/checkbox.jsx +1 -1
  19. package/components/checkbox/styles/index.less +13 -1
  20. package/components/colorPicker/colorpicker.jsx +59 -35
  21. package/components/colorPicker/demo/shape.md +1 -0
  22. package/components/colorPicker/index.md +1 -0
  23. package/components/colorPicker/styles/index.less +68 -56
  24. package/components/datePicker/datepicker.jsx +2 -1
  25. package/components/datePicker/demo/base.md +0 -3
  26. package/components/drawer/drawer.jsx +1 -1
  27. package/components/dropdown/dropdown.jsx +1 -1
  28. package/components/form/demo/base.md +19 -2
  29. package/components/form/demo/length.md +1 -1
  30. package/components/form/demo/valid.md +21 -6
  31. package/components/form/form.jsx +4 -2
  32. package/components/form/formitem.jsx +3 -1
  33. package/components/form/styles/index.less +4 -2
  34. package/components/index.js +2 -0
  35. package/components/input/demo/base.md +2 -2
  36. package/components/input/demo/event.md +2 -2
  37. package/components/input/demo/group.md +20 -3
  38. package/components/input/demo/icon.md +8 -2
  39. package/components/input/demo/index.vue +1 -15
  40. package/components/input/demo/size.md +2 -2
  41. package/components/input/demo/suffix.md +63 -29
  42. package/components/input/demo/textarea.md +2 -2
  43. package/components/input/demo/theme.md +2 -4
  44. package/components/input/index.md +20 -10
  45. package/components/input/input.jsx +3 -0
  46. package/components/input/inputGroup.jsx +7 -4
  47. package/components/input/styles/index.less +104 -2
  48. package/components/input/textarea.jsx +1 -0
  49. package/components/inputNumber/demo/base.md +6 -12
  50. package/components/inputNumber/demo/ffix.md +3 -9
  51. package/components/inputNumber/inputNumber.jsx +9 -5
  52. package/components/inputNumber/styles/index.less +34 -20
  53. package/components/menu/styles/index.less +1 -1
  54. package/components/message/demo/index.vue +1 -10
  55. package/components/message/demo/types.md +3 -3
  56. package/components/modal/demo/base.md +2 -2
  57. package/components/modal/demo/confrim.md +2 -2
  58. package/components/modal/demo/custom.md +2 -2
  59. package/components/modal/demo/global.md +2 -2
  60. package/components/modal/demo/index.vue +1 -10
  61. package/components/modal/demo/more.md +2 -2
  62. package/components/notice/demo/close.md +2 -2
  63. package/components/notice/demo/icon.md +2 -2
  64. package/components/notice/demo/index.vue +1 -10
  65. package/components/notice/demo/types.md +4 -4
  66. package/components/popconfirm/demo/index.vue +1 -10
  67. package/components/popconfirm/demo/local.md +17 -15
  68. package/components/popconfirm/demo/placement.md +50 -46
  69. package/components/popconfirm/popconfirm.jsx +1 -1
  70. package/components/poptip/demo/base.md +16 -14
  71. package/components/poptip/demo/index.vue +1 -10
  72. package/components/poptip/demo/placement.md +99 -94
  73. package/components/poptip/demo/trigger.md +16 -14
  74. package/components/rate/demo/base.md +2 -5
  75. package/components/rate/demo/character.md +2 -4
  76. package/components/rate/demo/clear.md +2 -3
  77. package/components/rate/demo/custom.md +3 -5
  78. package/components/rate/demo/disabled.md +4 -8
  79. package/components/rate/demo/tips.md +2 -2
  80. package/components/select/styles/index.less +5 -1
  81. package/components/space/demo/compact.md +23 -6
  82. package/components/space/space.jsx +25 -25
  83. package/components/space/styles/index.less +5 -0
  84. package/components/styles/index.less +1 -0
  85. package/components/tooltip/demo/index.vue +1 -14
  86. package/components/tooltip/demo/placement.md +50 -46
  87. package/components/tooltip/tooltip.jsx +1 -1
  88. package/components/tree/demo/checkable.md +5 -1
  89. package/components/tree/demo/directory.md +27 -31
  90. package/components/tree/index.md +22 -15
  91. package/components/tree/node.jsx +43 -23
  92. package/components/tree/styles/index.less +257 -215
  93. package/components/tree/tree.jsx +39 -6
  94. package/components/treeselect/demo/base.md +59 -0
  95. package/components/treeselect/demo/checkable.md +59 -0
  96. package/components/treeselect/demo/index.vue +30 -0
  97. package/components/treeselect/demo/info.md +7 -0
  98. package/components/treeselect/demo/multiple.md +59 -0
  99. package/components/treeselect/demo/sync.md +38 -0
  100. package/components/treeselect/index.md +38 -0
  101. package/components/treeselect/styles/index.less +579 -27
  102. package/components/treeselect/treeselect.jsx +508 -0
  103. package/dist/k-ui.css +2 -2
  104. package/dist/k-ui.js +2 -2
  105. package/package.json +2 -1
  106. package/components/treeselect/treeselect.vue +0 -200
@@ -0,0 +1,508 @@
1
+ import Icon from "../icon";
2
+ import Empty from '../empty';
3
+ import { hasProp, getChild, isNotEmpty } from '../_tool/utils'
4
+
5
+ import Drop from '../base/drop'
6
+ import { t } from '../locale';
7
+ import { Sync, Close, CloseCircle, ChevronDown } from 'kui-icons'
8
+ import { Tree } from '../tree'
9
+ const cloneDeep = require('lodash.clonedeep');
10
+
11
+ // const cloneDeep = require('lodash/cloneDeep')
12
+ export default {
13
+ name: "TreeSelect",
14
+ props: {
15
+ placeholder: String,
16
+ size: {
17
+ default: 'default',
18
+ validator(value) {
19
+ return ["small", "large", "default"].indexOf(value) >= 0;
20
+ }
21
+ },
22
+ transfer: { type: Boolean, default: true },
23
+ width: Number,
24
+ value: [String, Number, Array],
25
+ clearable: Boolean,
26
+ filterable: Boolean,
27
+ disabled: Boolean,
28
+ multiple: Boolean,
29
+ loading: Boolean,
30
+ bordered: { type: Boolean, default: true },
31
+ showArrow: { type: Boolean, default: true },
32
+ theme: String,
33
+ emptyText: String,
34
+ icon: [String, Array],
35
+ shape: String,
36
+ arrowIcon: [String, Array],
37
+
38
+ treeData: Array,
39
+ treeCheckable: Boolean,
40
+ treeShowLine: Boolean,
41
+ treeShowIcon: { type: Boolean, default: true },
42
+ treeCheckStrictly: Boolean,
43
+ treeExpandedKeys: Array,
44
+ treeExpandedAll: Boolean,
45
+
46
+ },
47
+ provide() {
48
+ return {
49
+ Select: this
50
+ }
51
+ },
52
+ data() {
53
+ return {
54
+ label: "",
55
+ opened: false,
56
+ currentValue: this.value || this.multiple ? [] : '',
57
+ showSearch: false,
58
+ queryKey: '',
59
+ selectWidth: this.width,
60
+ isFocus: false
61
+ };
62
+ },
63
+ watch: {
64
+ value(value) {
65
+ if (isNotEmpty(value)) {
66
+ this.currentValue = value
67
+ } else {
68
+ this.currentValue = this.multiple ? [] : ''
69
+ }
70
+ },
71
+ currentValue(n, o) {
72
+ this.setLabel()
73
+ }
74
+ },
75
+ methods: {
76
+ hideDrop() {
77
+ if (this.showSearch) {
78
+ this.queryKey = ''
79
+ this.$refs.search.value = ''
80
+ this.$refs.search.style.width = ''
81
+ }
82
+ this.showSearch = false
83
+ },
84
+ findNodeByKeyIterative(tree, key) {
85
+ //迭代搜索(深度优先搜索,DFS) 当树的深度可能导致递归方法栈溢出时。
86
+ const stack = [...tree];
87
+ while (stack.length) {
88
+ const node = stack.pop();
89
+ if (node.key === key) {
90
+ return node;
91
+ }
92
+ if (node.children) {
93
+ stack.push(...node.children);
94
+ }
95
+ }
96
+ return null;
97
+ },
98
+ filterTreeByKeyword(tree, keyword) {
99
+ // 使用 lodash 的 cloneDeep 函数深度拷贝树
100
+ return cloneDeep(tree).filter(function iter(node) {
101
+ // 使用 _.some 遍历判断子节点是否符合条件
102
+ if (node.title.includes(keyword)) return true;
103
+ if (node.children) node.children = node.children.filter(iter);
104
+ return node.children && node.children.length > 0;
105
+ });
106
+
107
+
108
+ // // 创建一个栈来迭代树,存储节点及其父节点信息
109
+ // const stack = tree.map(node => ({ node, parent: null }));
110
+ // const result = [];
111
+
112
+ // // 递归函数,克隆并添加节点及其所有子节点
113
+ // function addNodeWithChildren(node) {
114
+ // // 深拷贝节点以防止原树被修改
115
+ // const newNode = { ...node, children: [] };
116
+ // if (node.children) {
117
+ // for (const child of node.children) {
118
+ // newNode.children.push(addNodeWithChildren(child));
119
+ // }
120
+ // }
121
+ // return newNode;
122
+ // }
123
+
124
+ // // 存储节点的所有父节点,确保结果包含父节点链
125
+ // const parentMap = new Map();
126
+
127
+ // // 开始迭代树
128
+ // while (stack.length > 0) {
129
+ // const { node, parent } = stack.pop();
130
+
131
+ // // 如果节点名包含关键字
132
+ // if (node.name.includes(keyword)) {
133
+ // // 把该节点的父节点链添加到结果中
134
+ // let currentNode = parent;
135
+ // while (currentNode) {
136
+ // if (!parentMap.has(currentNode.key)) {
137
+ // parentMap.set(currentNode.key, addNodeWithChildren(currentNode));
138
+ // result.push(parentMap.get(currentNode.key));
139
+ // }
140
+ // currentNode = parentMap.get(currentNode.key);
141
+ // }
142
+
143
+ // // 将当前节点及其子节点添加到结果中
144
+ // result.push(addNodeWithChildren(node));
145
+ // }
146
+
147
+ // // 把子节点加入堆栈继续遍历
148
+ // if (node.children) {
149
+ // for (const child of node.children) {
150
+ // stack.push({ node: child, parent: node });
151
+ // }
152
+ // }
153
+ // }
154
+ // return result;
155
+ },
156
+ getLabel(childs, labelValue) {
157
+ let node = this.findNodeByKeyIterative(childs, labelValue)
158
+ return node?.title || labelValue;
159
+ },
160
+ setLabel() {
161
+ let { currentValue, multiple, label } = this
162
+
163
+ currentValue = isNotEmpty(currentValue) ? currentValue : (multiple ? [] : '')
164
+ let currentLabel = isNotEmpty(label) ? label : (multiple ? [] : '')
165
+
166
+ if (multiple) {
167
+ if (currentValue.length) {
168
+ let labels = []
169
+ currentValue.forEach((value) => {
170
+ let label = this.getLabel(this.treeData, value)
171
+ labels.push({ label, key: `label_${value}`, value })
172
+ })
173
+ currentLabel = labels
174
+ } else {
175
+ currentLabel = []
176
+ }
177
+
178
+ } else {
179
+ currentLabel = this.getLabel(this.treeData, currentValue)
180
+ }
181
+ this.label = currentLabel
182
+
183
+ setTimeout(e => { this.setPosition() }, 230);
184
+
185
+ },
186
+ clear(e) {
187
+ let label = this.multiple ? [] : ""
188
+ let value = this.multiple ? [] : ""
189
+ this.label = label
190
+ this.currentValue = value
191
+ this.$emit("input", value);
192
+ this.$emit("change", value);
193
+ e.stopPropagation()
194
+ },
195
+ showDrops() {
196
+ let isSearch = ('search' in this.$listeners)
197
+
198
+ this.opened = !this.opened;
199
+ if (this.filterable || isSearch) {
200
+ this.showSearch = this.opened
201
+ if (this.opened) {
202
+ this.$nextTick(e => {
203
+ this.isFocus = true
204
+ this.$refs.search.focus()
205
+ })
206
+ } else {
207
+ this.$refs.search.blur()
208
+ this.isFocus = false
209
+
210
+ setTimeout(() => {
211
+ this.queryKey = ''
212
+ this.$refs.search.value = ''
213
+ }, 200);
214
+ }
215
+ }
216
+ // this.$nextTick(e => this.setPosition())
217
+ },
218
+ toggleDrop() {
219
+ if (this.disabled) {
220
+ return false;
221
+ }
222
+ let isSearch = ('search' in this.$listeners)
223
+ if (isSearch) {
224
+ // this.$nextTick(e => {
225
+ this.showSearch = true
226
+ this.$nextTick(e => {
227
+ this.$refs.search.focus()
228
+ this.isFocus = true
229
+ })
230
+ // })
231
+ return;
232
+ }
233
+ this.showDrops()
234
+ },
235
+ setPosition() {
236
+ // if (!hasProp(this, 'width')) {
237
+ // this.selectWidth = this.$el.offsetWidth
238
+ // }
239
+ if (this.opened) {
240
+ this.$refs.overlay.setPosition()
241
+ }
242
+ },
243
+ select({ selectedKeys, selected, node }) {
244
+ let item = { label: node.title, value: node.key }
245
+ let { multiple, value, currentValue } = this
246
+ // console.log(value, currentValue, item)
247
+
248
+ if (this.showSearch) {
249
+ this.queryKey = ''
250
+ this.$refs.search.value = ''
251
+ this.$refs.search.style.width = ''
252
+ }
253
+ if (!multiple) {
254
+ this.opened = false
255
+ this.showSearch = false
256
+ } else if ('search' in this.$listeners || this.filterable) {
257
+ this.$nextTick(e => {
258
+ this.$refs.search.focus()
259
+ this.isFocus = true
260
+ })
261
+ }
262
+ let hasValue = hasProp(this, 'value')
263
+ //set value
264
+ let newValue = value
265
+ if (!hasValue) {
266
+ newValue = this.multiple ? currentValue || [] : item.value
267
+ this.currentValue = newValue
268
+ }
269
+
270
+ if (!multiple) {
271
+ this.currentValue = item.value
272
+ this.currentLabel = item.title
273
+ }
274
+
275
+ //set label
276
+ if (!hasValue) {
277
+ if (multiple) {
278
+ let currentLabel = this.label || []
279
+ let index = currentLabel.findIndex(x => x.value === item.value)// .map(x => x.label).indexOf(item.label)
280
+ if (index === -1) {
281
+ currentLabel.push({ label: item.label, key: item.label + item.value, value: item.value })
282
+ } else {
283
+ currentLabel.splice(index, 1)
284
+ }
285
+ this.label = currentLabel
286
+ } else {
287
+ this.label = item.label
288
+ }
289
+ setTimeout(e => { this.setPosition() }, 230);
290
+ } else {
291
+ this.$nextTick(e => this.setPosition())
292
+ }
293
+ this.$emit("input", this.currentValue);
294
+ this.$emit("change", this.currentValue);
295
+
296
+ this.$emit('select', {
297
+ selectedKeys,
298
+ selected,
299
+ node
300
+ })
301
+ },
302
+ removeTag(e, i) {
303
+ if (this.disabled) return
304
+ // let values = this.currentValue || []
305
+ // let labels = this.label || []
306
+ // this.change({ value: values[i], label: labels[i].label })
307
+
308
+ this.currentValue.splice(i, 1)
309
+ this.$emit("input", this.currentValue);
310
+ // console.log(this.currentValue,this.label)
311
+ this.$emit("change", this.currentValue);
312
+ e.stopPropagation()
313
+ },
314
+ searchInput(e) {
315
+ this.queryKey = e.target.value
316
+ //todo:
317
+ this.$nextTick(k => {
318
+ // let max = this.selectWidth - 15 - (this.showArrow ? 25 : 0)
319
+ e.target.style.width = this.$refs.mirror.offsetWidth + 'px'
320
+ this.setPosition()
321
+ })
322
+ if ('search' in this.$listeners) {
323
+ clearTimeout(this.timer)
324
+ this.timer = setTimeout(() => {
325
+ this.opened = true;
326
+ this.$emit('search', e)
327
+ }, 500);
328
+ }
329
+ },
330
+ emptyClick(e) {
331
+ if (this.showSearch) {
332
+ this.$nextTick(e => {
333
+ this.$refs.search.focus()
334
+ this.isFocus = true
335
+
336
+ })
337
+ }
338
+ },
339
+ treeCheck() {
340
+ // console.log(e)
341
+ // console.log(checkedKeys)
342
+ }
343
+ },
344
+ mounted() {
345
+ if (hasProp(this, 'value'))
346
+ this.setLabel()
347
+ },
348
+ render() {
349
+ let { disabled, size, multiple,
350
+ opened, placeholder, showArrow, bordered,
351
+ clear, removeTag, queryKey, theme, arrowIcon, icon, shape, filterable,
352
+ clearable, label, toggleDrop, isFocus, currentValue,
353
+ treeData, treeCheckable, treeShowLine, treeShowIcon, treeCheckStrictly, treeExpandedKeys, treeExpandedAll
354
+ } = this
355
+ let childNode = []
356
+ if (arrowIcon == undefined) {
357
+ arrowIcon = ChevronDown
358
+ }
359
+ const classes = [
360
+ "k-tree-select",
361
+ {
362
+ "k-tree-select-disabled": disabled,
363
+ "k-tree-select-open": opened,
364
+ 'k-tree-select-borderless': bordered === false,
365
+ "k-tree-select-lg": size == 'large',
366
+ "k-tree-select-sm": size == 'small',
367
+ "k-tree-select-light": theme == 'light',
368
+ "k-tree-select-has-icon": !!icon,
369
+ "k-tree-select-circle": shape == 'circle' && !multiple,
370
+ "k-tree-select-multiple": multiple,
371
+ "k-tree-select-show-search": isFocus,
372
+ "k-tree-select-show-tags": multiple && (label || []).length
373
+ }
374
+ ]
375
+
376
+ const queryProps = {
377
+ on: {
378
+ input: this.searchInput,
379
+ blur: () => {
380
+ if (!this.opened) this.showSearch = false
381
+ this.isFocus = false
382
+
383
+ }
384
+ },
385
+ ref: 'search',
386
+ class: 'k-tree-select-search',
387
+ attrs: {
388
+ autoComplete: 'off',
389
+ }
390
+ }
391
+ const queryNode = <div v-show={this.showSearch} key="search" class="k-tree-select-search-wrap">
392
+ <input {...queryProps} />
393
+ <span class="k-tree-select-search-mirror" ref="mirror">{queryKey}</span>
394
+ </div>
395
+
396
+
397
+ const loadingNode = <div class="k-tree-select-loading"><Icon type={Sync} spin /><span>{t('k.select.loading')}</span></div>
398
+ const props = {
399
+ ref: 'overlay',
400
+ props: {
401
+ width: this.selectWidth,
402
+ value: opened,
403
+ selection: this.$el,
404
+ transfer: true,
405
+ extendWidth: true,
406
+ transitionName: 'k-tree-select',
407
+ className: ['k-tree-select-dropdown', { 'k-tree-select-dropdown-multiple': this.multiple, 'k-tree-select-dropdown-sm': size == 'small' }]
408
+ },
409
+ on: {
410
+ input: e => {
411
+ this.opened = e
412
+ },
413
+ hide: () => {
414
+ this.opened = false
415
+ setTimeout(() => {
416
+ this.hideDrop()
417
+ }, 300)
418
+ }
419
+ }
420
+ }
421
+ const selectedKeys = this.multiple ? currentValue || [] : [currentValue]
422
+ // console.log(this.$listeners)
423
+ const treeProps = {
424
+ props: {
425
+ data: treeData,
426
+ checkable: treeCheckable,
427
+ multiple: multiple,
428
+ showLine: treeShowLine,
429
+ showIcon: treeShowIcon,
430
+ checkStrictly: treeCheckStrictly,
431
+ expandedKeys: treeExpandedKeys,
432
+ selectedKeys: selectedKeys,
433
+ checkedKeys: selectedKeys,
434
+ },
435
+ on: {
436
+ select: this.select,
437
+ check: this.treeCheck
438
+ }
439
+ }
440
+ if ('tree-load-data' in this.$listeners) {
441
+ treeProps.on['load-data'] = this.$listeners['tree-load-data']
442
+ }
443
+ if (this.filterable && queryKey && !this.$listeners.search) {
444
+ let parsedQuery = String(queryKey).replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, "\\$1");
445
+ treeProps.props.data = this.filterTreeByKeyword(treeData, parsedQuery)
446
+ }
447
+ let overlay = <Drop {...props}>
448
+ {this.loading ? loadingNode : (!(treeProps.props.data && treeProps.props.data.length) ?
449
+ <Empty onClick={this.emptyClick} description={this.emptyText} /> :
450
+ <Tree {...treeProps} />)}
451
+ </Drop>
452
+
453
+ label = multiple ? (label || []) : label + ''
454
+ placeholder = placeholder || t('k.select.placeholder')
455
+ const placeNode = ((placeholder && (((label === null || label === undefined) || !label.length) && !queryKey))
456
+ ? <div class="k-tree-select-placeholder">{placeholder}</div>
457
+ : null
458
+ )
459
+ const tags = multiple ?
460
+ label.map((c, i) => {
461
+ return <span class="k-tree-select-tag" key={c.key}>{c.label}<Icon type={Close} onClick={e => removeTag(e, i)} /></span>
462
+ })
463
+ : null
464
+
465
+ const labelStyle = {
466
+ // opacity: this.showSearch ? .4 : 1,
467
+ display: queryKey.length ? 'none' : ''
468
+ }
469
+ const labelsNode = ((multiple)
470
+ ? (
471
+ [<div class="k-tree-select-labels" name="k-tree-select-tag">{tags}{queryNode}</div>]
472
+ )
473
+ : (label.length ? <div class="k-tree-select-label" style={labelStyle}>{label}</div> : null)
474
+ )
475
+ let isSearch = ('search' in this.$listeners)
476
+ childNode.push(labelsNode);
477
+ placeNode && childNode.push(placeNode);
478
+
479
+
480
+ if ((filterable || isSearch) && !multiple) {
481
+ childNode.push(queryNode)
482
+ }
483
+ // label = "1"
484
+ const styles = { width: `${this.width}px` }
485
+ let showClear = !disabled && clearable && isNotEmpty(label) && label.length > 0
486
+
487
+ classes[1]['k-tree-select-has-clear'] = showClear
488
+ const iconNodes = []
489
+
490
+ if (!isSearch && showArrow) {
491
+ iconNodes.push(<Icon class="k-tree-select-arrow" type={arrowIcon} />)
492
+ }
493
+ if (showClear) {
494
+ iconNodes.push(<Icon class="k-tree-select-clearable" type={CloseCircle} onClick={clear} />)
495
+ }
496
+ // console.log(iconNodes)
497
+
498
+ iconNodes.push(" ")
499
+ return (
500
+ <div tabIndex="0" class={classes} style={styles} onClick={toggleDrop} ref="rel">
501
+ {icon ? <Icon type={icon} class="k-tree-select-icon" /> : null}
502
+ <div class="k-tree-select-selection">{childNode}</div>
503
+ {iconNodes}
504
+ {overlay}
505
+ </div >
506
+ )
507
+ }
508
+ };