地址路径修改

This commit is contained in:
2025-10-26 13:15:04 +08:00
parent be2323074b
commit 271b88232c
77 changed files with 13254 additions and 228 deletions

View File

@@ -1,6 +1,9 @@
// 管理员界面 - 全屏管理面板
import { UserInfo } from '../../types';
import { Role } from '../../utils/roleUtils';
import userService from '../../services/userService';
import statisticsService from '../../services/statisticsService';
import { API_BASE_URL } from '../../services/apiService';
Page({
data: {
@@ -60,7 +63,7 @@ Page({
currentTime: ''
},
onLoad() {
onLoad: function() {
this.getUserInfo();
this.loadStatistics();
this.updateCurrentTime();
@@ -70,49 +73,143 @@ Page({
}, 1000);
},
onShow() {
onShow: function() {
this.loadStatistics();
this.updateCurrentTime();
},
/**
* 获取完整的头像URL
* @param avatarPath 头像相对路径
* @returns 完整的头像URL
*/
getFullAvatarUrl: function(avatarPath: string | undefined): string {
if (!avatarPath) {
return '/images/user-avatar.png';
}
// 如果已经是完整URL直接返回
if (avatarPath.startsWith('http')) {
return avatarPath;
}
// 将相对路径转换为完整URL
return `${API_BASE_URL}${avatarPath}`;
},
/**
* 处理用户信息预先准备好完整的头像URL
* @param userInfo 原始用户信息
* @returns 处理后的用户信息
*/
processUserInfo: function(userInfo: any): any {
if (!userInfo) {
return {
id: 0,
role: Role.ADMIN,
name: '管理员',
fullAvatarUrl: '/images/user-avatar.png'
};
}
// 预先准备好完整的头像URL
const processedUserInfo = { ...userInfo };
if (userInfo.avatarPath) {
processedUserInfo.fullAvatarUrl = this.getFullAvatarUrl(userInfo.avatarPath);
} else {
processedUserInfo.fullAvatarUrl = '/images/user-avatar.png';
}
return processedUserInfo;
},
/**
* 获取用户信息
*/
getUserInfo() {
const app = getApp<any>();
if (app.globalData.userInfo) {
const userInfo = app.globalData.userInfo;
this.setData({ userInfo });
getUserInfo: async function() {
try {
const app = getApp<any>();
// 验证是否为管理员
if (userInfo.role !== 'ADMIN') {
wx.showToast({
title: '无权限访问',
icon: 'none'
});
wx.navigateBack();
// 如果全局数据中没有用户信息,尝试从用户服务获取
if (!app.globalData.userInfo) {
const userInfo = await userService.getUserInfo();
if (userInfo) {
app.globalData.userInfo = userInfo;
}
}
if (app.globalData.userInfo) {
const userInfo = this.processUserInfo(app.globalData.userInfo);
this.setData({ userInfo });
// 验证是否为管理员
if (userInfo.role !== Role.ADMIN) {
wx.showToast({
title: '无权限访问',
icon: 'none'
});
wx.navigateBack();
}
} else {
// 如果仍然没有用户信息,显示默认信息
this.setData({
userInfo: this.processUserInfo(null)
});
}
} catch (error) {
console.error('获取用户信息失败:', error);
// 出错时显示默认信息
this.setData({
userInfo: this.processUserInfo(null)
});
}
},
/**
* 加载统计数据
*/
loadStatistics() {
// 模拟加载统计数据
this.setData({
stats: {
employeeCount: 25,
orderCount: 156,
warehouseCount: 8
}
});
loadStatistics: async function() {
try {
wx.showLoading({
title: '加载数据中...'
});
// 使用统计服务获取真实数据
const stats = await statisticsService.getSystemStats();
this.setData({
stats: {
employeeCount: stats.employeeCount,
orderCount: stats.orderCount,
warehouseCount: stats.warehouseCount
}
});
wx.hideLoading();
} catch (error) {
console.error('加载统计数据失败:', error);
wx.hideLoading();
// 出错时使用默认值
this.setData({
stats: {
employeeCount: 0,
orderCount: 0,
warehouseCount: 0
}
});
wx.showToast({
title: '数据加载失败',
icon: 'none'
});
}
},
/**
* 菜单项点击事件
*/
onMenuItemTap(e: any) {
onMenuItemTap: function(e: any) {
const itemId = e.currentTarget.dataset.id;
switch (itemId) {
@@ -152,14 +249,14 @@ Page({
/**
* 返回首页
*/
goBack() {
goBack: function() {
wx.navigateBack();
},
/**
* 刷新数据
*/
onRefresh() {
onRefresh: function() {
this.loadStatistics();
this.updateCurrentTime();
wx.showToast({
@@ -171,7 +268,7 @@ Page({
/**
* 更新当前时间
*/
updateCurrentTime() {
updateCurrentTime: function() {
const now = new Date();
const timeString = now.toLocaleString('zh-CN', {
year: 'numeric',
@@ -189,7 +286,7 @@ Page({
/**
* 解绑微信处理
*/
async onUnbindWechat() {
onUnbindWechat: async function() {
try {
// 确认对话框
wx.showModal({