|
@@ -0,0 +1,137 @@
|
|
|
+<template>
|
|
|
+ <div class="tabbar-module">
|
|
|
+ <van-tabbar
|
|
|
+ class="footer-box"
|
|
|
+ :value="activeTabKey"
|
|
|
+ >
|
|
|
+ <van-tabbar-item
|
|
|
+ v-for="(item) in tabbars"
|
|
|
+ :key="item.key"
|
|
|
+ :name="item.key"
|
|
|
+ :badge="item.badge"
|
|
|
+ @click="onSwitchTab(item)"
|
|
|
+ >
|
|
|
+ <template #icon="props">
|
|
|
+ <span class="iconfont" :class="props.active ? item.activeIcon : item.icon"></span>
|
|
|
+ </template>
|
|
|
+ {{item.text}}
|
|
|
+ </van-tabbar-item>
|
|
|
+ </van-tabbar>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { Tabbar, TabbarItem } from "vant";
|
|
|
+import { mapGetters, mapMutations } from "vuex";
|
|
|
+import Taro from "@tarojs/taro";
|
|
|
+
|
|
|
+export default {
|
|
|
+ components: {
|
|
|
+ [Tabbar.name]: Tabbar,
|
|
|
+ [TabbarItem.name]: TabbarItem
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.checkActiveTabbar()
|
|
|
+ },
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ active: 'home',
|
|
|
+ tabbars: [
|
|
|
+ {
|
|
|
+ key: 'home',
|
|
|
+ text: '订阅',
|
|
|
+ path: '/pages/tabbar/home/index',
|
|
|
+ icon: 'icon-nav_un_book',
|
|
|
+ activeIcon: 'icon-nav_un_book',
|
|
|
+ badge: ''
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'search',
|
|
|
+ text: '搜索',
|
|
|
+ path: '/pages/tabbar/search/index',
|
|
|
+ icon: 'icon-sousuo1',
|
|
|
+ activeIcon: 'icon-sousuo1',
|
|
|
+ badge: ''
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'box',
|
|
|
+ text: '全部商机',
|
|
|
+ path: '/pages/tabbar/box/index',
|
|
|
+ icon: 'icon-workSpace',
|
|
|
+ activeIcon: 'icon-workSpace',
|
|
|
+ badge: 'HOT'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'mine',
|
|
|
+ text: '我的',
|
|
|
+ path: '/pages/tabbar/mine/index',
|
|
|
+ icon: 'icon-nav_un_mine',
|
|
|
+ activeIcon: 'icon-nav_un_mine',
|
|
|
+ badge: ''
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapGetters('tabbar', ['activeTabKey'])
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapMutations('tabbar', ['doSwitchTab']),
|
|
|
+ checkActiveTabbar () {
|
|
|
+ const activeKey = this.getComputedActiveKey(this.activeTabKey || this.tabbars[0].key)
|
|
|
+ this.doSwitchTab(activeKey)
|
|
|
+ },
|
|
|
+ getComputedActiveKey (defaultActive = '') {
|
|
|
+ let active = defaultActive
|
|
|
+ try {
|
|
|
+ const pagePath = Taro.getCurrentInstance().router?.path
|
|
|
+ const item = this.tabbars.find(item => item.path.indexOf(pagePath) !== -1)
|
|
|
+ active = item?.key || defaultActive
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e)
|
|
|
+ }
|
|
|
+ return active
|
|
|
+ },
|
|
|
+ onSwitchTab (item) {
|
|
|
+ this.doSwitchTab(item.key)
|
|
|
+ Taro.switchTab({
|
|
|
+ url: item.path
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+@import '../app.scss';
|
|
|
+.tabbar-module {
|
|
|
+ .van-tabbar-item__icon .iconfont {
|
|
|
+ font-size: 24px;
|
|
|
+ }
|
|
|
+ .van-tabbar-item {
|
|
|
+ color: #171826;
|
|
|
+ &.van-tabbar-item--active {
|
|
|
+ color: $main;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .van-info {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ right: 0;
|
|
|
+ box-sizing: border-box;
|
|
|
+ min-width: 4.267vw;
|
|
|
+ padding: 0 .8vw;
|
|
|
+ color: #fff;
|
|
|
+ font-weight: 500;
|
|
|
+ font-size: 3.2vw;
|
|
|
+ font-family: -apple-system-font, Helvetica Neue, Arial, sans-serif;
|
|
|
+ line-height: 1.2;
|
|
|
+ text-align: center;
|
|
|
+ background-color: #ee0a24;
|
|
|
+ border: 1px solid #fff;
|
|
|
+ border-radius: 4.267vw;
|
|
|
+ transform: translate(50%, -50%);
|
|
|
+ transform-origin: 100%;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|