// 管理员界面 - 全屏管理面板 import { UserInfo } from '../../types'; import userService from '../../services/userService'; Page({ data: { userInfo: null as 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(); }, /** * 获取用户信息 */ getUserInfo() { const app = getApp(); if (app.globalData.userInfo) { const userInfo = app.globalData.userInfo; this.setData({ userInfo }); // 验证是否为管理员 if (userInfo.role !== 'ADMIN') { wx.showToast({ title: '无权限访问', icon: 'none' }); wx.navigateBack(); } } }, /** * 加载统计数据 */ loadStatistics() { // 模拟加载统计数据 this.setData({ stats: { employeeCount: 25, orderCount: 156, warehouseCount: 8 } }); }, /** * 菜单项点击事件 */ onMenuItemTap(e: any) { 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.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' }); } } });