@veltra/desktop 1.12.1 → 1.13.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/dist/components/drawer/drawer.js +6 -2
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/drawer/style2.css +11 -4
- package/dist/components/empty/empty.js +6 -2
- package/dist/components/empty/empty.js.map +1 -1
- package/dist/components/empty/style2.css +9 -0
- package/dist/components/multi-select/multi-select.js +11 -5
- package/dist/components/multi-select/multi-select.js.map +1 -1
- package/dist/components/multi-tree-select/multi-tree-select.js +9 -3
- package/dist/components/multi-tree-select/multi-tree-select.js.map +1 -1
- package/dist/components/select/select.js +21 -11
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/select/use-options.js +3 -2
- package/dist/components/select/use-options.js.map +1 -1
- package/dist/components/table/style2.css +6 -1
- package/dist/components/table/table-body.js +1 -1
- package/dist/components/table/table-body.js.map +1 -1
- package/dist/components/tree/tree.js +5 -3
- package/dist/components/tree/tree.js.map +1 -1
- package/dist/components/tree/use-filter.js +4 -2
- package/dist/components/tree/use-filter.js.map +1 -1
- package/dist/components/tree-select/tree-select.js +20 -8
- package/dist/components/tree-select/tree-select.js.map +1 -1
- package/dist/types/drawer.d.ts +5 -0
- package/dist/types/empty.d.ts +5 -0
- package/dist/types/multi-select.d.ts +8 -0
- package/dist/types/select.d.ts +14 -1
- package/dist/types/tree.d.ts +8 -0
- package/package.json +8 -3
- package/src/components/drawer/__test__/drawer.test.ts +42 -0
- package/src/components/drawer/drawer.vue +9 -4
- package/src/components/drawer/style.scss +10 -3
- package/src/components/empty/__test__/empty.test.ts +38 -0
- package/src/components/empty/empty.vue +2 -2
- package/src/components/empty/style.scss +7 -0
- package/src/components/multi-select/__test__/multi-select.test.ts +133 -0
- package/src/components/multi-select/multi-select.vue +11 -5
- package/src/components/multi-tree-select/__test__/multi-tree-select.test.ts +27 -0
- package/src/components/multi-tree-select/multi-tree-select.vue +9 -3
- package/src/components/select/__test__/select.test.ts +101 -0
- package/src/components/select/select.vue +28 -11
- package/src/components/select/use-options.ts +4 -2
- package/src/components/table/style.scss +4 -1
- package/src/components/table/table-body.vue +5 -3
- package/src/components/tree/tree.vue +7 -3
- package/src/components/tree/use-filter.ts +7 -2
- package/src/components/tree-select/__test__/tree-select.test.ts +85 -0
- package/src/components/tree-select/tree-select.vue +20 -8
- package/src/types/drawer.ts +6 -0
- package/src/types/empty.ts +6 -0
- package/src/types/multi-select.ts +8 -0
- package/src/types/select.ts +14 -1
- package/src/types/tree.ts +8 -0
package/dist/types/tree.d.ts
CHANGED
|
@@ -27,6 +27,14 @@ export interface TreeProps {
|
|
|
27
27
|
expandOnClickNode?: boolean;
|
|
28
28
|
/** label键 */
|
|
29
29
|
labelKey?: string;
|
|
30
|
+
/**
|
|
31
|
+
* 标签展示模板
|
|
32
|
+
* @description `{fieldKey}` 占位符按节点数据字段插值(支持嵌套路径取值),
|
|
33
|
+
* 模板引用的字段在节点数据中取不到时整体回退 `node[labelKey]`;
|
|
34
|
+
* 配置后节点文本与字符串过滤统一按模板结果渲染 / 匹配
|
|
35
|
+
* @example '{label}({code})'
|
|
36
|
+
*/
|
|
37
|
+
labelTemplate?: string;
|
|
30
38
|
/** value键 */
|
|
31
39
|
valueKey?: string;
|
|
32
40
|
/** 子节点键 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veltra/desktop",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"homepage": "https://github.com/cabinet-fe/ultra-ui#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/cabinet-fe/ultra-ui/issues"
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"@lexical/selection": "^0.52.0",
|
|
57
57
|
"@lexical/utils": "^0.52.0",
|
|
58
58
|
"docx-preview": "^0.4.1",
|
|
59
|
-
"infinitable": "^0.1.8",
|
|
60
59
|
"lexical": "^0.52.0",
|
|
61
60
|
"pdfjs-dist": "6.4.299"
|
|
62
61
|
},
|
|
@@ -85,6 +84,12 @@
|
|
|
85
84
|
"@veltra/icons": "^1.5.0",
|
|
86
85
|
"@veltra/styles": "^1.7.14",
|
|
87
86
|
"@veltra/utils": "^1.7.14",
|
|
88
|
-
"
|
|
87
|
+
"infinitable": "^0.2.3",
|
|
88
|
+
"vue": ">=3.5.44"
|
|
89
|
+
},
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"infinitable": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
89
94
|
}
|
|
90
95
|
}
|
|
@@ -73,6 +73,48 @@ describe('UDrawer title', () => {
|
|
|
73
73
|
})
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
+
describe('UDrawer size', () => {
|
|
77
|
+
it('左右方向映射为宽度,数字按 px 处理', async () => {
|
|
78
|
+
const ctx = mountDrawer({ size: 640 })
|
|
79
|
+
await openDrawer(ctx)
|
|
80
|
+
|
|
81
|
+
expect(ctx.panel()!.style.width).toBe('640px')
|
|
82
|
+
|
|
83
|
+
ctx.unmount()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('上下方向映射为高度,支持字符串', async () => {
|
|
87
|
+
const ctx = mountDrawer({ direction: 'bottom', size: '50vh' })
|
|
88
|
+
await openDrawer(ctx)
|
|
89
|
+
|
|
90
|
+
expect(ctx.panel()!.style.height).toBe('50vh')
|
|
91
|
+
expect(ctx.panel()!.style.width).toBe('')
|
|
92
|
+
|
|
93
|
+
ctx.unmount()
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('不传 size 时不输出内联尺寸,走主题 token', async () => {
|
|
97
|
+
const ctx = mountDrawer()
|
|
98
|
+
await openDrawer(ctx)
|
|
99
|
+
|
|
100
|
+
expect(ctx.panel()!.style.width).toBe('')
|
|
101
|
+
|
|
102
|
+
ctx.unmount()
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
describe('UDrawer body', () => {
|
|
107
|
+
it('默认插槽内容渲染在 body 容器内', async () => {
|
|
108
|
+
const ctx = mountDrawer({ title: '详情' })
|
|
109
|
+
await openDrawer(ctx)
|
|
110
|
+
|
|
111
|
+
const body = ctx.panel()!.querySelector('.u-drawer__body')
|
|
112
|
+
expect(body?.textContent).toBe('抽屉内容')
|
|
113
|
+
|
|
114
|
+
ctx.unmount()
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
76
118
|
describe('UDrawer closed', () => {
|
|
77
119
|
it('关闭动画结束后触发 closed,且晚于 close', async () => {
|
|
78
120
|
const order: string[] = []
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
<span :class="cls.e('close')" @click="close" v-if="showClose">
|
|
17
17
|
<u-icon><Close /></u-icon>
|
|
18
18
|
</span>
|
|
19
|
-
<
|
|
19
|
+
<div :class="cls.e('body')">
|
|
20
|
+
<slot />
|
|
21
|
+
</div>
|
|
20
22
|
</div>
|
|
21
23
|
</transition>
|
|
22
24
|
</div>
|
|
@@ -55,11 +57,14 @@ const drawerClass = computed(() => {
|
|
|
55
57
|
return [cls.b, bem.is(props.direction)]
|
|
56
58
|
})
|
|
57
59
|
|
|
58
|
-
//
|
|
60
|
+
// 计算抽屉样式:size 左右方向映射为宽度、上下方向映射为高度
|
|
59
61
|
const drawerStyle = computed(() => {
|
|
60
|
-
const
|
|
62
|
+
const { size, direction } = props
|
|
63
|
+
if (size == null) return null
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
const dimension = typeof size === 'number' ? `${size}px` : size
|
|
66
|
+
const axis = direction === 'top' || direction === 'bottom' ? 'height' : 'width'
|
|
67
|
+
return { [axis]: dimension }
|
|
63
68
|
})
|
|
64
69
|
|
|
65
70
|
const onEnter = () => {
|
|
@@ -9,7 +9,6 @@ $root-name: drawer;
|
|
|
9
9
|
$overlay-name: #{$root-name}-overlay;
|
|
10
10
|
|
|
11
11
|
$edge-offset: 4px;
|
|
12
|
-
$drawer-size: 320px;
|
|
13
12
|
$close-size: 48px;
|
|
14
13
|
|
|
15
14
|
$directions: (right, left, top, bottom);
|
|
@@ -22,6 +21,8 @@ $direction-map: (
|
|
|
22
21
|
);
|
|
23
22
|
@include m.b($root-name) {
|
|
24
23
|
position: absolute;
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: column;
|
|
25
26
|
border-radius: fn.use-var(radius, large);
|
|
26
27
|
background-color: fn.use-var(bg-color, top);
|
|
27
28
|
backdrop-filter: fn.use-var(bg-filter);
|
|
@@ -55,11 +56,17 @@ $direction-map: (
|
|
|
55
56
|
line-height: 1em;
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
@include m.e(body) {
|
|
60
|
+
flex: 1;
|
|
61
|
+
overflow: auto;
|
|
62
|
+
padding: fn.use-var(gap, default);
|
|
63
|
+
}
|
|
64
|
+
|
|
58
65
|
@include m.is(right, left) {
|
|
59
66
|
top: $edge-offset;
|
|
60
67
|
bottom: $edge-offset;
|
|
61
68
|
height: calc(100% - $edge-offset * 2);
|
|
62
|
-
width:
|
|
69
|
+
width: fn.component-var(drawer, size, 320px);
|
|
63
70
|
|
|
64
71
|
@include m.bem($root-name, close) {
|
|
65
72
|
top: 0;
|
|
@@ -72,7 +79,7 @@ $direction-map: (
|
|
|
72
79
|
left: $edge-offset;
|
|
73
80
|
right: $edge-offset;
|
|
74
81
|
width: calc(100% - $edge-offset * 2);
|
|
75
|
-
height:
|
|
82
|
+
height: fn.component-var(drawer, size, 320px);
|
|
76
83
|
|
|
77
84
|
@include m.bem($root-name, close) {
|
|
78
85
|
left: 0;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vite-plus/test'
|
|
2
|
+
import { createApp, h } from 'vue'
|
|
3
|
+
|
|
4
|
+
import UEmpty from '../empty.vue'
|
|
5
|
+
|
|
6
|
+
function mountEmpty(props: Record<string, unknown> = {}) {
|
|
7
|
+
const host = document.createElement('div')
|
|
8
|
+
document.body.appendChild(host)
|
|
9
|
+
|
|
10
|
+
const app = createApp({ render: () => h(UEmpty, props) })
|
|
11
|
+
app.mount(host)
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
root: () => host.querySelector<HTMLElement>('.u-empty'),
|
|
15
|
+
unmount() {
|
|
16
|
+
app.unmount()
|
|
17
|
+
host.remove()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('UEmpty block', () => {
|
|
23
|
+
it('默认 inline-block,不输出 is-block 类', () => {
|
|
24
|
+
const ctx = mountEmpty()
|
|
25
|
+
|
|
26
|
+
expect(ctx.root()!.className).toBe('u-empty')
|
|
27
|
+
|
|
28
|
+
ctx.unmount()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('block 时输出 is-block 类', () => {
|
|
32
|
+
const ctx = mountEmpty({ block: true })
|
|
33
|
+
|
|
34
|
+
expect(ctx.root()!.className).toBe('u-empty is-block')
|
|
35
|
+
|
|
36
|
+
ctx.unmount()
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<span :class="cls.b">
|
|
2
|
+
<span :class="[cls.b, bem.is('block', block)]">
|
|
3
3
|
<u-icon :size="size"> <Empty /> </u-icon>
|
|
4
4
|
<div>{{ text }}</div>
|
|
5
5
|
</span>
|
|
@@ -14,7 +14,7 @@ import { UIcon } from '../icon'
|
|
|
14
14
|
|
|
15
15
|
defineOptions({ name: 'UEmpty' })
|
|
16
16
|
|
|
17
|
-
withDefaults(defineProps<EmptyProps>(), { size: 48, text: '暂无数据' })
|
|
17
|
+
withDefaults(defineProps<EmptyProps>(), { size: 48, text: '暂无数据', block: false })
|
|
18
18
|
|
|
19
19
|
const cls = bem('empty')
|
|
20
20
|
</script>
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vite-plus/test'
|
|
2
|
+
import { createApp, h, nextTick, ref, type Ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
import UMultiSelect from '../multi-select.vue'
|
|
5
|
+
|
|
6
|
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
7
|
+
|
|
8
|
+
function mountMultiSelect(props: Record<string, unknown> = {}) {
|
|
9
|
+
const host = document.createElement('div')
|
|
10
|
+
document.body.appendChild(host)
|
|
11
|
+
|
|
12
|
+
const model = ref(props.modelValue ?? []) as Ref<any[]>
|
|
13
|
+
const options = ref(props.options)
|
|
14
|
+
|
|
15
|
+
const app = createApp({
|
|
16
|
+
render() {
|
|
17
|
+
return h(UMultiSelect, {
|
|
18
|
+
...props,
|
|
19
|
+
modelValue: model.value,
|
|
20
|
+
options: options.value as any,
|
|
21
|
+
'onUpdate:modelValue': (value: any[]) => {
|
|
22
|
+
model.value = value
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
app.mount(host)
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
host,
|
|
32
|
+
model,
|
|
33
|
+
options,
|
|
34
|
+
unmount() {
|
|
35
|
+
app.unmount()
|
|
36
|
+
host.remove()
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function openDropdown(host: HTMLElement) {
|
|
42
|
+
const trigger = host.querySelector('.u-multi-select') as HTMLElement
|
|
43
|
+
trigger.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
|
|
44
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
45
|
+
await nextTick()
|
|
46
|
+
await sleep(25)
|
|
47
|
+
if (queryOptions().length > 0) return
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function queryOptions() {
|
|
52
|
+
return [...document.body.querySelectorAll<HTMLElement>('.u-multi-select__option')]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function queryTags(host: HTMLElement) {
|
|
56
|
+
return [...host.querySelectorAll<HTMLElement>('.u-tag')]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function clickOption(option: HTMLElement) {
|
|
60
|
+
option.dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
61
|
+
await nextTick()
|
|
62
|
+
await sleep(50)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function typeQuery(host: HTMLElement, text: string) {
|
|
66
|
+
const input = host.querySelector<HTMLInputElement>('.u-multi-select__input')!
|
|
67
|
+
input.focus()
|
|
68
|
+
input.value = ''
|
|
69
|
+
input.dispatchEvent(
|
|
70
|
+
new InputEvent('input', { bubbles: true, data: '', inputType: 'deleteContentBackward' })
|
|
71
|
+
)
|
|
72
|
+
await nextTick()
|
|
73
|
+
|
|
74
|
+
input.value = text
|
|
75
|
+
input.dispatchEvent(
|
|
76
|
+
new InputEvent('input', { bubbles: true, data: text, inputType: 'insertText' })
|
|
77
|
+
)
|
|
78
|
+
await nextTick()
|
|
79
|
+
// 本地过滤防抖 200ms
|
|
80
|
+
await sleep(250)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('UMultiSelect labelTemplate', () => {
|
|
84
|
+
const templateOptions = [
|
|
85
|
+
{ label: '启用', code: 'ENABLED', value: 'enabled' },
|
|
86
|
+
{ label: '禁用', value: 'disabled' }
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
it('renders tags and panel options with the template, falling back to label', async () => {
|
|
90
|
+
const { host, model, unmount } = mountMultiSelect({
|
|
91
|
+
modelValue: ['enabled'],
|
|
92
|
+
labelTemplate: '{label}({code})',
|
|
93
|
+
options: templateOptions
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
await nextTick()
|
|
98
|
+
// 已选标签渲染模板结果
|
|
99
|
+
expect(queryTags(host).map((el) => el.textContent)).toEqual(['启用(ENABLED)'])
|
|
100
|
+
|
|
101
|
+
await openDropdown(host)
|
|
102
|
+
expect(queryOptions().map((el) => el.textContent)).toEqual(['启用(ENABLED)', '禁用'])
|
|
103
|
+
|
|
104
|
+
// 勾选缺 code 的选项:标签回退纯 label
|
|
105
|
+
await clickOption(queryOptions().find((el) => el.textContent === '禁用')!)
|
|
106
|
+
expect(model.value).toEqual(['enabled', 'disabled'])
|
|
107
|
+
expect(queryTags(host).map((el) => el.textContent)).toEqual(['启用(ENABLED)', '禁用'])
|
|
108
|
+
} finally {
|
|
109
|
+
unmount()
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('matches filter queries against the rendered template result', async () => {
|
|
114
|
+
const { host, unmount } = mountMultiSelect({
|
|
115
|
+
filterable: true,
|
|
116
|
+
labelTemplate: '{label}({code})',
|
|
117
|
+
options: templateOptions
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
await openDropdown(host)
|
|
122
|
+
// 按编码搜索命中
|
|
123
|
+
await typeQuery(host, 'ENABLED')
|
|
124
|
+
expect(queryOptions().map((el) => el.textContent)).toEqual(['启用(ENABLED)'])
|
|
125
|
+
|
|
126
|
+
// 按原始 label 搜索仍然命中
|
|
127
|
+
await typeQuery(host, '禁用')
|
|
128
|
+
expect(queryOptions().map((el) => el.textContent)).toEqual(['禁用'])
|
|
129
|
+
} finally {
|
|
130
|
+
unmount()
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
})
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
size="small"
|
|
29
29
|
@close="handleClose(option)"
|
|
30
30
|
>
|
|
31
|
-
{{ option
|
|
31
|
+
{{ renderOptionLabel(option) }}
|
|
32
32
|
</u-tag>
|
|
33
33
|
<u-tag v-if="restTag" size="small"> {{ restTag }}+ </u-tag>
|
|
34
34
|
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
:checked="checkedSet.has(option)"
|
|
119
119
|
>
|
|
120
120
|
<slot v-bind="{ option, index }">
|
|
121
|
-
{{
|
|
121
|
+
{{ renderOptionLabel(option) }}
|
|
122
122
|
</slot>
|
|
123
123
|
</u-multi-select-option>
|
|
124
124
|
</template>
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
<div v-else-if="model?.length" :class="[cls.m(size), cls.e('readonly-tags')]">
|
|
134
134
|
<div :class="cls.e('tags')">
|
|
135
135
|
<u-tag v-for="option of tags" :key="option[valueKey]" size="small">
|
|
136
|
-
{{ option
|
|
136
|
+
{{ renderOptionLabel(option) }}
|
|
137
137
|
</u-tag>
|
|
138
138
|
</div>
|
|
139
139
|
</div>
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
import { o as chainObj } from '@cat-kit/core'
|
|
148
148
|
import { useFormFallbackProps, useVirtualizer } from '@veltra/compositions'
|
|
149
149
|
import { ArrowDown, Close } from '@veltra/icons/normal'
|
|
150
|
-
import { bem, fieldKey, FORM_EMPTY_CONTENT } from '@veltra/utils'
|
|
150
|
+
import { bem, fieldKey, FORM_EMPTY_CONTENT, renderLabelTemplate } from '@veltra/utils'
|
|
151
151
|
import { injectFormContext } from '@veltra/utils'
|
|
152
152
|
import {
|
|
153
153
|
computed,
|
|
@@ -196,6 +196,12 @@ const cls = bem('multi-select')
|
|
|
196
196
|
const labelKey = computed(() => fieldKey(props.labelKey, 'label'))
|
|
197
197
|
const valueKey = computed(() => fieldKey(props.valueKey, 'value'))
|
|
198
198
|
|
|
199
|
+
/** 选项展示文案:labelTemplate 渲染结果优先,未配置模板或引用字段缺失时回退 labelKey 取值 */
|
|
200
|
+
function renderOptionLabel(option: Record<string, any> | undefined) {
|
|
201
|
+
if (!option) return undefined
|
|
202
|
+
return renderLabelTemplate(props.labelTemplate, option) ?? chainObj(option).get(labelKey.value)
|
|
203
|
+
}
|
|
204
|
+
|
|
199
205
|
const { formProps } = injectFormContext()
|
|
200
206
|
|
|
201
207
|
const { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {
|
|
@@ -257,7 +263,7 @@ const virtualOptions = computed(() => {
|
|
|
257
263
|
val,
|
|
258
264
|
key: v.index,
|
|
259
265
|
offset: v.start,
|
|
260
|
-
label:
|
|
266
|
+
label: renderOptionLabel(option)
|
|
261
267
|
}
|
|
262
268
|
})
|
|
263
269
|
})
|
|
@@ -220,3 +220,30 @@ describe('UMultiTreeSelect check-strictly and ctrl-key behavior', () => {
|
|
|
220
220
|
}
|
|
221
221
|
})
|
|
222
222
|
})
|
|
223
|
+
|
|
224
|
+
describe('UMultiTreeSelect labelTemplate', () => {
|
|
225
|
+
const templateData = [
|
|
226
|
+
{ label: '启用', value: 'enabled', code: 'ENABLED' },
|
|
227
|
+
{ label: '禁用', value: 'disabled' }
|
|
228
|
+
]
|
|
229
|
+
|
|
230
|
+
it('renders checked tags with the template, falling back to label', async () => {
|
|
231
|
+
const { host, model, unmount } = mountMultiTreeSelect({
|
|
232
|
+
labelTemplate: '{label}({code})',
|
|
233
|
+
data: templateData
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
try {
|
|
237
|
+
await openDropdown(host)
|
|
238
|
+
await clickNodeByLabel('启用(ENABLED)')
|
|
239
|
+
await clickNodeByLabel('禁用')
|
|
240
|
+
expect(model.value).toEqual(['enabled', 'disabled'])
|
|
241
|
+
|
|
242
|
+
// 标签:命中字段渲染模板结果,缺 code 的行回退纯 label
|
|
243
|
+
const tagTexts = [...host.querySelectorAll('.u-tag')].map((el) => el.textContent)
|
|
244
|
+
expect(tagTexts).toEqual(['启用(ENABLED)', '禁用'])
|
|
245
|
+
} finally {
|
|
246
|
+
unmount()
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
})
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
:closable="!disabled"
|
|
29
29
|
@close="handleRemove(index)"
|
|
30
30
|
>
|
|
31
|
-
{{ tag
|
|
31
|
+
{{ renderNodeLabel(tag) }}
|
|
32
32
|
</u-tag>
|
|
33
33
|
<u-tag v-if="hiddenCount > 0">+{{ hiddenCount }}</u-tag>
|
|
34
34
|
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
<div v-else-if="model.length" :class="[cls.m(size), cls.e('readonly-tags')]">
|
|
94
94
|
<div :class="cls.e('tags')">
|
|
95
95
|
<u-tag v-for="option of tags" :key="option[valueKey]">
|
|
96
|
-
{{ option
|
|
96
|
+
{{ renderNodeLabel(option) }}
|
|
97
97
|
</u-tag>
|
|
98
98
|
</div>
|
|
99
99
|
</div>
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
import { debounce, dfs, o } from '@cat-kit/core'
|
|
108
108
|
import { useFormFallbackProps } from '@veltra/compositions'
|
|
109
109
|
import { ArrowDown, Close } from '@veltra/icons/normal'
|
|
110
|
-
import { bem, fieldKey, FORM_EMPTY_CONTENT } from '@veltra/utils'
|
|
110
|
+
import { bem, fieldKey, FORM_EMPTY_CONTENT, renderLabelTemplate } from '@veltra/utils'
|
|
111
111
|
import { injectFormContext } from '@veltra/utils'
|
|
112
112
|
import { computed, nextTick, shallowRef, useTemplateRef, watch } from 'vue'
|
|
113
113
|
|
|
@@ -144,6 +144,12 @@ const props = withDefaults(defineProps<MultiTreeSelectProps>(), {
|
|
|
144
144
|
const labelKey = computed(() => fieldKey(props.labelKey, 'label'))
|
|
145
145
|
const valueKey = computed(() => fieldKey(props.valueKey, 'value'))
|
|
146
146
|
|
|
147
|
+
/** 节点展示文案:labelTemplate 渲染结果优先,未配置模板或引用字段缺失时回退 labelKey 取值 */
|
|
148
|
+
function renderNodeLabel(data: Record<string, any> | undefined | null) {
|
|
149
|
+
if (!data) return undefined
|
|
150
|
+
return renderLabelTemplate(props.labelTemplate, data) ?? o(data).get(labelKey.value)
|
|
151
|
+
}
|
|
152
|
+
|
|
147
153
|
const treeProps = computed(() => {
|
|
148
154
|
return o(props as Record<string, any>).omit([
|
|
149
155
|
'tips',
|
|
@@ -364,3 +364,104 @@ describe('USelect', () => {
|
|
|
364
364
|
}
|
|
365
365
|
})
|
|
366
366
|
})
|
|
367
|
+
|
|
368
|
+
describe('USelect labelTemplate', () => {
|
|
369
|
+
const templateOptions = [
|
|
370
|
+
{ label: '启用', code: 'ENABLED', value: 'enabled' },
|
|
371
|
+
{ label: '禁用', value: 'disabled' }
|
|
372
|
+
]
|
|
373
|
+
|
|
374
|
+
it('renders the template in options and echo, falling back to label when fields are missing', async () => {
|
|
375
|
+
const { host, model, texts, unmount } = mountSelect({
|
|
376
|
+
modelValue: 'enabled',
|
|
377
|
+
labelTemplate: '{label}({code})',
|
|
378
|
+
options: templateOptions
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
try {
|
|
382
|
+
await nextTick()
|
|
383
|
+
// 未配置 labelKey:展示与 update:text 均为模板渲染结果(模板即标签)
|
|
384
|
+
expect(host.querySelector('input')!.value).toBe('启用(ENABLED)')
|
|
385
|
+
expect(texts.at(-1)).toBe('启用(ENABLED)')
|
|
386
|
+
|
|
387
|
+
// 下拉选项:命中字段渲染模板,缺 code 的行回退纯 label
|
|
388
|
+
await openDropdown(host)
|
|
389
|
+
expect(queryOptions().map((el) => el.textContent)).toEqual(['启用(ENABLED)', '禁用'])
|
|
390
|
+
|
|
391
|
+
// 选中缺 code 的选项:渲染回退纯 label,展示与回发同为回退结果
|
|
392
|
+
await clickOption(queryOptions().find((el) => el.textContent === '禁用')!)
|
|
393
|
+
expect(model.value).toBe('disabled')
|
|
394
|
+
expect(host.querySelector('input')!.value).toBe('禁用')
|
|
395
|
+
expect(texts.at(-1)).toBe('禁用')
|
|
396
|
+
|
|
397
|
+
// 选中命中模板的选项:展示与回发同为模板渲染结果
|
|
398
|
+
await openDropdown(host)
|
|
399
|
+
await clickOption(queryOptions().find((el) => el.textContent === '启用(ENABLED)')!)
|
|
400
|
+
expect(model.value).toBe('enabled')
|
|
401
|
+
expect(host.querySelector('input')!.value).toBe('启用(ENABLED)')
|
|
402
|
+
expect(texts.at(-1)).toBe('启用(ENABLED)')
|
|
403
|
+
} finally {
|
|
404
|
+
unmount()
|
|
405
|
+
}
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
it('emits the raw labelKey value when labelKey is explicitly configured', async () => {
|
|
409
|
+
const { host, texts, unmount } = mountSelect({
|
|
410
|
+
modelValue: 'enabled',
|
|
411
|
+
labelKey: 'label',
|
|
412
|
+
labelTemplate: '{label}({code})',
|
|
413
|
+
options: templateOptions
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
try {
|
|
417
|
+
await nextTick()
|
|
418
|
+
// 展示为模板渲染结果;显式配置 labelKey 时 update:text 回发原始取值
|
|
419
|
+
expect(host.querySelector('input')!.value).toBe('启用(ENABLED)')
|
|
420
|
+
expect(texts.at(-1)).toBe('启用')
|
|
421
|
+
} finally {
|
|
422
|
+
unmount()
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
it('matches filter queries against the rendered template result', async () => {
|
|
427
|
+
const { host, unmount } = mountSelect({
|
|
428
|
+
filterable: true,
|
|
429
|
+
labelTemplate: '{label}({code})',
|
|
430
|
+
options: templateOptions
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
try {
|
|
434
|
+
await openDropdown(host)
|
|
435
|
+
// 按编码搜索命中
|
|
436
|
+
await typeQuery(host, 'ENABLED')
|
|
437
|
+
expect(queryOptions().map((el) => el.textContent)).toEqual(['启用(ENABLED)'])
|
|
438
|
+
|
|
439
|
+
// 按原始 label 搜索仍然命中
|
|
440
|
+
await typeQuery(host, '启用')
|
|
441
|
+
expect(queryOptions().map((el) => el.textContent)).toEqual(['启用(ENABLED)'])
|
|
442
|
+
} finally {
|
|
443
|
+
unmount()
|
|
444
|
+
}
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
it('renders created temp options via the same fallback', async () => {
|
|
448
|
+
const { host, model, unmount } = mountSelect({
|
|
449
|
+
filterable: true,
|
|
450
|
+
creatable: true,
|
|
451
|
+
labelTemplate: '{label}({code})',
|
|
452
|
+
options: templateOptions
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
try {
|
|
456
|
+
await openDropdown(host)
|
|
457
|
+
await typeQuery(host, '新选项')
|
|
458
|
+
// 临时选项缺 code 字段:回退纯文本,而不是「新选项()」
|
|
459
|
+
expect(queryOptions().some((el) => el.textContent === '新选项')).toBe(true)
|
|
460
|
+
await clickOption(queryOptions().find((el) => el.textContent === '新选项')!)
|
|
461
|
+
expect(model.value).toBe('新选项')
|
|
462
|
+
expect(host.querySelector('input')!.value).toBe('新选项')
|
|
463
|
+
} finally {
|
|
464
|
+
unmount()
|
|
465
|
+
}
|
|
466
|
+
})
|
|
467
|
+
})
|