口才和会议场景
This commit is contained in:
109
App.vue
109
App.vue
@@ -23,6 +23,11 @@
|
||||
initApp();
|
||||
uniIdPageInit()
|
||||
|
||||
// #ifdef H5
|
||||
this.hideEduTabIfNeed() // 初始化尝试隐藏教务 tab(非教务角色)
|
||||
uni.$on('tabbar:refresh', this.hideEduTabIfNeed) // 登录后触发
|
||||
// #endif
|
||||
|
||||
// 设置全局路由拦截,检查登录状态
|
||||
this.setupRouteInterceptor()
|
||||
|
||||
@@ -56,11 +61,115 @@
|
||||
console.log('App Show')
|
||||
// 每次应用显示时也检查当前页面是否需要登录
|
||||
this.checkCurrentPageLogin()
|
||||
|
||||
// #ifdef H5
|
||||
// 返回前台时再尝试隐藏一次
|
||||
this.hideEduTabIfNeed()
|
||||
// #endif
|
||||
},
|
||||
onHide: function() {
|
||||
console.log('App Hide')
|
||||
},
|
||||
methods: {
|
||||
// #ifdef H5
|
||||
/**
|
||||
* H5 平台:根据当前登录角色,动态控制原生 tabbar 可见项
|
||||
*
|
||||
* 规则:
|
||||
* - admin:不限制,所有 tab 都显示
|
||||
* - speaking_training_teacher:仅显示【教务、语音、表达、我的】
|
||||
* - speaking_training_students:仅显示【作业、语音、表达、我的】
|
||||
* - 其他角色:隐藏【作业、教务、语音、表达】
|
||||
*/
|
||||
hideEduTabIfNeed() {
|
||||
try {
|
||||
const normalize = (val) =>
|
||||
typeof val === 'string'
|
||||
? val
|
||||
.split(',')
|
||||
.map((s) => s.trim().toLowerCase())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
const storedRole = uni.getStorageSync('backend-role-name') || '';
|
||||
const loginResp = uni.getStorageSync('backend-login-response') || {};
|
||||
const respRole = loginResp.roleName || '';
|
||||
const roles = [...normalize(storedRole), ...normalize(respRole)];
|
||||
const isTeacher = roles.includes('speaking_training_teacher');
|
||||
const isStudent = roles.includes('speaking_training_students');
|
||||
const isAdmin = roles.includes('admin');
|
||||
const isMeetingAdmin = roles.includes('meeting_admin');
|
||||
|
||||
// 会议相关的tab标签
|
||||
const meetingTabLabels = ['总结和统计'];
|
||||
|
||||
const teacherAllowed = ['我的'];
|
||||
const studentAllowed = ['我的'];
|
||||
const otherHidden = ['作业', '教务', '语音', '表达'];
|
||||
|
||||
// tabBar 顺序(根据 pages.json 中的 tabBar.list 顺序)
|
||||
// 0: 接待, 1: 客户, 2: 团队, 3: 销冠, 4: 工作台, 5: 我的(ucenter)
|
||||
// 6: 总结和统计
|
||||
const meetingTabIndices = [6]; // 会议相关tab的索引位置
|
||||
|
||||
const shouldShow = (label, index) => {
|
||||
// 任何角色都应该能看到"我的"(ucenter)
|
||||
if (label === '我的') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// meeting_admin 角色:显示会议相关的tab和"我的"
|
||||
if (isMeetingAdmin) {
|
||||
return meetingTabIndices.includes(index);
|
||||
}
|
||||
|
||||
// 非 meeting_admin 角色:隐藏所有会议相关的tab
|
||||
if (meetingTabIndices.includes(index)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 对于非会议相关的tab,按角色判断
|
||||
if (isAdmin) return true;
|
||||
if (isTeacher) return teacherAllowed.includes(label);
|
||||
if (isStudent) return studentAllowed.includes(label);
|
||||
// 其他角色:只隐藏指定的几个,其余保留
|
||||
return !otherHidden.includes(label);
|
||||
};
|
||||
|
||||
// 延迟+多次尝试,等待原生 tabbar DOM 渲染
|
||||
let attempts = 0;
|
||||
const maxAttempts = 15;
|
||||
const timer = setInterval(() => {
|
||||
attempts += 1;
|
||||
const items = Array.from(document.querySelectorAll('.uni-tabbar .uni-tabbar__item'));
|
||||
if (items && items.length) {
|
||||
items.forEach((el, index) => {
|
||||
const label = (el.textContent || '').trim();
|
||||
const show = shouldShow(label, index);
|
||||
|
||||
if (show) {
|
||||
el.style.display = '';
|
||||
el.style.flex = '';
|
||||
el.style.width = '';
|
||||
el.style.padding = '';
|
||||
} else {
|
||||
el.style.display = 'none';
|
||||
el.style.flex = '0 0 0';
|
||||
el.style.width = '0';
|
||||
el.style.padding = '0';
|
||||
}
|
||||
});
|
||||
console.log('[TabBar][H5 role-hide] roles:', roles, 'isAdmin:', isAdmin, 'isTeacher:', isTeacher, 'isStudent:', isStudent, 'items:', items.length, 'attempt:', attempts);
|
||||
clearInterval(timer);
|
||||
}
|
||||
if (attempts >= maxAttempts) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, 200);
|
||||
} catch (e) {
|
||||
console.warn('[TabBar][H5 hide] failed:', e);
|
||||
}
|
||||
},
|
||||
// #endif
|
||||
/**
|
||||
* 设置全局路由拦截
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user