From 6cc1e5663bc637c78438278f48f135e0e63278f0 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Tue, 15 Apr 2025 20:04:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(student):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=AD=A6=E5=91=98=E9=A6=96=E9=A1=B5=E8=B7=B3=E8=BD=AC=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 path_arr 对象,定义不同用户类型的首页路径 - 实现 openViewHome 方法,用于检测和重定向到正确的首页 - 在页面显示时调用 openViewHome,确保用户始终跳转到对应的首页 --- pages/student/index/index.vue | 39 ++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/pages/student/index/index.vue b/pages/student/index/index.vue index 775b0b1..6b14a38 100644 --- a/pages/student/index/index.vue +++ b/pages/student/index/index.vue @@ -157,13 +157,21 @@ weekday: "" // 课程星期 } },//首页数据 + + path_arr:{ + '1':'/pages/coach/home/index',//教练 + '2':'/pages/market/index/index',//销售 + '3':'/pages/student/index/index',//学员 + }, + thisPath:'',//当前页面的路径(默认'') + openPath:'',//正确的跳转路径(默认'') } }, onLoad() { }, onShow(){ - this.init() + this.openViewHome()//检测首页是否正确跳转-不正确则进行重定向 }, methods: { //初始化 @@ -174,6 +182,35 @@ 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(){ let res = await memberApi.memberIndex({}) if(res.code != 1){