130 lines
3.2 KiB
Vue
130 lines
3.2 KiB
Vue
<template>
|
|
<view class="content-tabs">
|
|
<view v-for="(tab, index) in tabs" :key="tab.key" class="tab-item" :class="{ active: modelValue === tab.key }"
|
|
:data-key="tab.key" @click="handleTabClick">
|
|
<!-- 背景图片 -->
|
|
<!-- <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' }" />
|
|
<!-- 右侧文字 -->
|
|
<text class="tab-label">{{ tab.label }}</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
const props = defineProps({
|
|
modelValue: { type: String, default: 'hot' }
|
|
})
|
|
|
|
const emit = defineEmits(['update:modelValue'])
|
|
|
|
const handleTabClick = (e) => {
|
|
const key = e.currentTarget.dataset.key
|
|
console.log(key)
|
|
emit('update:modelValue', key)
|
|
}
|
|
|
|
const tabs = [
|
|
{ key: 'displaying', label: '日榜', emoji: null, icon: '/static/square/1.png', iconWidth: 32, iconHeight: 40 },
|
|
{ key: 'week', label: '周榜', emoji: null, icon: '/static/square/1.png', iconWidth: 32, iconHeight: 40 },
|
|
{ key: 'month', label: '月榜', emoji: null, icon: '/static/square/1.png', iconWidth: 32, iconHeight: 40 },
|
|
]
|
|
</script>
|
|
|
|
<style scoped>
|
|
.content-tabs {
|
|
position: relative;
|
|
top: unset;
|
|
left: unset;
|
|
right: unset;
|
|
bottom: 16rpx;
|
|
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 {
|
|
max-width: 134rpx;
|
|
height: 42rpx;
|
|
border-radius: 21rpx;
|
|
opacity: 0.78;
|
|
position: relative;
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: center;
|
|
overflow: visible;
|
|
background: linear-gradient(90deg, rgba(255, 222, 8, 0.2989) -17.54%, rgba(252, 100, 102, 0.61) 64.4%, rgba(244, 88, 104, 0.61) 116.67%);
|
|
box-shadow: 2px 2px 4px 0px #F2151578;
|
|
}
|
|
|
|
/* 背景图片铺满整个 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 {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 4rpx 30rpx 4rpx 20rpx ;
|
|
transition: transform 0.25s ease;
|
|
}
|
|
|
|
/* 选中时图标上移 */
|
|
/* .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: 24rpx;
|
|
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: 14rpx;
|
|
}
|
|
|
|
.tab-item.active .tab-label {
|
|
color: #ffffff;
|
|
}
|
|
</style>
|