148 lines
3.3 KiB
Vue
148 lines
3.3 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 === 2 }">
|
|
<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: 'random' }
|
|
})
|
|
|
|
defineEmits(['update:modelValue'])
|
|
|
|
const tabs = [
|
|
{ key: 'hot', label: '人气王者', emoji: null, icon: '/static/square/3.png',iconWidth: 80, iconHeight: 80 },
|
|
{ key: 'new', label: '新鲜上架', emoji: null, icon: '/static/square/2.png',iconWidth: 80, iconHeight: 80 },
|
|
{ key: 'potential', label: '潜力之星', emoji: null, icon: '/static/square/1.png',iconWidth: 96, iconHeight: 96 },
|
|
{ key: 'random', label: '随机寻宝', emoji: null, icon: '/static/square/4.png',iconWidth: 80, iconHeight: 80 },
|
|
]
|
|
</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: -16rpx;
|
|
top: 35%;
|
|
transform: translateY(-50%) rotateZ(8deg);
|
|
width: 80rpx;
|
|
height: 80rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: transform 0.25s ease;
|
|
}
|
|
|
|
/* 第一个 tab 图标单独样式 */
|
|
.tab-left-first {
|
|
top: 23%;
|
|
|
|
}
|
|
|
|
/* 选中时图标上移 */
|
|
/* .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: 18rpx;
|
|
font-weight: 600;
|
|
color: rgba(255, 255, 255, 0.95);
|
|
/* color: #ffffff; */
|
|
text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.8);
|
|
white-space: nowrap;
|
|
margin-left: 48rpx;
|
|
}
|
|
|
|
.tab-item.active .tab-label {
|
|
color: #ffffff;
|
|
}
|
|
</style>
|