@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
|
@@ -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
|
|
|
@@ -148,7 +155,6 @@ import { useOptions } from './use-options'
|
|
|
148
155
|
defineOptions({ name: 'USelect', inheritAttrs: false })
|
|
149
156
|
|
|
150
157
|
const props = withDefaults(defineProps<SelectProps>(), {
|
|
151
|
-
labelKey: 'label',
|
|
152
158
|
valueKey: 'value',
|
|
153
159
|
placeholder: '请选择',
|
|
154
160
|
clearable: true,
|
|
@@ -170,6 +176,17 @@ const cls = bem('select')
|
|
|
170
176
|
const labelKey = computed(() => fieldKey(props.labelKey, 'label'))
|
|
171
177
|
const valueKey = computed(() => fieldKey(props.valueKey, 'value'))
|
|
172
178
|
|
|
179
|
+
/** 选项展示文案:labelTemplate 渲染结果优先,未配置模板或引用字段缺失时回退 labelKey 取值 */
|
|
180
|
+
function renderOptionLabel(option: Record<string, any> | undefined) {
|
|
181
|
+
if (!option) return undefined
|
|
182
|
+
return renderLabelTemplate(props.labelTemplate, option) ?? o(option).get(labelKey.value)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** update:text 回发文案:显式配置 labelKey 时取原始取值;未配置时模板渲染结果即标签,与展示文案一致 */
|
|
186
|
+
function optionEmitText(option: Record<string, any>) {
|
|
187
|
+
return props.labelKey === undefined ? renderOptionLabel(option) : o(option).get(labelKey.value)
|
|
188
|
+
}
|
|
189
|
+
|
|
173
190
|
const optionClass = cls.e('option')
|
|
174
191
|
|
|
175
192
|
const { formProps } = injectFormContext()
|
|
@@ -187,7 +204,7 @@ const selected = shallowRef<Record<string, any>>()
|
|
|
187
204
|
const displayedValue = computed(() => {
|
|
188
205
|
if (label.value) return label.value
|
|
189
206
|
|
|
190
|
-
if (selected.value) return
|
|
207
|
+
if (selected.value) return renderOptionLabel(selected.value)
|
|
191
208
|
// 未命中选项:优先展示 text 兜底文案,避免露出不可读的编码
|
|
192
209
|
return props.text ?? String(props.modelValue ?? '')
|
|
193
210
|
})
|
|
@@ -262,11 +279,11 @@ function handleTriggerClickCapture(e: MouseEvent) {
|
|
|
262
279
|
|
|
263
280
|
const { userAction, isUserActive } = useUserAction()
|
|
264
281
|
|
|
265
|
-
/** 更新内部文案;值变化时 emit update:text(readonly
|
|
266
|
-
function setLabel(next?: string) {
|
|
282
|
+
/** 更新内部文案;值变化时 emit update:text(readonly 纯展示,不通知父级)。next:展示文案(模板渲染结果);text:回发文案(见 optionEmitText),缺省同 next */
|
|
283
|
+
function setLabel(next?: string, text: string | undefined = next) {
|
|
267
284
|
if (label.value === next) return
|
|
268
285
|
label.value = next
|
|
269
|
-
if (!readonly.value) emit('update:text',
|
|
286
|
+
if (!readonly.value) emit('update:text', text)
|
|
270
287
|
}
|
|
271
288
|
|
|
272
289
|
/** 按 modelValue 与完整选项列表同步高亮索引、选中项与显示标签(外部回显用,O(n)) */
|
|
@@ -285,7 +302,7 @@ function syncSelected(modelValue: any, sourceOptions: Record<string, any>[] | un
|
|
|
285
302
|
)
|
|
286
303
|
selected.value = currentIndex.value >= 0 ? sourceOptions[currentIndex.value] : undefined
|
|
287
304
|
if (selected.value) {
|
|
288
|
-
setLabel(
|
|
305
|
+
setLabel(renderOptionLabel(selected.value), optionEmitText(selected.value))
|
|
289
306
|
} else if (props.text) {
|
|
290
307
|
// 未命中但有 text 兜底:文案以父级为准,不回发
|
|
291
308
|
label.value = undefined
|
|
@@ -334,7 +351,7 @@ const virtualOptions = computed(() => {
|
|
|
334
351
|
return {
|
|
335
352
|
option,
|
|
336
353
|
index: item.index,
|
|
337
|
-
label:
|
|
354
|
+
label: renderOptionLabel(option),
|
|
338
355
|
val: o(option).get(valueKey.value),
|
|
339
356
|
key: item.index,
|
|
340
357
|
offset: item.start
|
|
@@ -394,7 +411,7 @@ const handleSelect = userAction((option: Record<string, any>, _index: number) =>
|
|
|
394
411
|
selected.value = option
|
|
395
412
|
|
|
396
413
|
emit('update:modelValue', value)
|
|
397
|
-
setLabel(option
|
|
414
|
+
setLabel(renderOptionLabel(option), optionEmitText(option))
|
|
398
415
|
emit('change', option)
|
|
399
416
|
if (option.__isTemp) {
|
|
400
417
|
// 转正延迟到面板关闭后:动画期间保持过滤列表,避免列表瞬间恢复全量导致面板变长闪烁
|
|
@@ -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
|
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
<script lang="ts" setup>
|
|
34
34
|
import { useFormFallbackProps, useVirtualizer } from '@veltra/compositions'
|
|
35
|
-
import { bem, nextFrame, scrollIntoContainerView } from '@veltra/utils'
|
|
35
|
+
import { bem, nextFrame, renderLabelTemplate, scrollIntoContainerView } from '@veltra/utils'
|
|
36
36
|
import { injectFormContext } from '@veltra/utils'
|
|
37
37
|
import { computed, provide, shallowRef, useSlots, watch, watchEffect, type VNode } from 'vue'
|
|
38
38
|
|
|
@@ -83,7 +83,11 @@ defineSlots<{ default: (props: TreeSlotsScope) => any }>()
|
|
|
83
83
|
const slots = useSlots()
|
|
84
84
|
|
|
85
85
|
function getTreeSlotsNode(ctx: TreeSlotsScope): VNode[] | string | undefined {
|
|
86
|
-
return (
|
|
86
|
+
return (
|
|
87
|
+
(props.slots?.default ?? slots.default)?.(ctx) ??
|
|
88
|
+
renderLabelTemplate(props.labelTemplate, ctx.node.data) ??
|
|
89
|
+
ctx.node.label
|
|
90
|
+
)
|
|
87
91
|
}
|
|
88
92
|
|
|
89
93
|
const { nodes, forest, getFlattedNodes, nodeDict } = useTreeNodes({ props })
|
|
@@ -98,7 +102,7 @@ watch(
|
|
|
98
102
|
{ immediate: true }
|
|
99
103
|
)
|
|
100
104
|
|
|
101
|
-
const { filter } = useFilter({ forest, getFlattedNodes })
|
|
105
|
+
const { filter } = useFilter({ forest, getFlattedNodes, labelTemplate: () => props.labelTemplate })
|
|
102
106
|
|
|
103
107
|
const { handleSelect, selectedData } = useSelect({ props, emit, nodeDict, getFlattedNodes })
|
|
104
108
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Forest } from '@cat-kit/core'
|
|
2
|
+
import { renderLabelTemplate } from '@veltra/utils'
|
|
2
3
|
import type { ShallowRef } from 'vue'
|
|
3
4
|
|
|
4
5
|
import type { TreeNode } from './tree-node'
|
|
@@ -6,6 +7,8 @@ import type { TreeNode } from './tree-node'
|
|
|
6
7
|
interface Options {
|
|
7
8
|
forest: ShallowRef<Forest<Record<string, unknown>, any>>
|
|
8
9
|
getFlattedNodes: () => void
|
|
10
|
+
/** labelTemplate 取值器:配置后字符串过滤同时匹配模板渲染结果 */
|
|
11
|
+
labelTemplate?: () => string | undefined
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
interface UseFilterReturned {
|
|
@@ -13,7 +16,7 @@ interface UseFilterReturned {
|
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export function useFilter(options: Options): UseFilterReturned {
|
|
16
|
-
const { forest, getFlattedNodes } = options
|
|
19
|
+
const { forest, getFlattedNodes, labelTemplate } = options
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* 追踪缓存
|
|
@@ -26,7 +29,9 @@ export function useFilter(options: Options): UseFilterReturned {
|
|
|
26
29
|
|
|
27
30
|
function defaultFilter(node: TreeNode, qs: string) {
|
|
28
31
|
if (!qs) return true
|
|
29
|
-
|
|
32
|
+
// 原始 label 与模板渲染结果任一命中即匹配
|
|
33
|
+
if (node.label.includes(qs)) return true
|
|
34
|
+
return renderLabelTemplate(labelTemplate?.(), node.data)?.includes(qs) ?? false
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
/**
|
|
@@ -296,3 +296,88 @@ describe('UTreeSelect', () => {
|
|
|
296
296
|
}
|
|
297
297
|
})
|
|
298
298
|
})
|
|
299
|
+
|
|
300
|
+
describe('UTreeSelect labelTemplate', () => {
|
|
301
|
+
const templateData = [
|
|
302
|
+
{ label: '北京', value: 'beijing', code: 'BJ' },
|
|
303
|
+
{ label: '上海', value: 'shanghai' }
|
|
304
|
+
]
|
|
305
|
+
|
|
306
|
+
it('renders node text and echo with the template, falling back to label', async () => {
|
|
307
|
+
const { host, model, texts, unmount } = mountTreeSelect({
|
|
308
|
+
modelValue: 'beijing',
|
|
309
|
+
labelTemplate: '{label}({code})',
|
|
310
|
+
data: templateData
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
await nextTick()
|
|
315
|
+
// 未配置 labelKey:展示与 update:text 均为模板渲染结果(模板即标签)
|
|
316
|
+
expect(texts.at(-1)).toBe('北京(BJ)')
|
|
317
|
+
expect(host.querySelector('input')!.value).toBe('北京(BJ)')
|
|
318
|
+
|
|
319
|
+
await openDropdown(host)
|
|
320
|
+
const nodeTexts = queryNodeContents().map((el) => el.textContent)
|
|
321
|
+
expect(nodeTexts.some((t) => t === '北京(BJ)')).toBe(true)
|
|
322
|
+
// 缺 code 的节点回退纯 label
|
|
323
|
+
expect(nodeTexts.some((t) => t === '上海')).toBe(true)
|
|
324
|
+
|
|
325
|
+
// 选中缺 code 的节点:渲染回退纯 label,展示与回发同为回退结果
|
|
326
|
+
await clickNodeByLabel('上海')
|
|
327
|
+
expect(model.value).toBe('shanghai')
|
|
328
|
+
expect(host.querySelector('input')!.value).toBe('上海')
|
|
329
|
+
expect(texts.at(-1)).toBe('上海')
|
|
330
|
+
|
|
331
|
+
// 选中命中模板的节点:展示与回发同为模板渲染结果
|
|
332
|
+
await openDropdown(host)
|
|
333
|
+
await clickNodeByLabel('北京(BJ)')
|
|
334
|
+
expect(model.value).toBe('beijing')
|
|
335
|
+
expect(host.querySelector('input')!.value).toBe('北京(BJ)')
|
|
336
|
+
expect(texts.at(-1)).toBe('北京(BJ)')
|
|
337
|
+
} finally {
|
|
338
|
+
unmount()
|
|
339
|
+
}
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
it('emits the raw labelKey value when labelKey is explicitly configured', async () => {
|
|
343
|
+
const { host, texts, unmount } = mountTreeSelect({
|
|
344
|
+
modelValue: 'beijing',
|
|
345
|
+
labelKey: 'label',
|
|
346
|
+
labelTemplate: '{label}({code})',
|
|
347
|
+
data: templateData
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
await nextTick()
|
|
352
|
+
// 展示为模板渲染结果;显式配置 labelKey 时 update:text 回发原始取值
|
|
353
|
+
expect(host.querySelector('input')!.value).toBe('北京(BJ)')
|
|
354
|
+
expect(texts.at(-1)).toBe('北京')
|
|
355
|
+
} finally {
|
|
356
|
+
unmount()
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
it('filters tree nodes by the rendered template result', async () => {
|
|
361
|
+
const { host, unmount } = mountTreeSelect({
|
|
362
|
+
filterable: true,
|
|
363
|
+
labelTemplate: '{label}({code})',
|
|
364
|
+
data: templateData
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
try {
|
|
368
|
+
await openDropdown(host)
|
|
369
|
+
// 按编码搜索命中
|
|
370
|
+
await typeQuery(host, 'BJ')
|
|
371
|
+
let nodeTexts = queryNodeContents().map((el) => el.textContent)
|
|
372
|
+
expect(nodeTexts.some((t) => t?.includes('北京(BJ)'))).toBe(true)
|
|
373
|
+
expect(nodeTexts.some((t) => t?.includes('上海'))).toBe(false)
|
|
374
|
+
|
|
375
|
+
// 按原始 label 搜索仍然命中
|
|
376
|
+
await typeQuery(host, '上海')
|
|
377
|
+
nodeTexts = queryNodeContents().map((el) => el.textContent)
|
|
378
|
+
expect(nodeTexts.some((t) => t?.includes('上海'))).toBe(true)
|
|
379
|
+
} finally {
|
|
380
|
+
unmount()
|
|
381
|
+
}
|
|
382
|
+
})
|
|
383
|
+
})
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
import { debounce, dfs, o } from '@cat-kit/core'
|
|
77
77
|
import { useFormFallbackProps, useUserAction } from '@veltra/compositions'
|
|
78
78
|
import { ArrowDown, Close } from '@veltra/icons/normal'
|
|
79
|
-
import { bem, fieldKey, FORM_EMPTY_CONTENT } from '@veltra/utils'
|
|
79
|
+
import { bem, fieldKey, FORM_EMPTY_CONTENT, renderLabelTemplate } from '@veltra/utils'
|
|
80
80
|
import { injectFormContext } from '@veltra/utils'
|
|
81
81
|
import { computed, nextTick, shallowRef, useTemplateRef, watch } from 'vue'
|
|
82
82
|
|
|
@@ -91,7 +91,6 @@ import type { TreeSlotsScope } from '../tree/di'
|
|
|
91
91
|
defineOptions({ name: 'UTreeSelect', inheritAttrs: false })
|
|
92
92
|
|
|
93
93
|
const props = withDefaults(defineProps<TreeSelectProps>(), {
|
|
94
|
-
labelKey: 'label',
|
|
95
94
|
valueKey: 'value',
|
|
96
95
|
placeholder: '请选择',
|
|
97
96
|
expandAll: false,
|
|
@@ -133,6 +132,17 @@ const cls = bem('tree-select')
|
|
|
133
132
|
const labelKey = computed(() => fieldKey(props.labelKey, 'label'))
|
|
134
133
|
const valueKey = computed(() => fieldKey(props.valueKey, 'value'))
|
|
135
134
|
|
|
135
|
+
/** 节点展示文案:labelTemplate 渲染结果优先,未配置模板或引用字段缺失时回退 labelKey 取值 */
|
|
136
|
+
function renderNodeLabel(data: Record<string, any> | undefined | null) {
|
|
137
|
+
if (!data) return undefined
|
|
138
|
+
return renderLabelTemplate(props.labelTemplate, data) ?? o(data).get(labelKey.value)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** update:text 回发文案:显式配置 labelKey 时取原始取值;未配置时模板渲染结果即标签,与展示文案一致 */
|
|
142
|
+
function nodeEmitText(data: Record<string, any>) {
|
|
143
|
+
return props.labelKey === undefined ? renderNodeLabel(data) : o(data).get(labelKey.value)
|
|
144
|
+
}
|
|
145
|
+
|
|
136
146
|
/** 是否可搜索:显式声明或数据源为远程函数 */
|
|
137
147
|
const filterable = computed(() => props.filterable || typeof props.data === 'function')
|
|
138
148
|
|
|
@@ -206,11 +216,11 @@ const querying = shallowRef(false)
|
|
|
206
216
|
|
|
207
217
|
const inputRef = useTemplateRef<InputExposed>('inputRef')
|
|
208
218
|
|
|
209
|
-
/** 更新内部文案;值变化时 emit update:text(readonly
|
|
210
|
-
function setLabel(next?: string) {
|
|
219
|
+
/** 更新内部文案;值变化时 emit update:text(readonly 纯展示,不通知父级)。next:展示文案(模板渲染结果);text:回发文案(见 nodeEmitText),缺省同 next */
|
|
220
|
+
function setLabel(next?: string, text: string | undefined = next) {
|
|
211
221
|
if (label.value === next) return
|
|
212
222
|
label.value = next
|
|
213
|
-
if (!readonly.value) emit('update:text',
|
|
223
|
+
if (!readonly.value) emit('update:text', text)
|
|
214
224
|
}
|
|
215
225
|
|
|
216
226
|
/** 触发输入框的值:查询态下承载查询串,否则展示选中标签 */
|
|
@@ -293,6 +303,7 @@ watch(
|
|
|
293
303
|
if (!data?.length) return
|
|
294
304
|
|
|
295
305
|
let nextLabel: string | undefined
|
|
306
|
+
let nextText: string | undefined
|
|
296
307
|
const childrenKey = props.childrenKey ?? 'children'
|
|
297
308
|
data.some((item) => {
|
|
298
309
|
let founded = false
|
|
@@ -300,7 +311,8 @@ watch(
|
|
|
300
311
|
item,
|
|
301
312
|
(v) => {
|
|
302
313
|
if (v[valueKey.value] === modelVal) {
|
|
303
|
-
nextLabel = v
|
|
314
|
+
nextLabel = renderNodeLabel(v)
|
|
315
|
+
nextText = nodeEmitText(v)
|
|
304
316
|
founded = true
|
|
305
317
|
return true
|
|
306
318
|
}
|
|
@@ -311,7 +323,7 @@ watch(
|
|
|
311
323
|
return founded
|
|
312
324
|
})
|
|
313
325
|
if (nextLabel !== undefined) {
|
|
314
|
-
setLabel(nextLabel)
|
|
326
|
+
setLabel(nextLabel, nextText)
|
|
315
327
|
} else if (props.text) {
|
|
316
328
|
// 未命中但有 text 兜底:文案以父级为准,不回发
|
|
317
329
|
label.value = undefined
|
|
@@ -329,7 +341,7 @@ const handleSelect = userAction(
|
|
|
329
341
|
model.value = selected ?? ''
|
|
330
342
|
|
|
331
343
|
if (selectedData) {
|
|
332
|
-
setLabel(
|
|
344
|
+
setLabel(renderNodeLabel(selectedData), nodeEmitText(selectedData))
|
|
333
345
|
} else {
|
|
334
346
|
setLabel(undefined)
|
|
335
347
|
}
|
package/src/types/drawer.ts
CHANGED
|
@@ -13,6 +13,12 @@ export interface DrawerProps {
|
|
|
13
13
|
/** 抽屉方向 */
|
|
14
14
|
direction?: DrawerDirection
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* 抽屉尺寸;左右方向为宽度,上下方向为高度,数字按 px 处理
|
|
18
|
+
* @description 不传时走主题 token `--u-drawer-size`(默认 320px)
|
|
19
|
+
*/
|
|
20
|
+
size?: number | string
|
|
21
|
+
|
|
16
22
|
/** 是否显示关闭按钮 */
|
|
17
23
|
showClose?: boolean
|
|
18
24
|
/**
|
package/src/types/empty.ts
CHANGED
|
@@ -13,6 +13,14 @@ export interface MultiSelectProps extends FormComponentProps {
|
|
|
13
13
|
valueKey?: string
|
|
14
14
|
/** 标签字段 */
|
|
15
15
|
labelKey?: string
|
|
16
|
+
/**
|
|
17
|
+
* 标签展示模板
|
|
18
|
+
* @description `{fieldKey}` 占位符按选项行字段插值(支持嵌套路径取值),
|
|
19
|
+
* 模板引用的字段在行中取不到时整体回退 `row[labelKey]`;
|
|
20
|
+
* 配置后下拉选项、已选标签等展示文案统一渲染模板结果
|
|
21
|
+
* @example '{label}({code})'
|
|
22
|
+
*/
|
|
23
|
+
labelTemplate?: string
|
|
16
24
|
/** 是否可清除 */
|
|
17
25
|
clearable?: boolean
|
|
18
26
|
/** 占位符 */
|
package/src/types/select.ts
CHANGED
|
@@ -14,8 +14,21 @@ export interface SelectProps extends FormComponentProps {
|
|
|
14
14
|
| ((qs: string) => Promise<Record<string, any>[]> | Record<string, any>[])
|
|
15
15
|
/** 值字段 */
|
|
16
16
|
valueKey?: string
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* 标签字段
|
|
19
|
+
* @default 'label'
|
|
20
|
+
* @description 显式配置时 update:text 回发 `row[labelKey]` 原始取值;未配置时回发展示文案(labelTemplate 渲染结果)
|
|
21
|
+
*/
|
|
18
22
|
labelKey?: string
|
|
23
|
+
/**
|
|
24
|
+
* 标签展示模板
|
|
25
|
+
* @description `{fieldKey}` 占位符按选项行字段插值(支持嵌套路径取值),
|
|
26
|
+
* 模板引用的字段在行中取不到时整体回退 `row[labelKey]`;
|
|
27
|
+
* 配置后下拉选项与选中回显等展示文案统一渲染模板结果;
|
|
28
|
+
* update:text 回发显式配置的 `labelKey` 原始取值,未配置 labelKey 时回发模板渲染结果
|
|
29
|
+
* @example '{label}({code})'
|
|
30
|
+
*/
|
|
31
|
+
labelTemplate?: string
|
|
19
32
|
/**
|
|
20
33
|
* 兜底展示文案
|
|
21
34
|
* @description modelValue 未命中选项时展示 text(如回显数据已不在选项中),命中时展示选项 label
|
package/src/types/tree.ts
CHANGED
|
@@ -32,6 +32,14 @@ export interface TreeProps {
|
|
|
32
32
|
expandOnClickNode?: boolean
|
|
33
33
|
/** label键 */
|
|
34
34
|
labelKey?: string
|
|
35
|
+
/**
|
|
36
|
+
* 标签展示模板
|
|
37
|
+
* @description `{fieldKey}` 占位符按节点数据字段插值(支持嵌套路径取值),
|
|
38
|
+
* 模板引用的字段在节点数据中取不到时整体回退 `node[labelKey]`;
|
|
39
|
+
* 配置后节点文本与字符串过滤统一按模板结果渲染 / 匹配
|
|
40
|
+
* @example '{label}({code})'
|
|
41
|
+
*/
|
|
42
|
+
labelTemplate?: string
|
|
35
43
|
/** value键 */
|
|
36
44
|
valueKey?: string
|
|
37
45
|
/** 子节点键 */
|