Files

40 lines
894 B
JavaScript
Raw Permalink Normal View History

var app = getApp();
Component({
data: {
selected: 0,
tabs: []
},
lifetimes: {
attached() {
this._lastRole = '';
this.updateTabs();
}
},
pageLifetimes: {
show() {
this.updateTabs();
}
},
methods: {
// 仅当角色实际变化时才更新 tabs,避免无意义重渲染
updateTabs() {
var userType = app.globalData.userType || 'C';
if (this._lastRole === userType) return;
this._lastRole = userType;
var tabs = app.globalData.ROLE_TABS[userType] || app.globalData.ROLE_TABS['C'];
this.setData({ tabs: tabs });
},
switchTab(e) {
var index = e.currentTarget.dataset.index;
var pages = ['/pages/index/index', '/pages/service/service', '/pages/order/order', '/pages/my/my'];
if (this.data.selected === index) return;
wx.switchTab({ url: pages[index] });
}
}
});