2025-08-11 00:40:21 +08:00
|
|
|
|
import Toast from 'tdesign-miniprogram/toast/index';
|
2025-08-09 17:41:14 +08:00
|
|
|
|
Component({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
img1: 'https://tdesign.gtimg.com/mobile/demos/example1.png',
|
|
|
|
|
|
img2: 'https://tdesign.gtimg.com/mobile/demos/example2.png',
|
|
|
|
|
|
img3: 'https://tdesign.gtimg.com/mobile/demos/example3.png',
|
|
|
|
|
|
image: 'https://tdesign.gtimg.com/mobile/demos/avatar1.png',
|
2025-08-11 00:40:21 +08:00
|
|
|
|
hasToken: false,
|
|
|
|
|
|
username: ''
|
2025-08-09 17:41:14 +08:00
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
userlogin(){
|
|
|
|
|
|
wx.navigateTo({url:'/pages/user-login/user-login'})
|
2025-08-11 00:40:21 +08:00
|
|
|
|
},
|
|
|
|
|
|
refreshUserStatus(){
|
|
|
|
|
|
console.log("主动刷新user界面")
|
|
|
|
|
|
const app = getApp();
|
|
|
|
|
|
console.log("全局userinfo",app.globalData.userInfo)
|
|
|
|
|
|
console.log("全局用户信息:", app.globalData.userInfo.username); // 这里打印的是 userInfo
|
|
|
|
|
|
const userInfo = app.globalData.userInfo || {};
|
|
|
|
|
|
console.log("user中的userInfo:",userInfo)
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
hasToken: !!app.globalData.token, // 从全局变量获取token状态
|
|
|
|
|
|
username: userInfo.username
|
|
|
|
|
|
});
|
|
|
|
|
|
// 调试:确认页面数据是否正确
|
|
|
|
|
|
console.log("页面username赋值后:", this.data.username);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2025-08-09 17:41:14 +08:00
|
|
|
|
},
|
2025-08-11 00:40:21 +08:00
|
|
|
|
lifetimes:{
|
|
|
|
|
|
attached(){
|
|
|
|
|
|
console.log("user界面刷新")
|
|
|
|
|
|
this.refreshUserStatus()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-08-09 17:41:14 +08:00
|
|
|
|
})
|