Browse Source

fix(student): 优化学员端页面初始化和跳转逻辑

- 在学员首页和登录页添加标记位控制 init 只执行一次
- 修复学员首页头像显示逻辑,添加默认头像
-优化登录页跳转逻辑,确保正确跳转到对应角色首页- 调整 my 页面 member_init 方法,添加测试 alert
master
liutong 10 months ago
parent
commit
95a32da069
  1. 29
      pages/student/index/index.vue
  2. 50
      pages/student/login/login.vue

29
pages/student/index/index.vue

@ -6,7 +6,7 @@
<view class="head"> <view class="head">
<view class="head-img"> <view class="head-img">
<!-- <fui-avatar width="136" :src="$util.img(member_info.headimg)"></fui-avatar> --> <!-- <fui-avatar width="136" :src="$util.img(member_info.headimg)"></fui-avatar> -->
<image class="pic" :src="member_info.memberHasOne ? member_info.memberHasOne.headimg : ''"></image> <image class="pic" :src="member_info.memberHasOne ? member_info.memberHasOne.headimg : $util.img('/uniapp_src/static/images/common/yong_hu.png')"></image>
<view class="head-text">{{member_info.name}}</view> <view class="head-text">{{member_info.name}}</view>
</view> </view>
</view> </view>
@ -133,6 +133,8 @@
}, },
data() { data() {
return { return {
inited: false, // init
// //
uploadApiUrl: ``, uploadApiUrl: ``,
uploadImageApiUrl: `${Api_url}/file/image`, uploadImageApiUrl: `${Api_url}/file/image`,
@ -173,7 +175,13 @@
onLoad() { onLoad() {
this.openViewHome()//- this.openViewHome()//-
}, },
onShow(){}, onShow(){
// onShow init
if (!this.inited) {
this.init()
this.inited = true
}
},
methods: { methods: {
// //
async init(){ async init(){
@ -184,8 +192,8 @@
}, },
//-
async openViewHome(){ async openViewHome_COPY(){
// //
let pages = getCurrentPages(); let pages = getCurrentPages();
// //
@ -195,21 +203,24 @@
this.openPath = this.path_arr[userType] this.openPath = this.path_arr[userType]
console.log(
'跳转',
this.thisPath,
userType,
this.path_arr[userType]
)
if(this.thisPath != this.openPath){ if(this.thisPath != this.openPath){
console.log('打印1')
//tabBar- //tabBar-
uni.setStorageSync('tabBerIndex', 0) uni.setStorageSync('tabBerIndex', 0)
uni.navigateTo({ uni.navigateTo({
url: this.openPath url: this.openPath
}) })
return
}else{ }else{
//-> //->
this.init() this.init()
} }
console.log(123123123123,this.thisPath,userType,this.path_arr[userType])
}, },
async getMemberIndex(){ async getMemberIndex(){

50
pages/student/login/login.vue

@ -63,6 +63,8 @@ import apiRoute from '@/api/apiRoute.js';
export default { export default {
data() { data() {
return { return {
inited: false, // init
password: true, password: true,
user: '', // user: '', //
password1: '', // password1: '', //
@ -85,6 +87,13 @@ export default {
} }
], ],
picker_show_loginType:false,// picker_show_loginType:false,//
path_arr:{
'1':'/pages/coach/home/index',//
'2':'/pages/market/index/index',//
'3':'/pages/student/index/index',//
},
} }
}, },
onLoad(options) { onLoad(options) {
@ -93,7 +102,11 @@ export default {
this.loginType_str = selectedItem ? selectedItem.text : '未知类型'; this.loginType_str = selectedItem ? selectedItem.text : '未知类型';
// uni.hideHomeButton() // uni.hideHomeButton()
// console.log(uni.getStorageSync('um_id')) // console.log(uni.getStorageSync('um_id'))
this.init() // onShow init
if (!this.inited) {
this.openViewHome()
this.inited = true
}
}, },
methods: { methods: {
async init(){ async init(){
@ -103,7 +116,7 @@ export default {
//#endif //#endif
}, },
input(e) { input(e) {
console.log(e) //console.log(e)
}, },
change() { change() {
this.password = !this.password this.password = !this.password
@ -267,6 +280,39 @@ export default {
} }
}, },
//-
async openViewHome() {
const userType = String(uni.getStorageSync('userType') || '');
const token = uni.getStorageSync('token') || ''
if(!userType || !token){
return
}
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const thisPath = '/' + currentPage.route;
const openPath = this.path_arr[userType];
console.log('当前路径:', thisPath);
console.log('用户类型:', userType);
console.log('应跳转路径:', openPath);
if (thisPath !== openPath) {
//
uni.setStorageSync('tabBerIndex', 0)
// 使 redirectTo navigateTo
uni.redirectTo({
url: openPath
});
return
}
// onShow
},
} }
} }
</script> </script>

Loading…
Cancel
Save