123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- Component({
- data: {
- active: 0,
- list: [],
- initList: [
- {
- icon: 'home-o',
- text: '首页',
- url: '/pages/index/index',
- hidden: false
- },
- {
- icon: 'bar-chart-o',
- text: '数据中心',
- url: '/pages/data/index',
- hidden: true
- },
- {
- icon: 'user-o',
- text: '个人中心',
- url: '/pages/account/index',
- hidden: false
- }
- ],
- role: ''
- },
- lifetimes: {
- attached: function() {
-
- },
- },
- methods: {
- onChange(e) {
- this.setData({ active: e.detail });
- var active = e.detail
- var cnt = -1;
- var list = this.data.list
- var url = '';
- for(var i = 0; i < list.length; ++i) {
- if(!list[i].hidden) cnt = cnt + 1;
- if(cnt == active) {
- url = list[i].url
- break;
- }
- }
- wx.switchTab({
- url: url
- });
- },
- init() {
- const page = getCurrentPages().pop();
- var userInfo = getApp().globalData.userInfo
- var role = userInfo ? userInfo.topRole : ''
- var list = this.data.initList
- if(role && role.key == 'leader') {
- // list = this.data.initList.slice(1)
- list[0].hidden = true;
- }
- if(role && role.rights && role.rights.dataView) {
- list[1].hidden = false;
- }
- this.setData({
- list: list
- })
- var active = -1;
- for(var i = 0; i < list.length; ++i) {
- if(!list[i].hidden) active = active + 1;
- if(list[i].url == '/' + page.route) break;
- }
- this.setData({
- active: active
- });
- if(role) {
- this.setData({role})
- }
- }
- }
- });
|