topfans/frontend/pages/square/components/ContentTabs.vue
2026-04-28 16:05:55 +08:00

147 lines
3.2 KiB
Vue

<template>
<view class="content-tabs" @click.stop>
<view
v-for="(tab, index) in tabs"
:key="tab.key"
class="tab-item"
:class="{ active: modelValue === tab.key }"
@click="$emit('update:modelValue', tab.key)"
>
<!-- 背景图片 -->
<image
class="tab-bg"
:class="{ 'tab-bg-inactive': modelValue !== tab.key }"
src="/static/nft/dingbutubiao_liang.png"
mode="scaleToFill"
/>
<!-- 左侧图标,绝对浮动覆盖背景左侧色块,不影响文字布局 -->
<view class="tab-left" :class="{ 'tab-left-first': index === 0 }">
<text v-if="tab.emoji" class="tab-emoji">{{ tab.emoji }}</text>
<image
v-else
class="tab-icon"
:src="tab.icon"
mode="aspectFill"
:style="{ width: tab.iconWidth + 'rpx', height: tab.iconHeight + 'rpx' }"
/>
</view>
<!-- 右侧文字 -->
<text class="tab-label">{{ tab.label }}</text>
</view>
</view>
</template>
<script setup>
defineProps({
modelValue: { type: String, default: 'hot' }
})
defineEmits(['update:modelValue'])
const tabs = [
{ key: 'hot', label: '热门作品', emoji: null, icon: '/static/square/rementubiao.png', iconWidth: 104, iconHeight: 104 },
{ key: 'xingka', label: '星卡', emoji: null, icon: '/static/square/xingka.png', iconWidth: 80, iconHeight: 80 },
{ key: 'baji', label: '把爱', emoji: null, icon: '/static/square/baji.png', iconWidth: 80, iconHeight: 80 },
{ key: 'haibao', label: '海报', emoji: null, icon: '/static/square/haibao.png', iconWidth: 96, iconHeight: 96 },
]
</script>
<style scoped>
.content-tabs {
position: relative;
top: unset;
left: unset;
right: unset;
z-index: 100;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
margin: 8rpx 16rpx 0;
padding: 0 4rpx;
height: 56rpx;
background: transparent;
overflow: visible;
}
.tab-item {
flex: 1;
max-width: 160rpx;
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
height: 56rpx;
margin: 0 4rpx;
overflow: visible;
}
/* 背景图片铺满整个 tab */
.tab-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
opacity: 1;
}
/* 未选中时加透明度 */
.tab-bg-inactive {
opacity: 0.4;
}
/* 左侧图标,绝对浮动覆盖背景左侧色块,不影响文字布局 */
.tab-left {
position: absolute;
z-index: 1;
left: -10rpx;
top: 50%;
transform: translateY(-50%);
width: 80rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.25s ease;
}
/* 第一个 tab 图标单独样式 */
.tab-left-first {
top: 40%;
transform: translateY(-70%);
}
/* 选中时图标上移 */
/* .tab-item.active .tab-left {
transform: translateY(-70%);
} */
.tab-emoji {
font-size: 52rpx;
line-height: 1;
margin-top: -4rpx;
}
.tab-icon {
display: block;
}
.tab-label {
position: relative;
z-index: 1;
font-size: 20rpx;
font-weight: 600;
color: rgba(255, 255, 255, 0.65);
white-space: nowrap;
margin-left: 60rpx;
}
.tab-item.active .tab-label {
color: #ffffff;
}
</style>