Issue#6·F3: ScSelect 统一下拉封装(契约 auto>5 搜索阈值)——options 数组模式选项>5 自动 filterable(sub2api Select.vue L210 同源语义 searchable=auto);searchable=false 可关/filterable 显式覆盖/slot 模式透传;示范替换 downlink 来源(4 项,无搜索)与状态(6 项,出搜索)正反例;新代码下拉一律用本件,web-next 将直译 sub2api 严格形态(面板首项=搜索输入);sc-select.spec 4 用例(auto 阈值/关闭/覆盖/slot 渲染);vitest 186 全绿+build ✓

This commit is contained in:
2026-11-18 10:58:18 +08:00
parent b3e6bcab5d
commit 53395007bb
3 changed files with 86 additions and 6 deletions
+56
View File
@@ -0,0 +1,56 @@
<!-- ScSelect.vue Issue#6·F3:下拉统一封装(对齐 sub2api Select searchable=auto 语义)
规则:options 数组模式下选项>5 自动 filterable(契约源 Select.vue L210:
options.length > 5);slot 模式纯透传(调用方自控)。新代码下拉一律用本件;
web-next 新工程将 1:1 直译 sub2api Select(面板首项=搜索输入的严格形态)。 -->
<template>
<el-select
:model-value="modelValue"
:filterable="autoFilter || filterable"
:placeholder="placeholder"
:clearable="clearable"
:disabled="disabled"
:size="size"
@update:model-value="$emit('update:modelValue', $event)"
>
<slot>
<el-option v-for="o in options" :key="String(o.value)" :value="o.value" :label="o.label" :disabled="o.disabled" />
</slot>
</el-select>
</template>
<script setup lang="ts">
import { computed } from 'vue'
defineOptions({ name: 'ScSelect', inheritAttrs: true })
export interface ScOption {
value: string | number | boolean
label: string
disabled?: boolean
}
const props = withDefaults(
defineProps<{
modelValue: unknown
/** 选项数组(推荐:驱动 auto>5 阈值);缺省走 slot */
options?: ScOption[]
placeholder?: string
clearable?: boolean
disabled?: boolean
size?: 'large' | 'default' | 'small'
/** 显式可搜(手写覆盖,等同 el-select filterable) */
filterable?: boolean
/** 契约 auto 阈值:'auto'(默认,>5 出搜索)|true|false;仅 options 数组模式生效 */
searchable?: boolean | 'auto'
}>(),
{ clearable: true, searchable: 'auto' },
)
defineEmits<{ 'update:modelValue': [value: unknown] }>()
const autoFilter = computed(() => {
if (props.filterable || props.searchable === false) return false
const n = props.options?.length ?? 0
return props.searchable === true || n > 5
})
</script>
+3 -6
View File
@@ -28,9 +28,7 @@
</el-select>
<el-input-number v-model="query.fee" :min="0" :controls="false" placeholder="条" @keyup.enter="search" />
</div>
<el-select v-model="query.source" clearable placeholder="提交来源·全部" @change="search">
<el-option v-for="o in SOURCE_OPTIONS" :key="o.value" :value="o.value" :label="o.label" />
</el-select>
<ScSelect v-model="query.source" :options="[...SOURCE_OPTIONS]" clearable placeholder="提交来源·全部" @change="search" />
<el-select v-model="query.carrier" clearable placeholder="运营商·全部" @change="search">
<el-option v-for="c in ['移动', '联通', '电信']" :key="c" :value="c" :label="c" />
</el-select>
@@ -38,9 +36,7 @@
<el-select v-model="query.channel_id" filterable clearable placeholder="通道编号·全部" @change="search">
<el-option v-for="c in channelOptions" :key="c.id" :value="c.id" :label="c.label" :disabled="c.disabled" />
</el-select>
<el-select v-model="query.status" clearable placeholder="状态·全部" @change="search">
<el-option v-for="o in DOWNLINK_STATUS_OPTIONS" :key="o.value" :value="o.value" :label="o.label" />
</el-select>
<ScSelect v-model="query.status" :options="[...DOWNLINK_STATUS_OPTIONS]" clearable placeholder="状态·全部" @change="search" />
<el-input v-model="query.channel_number" placeholder="通道号码 前缀:10659*" clearable @keyup.enter="search" />
<el-input v-model="query.call_data" placeholder="CallData 模糊" clearable @keyup.enter="search" />
</div>
@@ -126,6 +122,7 @@ import { onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ArrowDown } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import ScSelect from '@/components/ScSelect.vue'
import { accountApi } from '@/api/account'
import { channelApi } from '@/api/channel'
import {
+27
View File
@@ -0,0 +1,27 @@
// Issue#6·F3:ScSelect auto>5 搜索阈值(sub2api Select searchable='auto' 契约)
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import ScSelect from '@/components/ScSelect.vue'
const opts = (n: number) => Array.from({ length: n }, (_, i) => ({ value: i, label: `选项${i}` }))
describe('ScSelect auto 阈值', () => {
it('options>5 → filterable 生效(trigger 内可输入)', () => {
const w = mount(ScSelect, { props: { modelValue: '', options: opts(6) }, global: { stubs: { 'el-select': { template: '<div><slot/><input v-if="filterable" data-testid="f" /></div>', props: ['filterable','modelValue'] } } } })
expect(w.find('[data-testid="f"]').exists()).toBe(true)
})
it('options≤5 → 无 filterable', () => {
const w = mount(ScSelect, { props: { modelValue: '', options: opts(5) }, global: { stubs: { 'el-select': { template: '<div><slot/><input v-if="filterable" data-testid="f" /></div>', props: ['filterable','modelValue'] } } } })
expect(w.find('[data-testid="f"]').exists()).toBe(false)
})
it('searchable=false 关闭 auto;filterable 显式覆盖', () => {
const off = mount(ScSelect, { props: { modelValue: '', options: opts(9), searchable: false }, global: { stubs: { 'el-select': { template: '<div><input v-if="filterable" data-testid="f" /></div>', props: ['filterable'] } } } })
expect(off.find('[data-testid="f"]').exists()).toBe(false)
const on = mount(ScSelect, { props: { modelValue: '', options: opts(2), filterable: true }, global: { stubs: { 'el-select': { template: '<div><input v-if="filterable" data-testid="f" /></div>', props: ['filterable'] } } } })
expect(on.find('[data-testid="f"]').exists()).toBe(true)
})
it('options 渲染到默认 slot(el-option 数=传入数)', () => {
const w = mount(ScSelect, { props: { modelValue: '', options: opts(4) }, global: { stubs: { 'el-select': { template: '<div><slot /></div>', props: ['modelValue'] }, 'el-option': { template: '<div class="opt" />' } } } })
expect(w.findAll('.opt').length).toBe(4)
})
})