在custom-tab-bar文件夹中,index.js文件中,
Component({
data: {
selected: 0,
color: "#B2B2B2",
selectedColor: "#FF502F",
allList: [{
// cheguanyuan
vehicleControllerList: [{
pagePath: "/pages/home/home",
iconPath: "/static/images/tab0_icon.png",
selectedIconPath: "/static/images/tab0_active.png",
text: "首页"
}, {
pagePath: "/pages/deliverGoods/deliverGoods",
iconPath: "/static/images/tab1.png",
selectedIconPath: "/static/images/tab1.png",
text: "发货"
},{
pagePath: "/pages/mine/mine",
iconPath: "/static/images/tab2_icon.png",
selectedIconPath: "/static/images/tab2_active.png",
text: "我的"
}],
// siji
driverList: [{
pagePath: "/pages/home/home",
iconPath: "/static/images/tab0_icon.png",
selectedIconPath: "/static/images/tab0_active.png",
text: "首页"
}, {
pagePath: "/pages/mine/mine",
iconPath: "/static/images/tab2_icon.png",
selectedIconPath: "/static/images/tab2_active.png",
text: "我的"
}]
}],
list: []
},
attached() {
if(wx.getStorageSync('userInfo')){
const role = wx.getStorageSync('userInfo').role
if(role == 2){ // 车管员
this.setData({
list: this.data.allList[0].vehicleControllerList
})
}else if(role == 3){ // 司机
this.setData({
list: this.data.allList[0].driverList
})
}
}
},
methods: {
switchTab(e) {
const data = e.currentTarget.dataset
const url = data.path
this.setData({
selected: data.index
})
wx.switchTab({url})
},
// 初始化赋值
init() {
if(wx.getStorageSync('userInfo')){
const role = wx.getStorageSync('userInfo').role
if(role == 2){ // 车管员
this.setData({
list: this.data.allList[0].vehicleControllerList
})
}else if(role == 3){ // 司机
this.setData({
list: this.data.allList[0].driverList
})
}
}
}
}
})