You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.4 KiB

4 months ago
<template>
<view class="custom-tab-bar">
<view
class="tab-item"
v-for="(item, i) in tabBarList"
:key="i"
v-if="tabBarShowList[i]"
@click="switchTab(i)"
>
<text :style="{ color: currentTab === i ? item.selectColor : '#fff' }">{{
item.text
}}</text>
4 months ago
</view>
</view>
4 months ago
</template>
<script>
export default {
props: {
currentTab: {
type: Number,
default: 0,
4 months ago
},
},
data() {
return {
tabBarList: [
{
pagePath: "pages/index/index",
selectColor: "#00FF00",
text: "首页",
},
{
pagePath: "pages/index/readingBody",
selectColor: "#00FF00",
text: "阅读体",
},
3 months ago
// {
// pagePath: "pages/index/sensoryStore",
// selectColor: "#00FF00",
// text: "有感商店",
// },
{
3 months ago
pagePath: "pages/index/timeShopBank",
selectColor: "#00FF00",
3 months ago
text: "时间银行",
},
{
pagePath: "pages/index/intelligentAgent",
selectColor: "#00FFFF",
text: "智能体",
4 months ago
},
{
pagePath: "pages/index/iSoul",
selectColor: "#00FF00",
text: "iSoul",
},
],
tabBarShowList: [],
};
},
onLoad() {
this.getCurrentTab();
},
mounted() {
this.tabBarShowList = uni
.getStorageSync("SHFlag")
.split(",")
.map((item) => {
return item.trim().toLowerCase() === "true";
});
},
methods: {
getCurrentTab() {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const currentPath = currentPage.route;
this.tabBarList.forEach((item, index) => {
if (item.pagePath === currentPath) {
this.currentTab = index;
4 months ago
}
});
},
switchTab(index) {
if (this.currentTab === index) return;
uni.switchTab({
url: "/" + this.tabBarList[index].pagePath,
});
},
},
4 months ago
};
</script>
<style scoped>
.custom-tab-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-around;
align-items: center;
height: 123rpx;
z-index: 30;
background: #989898;
4 months ago
}
.tab-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex-shrink: 0;
height: 100%;
4 months ago
}
.tab-item text {
font-size: 31rpx;
4 months ago
}
</style>