地址路径修改
This commit is contained in:
@@ -4,6 +4,10 @@ import mapService from '../../services/mapService';
|
||||
import warehouseService from '../../services/warehouseService';
|
||||
import orderService from '../../services/orderService';
|
||||
import deliveryService from '../../services/deliveryPersonService';
|
||||
import userService from '../../services/userService';
|
||||
import { avatarCache } from '../../utils/avatarCache';
|
||||
import { Role } from '../../utils/roleUtils';
|
||||
import { API_BASE_URL } from '../../services/apiService';
|
||||
|
||||
|
||||
Page({
|
||||
@@ -36,28 +40,54 @@ Page({
|
||||
currentTab: 'main'
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 模拟管理员登录状态
|
||||
this.setData({
|
||||
userInfo: {
|
||||
id: 1,
|
||||
name: '管理员',
|
||||
role: 'ADMIN' as any,
|
||||
phone: '13800138000'
|
||||
}
|
||||
});
|
||||
onLoad: function() {
|
||||
// 获取用户信息
|
||||
this.getUserInfo();
|
||||
|
||||
// 初始化数据
|
||||
this.initData();
|
||||
},
|
||||
|
||||
onShow() {
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
getUserInfo: async function() {
|
||||
try {
|
||||
const app = getApp<any>();
|
||||
let userInfo = app.globalData.userInfo;
|
||||
|
||||
if (!userInfo) {
|
||||
userInfo = await userService.getUserInfo();
|
||||
}
|
||||
|
||||
// 处理用户信息,添加完整的头像URL
|
||||
const processedUserInfo = await this.processUserInfo(userInfo);
|
||||
|
||||
this.setData({
|
||||
userInfo: processedUserInfo
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
|
||||
// 设置默认用户信息
|
||||
this.setData({
|
||||
userInfo: {
|
||||
id: -1,
|
||||
name: '管理员',
|
||||
role: Role.ADMIN,
|
||||
avatarPath: '/images/user-avatar.png'
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onShow: function() {
|
||||
// 页面显示时刷新数据
|
||||
this.refreshData();
|
||||
},
|
||||
|
||||
// 初始化数据
|
||||
initData() {
|
||||
initData: function() {
|
||||
// 获取仓库数据
|
||||
warehouseService.getWarehouses().then(warehouses => {
|
||||
this.setData({
|
||||
@@ -66,22 +96,78 @@ Page({
|
||||
}).catch(error => {
|
||||
console.error('获取仓库数据失败:', error);
|
||||
});
|
||||
// 刷新数据
|
||||
this.refreshData();
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取完整的头像URL
|
||||
*/
|
||||
getFullAvatarUrl(avatarPath: string | undefined): string {
|
||||
if (!avatarPath) {
|
||||
return '/images/user-avatar.png';
|
||||
}
|
||||
|
||||
// 如果已经是完整URL,直接返回
|
||||
if (avatarPath.startsWith('http')) {
|
||||
return avatarPath;
|
||||
}
|
||||
|
||||
// 将相对路径转换为完整URL
|
||||
return `${API_BASE_URL}${avatarPath}`;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取本地缓存的头像路径
|
||||
*/
|
||||
async getLocalAvatarPath(avatarPath: string | undefined): Promise<string> {
|
||||
if (!avatarPath) {
|
||||
return '/images/user-avatar.png';
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用头像缓存获取本地文件路径
|
||||
const fullAvatarUrl = this.getFullAvatarUrl(avatarPath);
|
||||
const localAvatarPath = await avatarCache.getAvatarPath(fullAvatarUrl);
|
||||
return localAvatarPath;
|
||||
} catch (error) {
|
||||
console.error('获取头像缓存失败:', error);
|
||||
// 如果缓存失败,回退到远程URL
|
||||
return this.getFullAvatarUrl(avatarPath);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理用户信息,添加完整的头像URL
|
||||
*/
|
||||
async processUserInfo(userInfo: any): Promise<any> {
|
||||
if (!userInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const processedUserInfo = { ...userInfo };
|
||||
processedUserInfo.fullAvatarUrl = await this.getLocalAvatarPath(userInfo.avatarPath);
|
||||
|
||||
return processedUserInfo;
|
||||
},
|
||||
|
||||
// 刷新数据
|
||||
refreshData() {
|
||||
refreshData: function() {
|
||||
// 获取订单数据 - 使用正确的getPendingOrders方法
|
||||
orderService.getPendingOrders().then(orders => {
|
||||
// 获取员工数据 - 使用正确的getDeliveryPersons方法
|
||||
deliveryService.getDeliveryPersons().then(deliveryPersons => {
|
||||
// 处理员工数据,添加完整的头像URL
|
||||
const processedDeliveryPersons = deliveryPersons.map(person => ({
|
||||
...person,
|
||||
fullAvatarUrl: person.avatarPath ? this.getFullAvatarUrl(person.avatarPath) : '/images/user-avatar.png'
|
||||
}));
|
||||
|
||||
// 更新地图标记点
|
||||
const markers = this.generateMarkers(orders, deliveryPersons);
|
||||
const markers = this.generateMarkers(orders, processedDeliveryPersons);
|
||||
|
||||
this.setData({
|
||||
orders,
|
||||
deliveryPersons,
|
||||
deliveryPersons: processedDeliveryPersons,
|
||||
markers
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user