zhaoxiaohai 3 年之前
父節點
當前提交
3ac997ad3a
共有 2 個文件被更改,包括 67 次插入22 次删除
  1. 51 17
      custom-tab-bar/index.js
  2. 16 5
      custom-tab-bar/index.wxml

+ 51 - 17
custom-tab-bar/index.js

@@ -4,42 +4,73 @@ Component({
      */
     properties: {},
     lifetimes: {
-        attached() {},
-        ready: function () {
+        attached() {
             // 在组件实例进入页面节点树时执行
         },
+        ready: function () {
+            if (this.data.count == 1) return;
+            if (!wx.getStorageSync('userauth')) return;
+            //判断页面 以免一直触发
+            let pages = getCurrentPages();
+            let prevPage = pages[pages.length - 1];
+            if (prevPage.route == 'pages/login/selectSite' || prevPage.route.includes('pages/tabbar/')) {
+                let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心', '消息中心']);
+                let auth2 = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['营销物料']);
+                let list = ['首页'];
+                auth.forEach(v => {
+                    switch (v.systemmodulename) {
+                        case "个人中心":
+                            list.push('我的')
+                            break;
+                        case "消息中心":
+                            list.push('信息')
+                            break;
+                    }
+                })
+                if (auth2.length == 1) list.push('营销物料');
+                this.setData({
+                    Permission: list
+                })
+            }
+        },
     },
     /**
      * 组件的初始数据
      */
 
-     /* 
-            {
-                icon: 'icon-a-biaoqianlangongzuo',
-                text: '工作',
-                url: '/pages/tabbar/workbench/index'
-            }, */
+    /* 
+           {
+               icon: 'icon-a-biaoqianlangongzuo',
+               text: '工作',
+               url: '/pages/tabbar/workbench/index'
+           }, 
+    */
     data: {
-        active: 0,
+        active: 'home',
+        Permission: ['首页'],
         tabbarList: [{
                 icon: 'icon-a-biaoqianlanshouyexuanzhong',
                 text: '首页',
-                url: '/pages/tabbar/home/index'
+                url: '/pages/tabbar/home/index',
+                name: 'home'
             },
             {
                 icon: 'icon-a-biaoqianlanxiaoxi',
                 text: '信息',
-                url: '/pages/tabbar/message/index'
+                url: '/pages/tabbar/message/index',
+                name: 'message'
             },
             {
                 icon: 'icon-a-biaoqianlanzhiku',
                 text: '营销物料',
                 url: '/pages/tabbar/smartStore/index',
+                name: 'smartStore'
             },
             {
                 icon: 'icon-a-biaoqianlanwode',
                 text: '我的',
-                url: '/pages/tabbar/mine/index'
+                url: '/pages/tabbar/mine/index',
+                name: 'mine'
             }
         ],
     },
@@ -50,17 +81,20 @@ Component({
     methods: {
         /* tabbar */
         onChange(event) {
-            this.setData({
-                active: event.target.dataset.index
-            });
+            let active = event.detail;
+            let obj = this.data.tabbarList.find(v => v.name == active);
             wx.switchTab({
-                url: event.target.dataset.url
+                url: obj.url
+            });
+            this.setData({
+                active
             });
         },
         init() {
             const page = getCurrentPages().pop();
+            let obj = this.data.tabbarList.find(item => item.url === `/${page.route}`);
             this.setData({
-                active: this.data.tabbarList.findIndex(item => item.url === `/${page.route}`)
+                active: obj.name
             });
         },
     },

+ 16 - 5
custom-tab-bar/index.wxml

@@ -1,7 +1,18 @@
-<van-tabbar active="{{ active }}" placeholder active-color='#3874F6'>
-    <van-tabbar-item bindtap="onChange" info="{{item.fcount}}" data-index="{{index}}" data-url="{{item.url}}" wx:for="{{tabbarList}}" wx:key="index">
-        <text slot='icon' class="{{'iconfont '+item.icon}}" style="font-size: 44rpx; color: #999999;" data-index="{{index}}" data-url="{{item.url}}" />
-        <text slot='icon-active' class="{{'iconfont '+item.icon}}" style="font-size: 44rpx; color: #3874F6;" data-index="{{index}}" data-url="{{item.url}}" />
+<van-tabbar active="{{ active }}" placeholder active-color='#3874F6' bindchange="onChange">
+    <van-tabbar-item wx:if="{{per.query(Permission,item.text)}}" info="{{item.fcount}}" name="{{item.name}}" wx:for="{{tabbarList}}" wx:key="index">
+        <text slot='icon' class="{{'iconfont '+item.icon}}" style="font-size: 44rpx; color: #999999;" />
+        <text slot='icon-active' class="{{'iconfont '+item.icon}}" style="font-size: 44rpx; color: #3874F6;" />
         {{item.text}}
     </van-tabbar-item>
-</van-tabbar>
+</van-tabbar>
+
+<wxs module="per">
+    function query(list, name) {
+        // console.log(list.includes(name))
+        return a1 = list.some(function (v) {
+            return v == name
+        });
+    };
+
+    module.exports.query = query
+</wxs>