地址路径修改
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// 引入服务和工具函数
|
||||
|
||||
import userService from '../../services/userService';
|
||||
import { avatarCache } from '../../utils/avatarCache';
|
||||
|
||||
// 引入主页面模块
|
||||
import { MainPageModule } from './modules/mainPageModule';
|
||||
@@ -41,7 +42,7 @@ Component<IndexPageComponent['data'], any, any, any, false>({
|
||||
showSignOutButton: false,
|
||||
showSignInButton: false,
|
||||
showRegisterButton: false,
|
||||
showAuthButton: true,
|
||||
showAuthButton: true
|
||||
// mainPageModule: null as MainPageModule | null
|
||||
},
|
||||
|
||||
@@ -78,6 +79,20 @@ Component<IndexPageComponent['data'], any, any, any, false>({
|
||||
|
||||
methods: {
|
||||
|
||||
// 获取完整的头像URL(用于wxml显示)
|
||||
getFullAvatarUrl(avatarPath: string | undefined): string {
|
||||
if (!avatarPath) {
|
||||
return '/images/truck.png';
|
||||
}
|
||||
|
||||
// 如果已经是完整URL,直接返回
|
||||
if (avatarPath.startsWith('http')) {
|
||||
return avatarPath;
|
||||
}
|
||||
|
||||
// 将相对路径转换为完整URL
|
||||
return `${API_BASE_URL}${avatarPath}`;
|
||||
},
|
||||
|
||||
|
||||
// 处理货运人员底部弹窗关闭
|
||||
@@ -169,9 +184,9 @@ Component<IndexPageComponent['data'], any, any, any, false>({
|
||||
// 本地已有登录状态,此时可以安全获取用户状态(因为有token)
|
||||
const userStatus = await loginModule.determineUserStatus(app.globalData.userInfo);
|
||||
|
||||
// 更新页面状态
|
||||
// 更新页面状态,使用头像缓存方法
|
||||
await this.updateUserInfoWithAvatarCache(app.globalData.userInfo);
|
||||
this.setData({
|
||||
userInfo: app.globalData.userInfo,
|
||||
'authStatus.hasWxCode': true,
|
||||
'authStatus.userStatus': userStatus
|
||||
});
|
||||
@@ -191,15 +206,15 @@ Component<IndexPageComponent['data'], any, any, any, false>({
|
||||
const app = getApp<any>();
|
||||
|
||||
// 登录成功,更新全局用户信息
|
||||
app.globalData.userInfo = loginResult.userInfo;
|
||||
app.globalData.isLoggedIn = true;
|
||||
|
||||
app.globalData.userInfo = loginResult.userInfo;
|
||||
app.globalData.isLoggedIn = true;
|
||||
|
||||
// 登录成功后,此时已经有token,可以安全获取用户状态
|
||||
const userStatus = await loginModule.determineUserStatus(loginResult.userInfo);
|
||||
|
||||
// 更新页面状态
|
||||
// 更新页面状态,使用头像缓存方法
|
||||
await this.updateUserInfoWithAvatarCache(loginResult.userInfo);
|
||||
this.setData({
|
||||
userInfo: loginResult.userInfo,
|
||||
'authStatus.hasWxCode': true,
|
||||
'authStatus.userStatus': userStatus
|
||||
});
|
||||
@@ -250,6 +265,62 @@ Component<IndexPageComponent['data'], any, any, any, false>({
|
||||
|
||||
console.log('✅ 按钮状态已更新到页面');
|
||||
},
|
||||
|
||||
// 处理用户信息更新,包含头像URL预处理
|
||||
async updateUserInfoWithAvatarCache(userInfo: any) {
|
||||
if (!userInfo) {
|
||||
this.setData({ userInfo: null });
|
||||
return;
|
||||
}
|
||||
|
||||
// 预处理头像URL
|
||||
const processedUserInfo = { ...userInfo };
|
||||
if (userInfo.avatarPath) {
|
||||
try {
|
||||
// 使用头像缓存获取本地文件路径
|
||||
const fullAvatarUrl = this.getFullAvatarUrl(userInfo.avatarPath);
|
||||
const localAvatarPath = await avatarCache.getAvatarPath(fullAvatarUrl);
|
||||
processedUserInfo.fullAvatarUrl = localAvatarPath;
|
||||
} catch (error) {
|
||||
console.error('获取用户头像缓存失败:', error);
|
||||
// 如果缓存失败,使用默认头像
|
||||
processedUserInfo.fullAvatarUrl = '/images/truck.png';
|
||||
}
|
||||
} else {
|
||||
// 如果没有头像路径,使用默认头像
|
||||
processedUserInfo.fullAvatarUrl = '/images/truck.png';
|
||||
}
|
||||
|
||||
this.setData({ userInfo: processedUserInfo });
|
||||
},
|
||||
|
||||
// 处理货运人员信息更新,包含头像URL预处理
|
||||
async updateDeliveryPersonWithAvatarCache(deliveryPerson: any) {
|
||||
if (!deliveryPerson) {
|
||||
this.setData({ currentDeliveryPerson: null });
|
||||
return;
|
||||
}
|
||||
|
||||
// 预处理头像URL
|
||||
const processedDeliveryPerson = { ...deliveryPerson };
|
||||
if (deliveryPerson.avatarPath) {
|
||||
try {
|
||||
// 使用头像缓存获取本地文件路径,而不是远程URL
|
||||
const fullAvatarUrl = this.getFullAvatarUrl(deliveryPerson.avatarPath);
|
||||
const localAvatarPath = await avatarCache.getAvatarPath(fullAvatarUrl);
|
||||
processedDeliveryPerson.fullAvatarUrl = localAvatarPath;
|
||||
} catch (error) {
|
||||
console.error('获取货运人员头像缓存失败:', error);
|
||||
// 如果缓存失败,回退到远程URL
|
||||
processedDeliveryPerson.fullAvatarUrl = this.getFullAvatarUrl(deliveryPerson.avatarPath);
|
||||
}
|
||||
} else {
|
||||
// 如果没有头像路径,使用默认头像
|
||||
processedDeliveryPerson.fullAvatarUrl = '/images/truck.png';
|
||||
}
|
||||
|
||||
this.setData({ currentDeliveryPerson: processedDeliveryPerson });
|
||||
},
|
||||
|
||||
// 登录成功后统一刷新页面
|
||||
async refreshPageAfterLogin() {
|
||||
@@ -331,9 +402,11 @@ Component<IndexPageComponent['data'], any, any, any, false>({
|
||||
|
||||
if (success) {
|
||||
const app = getApp<any>();
|
||||
const userStatus = loginModule.determineUserStatus(app.globalData.userInfo);
|
||||
const userStatus = await loginModule.determineUserStatus(app.globalData.userInfo);
|
||||
|
||||
// 更新页面状态,使用头像缓存方法
|
||||
await this.updateUserInfoWithAvatarCache(app.globalData.userInfo);
|
||||
this.setData({
|
||||
userInfo: app.globalData.userInfo,
|
||||
'authStatus.hasWxCode': true,
|
||||
'authStatus.userStatus': userStatus
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user