Browse Source

refactor(student): 优化学员首页跳转逻辑

- 添加 path_arr 对象,定义不同用户类型的首页路径
- 实现 openViewHome 方法,用于检测和重定向到正确的首页
- 在页面显示时调用 openViewHome,确保用户始终跳转到对应的首页
master
liutong 1 year ago
parent
commit
6cc1e5663b
  1. 39
      pages/student/index/index.vue

39
pages/student/index/index.vue

@ -157,13 +157,21 @@
weekday: "" // 课程星期 weekday: "" // 课程星期
} }
},//首页数据 },//首页数据
path_arr:{
'1':'/pages/coach/home/index',//教练
'2':'/pages/market/index/index',//销售
'3':'/pages/student/index/index',//学员
},
thisPath:'',//当前页面的路径(默认'')
openPath:'',//正确的跳转路径(默认'')
} }
}, },
onLoad() { onLoad() {
}, },
onShow(){ onShow(){
this.init() this.openViewHome()//检测首页是否正确跳转-不正确则进行重定向
}, },
methods: { methods: {
//初始化 //初始化
@ -174,6 +182,35 @@
this.getJobAssignmentsInfo() this.getJobAssignmentsInfo()
}, },
//检测首页是否正确跳转-不正确则进行重定向
async openViewHome(){
//获取当前页面路径
let pages = getCurrentPages();
//当前页面路径
this.thisPath = '/' + pages[0].route
//获取缓存用户登陆类型
let userType = String(uni.getStorageSync('userType'))
this.openPath = this.path_arr[userType]
if(this.thisPath != this.openPath){
//跳转tabBar首页-页面
uni.setStorageSync('tabBerIndex', 0)
uni.navigateTo({
url: this.openPath
})
}else{
//页面正确的情况下
this.init()
}
console.log(123123123123,this.thisPath,userType,this.path_arr[userType])
},
async getMemberIndex(){ async getMemberIndex(){
let res = await memberApi.memberIndex({}) let res = await memberApi.memberIndex({})
if(res.code != 1){ if(res.code != 1){

Loading…
Cancel
Save