地址路径修改
This commit is contained in:
300
dist/pages/staff/admin-dashboard.js
vendored
Normal file
300
dist/pages/staff/admin-dashboard.js
vendored
Normal file
@@ -0,0 +1,300 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const roleUtils_1 = require("../../utils/roleUtils");
|
||||
const userService_1 = __importDefault(require("../../services/userService"));
|
||||
const statisticsService_1 = __importDefault(require("../../services/statisticsService"));
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
// Grid布局的功能菜单
|
||||
menuItems: [
|
||||
{
|
||||
id: 'employee',
|
||||
name: '员工管理',
|
||||
icon: '👥',
|
||||
color: '#3498db',
|
||||
description: '管理员工信息'
|
||||
},
|
||||
{
|
||||
id: 'order',
|
||||
name: '订单管理',
|
||||
icon: '📦',
|
||||
color: '#e74c3c',
|
||||
description: '处理订单分配'
|
||||
},
|
||||
{
|
||||
id: 'warehouse',
|
||||
name: '仓库管理',
|
||||
icon: '🏭',
|
||||
color: '#f39c12',
|
||||
description: '管理库存信息'
|
||||
},
|
||||
{
|
||||
id: 'statistics',
|
||||
name: '数据统计',
|
||||
icon: '📊',
|
||||
color: '#9b59b6',
|
||||
description: '查看业务数据'
|
||||
},
|
||||
{
|
||||
id: 'settings',
|
||||
name: '系统设置',
|
||||
icon: '⚙️',
|
||||
color: '#34495e',
|
||||
description: '系统配置管理'
|
||||
},
|
||||
{
|
||||
id: 'map',
|
||||
name: '地图监控',
|
||||
icon: '🗺️',
|
||||
color: '#27ae60',
|
||||
description: '实时位置监控'
|
||||
}
|
||||
],
|
||||
// 统计数据
|
||||
stats: {
|
||||
employeeCount: 0,
|
||||
orderCount: 0,
|
||||
warehouseCount: 0
|
||||
},
|
||||
// 当前时间
|
||||
currentTime: ''
|
||||
},
|
||||
onLoad() {
|
||||
this.getUserInfo();
|
||||
this.loadStatistics();
|
||||
this.updateCurrentTime();
|
||||
// 每秒更新一次时间
|
||||
setInterval(() => {
|
||||
this.updateCurrentTime();
|
||||
}, 1000);
|
||||
},
|
||||
onShow() {
|
||||
this.loadStatistics();
|
||||
this.updateCurrentTime();
|
||||
},
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
async getUserInfo() {
|
||||
try {
|
||||
const app = getApp();
|
||||
// 如果全局数据中没有用户信息,尝试从用户服务获取
|
||||
if (!app.globalData.userInfo) {
|
||||
const userInfo = await userService_1.default.getUserInfo();
|
||||
if (userInfo) {
|
||||
app.globalData.userInfo = userInfo;
|
||||
}
|
||||
}
|
||||
if (app.globalData.userInfo) {
|
||||
const userInfo = app.globalData.userInfo;
|
||||
this.setData({ userInfo });
|
||||
// 验证是否为管理员
|
||||
if (userInfo.role !== roleUtils_1.Role.ADMIN) {
|
||||
wx.showToast({
|
||||
title: '无权限访问',
|
||||
icon: 'none'
|
||||
});
|
||||
wx.navigateBack();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 如果仍然没有用户信息,显示默认信息
|
||||
this.setData({
|
||||
userInfo: {
|
||||
id: 0,
|
||||
role: roleUtils_1.Role.ADMIN,
|
||||
name: '管理员',
|
||||
avatarUrl: undefined
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
// 出错时显示默认信息
|
||||
this.setData({
|
||||
userInfo: {
|
||||
id: 0,
|
||||
role: roleUtils_1.Role.ADMIN,
|
||||
name: '管理员',
|
||||
avatarUrl: undefined
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 加载统计数据
|
||||
*/
|
||||
async loadStatistics() {
|
||||
try {
|
||||
wx.showLoading({
|
||||
title: '加载数据中...'
|
||||
});
|
||||
// 使用统计服务获取真实数据
|
||||
const stats = await statisticsService_1.default.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) {
|
||||
const itemId = e.currentTarget.dataset.id;
|
||||
switch (itemId) {
|
||||
case 'employee':
|
||||
wx.navigateTo({
|
||||
url: '/pages/staff/employee-management'
|
||||
});
|
||||
break;
|
||||
case 'order':
|
||||
wx.navigateTo({
|
||||
url: '/pages/staff/order-management'
|
||||
});
|
||||
break;
|
||||
case 'warehouse':
|
||||
wx.navigateTo({
|
||||
url: '/pages/staff/warehouse-management'
|
||||
});
|
||||
break;
|
||||
case 'statistics':
|
||||
wx.navigateTo({
|
||||
url: '/pages/staff/statistics'
|
||||
});
|
||||
break;
|
||||
case 'settings':
|
||||
wx.navigateTo({
|
||||
url: '/pages/staff/settings'
|
||||
});
|
||||
break;
|
||||
case 'map':
|
||||
wx.navigateTo({
|
||||
url: '/pages/map/map'
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 返回首页
|
||||
*/
|
||||
goBack() {
|
||||
wx.navigateBack();
|
||||
},
|
||||
/**
|
||||
* 刷新数据
|
||||
*/
|
||||
onRefresh() {
|
||||
this.loadStatistics();
|
||||
this.updateCurrentTime();
|
||||
wx.showToast({
|
||||
title: '数据已刷新',
|
||||
icon: 'success'
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 更新当前时间
|
||||
*/
|
||||
updateCurrentTime() {
|
||||
const now = new Date();
|
||||
const timeString = now.toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
});
|
||||
this.setData({
|
||||
currentTime: timeString
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 解绑微信处理
|
||||
*/
|
||||
async onUnbindWechat() {
|
||||
try {
|
||||
// 确认对话框
|
||||
wx.showModal({
|
||||
title: '确认解绑',
|
||||
content: '解绑微信后,您将需要重新登录并绑定账号。确定要继续吗?',
|
||||
confirmText: '确定解绑',
|
||||
confirmColor: '#e74c3c',
|
||||
cancelText: '取消',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
// 显示加载中
|
||||
wx.showLoading({
|
||||
title: '解绑中...',
|
||||
mask: true
|
||||
});
|
||||
try {
|
||||
// 调用解绑服务
|
||||
const result = await userService_1.default.unbindWechat();
|
||||
wx.hideLoading();
|
||||
if (result.success) {
|
||||
wx.showToast({
|
||||
title: '解绑成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
// 延迟跳转到登录页面
|
||||
setTimeout(() => {
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
else {
|
||||
wx.showToast({
|
||||
title: result.message || '解绑失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '解绑失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
console.error('解绑微信错误:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.error('解绑微信处理错误:', error);
|
||||
wx.showToast({
|
||||
title: '操作失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user