Files
cz-web/src/views/message/cpns/MessageTabs.vue
2026-10-13 16:08:55 +08:00

99 lines
2.3 KiB
Vue

<script setup lang="ts">
import type { MessageTabCounts } from '@/stores/modules/message'
import type { MessageType } from '@/types/business/message'
interface Props {
active: MessageType | 'all'
counts: MessageTabCounts
}
defineProps<Props>()
const emit = defineEmits<{ tabChange: [type: MessageType | 'all'] }>()
const tabs: Array<{ label: string; value: MessageType | 'all' }> = [
{ label: '全部', value: 'all' },
{ label: '在线客服', value: '在线客服' },
{ label: '状态通知', value: '状态通知' },
{ label: '系统通知', value: '系统通知' },
]
function countOf(value: MessageType | 'all', counts: MessageTabCounts): number {
return counts[value]
}
</script>
<template>
<div class="message-tabs">
<button
v-for="tab in tabs"
:key="tab.value"
class="message-tabs__tab"
:class="{ 'is-active': active === tab.value }"
@click="emit('tabChange', tab.value)"
>
{{ tab.label }}
<span class="message-tabs__count">{{ countOf(tab.value, counts) }}</span>
</button>
</div>
</template>
<style lang="less" scoped>
.message-tabs {
.flex(column, flex-start, stretch);
gap: 2px;
min-height: 0;
padding: @spacing-sm 0;
border: 1px solid @border-color;
border-radius: @radius-base;
background: @white;
box-sizing: border-box;
&__tab {
.flex(row, space-between, center);
gap: @spacing-sm;
height: 40px;
margin: 0 @spacing-sm;
padding: 0 @spacing-base;
border-radius: @radius-sm;
background: transparent;
color: @message-tabs-text;
font-size: @font-size-sm;
font-weight: 400;
line-height: 1.4;
transition: color 0.2s, background-color 0.2s;
&:hover {
color: @primary-strong;
background: @bg-color-light;
}
&.is-active {
background: @filter-selected-bg;
color: @primary-strong;
font-weight: 600;
}
}
&__count {
flex-shrink: 0;
min-width: 18px;
height: 18px;
padding: 0 @spacing-xs;
border-radius: @radius-round;
background: @bg-color-light;
color: @text-color-secondary;
font-size: @font-size-xs;
font-weight: 500;
line-height: 18px;
text-align: center;
box-sizing: border-box;
}
&__tab.is-active &__count {
background: fade(@primary-strong, 12%);
color: @primary-strong;
}
}
</style>