YD_WeChatApplet/utils/tab-serve.js

152 lines
4.3 KiB
JavaScript
Raw Permalink Normal View History

2025-06-06 15:17:30 +08:00
// tabBar的data
let tabData = {
tabIndex: 0, //底部按钮高亮下标
tabBar: {
"custom": true,
"color": "#999999",
"selectedColor": "#0082FF",
"borderStyle": "black",
"backgroundColor": "#fff",
list: []
}
}
// 更新菜单
const updateRole = (that, type) => {
//这里设置权限分3种权限student、teacher、parent
if (type === 'user') {
tabData.tabBar.list = [{
"pagePath": "pages/student/train/train",
"iconPath": "/static/student/train.png",
"selectedIconPath": "/static/student/train-s.png",
"text": "训练",
"theme": "student"
},
{
"pagePath": "pages/student/teach/teach",
"iconPath": "/static/student/teach.png",
"selectedIconPath": "/static/student/teach-s.png",
"text": "教学",
"theme": "student"
},
{
"pagePath": "pages/student/talk/talk",
"iconPath": "/static/student/talk.png",
"selectedIconPath": "/static/student/talk-s.png",
"text": "资讯",
"theme": "student"
},
{
"pagePath": "pages/student/match/match",
"iconPath": "/static/student/match.png",
"selectedIconPath": "/static/student/match-s.png",
"text": "赛事",
"theme": "student"
},
{
"pagePath": "pages/student/my/my",
"iconPath": "/static/student/my.png",
"selectedIconPath": "/static/student/my-s.png",
"text": '我的',
"theme": "student"
},
]
} else if (type === 'parent') {
tabData.tabBar.list = [{
"pagePath": "pages/parent/train/train",
"iconPath": "/static/student/train.png",
"selectedIconPath": "/static/student/train-s.png",
"text": "训练"
},
{
"pagePath": "pages/teacher/work/workrecord/workrecord",
"iconPath": "/static/teacher/work.png",
"selectedIconPath": "/static/teacher/work-s.png",
"text": "作业",
},
{
"pagePath": "pages/parent/report/report",
"iconPath": "/static/parent/report.png",
"selectedIconPath": "/static/parent/report-s.png",
"text": "报告"
},
// {
// "pagePath": "pages/student/match/match",
// "iconPath": "/static/student/match.png",
// "selectedIconPath": "/static/student/match-s.png",
// "text": "赛事",
// "theme":"student"
// },
{
"pagePath": "pages/student/my/my",
"iconPath": "/static/student/my.png",
"selectedIconPath": "/static/student/my-s.png",
"text": '我的',
},
]
} else if (type == 'teacher') {
tabData.tabBar.list = [{
"pagePath": "pages/teacher/resource/resource",
"iconPath": "/static/teacher/resource.png",
"selectedIconPath": "/static/teacher/resource-s.png",
"text": "资源库",
},
{
"pagePath": "pages/teacher/work/workrecord/workrecord",
"iconPath": "/static/teacher/work.png",
"selectedIconPath": "/static/teacher/work-s.png",
"text": "作业",
},
{
"pagePath": "pages/teacher/count/count",
"iconPath": "/static/teacher/report.png",
"selectedIconPath": "/static/teacher/report-s.png",
"text": "统计",
},
{
"pagePath": "pages/teacher/vedio/vedio",
"iconPath": "/static/teacher/vedio.png",
"selectedIconPath": "/static/teacher/vedio-s.png",
2025-06-09 17:19:11 +08:00
"text": "课程库",
2025-06-06 15:17:30 +08:00
},
{
"pagePath": "pages/student/my/my",
"iconPath": "/static/student/my.png",
"selectedIconPath": "/static/student/my-s.png",
"text": '我的',
},
]
}
updateTab(that);
}
// 更新底部高亮
const updateIndex = (that, index) => {
tabData.tabIndex = index;
updateTab(that);
}
// 更新Tab状态+
const updateTab = (that) => {
console.log('判断是否有tab更新方法')
console.log(typeof that.getTabBar)
if (typeof that.getTabBar == 'function') {
console.log("更新tabbar")
that.getTabBar(tab=>{
tab.setData(tabData)
});
}else {
// setTimeout(()=>{
// // updateTab(that)
// },500)
}
}
// 将可调用的方法抛出让外面调用
module.exports = {
updateRole,
updateTab,
updateIndex,
tabBar: tabData.tabBar.list
}