topfans/frontend/pages/square/components/ContentTabs.vue

160 lines
3.3 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">
<!-- <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: "xinghe",
label: "星河",
emoji: null,
icon: "/static/square/1.png",
iconWidth: 32,
iconHeight: 40,
},
{
key: "xingbang",
label: "星榜",
emoji: null,
icon: "/static/square/1.png",
iconWidth: 32,
iconHeight: 40,
},
{
key: "guangchang",
label: "广场",
emoji: null,
icon: "/static/square/1.png",
iconWidth: 32,
iconHeight: 40,
},
];
</script>
<style scoped>
.content-tabs {
position: relative;
left: 50%;
bottom: 0.25rem;
transform: translateX(-50%);
z-index: 100;
display: flex;
align-items: center;
justify-content: space-between;
margin: 8rpx 16rpx;
padding: 0 8rpx;
width: 336rpx;
height: 64rpx;
border-radius: 16px;
overflow: visible;
background: #d9d9d91c;
box-shadow: 0px 4px 4px 0px #b3323240;
}
.tab-item {
width: 112rpx;
height: 42rpx;
border-radius: 21rpx;
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
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 {
display: flex;
align-items: center;
justify-content: center;
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{
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;
}
</style>