@veltra/desktop 1.12.1 → 1.13.0
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 +13 -7
- 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 +9 -3
- 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 +8 -0
- package/dist/types/tree.d.ts +8 -0
- package/package.json +7 -2
- 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 +76 -0
- package/src/components/select/select.vue +20 -7
- 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 +60 -0
- package/src/components/tree-select/tree-select.vue +9 -3
- 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 +8 -0
- package/src/types/tree.ts +8 -0
|
@@ -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,79 @@ 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
|
+
// 回显与 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 的选项:文案与回发同为回退结果
|
|
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
|
+
} finally {
|
|
397
|
+
unmount()
|
|
398
|
+
}
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
it('matches filter queries against the rendered template result', async () => {
|
|
402
|
+
const { host, unmount } = mountSelect({
|
|
403
|
+
filterable: true,
|
|
404
|
+
labelTemplate: '{label}({code})',
|
|
405
|
+
options: templateOptions
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
try {
|
|
409
|
+
await openDropdown(host)
|
|
410
|
+
// 按编码搜索命中
|
|
411
|
+
await typeQuery(host, 'ENABLED')
|
|
412
|
+
expect(queryOptions().map((el) => el.textContent)).toEqual(['启用(ENABLED)'])
|
|
413
|
+
|
|
414
|
+
// 按原始 label 搜索仍然命中
|
|
415
|
+
await typeQuery(host, '启用')
|
|
416
|
+
expect(queryOptions().map((el) => el.textContent)).toEqual(['启用(ENABLED)'])
|
|
417
|
+
} finally {
|
|
418
|
+
unmount()
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
it('renders created temp options via the same fallback', async () => {
|
|
423
|
+
const { host, model, unmount } = mountSelect({
|
|
424
|
+
filterable: true,
|
|
425
|
+
creatable: true,
|
|
426
|
+
labelTemplate: '{label}({code})',
|
|
427
|
+
options: templateOptions
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
try {
|
|
431
|
+
await openDropdown(host)
|
|
432
|
+
await typeQuery(host, '新选项')
|
|
433
|
+
// 临时选项缺 code 字段:回退纯文本,而不是「新选项()」
|
|
434
|
+
expect(queryOptions().some((el) => el.textContent === '新选项')).toBe(true)
|
|
435
|
+
await clickOption(queryOptions().find((el) => el.textContent === '新选项')!)
|
|
436
|
+
expect(model.value).toBe('新选项')
|
|
437
|
+
expect(host.querySelector('input')!.value).toBe('新选项')
|
|
438
|
+
} finally {
|
|
439
|
+
unmount()
|
|
440
|
+
}
|
|
441
|
+
})
|
|
442
|
+
})
|
|
@@ -99,11 +99,11 @@
|
|
|
99
99
|
:class="[optionClass, bem.is('selected', index === currentIndex)]"
|
|
100
100
|
@click="handleSelect(option, index)"
|
|
101
101
|
:data-index="index"
|
|
102
|
-
:title="
|
|
102
|
+
:title="renderOptionLabel(option)"
|
|
103
103
|
:key="o(option).get(valueKey)"
|
|
104
104
|
>
|
|
105
105
|
<slot v-bind="{ option, index }">
|
|
106
|
-
{{
|
|
106
|
+
{{ renderOptionLabel(option) }}
|
|
107
107
|
</slot>
|
|
108
108
|
</li>
|
|
109
109
|
</template>
|
|
@@ -124,7 +124,14 @@
|
|
|
124
124
|
import { o } from '@cat-kit/core'
|
|
125
125
|
import { useFormFallbackProps, useUserAction, useVirtualizer } from '@veltra/compositions'
|
|
126
126
|
import { ArrowDown, Close } from '@veltra/icons/normal'
|
|
127
|
-
import {
|
|
127
|
+
import {
|
|
128
|
+
bem,
|
|
129
|
+
fieldKey,
|
|
130
|
+
FORM_EMPTY_CONTENT,
|
|
131
|
+
renderLabelTemplate,
|
|
132
|
+
scrollIntoContainerView,
|
|
133
|
+
withUnit
|
|
134
|
+
} from '@veltra/utils'
|
|
128
135
|
import { injectFormContext } from '@veltra/utils'
|
|
129
136
|
import { computed, nextTick, shallowRef, useTemplateRef, watch } from 'vue'
|
|
130
137
|
|
|
@@ -170,6 +177,12 @@ const cls = bem('select')
|
|
|
170
177
|
const labelKey = computed(() => fieldKey(props.labelKey, 'label'))
|
|
171
178
|
const valueKey = computed(() => fieldKey(props.valueKey, 'value'))
|
|
172
179
|
|
|
180
|
+
/** 选项展示文案:labelTemplate 渲染结果优先,未配置模板或引用字段缺失时回退 labelKey 取值 */
|
|
181
|
+
function renderOptionLabel(option: Record<string, any> | undefined) {
|
|
182
|
+
if (!option) return undefined
|
|
183
|
+
return renderLabelTemplate(props.labelTemplate, option) ?? o(option).get(labelKey.value)
|
|
184
|
+
}
|
|
185
|
+
|
|
173
186
|
const optionClass = cls.e('option')
|
|
174
187
|
|
|
175
188
|
const { formProps } = injectFormContext()
|
|
@@ -187,7 +200,7 @@ const selected = shallowRef<Record<string, any>>()
|
|
|
187
200
|
const displayedValue = computed(() => {
|
|
188
201
|
if (label.value) return label.value
|
|
189
202
|
|
|
190
|
-
if (selected.value) return
|
|
203
|
+
if (selected.value) return renderOptionLabel(selected.value)
|
|
191
204
|
// 未命中选项:优先展示 text 兜底文案,避免露出不可读的编码
|
|
192
205
|
return props.text ?? String(props.modelValue ?? '')
|
|
193
206
|
})
|
|
@@ -285,7 +298,7 @@ function syncSelected(modelValue: any, sourceOptions: Record<string, any>[] | un
|
|
|
285
298
|
)
|
|
286
299
|
selected.value = currentIndex.value >= 0 ? sourceOptions[currentIndex.value] : undefined
|
|
287
300
|
if (selected.value) {
|
|
288
|
-
setLabel(
|
|
301
|
+
setLabel(renderOptionLabel(selected.value))
|
|
289
302
|
} else if (props.text) {
|
|
290
303
|
// 未命中但有 text 兜底:文案以父级为准,不回发
|
|
291
304
|
label.value = undefined
|
|
@@ -334,7 +347,7 @@ const virtualOptions = computed(() => {
|
|
|
334
347
|
return {
|
|
335
348
|
option,
|
|
336
349
|
index: item.index,
|
|
337
|
-
label:
|
|
350
|
+
label: renderOptionLabel(option),
|
|
338
351
|
val: o(option).get(valueKey.value),
|
|
339
352
|
key: item.index,
|
|
340
353
|
offset: item.start
|
|
@@ -394,7 +407,7 @@ const handleSelect = userAction((option: Record<string, any>, _index: number) =>
|
|
|
394
407
|
selected.value = option
|
|
395
408
|
|
|
396
409
|
emit('update:modelValue', value)
|
|
397
|
-
setLabel(option
|
|
410
|
+
setLabel(renderOptionLabel(option))
|
|
398
411
|
emit('change', option)
|
|
399
412
|
if (option.__isTemp) {
|
|
400
413
|
// 转正延迟到面板关闭后:动画期间保持过滤列表,避免列表瞬间恢复全量导致面板变长闪烁
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { debounce, o as chainObj } from '@cat-kit/core'
|
|
2
|
-
import { fieldKey } from '@veltra/utils'
|
|
2
|
+
import { fieldKey, renderLabelTemplate } from '@veltra/utils'
|
|
3
3
|
import { computed, shallowRef, watch, type ShallowRef, type ComputedRef } from 'vue'
|
|
4
4
|
|
|
5
5
|
import type { SelectProps } from '../../types'
|
|
@@ -124,7 +124,9 @@ export function useOptions(o: Options): UseOptionsReturned {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
const _filteredOptions = sourceOptions.filter((item) => {
|
|
127
|
-
|
|
127
|
+
if (chainObj(item).get(labelKey)?.includes(qs)) return true
|
|
128
|
+
// labelTemplate 渲染结果同样参与匹配(如按编码搜索)
|
|
129
|
+
return renderLabelTemplate(props.labelTemplate, item)?.includes(qs) ?? false
|
|
128
130
|
})
|
|
129
131
|
|
|
130
132
|
setTempOption(qs, _filteredOptions)
|
|
@@ -171,10 +171,13 @@ $root-name: table;
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
// 空态包装层:sticky + translate 让空态始终随可视区水平居中(表格横向滚动时也保持可见)
|
|
174
175
|
@include m.e(empty) {
|
|
175
176
|
position: sticky;
|
|
176
177
|
left: 50%;
|
|
177
|
-
|
|
178
|
+
width: fit-content;
|
|
179
|
+
transform: translateX(-50%);
|
|
180
|
+
@include m.flex($justify: center);
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
@include m.e(foot) {
|
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
<!-- 空 -->
|
|
9
9
|
<tr v-if="!rows.length" :class="emptyRowCls">
|
|
10
10
|
<td :colspan="leafColumns.length">
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
|
|
11
|
+
<div :class="emptyCls">
|
|
12
|
+
<slot name="empty">
|
|
13
|
+
<UEmpty />
|
|
14
|
+
</slot>
|
|
15
|
+
</div>
|
|
14
16
|
</td>
|
|
15
17
|
</tr>
|
|
16
18
|
|