Files
shanxia2.0/web-admin/src/components/mp/MpStatusTabs.vue
T
2026-10-19 18:28:02 +08:00

49 lines
1.1 KiB
Vue

<template>
<nav class="mp-wv-status-tabs" :aria-label="ariaLabel">
<button
v-for="tab in tabs"
:key="String(tab.value)"
class="filter-tag"
:class="{ 'is-active': tab.value === modelValue }"
type="button"
:aria-pressed="tab.value === modelValue"
:disabled="tab.disabled"
@click="selectTab(tab)"
>
<span>{{ tab.label }}</span>
<span v-if="tab.count !== undefined" class="filter-tag__count">{{ tab.count }}</span>
</button>
</nav>
</template>
<script setup lang="ts" generic="T extends string | number">
interface MpStatusTab<T extends string | number = string> {
label: string
value: T
count?: number
disabled?: boolean
}
withDefaults(
defineProps<{
modelValue: T
tabs: MpStatusTab<T>[]
ariaLabel?: string
}>(),
{
ariaLabel: '状态筛选'
}
)
const emit = defineEmits<{
'update:modelValue': [value: T]
change: [value: T]
}>()
function selectTab(tab: MpStatusTab<T>) {
if (tab.disabled) return
emit('update:modelValue', tab.value)
emit('change', tab.value)
}
</script>