| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- Component({
- data: {
- tabList: [], // 动态生成的tab列表
- currentPath: '' // 当前页面路径
- },
-
- attached() {
- // 获取当前页面路径
- setTimeout(() => {
- const pages = getCurrentPages();
- console.log(pages);
- this.setData({
- currentPath: '/' + pages[pages.length - 1].route
- });
- }, 10);
- // 根据角色生成对应tab列表
- const role = wx.getStorageSync('partnerPosition');
- const allTabs = [
- { pagePath: '/pages/index/index',
- text: '首页',
- iconPath: '/static/sz3.png', // 未选中图标
- selectedIconPath: '/static/sz4.png' // 选中图标
- },
- { pagePath: '/pages/tool/index',
- text: '工单',
- iconPath: '/static/tool.png', // 未选中图标
- selectedIconPath: '/static/tool1.png' // 选中图标
- },
- {
- pagePath: "/pages/setup/index",
- text: "我的",
- iconPath: "/static/user1.png",
- selectedIconPath: "/static/user2.png"
- }
- ];
- const customer = [
- { pagePath: '/pages/home/index',
- text: '首页',
- iconPath: '/static/sz3.png', // 未选中图标
- selectedIconPath: '/static/sz4.png' // 选中图标
- },
- {
- pagePath: "/pages/setup/index",
- text: "我的",
- iconPath: "/static/user1.png",
- selectedIconPath: "/static/user2.png"
- }
- ];
- console.log(allTabs);
-
- // 筛选当前角色可见的tab
- let tabList = [];
- if (role.partnerPosition != 5) {
- tabList = allTabs
-
- } else{
- tabList = customer
- }
-
- this.setData({ tabList });
- },
-
- methods: {
- // 切换tab页
- switchTab(e) {
- console.log(e);
- const path = e.currentTarget.dataset.path;
- wx.switchTab({ url: path });
- }
- }
- });
|