46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
|   | // 自定义tabbar管理器
 | |||
|  | export const tabbarManager = { | |||
|  |   // 显示tabbar
 | |||
|  |   showTabBar() { | |||
|  |     if (typeof getTabBar === 'function' && getTabBar()) { | |||
|  |       getTabBar().setData({ | |||
|  |         selected: 0 | |||
|  |       }); | |||
|  |     } | |||
|  |   }, | |||
|  |    | |||
|  |   // 更新tabbar选中状态
 | |||
|  |   updateSelected(index) { | |||
|  |     if (typeof getTabBar === 'function' && getTabBar()) { | |||
|  |       getTabBar().setData({ | |||
|  |         selected: index | |||
|  |       }); | |||
|  |     } | |||
|  |   }, | |||
|  |    | |||
|  |   // 根据用户类型更新tabbar
 | |||
|  |   updateTabBarByUserType() { | |||
|  |     if (typeof getTabBar === 'function' && getTabBar()) { | |||
|  |       const userInfo = uni.getStorageSync('userInfo') || {}; | |||
|  |       const userType = userInfo.isCompanyUser !== undefined ? userInfo.isCompanyUser : 1; | |||
|  |       getTabBar().generateTabbarList(userType); | |||
|  |     } | |||
|  |   }, | |||
|  |    | |||
|  |   // 初始化tabbar
 | |||
|  |   initTabBar() { | |||
|  |     // 延迟初始化自定义tabbar
 | |||
|  |     setTimeout(() => { | |||
|  |       this.updateTabBarByUserType(); | |||
|  |     }, 200); | |||
|  |   }, | |||
|  |    | |||
|  |   // 强制刷新tabbar(登录后调用)
 | |||
|  |   refreshTabBar() { | |||
|  |     // 延迟刷新,确保用户信息已更新
 | |||
|  |     setTimeout(() => { | |||
|  |       this.updateTabBarByUserType(); | |||
|  |     }, 100); | |||
|  |   } | |||
|  | }; |