Issue#6·B3: Select 自绘下拉组件落地(sub2api common/Select.vue 契约直译)——Teleport 面板+首项搜索输入(searchable auto>5)+键盘 ↑↓/Enter/Esc/Tab+clearable ×+上下自适应+scroll/resize 跟随+instanceId 点击外闭;trigger r12·px-4·py-2.5,选中=primary-50 底+primary-700 字,hover/focused 中性,亮白/dark slate-800 全跟随。适配裁剪留痕:去 vue-i18n(中文硬编码)/Icon 组件→内联 lucide svg/裁 creatable+remote 远程搜索(本工程无场景);clearSelection 回空串(对齐原生筛选值域)。替换 3 页 7 处原生 select:账号(状态2+角色6含全部→auto 搜索)/通道(协议4+状态2)/下行明细(状态6 auto+通道动态+运营商3)。语义修正:selectedLabel 空值恒显 placeholder(数组含全部项时与原生一致)。验收:vue-tsc 0+build ✓(gzip 72.8KB)+Chrome 双主题 13 项断言全 PASS(auto 正反例:角色6出搜索/状态2不出;键盘搜索 adm→admin;选中 teal 底;dark slate-800);此后新页下拉直接复用本组件,剩 28 页逐页指令制交付
This commit is contained in:
@@ -0,0 +1,438 @@
|
|||||||
|
<!-- Select.vue Issue#6·B3:自绘下拉(sub2api common/Select.vue 契约直译,2026-11-17)
|
||||||
|
形态:Teleport 面板+首项搜索输入(auto>5 自动可搜)+键盘 ↑↓/Enter/Esc/Tab+clearable
|
||||||
|
+上下自适应+scroll/resize 跟随;trigger r12·px-4·py-2.5;选中=底色式 primary-50/600字。
|
||||||
|
适配裁剪(留痕):①去 vue-i18n(文案中文硬编码) ②Icon 组件→内联 svg(lucide 同款)
|
||||||
|
③裁 creatable/remote 远程搜索(本工程无场景,契约注释可溯源)。
|
||||||
|
用法:<Select v-model='x' :options='[{value,label}]' placeholder='状态:全部' class='!w-32' /> -->
|
||||||
|
<template>
|
||||||
|
<div ref='containerRef' class='relative'>
|
||||||
|
<button
|
||||||
|
ref='triggerRef'
|
||||||
|
type='button'
|
||||||
|
:class="['select-trigger', isOpen && 'select-trigger-open', disabled && 'select-trigger-disabled']"
|
||||||
|
:disabled='disabled'
|
||||||
|
:aria-expanded='isOpen'
|
||||||
|
aria-haspopup='listbox'
|
||||||
|
@click='toggle'
|
||||||
|
@keydown.down.prevent='onTriggerKeyDown'
|
||||||
|
@keydown.up.prevent='onTriggerKeyDown'
|
||||||
|
>
|
||||||
|
<span class='select-value' :class="!hasValue && 'text-gray-400 dark:text-dark-400'">{{ selectedLabel }}</span>
|
||||||
|
<span
|
||||||
|
v-if='clearable && hasValue && !disabled'
|
||||||
|
class='select-clear'
|
||||||
|
role='button'
|
||||||
|
tabindex='-1'
|
||||||
|
aria-label='Clear selection'
|
||||||
|
@click.stop='clearSelection'
|
||||||
|
@mousedown.stop
|
||||||
|
@keydown.enter.stop.prevent='clearSelection'
|
||||||
|
>
|
||||||
|
<svg class='h-3.5 w-3.5' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M18 6 6 18M6 6l12 12'/></svg>
|
||||||
|
</span>
|
||||||
|
<span class='select-icon'>
|
||||||
|
<svg
|
||||||
|
class='h-4 w-4 transition-transform duration-200'
|
||||||
|
:class="isOpen && 'rotate-180'"
|
||||||
|
viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'
|
||||||
|
><path d='m6 9 6 6 6-6'/></svg>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Teleport to='body'>
|
||||||
|
<Transition name='select-dropdown'>
|
||||||
|
<div
|
||||||
|
v-if='isOpen'
|
||||||
|
ref='dropdownRef'
|
||||||
|
:class="['select-dropdown-portal', instanceId]"
|
||||||
|
:style='dropdownStyle'
|
||||||
|
role='listbox'
|
||||||
|
tabindex='-1'
|
||||||
|
@click.stop
|
||||||
|
@mousedown.stop
|
||||||
|
@keydown='onDropdownKeyDown'
|
||||||
|
>
|
||||||
|
<div v-if='isSearchable' class='select-search'>
|
||||||
|
<svg class='h-4 w-4 text-gray-400' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>
|
||||||
|
<input ref='searchInputRef' v-model='searchQuery' type='text' :placeholder='searchPlaceholderText' :aria-label='searchPlaceholderText' class='select-search-input' @click.stop />
|
||||||
|
</div>
|
||||||
|
<div ref='optionsListRef' class='select-options'>
|
||||||
|
<div
|
||||||
|
v-for='(option, index) in filteredOptions'
|
||||||
|
:key='`${String(getOptionValue(option))}`'
|
||||||
|
role='option'
|
||||||
|
:aria-selected='isSelected(option)'
|
||||||
|
:aria-disabled='isOptionDisabled(option)'
|
||||||
|
:class="[
|
||||||
|
'select-option',
|
||||||
|
isSelected(option) && 'select-option-selected',
|
||||||
|
isOptionDisabled(option) && 'select-option-disabled',
|
||||||
|
focusedIndex === index && !isOptionDisabled(option) && 'select-option-focused'
|
||||||
|
]"
|
||||||
|
@click.stop='!isOptionDisabled(option) && selectOption(option)'
|
||||||
|
@mouseenter='handleOptionMouseEnter(option, index)'
|
||||||
|
>
|
||||||
|
<span class='select-option-label'>{{ getOptionLabel(option) }}</span>
|
||||||
|
<svg v-if='isSelected(option)' class='h-4 w-4 flex-shrink-0 text-primary-500' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 6 9 17l-5-5'/></svg>
|
||||||
|
</div>
|
||||||
|
<div v-if='filteredOptions.length === 0' class='select-empty'>{{ emptyTextDisplay }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
|
</Teleport>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang='ts'>
|
||||||
|
import { ref, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'
|
||||||
|
|
||||||
|
defineOptions({ name: 'Select' })
|
||||||
|
|
||||||
|
const instanceId = `select-${Math.random().toString(36).substring(2, 9)}`
|
||||||
|
|
||||||
|
export interface SelectOption {
|
||||||
|
value: string | number | boolean | null
|
||||||
|
label: string
|
||||||
|
disabled?: boolean
|
||||||
|
[key: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
modelValue: string | number | boolean | null | undefined
|
||||||
|
options: SelectOption[] | Array<Record<string, unknown>>
|
||||||
|
placeholder?: string
|
||||||
|
disabled?: boolean
|
||||||
|
searchable?: boolean | 'auto'
|
||||||
|
searchPlaceholder?: string
|
||||||
|
emptyText?: string
|
||||||
|
valueKey?: string
|
||||||
|
labelKey?: string
|
||||||
|
clearable?: boolean
|
||||||
|
/** 宽度:外层 class='!w-32' 控制(对齐 input 惯例),trigger w-full 撑满 */
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
disabled: false,
|
||||||
|
searchable: 'auto',
|
||||||
|
clearable: false,
|
||||||
|
valueKey: 'value',
|
||||||
|
labelKey: 'label',
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [value: string | number | boolean | null]
|
||||||
|
change: [value: string | number | boolean | null, option: SelectOption | null]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const isOpen = ref(false)
|
||||||
|
const searchQuery = ref('')
|
||||||
|
const focusedIndex = ref(-1)
|
||||||
|
const containerRef = ref<HTMLElement | null>(null)
|
||||||
|
const triggerRef = ref<HTMLButtonElement | null>(null)
|
||||||
|
const searchInputRef = ref<HTMLInputElement | null>(null)
|
||||||
|
const dropdownRef = ref<HTMLElement | null>(null)
|
||||||
|
const optionsListRef = ref<HTMLElement | null>(null)
|
||||||
|
const dropdownPosition = ref<'bottom' | 'top'>('bottom')
|
||||||
|
const triggerRect = ref<DOMRect | null>(null)
|
||||||
|
const dropdownViewportPadding = 8
|
||||||
|
const dropdownMinimumWidth = 200
|
||||||
|
|
||||||
|
const placeholderText = computed(() => props.placeholder ?? '请选择')
|
||||||
|
const searchPlaceholderText = computed(() => props.searchPlaceholder ?? '搜索…')
|
||||||
|
const emptyTextDisplay = computed(() => props.emptyText ?? '无匹配项')
|
||||||
|
|
||||||
|
/** 契约核心:searchable='auto'(默认)且选项>5 → 面板首项出搜索输入(sub2api Select L210 同源) */
|
||||||
|
const isSearchable = computed(() => {
|
||||||
|
if (props.searchable === 'auto') return props.options.length > 5
|
||||||
|
return props.searchable
|
||||||
|
})
|
||||||
|
|
||||||
|
const dropdownStyle = computed(() => {
|
||||||
|
if (!triggerRect.value) return {}
|
||||||
|
const rect = triggerRect.value
|
||||||
|
const viewportRight = Math.max(dropdownViewportPadding, window.innerWidth - dropdownViewportPadding)
|
||||||
|
const left = Math.min(Math.max(dropdownViewportPadding, rect.left), viewportRight)
|
||||||
|
const availableWidth = Math.max(0, viewportRight - left)
|
||||||
|
const preferredMinWidth = Math.max(dropdownMinimumWidth, rect.width)
|
||||||
|
const minWidth = Math.min(preferredMinWidth, availableWidth)
|
||||||
|
const style: Record<string, string> = {
|
||||||
|
position: 'fixed',
|
||||||
|
left: `${left}px`,
|
||||||
|
minWidth: `${minWidth}px`,
|
||||||
|
maxWidth: `${availableWidth}px`,
|
||||||
|
zIndex: '100000020',
|
||||||
|
}
|
||||||
|
if (dropdownPosition.value === 'top') {
|
||||||
|
style.bottom = `${window.innerHeight - rect.top + 4}px`
|
||||||
|
} else {
|
||||||
|
style.top = `${rect.bottom + 4}px`
|
||||||
|
}
|
||||||
|
return style
|
||||||
|
})
|
||||||
|
|
||||||
|
const getOptionValue = (option: any): any => {
|
||||||
|
if (typeof option === 'object' && option !== null) return option[props.valueKey]
|
||||||
|
return option
|
||||||
|
}
|
||||||
|
const getOptionLabel = (option: any): string => {
|
||||||
|
if (typeof option === 'object' && option !== null) return String(option[props.labelKey] ?? '')
|
||||||
|
return String(option ?? '')
|
||||||
|
}
|
||||||
|
const isOptionDisabled = (option: any): boolean => {
|
||||||
|
if (typeof option === 'object' && option !== null) return !!option.disabled
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const selectedOption = computed(() => props.options.find((opt: any) => getOptionValue(opt) === props.modelValue) || null)
|
||||||
|
// 空串值=未选(含数组内 value:'' 的全部项):trigger 恒显 placeholder,与原生 select 选中空 option 一致
|
||||||
|
const selectedLabel = computed(() => (hasValue.value && selectedOption.value ? getOptionLabel(selectedOption.value) : placeholderText.value))
|
||||||
|
const hasValue = computed(() => props.modelValue !== null && props.modelValue !== undefined && props.modelValue !== '')
|
||||||
|
|
||||||
|
const filteredOptions = computed(() => {
|
||||||
|
let opts = props.options as any[]
|
||||||
|
if (isSearchable.value && searchQuery.value) {
|
||||||
|
const query = searchQuery.value.toLowerCase()
|
||||||
|
opts = opts.filter((opt) => getOptionLabel(opt).toLowerCase().includes(query))
|
||||||
|
}
|
||||||
|
return opts
|
||||||
|
})
|
||||||
|
|
||||||
|
const isSelected = (option: any) => getOptionValue(option) === props.modelValue
|
||||||
|
|
||||||
|
const findNextEnabledIndex = (startIndex: number): number => {
|
||||||
|
const opts = filteredOptions.value
|
||||||
|
if (opts.length === 0) return -1
|
||||||
|
for (let offset = 0; offset < opts.length; offset++) {
|
||||||
|
const idx = (startIndex + offset) % opts.length
|
||||||
|
if (!isOptionDisabled(opts[idx])) return idx
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
const findPrevEnabledIndex = (startIndex: number): number => {
|
||||||
|
const opts = filteredOptions.value
|
||||||
|
if (opts.length === 0) return -1
|
||||||
|
for (let offset = 0; offset < opts.length; offset++) {
|
||||||
|
const idx = (startIndex - offset + opts.length) % opts.length
|
||||||
|
if (!isOptionDisabled(opts[idx])) return idx
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(filteredOptions, () => {
|
||||||
|
if (!isOpen.value) return
|
||||||
|
focusedIndex.value = findNextEnabledIndex(0)
|
||||||
|
if (focusedIndex.value >= 0) scrollToFocused()
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleOptionMouseEnter = (option: any, index: number) => {
|
||||||
|
if (isOptionDisabled(option)) return
|
||||||
|
focusedIndex.value = index
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateTriggerRect = () => {
|
||||||
|
if (containerRef.value) triggerRect.value = containerRef.value.getBoundingClientRect()
|
||||||
|
}
|
||||||
|
|
||||||
|
const calculateDropdownPosition = () => {
|
||||||
|
if (!containerRef.value) return
|
||||||
|
updateTriggerRect()
|
||||||
|
nextTick(() => {
|
||||||
|
if (!dropdownRef.value || !triggerRect.value) return
|
||||||
|
const dropdownHeight = dropdownRef.value.offsetHeight || 240
|
||||||
|
const spaceBelow = window.innerHeight - triggerRect.value.bottom
|
||||||
|
const spaceAbove = triggerRect.value.top
|
||||||
|
dropdownPosition.value = spaceBelow < dropdownHeight && spaceAbove > dropdownHeight ? 'top' : 'bottom'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggle = () => {
|
||||||
|
if (props.disabled) return
|
||||||
|
isOpen.value = !isOpen.value
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => props.disabled, (disabled) => { if (disabled) isOpen.value = false })
|
||||||
|
|
||||||
|
watch(isOpen, (open) => {
|
||||||
|
if (open) {
|
||||||
|
calculateDropdownPosition()
|
||||||
|
if (filteredOptions.value.length === 0) {
|
||||||
|
focusedIndex.value = -1
|
||||||
|
} else {
|
||||||
|
const selectedIdx = filteredOptions.value.findIndex(isSelected)
|
||||||
|
const initialIdx = selectedIdx >= 0 ? selectedIdx : 0
|
||||||
|
focusedIndex.value = isOptionDisabled(filteredOptions.value[initialIdx]) ? findNextEnabledIndex(initialIdx + 1) : initialIdx
|
||||||
|
}
|
||||||
|
if (isSearchable.value) nextTick(() => searchInputRef.value?.focus())
|
||||||
|
else nextTick(() => dropdownRef.value?.focus())
|
||||||
|
window.addEventListener('scroll', updateTriggerRect, { capture: true, passive: true })
|
||||||
|
window.addEventListener('resize', calculateDropdownPosition)
|
||||||
|
} else {
|
||||||
|
searchQuery.value = ''
|
||||||
|
focusedIndex.value = -1
|
||||||
|
window.removeEventListener('scroll', updateTriggerRect, { capture: true } as any)
|
||||||
|
window.removeEventListener('resize', calculateDropdownPosition)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const selectOption = (option: any) => {
|
||||||
|
const value = getOptionValue(option) ?? null
|
||||||
|
emit('update:modelValue', value)
|
||||||
|
emit('change', value, option)
|
||||||
|
isOpen.value = false
|
||||||
|
triggerRef.value?.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearSelection = () => {
|
||||||
|
if (props.disabled) return
|
||||||
|
// web-next 适配:筛选值域全为 string,清空回空串(=不过滤)而非 null,与原生 select 行为一致
|
||||||
|
emit('update:modelValue', '')
|
||||||
|
emit('change', '', null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onTriggerKeyDown = () => { if (!isOpen.value) isOpen.value = true }
|
||||||
|
|
||||||
|
const onDropdownKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.isComposing) return
|
||||||
|
switch (e.key) {
|
||||||
|
case 'ArrowDown':
|
||||||
|
e.preventDefault()
|
||||||
|
focusedIndex.value = findNextEnabledIndex(focusedIndex.value + 1)
|
||||||
|
if (focusedIndex.value >= 0) scrollToFocused()
|
||||||
|
break
|
||||||
|
case 'ArrowUp':
|
||||||
|
e.preventDefault()
|
||||||
|
focusedIndex.value = findPrevEnabledIndex(focusedIndex.value - 1)
|
||||||
|
if (focusedIndex.value >= 0) scrollToFocused()
|
||||||
|
break
|
||||||
|
case 'Enter':
|
||||||
|
e.preventDefault()
|
||||||
|
if (focusedIndex.value >= 0 && focusedIndex.value < filteredOptions.value.length) {
|
||||||
|
const opt = filteredOptions.value[focusedIndex.value]
|
||||||
|
if (!isOptionDisabled(opt)) selectOption(opt)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'Escape':
|
||||||
|
e.preventDefault()
|
||||||
|
isOpen.value = false
|
||||||
|
triggerRef.value?.focus()
|
||||||
|
break
|
||||||
|
case 'Tab':
|
||||||
|
isOpen.value = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const scrollToFocused = () => {
|
||||||
|
nextTick(() => {
|
||||||
|
const list = optionsListRef.value
|
||||||
|
if (!list) return
|
||||||
|
const focusedEl = list.children[focusedIndex.value] as HTMLElement
|
||||||
|
if (!focusedEl) return
|
||||||
|
if (focusedEl.offsetTop < list.scrollTop) list.scrollTop = focusedEl.offsetTop
|
||||||
|
else if (focusedEl.offsetTop + focusedEl.offsetHeight > list.scrollTop + list.offsetHeight) list.scrollTop = focusedEl.offsetTop + focusedEl.offsetHeight - list.offsetHeight
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
const target = event.target as HTMLElement
|
||||||
|
const isInDropdown = !!target.closest(`.${instanceId}`)
|
||||||
|
const isInTrigger = containerRef.value?.contains(target)
|
||||||
|
if (!isInDropdown && !isInTrigger && isOpen.value) isOpen.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => document.addEventListener('click', handleClickOutside))
|
||||||
|
onUnmounted(() => {
|
||||||
|
document.removeEventListener('click', handleClickOutside)
|
||||||
|
window.removeEventListener('scroll', updateTriggerRect, { capture: true } as any)
|
||||||
|
window.removeEventListener('resize', calculateDropdownPosition)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.select-trigger {
|
||||||
|
@apply flex w-full items-center justify-between gap-2;
|
||||||
|
@apply rounded-xl px-4 py-2.5 text-sm;
|
||||||
|
@apply bg-white dark:bg-dark-800;
|
||||||
|
@apply border border-gray-200 dark:border-dark-600;
|
||||||
|
@apply text-gray-900 dark:text-gray-100;
|
||||||
|
@apply transition-all duration-200;
|
||||||
|
@apply focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/30;
|
||||||
|
@apply hover:border-gray-300 dark:hover:border-dark-500;
|
||||||
|
@apply cursor-pointer;
|
||||||
|
}
|
||||||
|
.select-trigger-open {
|
||||||
|
@apply border-primary-500 ring-2 ring-primary-500/30;
|
||||||
|
}
|
||||||
|
.select-trigger-disabled {
|
||||||
|
@apply cursor-not-allowed bg-gray-100 opacity-60 dark:bg-dark-900;
|
||||||
|
}
|
||||||
|
.select-value {
|
||||||
|
@apply flex-1 truncate text-left;
|
||||||
|
}
|
||||||
|
.select-icon {
|
||||||
|
@apply flex-shrink-0 text-gray-400 dark:text-dark-400;
|
||||||
|
}
|
||||||
|
.select-clear {
|
||||||
|
@apply flex flex-shrink-0 cursor-pointer items-center justify-center;
|
||||||
|
@apply rounded text-gray-400 transition-colors;
|
||||||
|
@apply hover:text-gray-600 dark:hover:text-gray-200;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.select-dropdown-portal {
|
||||||
|
@apply w-max min-w-[200px];
|
||||||
|
@apply bg-white dark:bg-dark-800;
|
||||||
|
@apply rounded-xl;
|
||||||
|
@apply border border-gray-200 dark:border-dark-700;
|
||||||
|
@apply shadow-lg shadow-black/10 dark:shadow-black/30;
|
||||||
|
@apply overflow-hidden;
|
||||||
|
pointer-events: auto !important;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-search {
|
||||||
|
@apply flex items-center gap-2 px-3 py-2;
|
||||||
|
@apply border-b border-gray-100 dark:border-dark-700;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-search-input {
|
||||||
|
@apply flex-1 bg-transparent text-sm;
|
||||||
|
@apply text-gray-900 dark:text-gray-100;
|
||||||
|
@apply placeholder:text-gray-400 dark:placeholder:text-dark-400;
|
||||||
|
@apply focus:outline-none;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-options {
|
||||||
|
@apply max-h-80 overflow-y-auto py-1 outline-none;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-option {
|
||||||
|
@apply flex items-center justify-between gap-2;
|
||||||
|
@apply px-4 py-2.5 text-sm;
|
||||||
|
@apply text-gray-700 dark:text-gray-300;
|
||||||
|
@apply cursor-pointer transition-colors duration-150;
|
||||||
|
@apply hover:bg-gray-50 dark:hover:bg-dark-700;
|
||||||
|
pointer-events: auto !important;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-option-selected {
|
||||||
|
@apply bg-primary-50 dark:bg-primary-900/20;
|
||||||
|
@apply text-primary-700 dark:text-primary-300;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-option-focused {
|
||||||
|
@apply bg-gray-100 dark:bg-dark-700;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-option-disabled {
|
||||||
|
@apply cursor-not-allowed opacity-40;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-option-label {
|
||||||
|
@apply flex-1 min-w-0 truncate text-left;
|
||||||
|
}
|
||||||
|
.select-dropdown-portal .select-empty {
|
||||||
|
@apply px-4 py-8 text-center text-sm;
|
||||||
|
@apply text-gray-500 dark:text-dark-400;
|
||||||
|
}
|
||||||
|
.select-dropdown-enter-active,
|
||||||
|
.select-dropdown-leave-active {
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
.select-dropdown-enter-from,
|
||||||
|
.select-dropdown-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(-8px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -12,19 +12,8 @@
|
|||||||
<!-- 筛选区 -->
|
<!-- 筛选区 -->
|
||||||
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
||||||
<input v-model="filterUsername" class="input !w-56" placeholder="搜索账号名 / 手机号" @keyup.enter="search" />
|
<input v-model="filterUsername" class="input !w-56" placeholder="搜索账号名 / 手机号" @keyup.enter="search" />
|
||||||
<select v-model="filterStatus" class="input !w-32">
|
<Select v-model="filterStatus" :options="STATUS_OPTIONS" placeholder="状态:全部" clearable class="!w-32" />
|
||||||
<option value="">状态:全部</option>
|
<Select v-model="filterRole" :options="ROLE_OPTIONS" placeholder="角色:全部" clearable class="!w-32" />
|
||||||
<option value="1">启用</option>
|
|
||||||
<option value="0">停用</option>
|
|
||||||
</select>
|
|
||||||
<select v-model="filterRole" class="input !w-32">
|
|
||||||
<option value="">角色:全部</option>
|
|
||||||
<option value="customer">customer</option>
|
|
||||||
<option value="group">group</option>
|
|
||||||
<option value="service">service</option>
|
|
||||||
<option value="ops">ops</option>
|
|
||||||
<option value="admin">admin</option>
|
|
||||||
</select>
|
|
||||||
<button class="btn btn-primary" @click="search">搜索</button>
|
<button class="btn btn-primary" @click="search">搜索</button>
|
||||||
<button class="btn btn-secondary" @click="reset">重置</button>
|
<button class="btn btn-secondary" @click="reset">重置</button>
|
||||||
<span class="ml-auto text-xs text-gray-400">已选 {{ selected.size }} 项</span>
|
<span class="ml-auto text-xs text-gray-400">已选 {{ selected.size }} 项</span>
|
||||||
@@ -86,6 +75,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
|
import Select from '@/components/common/Select.vue'
|
||||||
import { accountApi, type Account } from '@/api/account'
|
import { accountApi, type Account } from '@/api/account'
|
||||||
|
|
||||||
defineOptions({ name: 'account-list' })
|
defineOptions({ name: 'account-list' })
|
||||||
@@ -97,6 +87,19 @@ const pageSize = 10
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const selected = reactive(new Set<number>())
|
const selected = reactive(new Set<number>())
|
||||||
|
|
||||||
|
// 筛选下拉选项(Select 组件 auto>5 自动出搜索;角色 6 项含全部)
|
||||||
|
const STATUS_OPTIONS = [
|
||||||
|
{ value: '1', label: '启用' },
|
||||||
|
{ value: '0', label: '停用' },
|
||||||
|
]
|
||||||
|
const ROLE_OPTIONS = [
|
||||||
|
{ value: '', label: '全部' },
|
||||||
|
{ value: 'customer', label: 'customer' },
|
||||||
|
{ value: 'group', label: 'group' },
|
||||||
|
{ value: 'service', label: 'service' },
|
||||||
|
{ value: 'ops', label: 'ops' },
|
||||||
|
{ value: 'admin', label: 'admin' },
|
||||||
|
]
|
||||||
const filterUsername = ref('')
|
const filterUsername = ref('')
|
||||||
const filterRole = ref('')
|
const filterRole = ref('')
|
||||||
const filterStatus = ref('')
|
const filterStatus = ref('')
|
||||||
|
|||||||
@@ -12,18 +12,8 @@
|
|||||||
<!-- 筛选区 -->
|
<!-- 筛选区 -->
|
||||||
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
||||||
<input v-model="filterName" class="input !w-56" placeholder="搜索通道名称 / 接入码" @keyup.enter="search" />
|
<input v-model="filterName" class="input !w-56" placeholder="搜索通道名称 / 接入码" @keyup.enter="search" />
|
||||||
<select v-model="filterProtocol" class="input !w-32">
|
<Select v-model="filterProtocol" :options="PROTOCOL_OPTIONS" placeholder="协议:全部" clearable class="!w-32" />
|
||||||
<option value="">协议:全部</option>
|
<Select v-model="filterStatus" :options="STATUS_OPTIONS" placeholder="状态:全部" clearable class="!w-32" />
|
||||||
<option value="cmpp">CMPP</option>
|
|
||||||
<option value="smpp">SMPP</option>
|
|
||||||
<option value="sgip">SGIP</option>
|
|
||||||
<option value="http">HTTP</option>
|
|
||||||
</select>
|
|
||||||
<select v-model="filterStatus" class="input !w-32">
|
|
||||||
<option value="">状态:全部</option>
|
|
||||||
<option value="1">在营</option>
|
|
||||||
<option value="0">停用</option>
|
|
||||||
</select>
|
|
||||||
<button class="btn btn-primary" @click="search">搜索</button>
|
<button class="btn btn-primary" @click="search">搜索</button>
|
||||||
<button class="btn btn-secondary" @click="reset">重置</button>
|
<button class="btn btn-secondary" @click="reset">重置</button>
|
||||||
<span class="ml-auto text-xs text-gray-400">已选 {{ selected.size }} 项</span>
|
<span class="ml-auto text-xs text-gray-400">已选 {{ selected.size }} 项</span>
|
||||||
@@ -114,6 +104,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
|
import Select from '@/components/common/Select.vue'
|
||||||
import { channelApi, type Channel } from '@/api/channel'
|
import { channelApi, type Channel } from '@/api/channel'
|
||||||
|
|
||||||
// Issue#2 keep-alive 锚点:组件名=路由名
|
// Issue#2 keep-alive 锚点:组件名=路由名
|
||||||
@@ -126,6 +117,16 @@ const pageSize = 10
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const selected = reactive(new Set<number>())
|
const selected = reactive(new Set<number>())
|
||||||
|
|
||||||
|
const PROTOCOL_OPTIONS = [
|
||||||
|
{ value: 'cmpp', label: 'CMPP' },
|
||||||
|
{ value: 'smpp', label: 'SMPP' },
|
||||||
|
{ value: 'sgip', label: 'SGIP' },
|
||||||
|
{ value: 'http', label: 'HTTP' },
|
||||||
|
]
|
||||||
|
const STATUS_OPTIONS = [
|
||||||
|
{ value: '1', label: '在营' },
|
||||||
|
{ value: '0', label: '停用' },
|
||||||
|
]
|
||||||
const filterName = ref('')
|
const filterName = ref('')
|
||||||
const filterProtocol = ref('')
|
const filterProtocol = ref('')
|
||||||
const filterStatus = ref('')
|
const filterStatus = ref('')
|
||||||
|
|||||||
@@ -13,24 +13,15 @@
|
|||||||
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
|
||||||
<input v-model="filter.batch_id" class="input !w-36" placeholder="批次ID 精确" @keyup.enter="search" />
|
<input v-model="filter.batch_id" class="input !w-36" placeholder="批次ID 精确" @keyup.enter="search" />
|
||||||
<input v-model="filter.mobile" class="input !w-40" placeholder="手机号 模糊:135****0000" @keyup.enter="search" />
|
<input v-model="filter.mobile" class="input !w-40" placeholder="手机号 模糊:135****0000" @keyup.enter="search" />
|
||||||
<select v-model="filter.status" class="input !w-36" @change="search">
|
<Select v-model="filter.status" :options="STATUS_SEL_OPTIONS" placeholder="状态:全部" clearable class="!w-36" @change="search" />
|
||||||
<option value="">状态:全部</option>
|
<Select v-model="filter.channel_id" :options="channelSelOptions" placeholder="通道:全部" clearable class="!w-44" @change="search" />
|
||||||
<option v-for="o in DOWNLINK_STATUS_OPTIONS" :key="o.value" :value="o.value">{{ o.label }}</option>
|
|
||||||
</select>
|
|
||||||
<select v-model="filter.channel_id" class="input !w-44" @change="search">
|
|
||||||
<option value="">通道:全部</option>
|
|
||||||
<option v-for="c in channelOptions" :key="c.id" :value="c.id">{{ c.name }}({{ c.protocol.toUpperCase() }})</option>
|
|
||||||
</select>
|
|
||||||
<button class="btn btn-primary" @click="search">搜索</button>
|
<button class="btn btn-primary" @click="search">搜索</button>
|
||||||
<button class="btn btn-secondary" @click="reset">重置</button>
|
<button class="btn btn-secondary" @click="reset">重置</button>
|
||||||
<button class="cursor-pointer text-sm text-primary-600 hover:underline" @click="expanded = !expanded">{{ expanded ? '收起 ▴' : '展开 ▾' }}</button>
|
<button class="cursor-pointer text-sm text-primary-600 hover:underline" @click="expanded = !expanded">{{ expanded ? '收起 ▴' : '展开 ▾' }}</button>
|
||||||
</div>
|
</div>
|
||||||
<div v-show="expanded" class="flex flex-wrap items-center gap-2 border-b border-gray-100 bg-gray-50/50 p-4 dark:border-dark-700 dark:bg-dark-800/30">
|
<div v-show="expanded" class="flex flex-wrap items-center gap-2 border-b border-gray-100 bg-gray-50/50 p-4 dark:border-dark-700 dark:bg-dark-800/30">
|
||||||
<input v-model="filter.content" class="input !w-40" placeholder="发送内容 模糊:验证码" @keyup.enter="search" />
|
<input v-model="filter.content" class="input !w-40" placeholder="发送内容 模糊:验证码" @keyup.enter="search" />
|
||||||
<select v-model="filter.carrier" class="input !w-28" @change="search">
|
<Select v-model="filter.carrier" :options="CARRIER_OPTIONS" placeholder="运营商:全部" clearable class="!w-28" @change="search" />
|
||||||
<option value="">运营商:全部</option>
|
|
||||||
<option value="移动">移动</option><option value="联通">联通</option><option value="电信">电信</option>
|
|
||||||
</select>
|
|
||||||
<input v-model="filter.raw_code" class="input !w-32" placeholder="详细状态:DELIVRD" @keyup.enter="search" />
|
<input v-model="filter.raw_code" class="input !w-32" placeholder="详细状态:DELIVRD" @keyup.enter="search" />
|
||||||
<input v-model="filter.startTime" type="datetime-local" class="input !w-52" @change="search" />
|
<input v-model="filter.startTime" type="datetime-local" class="input !w-52" @change="search" />
|
||||||
<span class="text-xs text-gray-400">至</span>
|
<span class="text-xs text-gray-400">至</span>
|
||||||
@@ -95,6 +86,7 @@ import {
|
|||||||
DOWNLINK_STATUS_OPTIONS, downlinkStatusText, fetchDownlinkDetails,
|
DOWNLINK_STATUS_OPTIONS, downlinkStatusText, fetchDownlinkDetails,
|
||||||
segmentDurations, sourceText, type DownlinkDetailRow,
|
segmentDurations, sourceText, type DownlinkDetailRow,
|
||||||
} from '@/api/sms'
|
} from '@/api/sms'
|
||||||
|
import Select from '@/components/common/Select.vue'
|
||||||
import { channelApi, type Channel } from '@/api/channel'
|
import { channelApi, type Channel } from '@/api/channel'
|
||||||
|
|
||||||
// Issue#2 keep-alive 锚点:组件名=路由名
|
// Issue#2 keep-alive 锚点:组件名=路由名
|
||||||
@@ -109,6 +101,16 @@ const loading = ref(false)
|
|||||||
const expanded = ref(false)
|
const expanded = ref(false)
|
||||||
const drilledBatch = ref('')
|
const drilledBatch = ref('')
|
||||||
const channelOptions = ref<Channel[]>([])
|
const channelOptions = ref<Channel[]>([])
|
||||||
|
// Select 组件选项(值域统一 string 对齐原生前 select;状态 6 项>5 → auto 出搜索)
|
||||||
|
const STATUS_SEL_OPTIONS = DOWNLINK_STATUS_OPTIONS.map((o) => ({ value: String(o.value), label: o.label }))
|
||||||
|
const channelSelOptions = computed(() =>
|
||||||
|
channelOptions.value.map((c) => ({ value: String(c.id), label: `${c.name}(${c.protocol.toUpperCase()})` }))
|
||||||
|
)
|
||||||
|
const CARRIER_OPTIONS = [
|
||||||
|
{ value: '移动', label: '移动' },
|
||||||
|
{ value: '联通', label: '联通' },
|
||||||
|
{ value: '电信', label: '电信' },
|
||||||
|
]
|
||||||
|
|
||||||
const filter = reactive({
|
const filter = reactive({
|
||||||
batch_id: '', mobile: '', status: '' as string | number, channel_id: '' as string | number,
|
batch_id: '', mobile: '', status: '' as string | number, channel_id: '' as string | number,
|
||||||
|
|||||||
Reference in New Issue
Block a user