地址路径修改

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

300
dist/pages/staff/admin-dashboard.js vendored Normal file
View 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'
});
}
}
});

217
dist/pages/staff/employee-dashboard.js vendored Normal file
View File

@@ -0,0 +1,217 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const userService_1 = __importDefault(require("../../services/userService"));
Page({
data: {
userInfo: null,
// Grid布局的功能菜单
menuItems: [
{
id: 'orders',
name: '我的订单',
icon: '📦',
color: '#3498db',
description: '查看分配订单'
},
{
id: 'location',
name: '位置上报',
icon: '📍',
color: '#e74c3c',
description: '上报当前位置'
},
{
id: 'schedule',
name: '工作安排',
icon: '📅',
color: '#f39c12',
description: '查看工作计划'
},
{
id: 'profile',
name: '个人信息',
icon: '👤',
color: '#9b59b6',
description: '个人资料管理'
},
{
id: 'messages',
name: '消息通知',
icon: '📨',
color: '#34495e',
description: '查看系统消息'
},
{
id: 'help',
name: '帮助中心',
icon: '❓',
color: '#27ae60',
description: '使用帮助文档'
}
],
// 工作统计
workStats: {
todayOrders: 0,
completedOrders: 0,
pendingOrders: 0
}
},
onLoad() {
this.getUserInfo();
this.loadWorkStats();
},
onShow() {
this.loadWorkStats();
},
/**
* 获取用户信息
*/
getUserInfo() {
const app = getApp();
if (app.globalData.userInfo) {
const userInfo = app.globalData.userInfo;
this.setData({ userInfo });
}
},
/**
* 加载工作统计数据
*/
loadWorkStats() {
// 模拟加载工作统计数据
this.setData({
workStats: {
todayOrders: 8,
completedOrders: 5,
pendingOrders: 3
}
});
},
/**
* 菜单项点击事件
*/
onMenuItemTap(e) {
const itemId = e.currentTarget.dataset.id;
switch (itemId) {
case 'orders':
wx.navigateTo({
url: '/pages/staff/my-orders'
});
break;
case 'location':
wx.navigateTo({
url: '/pages/staff/location-report'
});
break;
case 'schedule':
wx.navigateTo({
url: '/pages/staff/work-schedule'
});
break;
case 'profile':
wx.navigateTo({
url: '/pages/staff/profile'
});
break;
case 'messages':
wx.navigateTo({
url: '/pages/staff/messages'
});
break;
case 'help':
wx.navigateTo({
url: '/pages/staff/help'
});
break;
}
},
/**
* 返回首页
*/
goBack() {
wx.navigateBack();
},
/**
* 刷新数据
*/
onRefresh() {
this.loadWorkStats();
wx.showToast({
title: '数据已刷新',
icon: 'success'
});
},
/**
* 紧急联系
*/
onEmergencyContact() {
wx.makePhoneCall({
phoneNumber: '400-123-4567'
});
},
/**
* 解绑微信处理
*/
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'
});
}
}
});

535
dist/pages/staff/employee-management.js vendored Normal file
View File

@@ -0,0 +1,535 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const employeeService_1 = __importDefault(require("../../services/employeeService"));
const roleUtils_1 = require("../../utils/roleUtils");
Page({
data: {
// 员工列表
employees: [],
filteredEmployees: [],
// 页面状态
currentTab: 'list', // list: 列表页, add: 添加页, edit: 编辑页
loading: false,
// 添加员工表单数据
addForm: {
name: '',
phone: '',
role: roleUtils_1.Role.DELIVERY_PERSON
},
// 编辑员工表单数据
editForm: {
id: 0,
name: '',
phone: '',
role: roleUtils_1.Role.DELIVERY_PERSON,
avatarUrl: ''
},
// 错误信息
errorMessage: '',
successMessage: '',
// 搜索关键词
searchKeyword: '',
// 角色选项
roleOptions: (0, roleUtils_1.getRoleOptions)(),
// 用户信息
userInfo: null,
// 临时头像路径(用于头像上传)
tempAvatarPath: ''
},
onLoad() {
this.getUserInfo();
this.loadEmployees();
},
onShow() {
// 只在页面显示时检查是否需要刷新数据,避免频繁请求
if (this.data.employees.length === 0) {
this.loadEmployees();
}
},
/**
* 获取用户信息
*/
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();
}
}
},
/**
* 加载员工列表
*/
async loadEmployees() {
this.setData({
loading: true,
errorMessage: '',
successMessage: ''
});
try {
const employees = await employeeService_1.default.getEmployees();
// 为每个员工获取头像URL
const employeesWithAvatars = await Promise.all(employees.map(async (employee) => {
try {
const avatarUrl = await employeeService_1.default.getAvatarUrl(employee.id);
return {
...employee,
avatarUrl: avatarUrl
};
}
catch (error) {
console.error(`获取员工 ${employee.id} 头像失败:`, error);
return {
...employee,
avatarUrl: ''
};
}
}));
// 获取过滤后的员工列表
const filteredEmployees = this.getFilteredEmployees(employeesWithAvatars);
this.setData({
employees: employeesWithAvatars,
filteredEmployees,
loading: false
});
}
catch (error) {
console.error('加载员工列表失败:', error);
this.setData({
loading: false,
errorMessage: '加载员工列表失败,请稍后重试'
});
}
},
/**
* 切换页面标签
*/
switchTab(e) {
const tab = e.currentTarget.dataset.tab;
this.setData({
currentTab: tab,
errorMessage: '',
successMessage: ''
});
// 只在切换到列表页且没有数据时才加载,避免频繁请求
if (tab === 'list' && this.data.employees.length === 0) {
this.loadEmployees();
}
},
/**
* 处理添加员工表单输入
*/
onFormInput(e) {
const { field } = e.currentTarget.dataset;
const value = e.detail.value;
this.setData({
[`addForm.${field}`]: value,
errorMessage: '',
successMessage: ''
});
},
/**
* 处理角色选择
*/
onRoleChange(e) {
const index = e.detail.value;
const selectedRole = this.data.roleOptions[index].value;
this.setData({
'addForm.role': selectedRole
});
},
/**
* 验证表单数据
*/
validateForm() {
const { name, phone, role } = this.data.addForm;
if (!name.trim()) {
this.setData({
errorMessage: '请输入员工姓名'
});
return false;
}
if (!phone.trim()) {
this.setData({
errorMessage: '请输入员工工号'
});
return false;
}
// 简单的工号格式验证
const phoneRegex = /^\d+$/;
if (!phoneRegex.test(phone)) {
this.setData({
errorMessage: '工号只能包含数字'
});
return false;
}
if (!role) {
this.setData({
errorMessage: '请选择员工角色'
});
return false;
}
return true;
},
/**
* 提交添加员工表单
*/
async submitAddForm() {
if (!this.validateForm()) {
return;
}
this.setData({
loading: true,
errorMessage: '',
successMessage: ''
});
try {
await employeeService_1.default.addEmployee(this.data.addForm);
this.setData({
loading: false,
successMessage: '员工添加成功',
addForm: {
name: '',
phone: '',
role: roleUtils_1.Role.DELIVERY_PERSON
}
});
// 添加成功后自动切换到列表页
setTimeout(() => {
this.setData({
currentTab: 'list'
});
this.loadEmployees();
}, 1500);
}
catch (error) {
console.error('添加员工失败:', error);
this.setData({
loading: false,
errorMessage: error.message || '添加员工失败,请稍后重试'
});
}
},
/**
* 编辑员工
*/
editEmployee(e) {
const employeeId = e.currentTarget.dataset.id;
const employee = this.data.employees.find(emp => emp.id === employeeId);
if (employee) {
this.setData({
editForm: {
id: employee.id || 0,
name: employee.name || '',
phone: employee.phone || '',
role: employee.role || roleUtils_1.Role.DELIVERY_PERSON,
avatarUrl: employee.avatarUrl || ''
},
currentTab: 'edit'
});
}
},
/**
* 提交编辑员工表单
*/
async submitEditForm() {
if (!this.validateEditForm()) {
return;
}
this.setData({
loading: true,
errorMessage: '',
successMessage: ''
});
try {
// 调用更新员工的API方法
await employeeService_1.default.updateEmployee(this.data.editForm.id, {
name: this.data.editForm.name,
phone: this.data.editForm.phone,
role: this.data.editForm.role
});
// 如果有新头像,上传头像
if (this.data.tempAvatarPath) {
try {
const result = await employeeService_1.default.uploadAvatar(this.data.editForm.id, this.data.tempAvatarPath);
if (result.success && result.avatarUrl) {
// 更新头像URL
this.setData({
'editForm.avatarUrl': result.avatarUrl
});
}
}
catch (avatarError) {
console.error('上传头像失败:', avatarError);
wx.showToast({
title: '头像上传失败',
icon: 'error'
});
}
}
this.setData({
loading: false,
successMessage: '员工更新成功',
currentTab: 'list',
tempAvatarPath: ''
});
// 重新加载员工列表
this.loadEmployees();
}
catch (error) {
console.error('更新员工失败:', error);
this.setData({
loading: false,
errorMessage: '更新员工失败,请重试'
});
}
},
/**
* 选择头像
*/
chooseAvatar() {
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album'],
maxDuration: 30,
camera: 'back',
success: (res) => {
if (res.tempFiles && res.tempFiles.length > 0) {
const tempFilePath = res.tempFiles[0].tempFilePath;
this.setData({
'editForm.avatarUrl': tempFilePath,
tempAvatarPath: tempFilePath
});
}
},
fail: (err) => {
console.error('选择头像失败:', err);
wx.showToast({
title: '选择头像失败',
icon: 'error'
});
}
});
},
/**
* 拍照
*/
takePhoto() {
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['camera'],
maxDuration: 30,
camera: 'back',
success: (res) => {
if (res.tempFiles && res.tempFiles.length > 0) {
const tempFilePath = res.tempFiles[0].tempFilePath;
this.setData({
'editForm.avatarUrl': tempFilePath,
tempAvatarPath: tempFilePath
});
}
},
fail: (err) => {
console.error('拍照失败:', err);
wx.showToast({
title: '拍照失败',
icon: 'error'
});
}
});
},
/**
* 验证编辑表单
*/
validateEditForm() {
const { name, phone, role } = this.data.editForm;
if (!name.trim()) {
this.setData({
errorMessage: '请输入员工姓名'
});
return false;
}
if (!phone.trim()) {
this.setData({
errorMessage: '请输入员工工号'
});
return false;
}
// 简单的工号格式验证
const phoneRegex = /^\d+$/;
if (!phoneRegex.test(phone)) {
this.setData({
errorMessage: '工号只能包含数字'
});
return false;
}
if (!role) {
this.setData({
errorMessage: '请选择员工角色'
});
return false;
}
return true;
},
/**
* 取消编辑
*/
cancelEdit() {
this.setData({
currentTab: 'list',
errorMessage: '',
successMessage: ''
});
},
/**
* 编辑表单输入处理
*/
onEditFormInput(e) {
const { field } = e.currentTarget.dataset;
const value = e.detail.value;
this.setData({
[`editForm.${field}`]: value,
errorMessage: '',
successMessage: ''
});
},
/**
* 处理编辑角色选择
*/
onEditRoleChange(e) {
const index = e.detail.value;
const selectedRole = this.data.roleOptions[index].value;
this.setData({
'editForm.role': selectedRole
});
},
/**
* 删除员工
*/
async deleteEmployee(e) {
const employeeId = e.currentTarget.dataset.id;
const employee = this.data.employees.find(emp => emp.id === employeeId);
if (!employee) {
return;
}
wx.showModal({
title: '确认删除',
content: `确定要删除员工 ${employee.name} (${employee.phone}) 吗?此操作不可恢复。`,
confirmText: '删除',
confirmColor: '#ff4d4f',
cancelText: '取消',
success: async (res) => {
if (res.confirm) {
this.setData({
loading: true,
errorMessage: '',
successMessage: ''
});
try {
const result = await employeeService_1.default.deleteEmployee(employeeId);
if (result.success) {
this.setData({
loading: false,
successMessage: result.message || '员工删除成功'
});
// 重新加载员工列表
this.loadEmployees();
}
else {
this.setData({
loading: false,
errorMessage: result.message || '删除员工失败'
});
}
}
catch (error) {
console.error('删除员工失败:', error);
this.setData({
loading: false,
errorMessage: '删除员工失败,请稍后重试'
});
}
}
}
});
},
/**
* 搜索员工
*/
onSearchInput(e) {
const keyword = e.detail.value;
this.setData({
searchKeyword: keyword
});
// 更新过滤后的员工列表
this.updateFilteredEmployees();
},
/**
* 更新过滤后的员工列表
*/
updateFilteredEmployees() {
const { employees } = this.data;
const filteredEmployees = this.getFilteredEmployees(employees);
this.setData({
filteredEmployees
});
},
/**
* 获取过滤后的员工列表
*/
getFilteredEmployees(employees) {
const { searchKeyword } = this.data;
// 如果employees为空返回空数组
if (!employees || !Array.isArray(employees)) {
return [];
}
// 显示所有员工,包括当前用户
let filteredEmployees = employees;
// 更严格的搜索关键词检查
if (!searchKeyword || typeof searchKeyword !== 'string' || !searchKeyword.trim()) {
return filteredEmployees;
}
const keyword = searchKeyword.toLowerCase();
return filteredEmployees.filter(emp => emp.name.toLowerCase().includes(keyword) ||
emp.phone.includes(keyword) ||
(emp.role || '').toLowerCase().includes(keyword));
},
/**
* 获取角色显示文本
*/
getRoleText(role) {
const roleMap = {
'ADMIN': '管理员',
'DELIVERY_PERSON': '配送员',
'EMPLOYEE': '员工'
};
return roleMap[role] || role;
},
/**
* 清空消息
*/
clearMessages() {
this.setData({
errorMessage: '',
successMessage: ''
});
},
/**
* 返回上一页
*/
goBack() {
wx.navigateBack();
}
});

385
dist/pages/staff/order-management.js vendored Normal file
View File

@@ -0,0 +1,385 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const orderService_1 = __importDefault(require("../../services/orderService"));
const deliveryPersonService_1 = __importDefault(require("../../services/deliveryPersonService"));
const warehouseService_1 = __importDefault(require("../../services/warehouseService"));
Page({
data: {
userInfo: null,
// 订单相关数据
orders: [],
filteredOrders: [],
activeTab: 'all',
// 员工相关数据
deliveryPersons: [],
availableStaff: [],
// 仓库数据
warehouses: [],
// 弹窗状态
showAssignModal: false,
showAddModal: false,
selectedOrderId: 0,
// 新增订单表单数据
warehouseIndex: 0,
endName: '',
goodsType: '',
goodsWeight: 0,
// 页面状态
loading: false,
errorMessage: '',
successMessage: ''
},
onLoad() {
// 获取用户信息
this.getUserInfo();
// 初始化数据
this.initData();
},
onShow() {
// 页面显示时刷新数据
this.refreshData();
},
onPullDownRefresh() {
// 下拉刷新
this.refreshData().then(() => {
wx.stopPullDownRefresh();
});
},
// 获取用户信息
getUserInfo() {
try {
const userInfo = wx.getStorageSync('userInfo');
if (userInfo) {
this.setData({
userInfo
});
}
}
catch (error) {
console.error('获取用户信息失败:', error);
}
},
// 初始化数据
initData() {
// 获取仓库数据
warehouseService_1.default.getWarehouses().then(warehouses => {
this.setData({
warehouses
});
}).catch(error => {
console.error('获取仓库数据失败:', error);
this.showError('获取仓库数据失败');
});
},
// 刷新数据
async refreshData() {
this.setData({
loading: true,
errorMessage: '',
successMessage: ''
});
try {
// 获取订单数据
const orders = await orderService_1.default.getPendingOrders();
// 获取员工数据
const deliveryPersons = await deliveryPersonService_1.default.getDeliveryPersons();
this.setData({
orders,
deliveryPersons,
loading: false
});
// 过滤订单
this.filterOrders();
}
catch (error) {
console.error('刷新数据失败:', error);
this.setData({
loading: false
});
this.showError('刷新数据失败,请重试');
}
},
// 过滤订单
filterOrders() {
const { orders, activeTab } = this.data;
let filteredOrders = orders;
if (activeTab !== 'all') {
filteredOrders = orders.filter(order => order.status === activeTab);
}
this.setData({
filteredOrders
});
},
// 切换订单标签
switchTab(e) {
const tab = e.currentTarget.dataset.tab;
this.setData({
activeTab: tab
});
this.filterOrders();
},
// 处理订单点击
handleOrderTap(e) {
const orderId = e.currentTarget.dataset.id;
const order = this.data.orders.find(o => o.id === orderId);
if (!order)
return;
if (order.status === 'pending') {
// 未分配的订单,显示分配弹窗
const availableStaff = this.data.deliveryPersons.filter(person => person.status === 'idle');
this.setData({
showAssignModal: true,
selectedOrderId: orderId,
availableStaff
});
}
else {
// 显示订单详情
this.showOrderDetail(order);
}
},
// 显示订单详情
showOrderDetail(order) {
wx.showModal({
title: `订单 #${order.id}`,
content: `起点: ${order.startPoint.name}\n终点: ${order.endPoint.name}\n货物: ${order.goodsType} ${order.goodsWeight}kg\n状态: ${this.getStatusText(order.status)}`,
showCancel: false
});
},
// 显示新增订单弹窗
showAddOrderModal() {
this.setData({
showAddModal: true,
endName: '',
goodsType: '',
goodsWeight: 0,
warehouseIndex: 0
});
},
// 隐藏新增订单弹窗
hideAddModal() {
this.setData({
showAddModal: false
});
},
// 隐藏分配弹窗
hideAssignModal() {
this.setData({
showAssignModal: false
});
},
// 仓库选择变化
onWarehouseChange(e) {
this.setData({
warehouseIndex: e.detail.value
});
},
// 终点名称输入
onEndNameInput(e) {
this.setData({
endName: e.detail.value
});
},
// 货物类型输入
onGoodsTypeInput(e) {
this.setData({
goodsType: e.detail.value
});
},
// 货物重量输入
onGoodsWeightInput(e) {
this.setData({
goodsWeight: parseFloat(e.detail.value) || 0
});
},
// 创建订单
createOrder() {
const { warehouses, warehouseIndex, endName, goodsType, goodsWeight } = this.data;
// 表单验证
if (!warehouses[warehouseIndex]) {
this.showError('请选择仓库');
return;
}
if (!endName) {
this.showError('请输入终点名称');
return;
}
if (!goodsType) {
this.showError('请输入货物类型');
return;
}
if (goodsWeight <= 0) {
this.showError('请输入有效的货物重量');
return;
}
// 获取仓库信息
const warehouse = warehouses[warehouseIndex];
// 创建订单数据
const newOrder = {
startPoint: {
id: warehouse.id,
name: warehouse.name,
longitude: warehouse.longitude || 102.715,
latitude: warehouse.latitude || 25.045
},
endPoint: {
name: endName,
longitude: 102.715 + (Math.random() - 0.5) * 0.1,
latitude: 25.045 + (Math.random() - 0.5) * 0.1
},
status: 'pending',
goodsType,
goodsWeight
};
// 调用服务创建订单
orderService_1.default.createOrder(newOrder).then(() => {
this.showSuccess('订单创建成功');
this.refreshData();
}).catch(error => {
console.error('创建订单失败:', error);
this.showError('创建订单失败');
});
this.hideAddModal();
},
// 分配订单
assignOrder(e) {
const staffId = e.currentTarget.dataset.id;
const { selectedOrderId } = this.data;
if (!selectedOrderId || !staffId) {
this.showError('请选择订单和货运人员');
return;
}
// 分配订单
orderService_1.default.assignOrder(selectedOrderId, staffId).then(result => {
if (result.success) {
this.showSuccess('订单指派成功');
this.refreshData();
}
else {
this.showError(result.message || '指派失败');
}
}).catch(error => {
console.error('指派订单失败:', error);
this.showError('指派失败,请重试');
});
this.hideAssignModal();
},
// 删除订单
deleteOrder(e) {
const orderId = e.currentTarget.dataset.id;
wx.showModal({
title: '确认删除',
content: '确定要删除这个订单吗?',
success: (res) => {
if (res.confirm) {
// 调用删除订单接口
// orderService.deleteOrder(orderId).then(() => {
// this.showSuccess('订单删除成功');
// this.refreshData();
// }).catch(error => {
// console.error('删除订单失败:', error);
// this.showError('删除订单失败');
// });
// 暂时使用模拟删除
const orders = this.data.orders.filter(order => order.id !== orderId);
this.setData({
orders
});
this.filterOrders();
this.showSuccess('订单删除成功');
}
}
});
},
// 更新订单状态
updateOrderStatus(e) {
const orderId = e.currentTarget.dataset.id;
const status = e.currentTarget.dataset.status;
// 调用更新订单状态接口
orderService_1.default.updateOrderStatus(orderId, status).then(result => {
if (result.success) {
this.showSuccess('订单状态更新成功');
this.refreshData();
}
else {
this.showError(result.message || '更新失败');
}
}).catch(error => {
console.error('更新订单状态失败:', error);
this.showError('更新失败,请重试');
});
},
// 获取状态文本
getStatusText(status) {
const statusMap = {
'pending': '未分配',
'assigned': '已分配',
'in_transit': '配送中',
'delivered': '已完成',
'cancelled': '已取消'
};
return statusMap[status] || status;
},
// 格式化时间
formatTime(time) {
const date = new Date(time);
const now = new Date();
const diff = now.getTime() - date.getTime();
if (diff < 60000) {
return '刚刚';
}
else if (diff < 3600000) {
return `${Math.floor(diff / 60000)}分钟前`;
}
else if (diff < 86400000) {
return `${Math.floor(diff / 3600000)}小时前`;
}
else {
const month = date.getMonth() + 1;
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
return `${month}${day}${hour}:${minute < 10 ? '0' + minute : minute}`;
}
},
// 显示错误消息
showError(message) {
this.setData({
errorMessage: message,
successMessage: ''
});
// 3秒后自动清除
setTimeout(() => {
this.setData({
errorMessage: ''
});
}, 3000);
},
// 显示成功消息
showSuccess(message) {
this.setData({
successMessage: message,
errorMessage: ''
});
// 3秒后自动清除
setTimeout(() => {
this.setData({
successMessage: ''
});
}, 3000);
},
// 清除消息
clearMessage() {
this.setData({
errorMessage: '',
successMessage: ''
});
},
// 返回上一页
goBack() {
wx.navigateBack();
}
});

202
dist/pages/staff/profile.js vendored Normal file
View File

@@ -0,0 +1,202 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const userService_1 = __importDefault(require("../../services/userService"));
const statisticsService_1 = __importDefault(require("../../services/statisticsService"));
Page({
data: {
userInfo: null,
// 个人统计数据
personalStats: {
totalOrders: 0, // 总订单数
completedOrders: 0, // 已完成订单数
pendingOrders: 0, // 待处理订单数
deliveryRate: 0, // 配送成功率
averageTime: 0 // 平均配送时间
},
// 系统统计数据
systemStats: {
employeeCount: 0, // 员工总数
orderCount: 0, // 订单总数
warehouseCount: 0 // 仓库总数
},
loading: true
},
onLoad() {
this.loadUserInfo();
this.loadStatistics();
},
onShow() {
// 页面显示时重新加载数据
this.loadUserInfo();
this.loadStatistics();
},
/**
* 加载用户信息
*/
async loadUserInfo() {
try {
const app = getApp();
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo
});
}
else {
// 如果没有全局用户信息尝试从API获取
const userInfo = await userService_1.default.getUserInfo();
this.setData({ userInfo });
}
}
catch (error) {
console.error('加载用户信息失败:', error);
wx.showToast({
title: '加载用户信息失败',
icon: 'none'
});
}
},
/**
* 加载统计数据
*/
async loadStatistics() {
this.setData({ loading: true });
try {
wx.showLoading({
title: '加载统计数据...'
});
// 强制刷新统计数据,不使用缓存
const systemStats = await statisticsService_1.default.getSystemStats(true);
// 获取个人统计数据这里需要根据用户ID获取个人统计数据
const personalStats = await this.getPersonalStats();
this.setData({
systemStats: {
employeeCount: systemStats.employeeCount,
orderCount: systemStats.orderCount,
warehouseCount: systemStats.warehouseCount
},
personalStats,
loading: false
});
wx.hideLoading();
}
catch (error) {
console.error('加载统计数据失败:', error);
this.setData({ loading: false });
wx.hideLoading();
wx.showToast({
title: '加载统计数据失败',
icon: 'none'
});
}
},
/**
* 获取个人统计数据
*/
async getPersonalStats() {
try {
// 这里应该调用个人统计API
// 暂时使用模拟数据
return {
totalOrders: 156,
completedOrders: 142,
pendingOrders: 14,
deliveryRate: 91.0,
averageTime: 45
};
}
catch (error) {
console.error('获取个人统计数据失败:', error);
// 返回默认值
return {
totalOrders: 0,
completedOrders: 0,
pendingOrders: 0,
deliveryRate: 0,
averageTime: 0
};
}
},
/**
* 刷新数据
*/
onRefresh() {
this.loadStatistics();
},
/**
* 返回上一页
*/
goBack() {
wx.navigateBack();
},
/**
* 编辑个人信息
*/
onEditProfile() {
wx.showToast({
title: '编辑功能开发中',
icon: 'none'
});
},
/**
* 查看历史订单
*/
onViewHistory() {
wx.navigateTo({
url: '/pages/staff/order-management'
});
},
/**
* 联系客服
*/
onContactSupport() {
wx.makePhoneCall({
phoneNumber: '400-123-4567'
});
},
/**
* 退出登录
*/
onLogout() {
wx.showModal({
title: '确认退出',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
this.performLogout();
}
}
});
},
/**
* 执行退出登录操作
*/
async performLogout() {
try {
wx.showLoading({
title: '退出中...'
});
// 调用用户服务的退出登录方法
const userService = require('../../services/userService').default;
await userService.logout();
// 清除全局用户信息
const app = getApp();
app.globalData.userInfo = null;
wx.hideLoading();
// 跳转到首页
wx.reLaunch({
url: '/pages/index/index'
});
}
catch (error) {
console.error('退出登录失败:', error);
wx.hideLoading();
wx.showToast({
title: '退出登录失败',
icon: 'none'
});
}
}
});

73
dist/pages/staff/staff.js vendored Normal file
View File

@@ -0,0 +1,73 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Page({
data: {
userInfo: null,
isAdmin: false,
loading: true
},
onLoad() {
// 获取用户信息
this.getUserInfo();
},
onShow() {
// 页面显示时重新获取用户信息
this.getUserInfo();
},
/**
* 获取用户信息并判断角色
*/
getUserInfo() {
this.setData({ loading: true });
// 从全局数据获取用户信息
const app = getApp();
if (app.globalData.userInfo) {
const userInfo = app.globalData.userInfo;
const isAdmin = userInfo.role === 'ADMIN';
this.setData({
userInfo,
isAdmin,
loading: false
});
// 根据角色自动跳转到对应界面
this.redirectToRolePage();
}
else {
// 如果没有用户信息,跳转到登录页面
wx.redirectTo({
url: '/pages/index/index'
});
}
},
/**
* 根据用户角色跳转到对应页面
*/
redirectToRolePage() {
const { isAdmin } = this.data;
if (isAdmin) {
// 管理员跳转到管理员界面
wx.redirectTo({
url: '/pages/staff/admin-dashboard'
});
}
else {
// 员工跳转到员工界面
wx.redirectTo({
url: '/pages/staff/employee-dashboard'
});
}
},
/**
* 手动选择界面(用于测试或特殊情况)
*/
goToAdminPage() {
wx.redirectTo({
url: '/pages/staff/admin-dashboard'
});
},
goToEmployeePage() {
wx.redirectTo({
url: '/pages/staff/employee-dashboard'
});
}
});

480
dist/pages/staff/warehouse-management.js vendored Normal file
View File

@@ -0,0 +1,480 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// 仓库管理页面 - 处理仓库的增删改查和库存管理
const helpers_1 = require("../../utils/helpers");
const warehouseService_1 = __importDefault(require("../../services/warehouseService"));
Page({
data: {
// 仓库列表
warehouses: [],
filteredWarehouses: [],
// 页面状态
currentTab: 'list', // list: 列表页, add: 添加页, edit: 编辑页
loading: false,
// 添加仓库表单数据
addForm: {
name: '',
address: '',
contact: '',
phone: '',
description: '',
capacity: 500,
longitude: 102.833722,
latitude: 24.880095
},
// 编辑仓库表单数据
editForm: {
id: 0,
name: '',
address: '',
contact: '',
phone: '',
description: '',
capacity: 500,
longitude: 102.833722,
latitude: 24.880095,
status: 'open'
},
// 错误信息
errorMessage: '',
successMessage: '',
// 搜索关键词
searchKeyword: '',
// 用户信息
userInfo: null
},
onLoad() {
this.loadWarehouses();
},
onShow() {
// 只在页面显示时检查是否需要刷新数据,避免频繁请求
if (this.data.warehouses.length === 0) {
this.loadWarehouses();
}
},
// 加载仓库列表
async loadWarehouses() {
this.setData({
loading: true,
errorMessage: ''
});
try {
const warehouses = await warehouseService_1.default.getWarehouses();
this.setData({
warehouses,
filteredWarehouses: warehouses,
loading: false
});
}
catch (error) {
console.error('加载仓库列表失败:', error);
this.setData({
loading: false,
errorMessage: '加载仓库列表失败,请重试'
});
}
},
// 切换标签页
switchTab(e) {
const tab = e.currentTarget.dataset.tab;
this.setData({
currentTab: tab
});
},
// 搜索仓库
onSearchInput(e) {
const keyword = e.detail.value.trim();
this.setData({
searchKeyword: keyword
});
this.filterWarehouses(keyword);
},
// 过滤仓库列表
filterWarehouses(keyword) {
const { warehouses } = this.data;
if (!keyword) {
this.setData({
filteredWarehouses: warehouses
});
return;
}
const filtered = warehouses.filter(warehouse => warehouse.name.includes(keyword) ||
warehouse.address.includes(keyword) ||
warehouse.contact?.includes(keyword) ||
warehouse.phone?.includes(keyword));
this.setData({
filteredWarehouses: filtered
});
},
// 表单输入处理
onNameInput(e) {
this.setData({
'addForm.name': e.detail.value
});
},
onAddressInput(e) {
this.setData({
'addForm.address': e.detail.value
});
},
onContactInput(e) {
this.setData({
'addForm.contact': e.detail.value
});
},
onPhoneInput(e) {
this.setData({
'addForm.phone': e.detail.value
});
},
onDescriptionInput(e) {
this.setData({
'addForm.description': e.detail.value
});
},
onCapacityInput(e) {
this.setData({
'addForm.capacity': parseInt(e.detail.value) || 500
});
},
// 经度输入处理
onLongitudeInput(e) {
const value = parseFloat(e.detail.value) || 0;
this.setData({
'addForm.longitude': value
});
},
// 纬度输入处理
onLatitudeInput(e) {
const value = parseFloat(e.detail.value) || 0;
this.setData({
'addForm.latitude': value
});
},
// 地图选点功能
pickLocationFromMap() {
console.log('开始地图选点...');
wx.chooseLocation({
success: (res) => {
console.log('地图选点成功:', res);
if (res.longitude && res.latitude) {
console.log('更新表单数据 - 经度:', res.longitude, '纬度:', res.latitude);
this.setData({
'addForm.longitude': res.longitude,
'addForm.latitude': res.latitude
});
console.log('表单数据更新后:', this.data.addForm);
wx.showToast({
title: '位置已选择',
icon: 'success'
});
}
},
fail: (error) => {
console.error('地图选点失败:', error);
wx.showToast({
title: '选点失败,请重试',
icon: 'none'
});
}
});
},
// 验证表单
validateForm() {
const { name, address, contact, phone } = this.data.addForm;
if (!name.trim()) {
this.setData({
errorMessage: '请输入仓库名称'
});
return false;
}
if (!address.trim()) {
this.setData({
errorMessage: '请输入仓库地址'
});
return false;
}
if (!contact?.trim()) {
this.setData({
errorMessage: '请输入联系人'
});
return false;
}
if (!phone?.trim()) {
this.setData({
errorMessage: '请输入联系电话'
});
return false;
}
return true;
},
// 提交添加仓库表单
async submitAddForm() {
this.setData({
errorMessage: '',
successMessage: ''
});
if (!this.validateForm()) {
return;
}
this.setData({
loading: true
});
try {
await warehouseService_1.default.createWarehouse(this.data.addForm);
this.setData({
loading: false,
successMessage: '仓库添加成功',
currentTab: 'list'
});
// 重置表单
this.resetForm();
// 重新加载仓库列表
this.loadWarehouses();
(0, helpers_1.showToast)('仓库添加成功');
}
catch (error) {
console.error('添加仓库失败:', error);
this.setData({
loading: false,
errorMessage: '添加仓库失败,请重试'
});
}
},
// 重置表单
resetForm() {
this.setData({
addForm: {
name: '',
address: '',
contact: '',
phone: '',
description: '',
capacity: 500,
longitude: 102.833722,
latitude: 24.880095
}
});
},
// 取消编辑
cancelEdit() {
this.setData({
currentTab: 'list',
errorMessage: '',
successMessage: ''
});
},
// 编辑表单输入处理
onEditNameInput(e) {
this.setData({
'editForm.name': e.detail.value
});
},
onEditAddressInput(e) {
this.setData({
'editForm.address': e.detail.value
});
},
onEditContactInput(e) {
this.setData({
'editForm.contact': e.detail.value
});
},
onEditPhoneInput(e) {
this.setData({
'editForm.phone': e.detail.value
});
},
onEditDescriptionInput(e) {
this.setData({
'editForm.description': e.detail.value
});
},
onEditCapacityInput(e) {
this.setData({
'editForm.capacity': parseInt(e.detail.value) || 500
});
},
onEditLongitudeInput(e) {
this.setData({
'editForm.longitude': parseFloat(e.detail.value) || 102.833722
});
},
onEditLatitudeInput(e) {
this.setData({
'editForm.latitude': parseFloat(e.detail.value) || 24.880095
});
},
onEditStatusChange(e) {
this.setData({
'editForm.status': e.detail.value
});
},
// 编辑仓库
editWarehouse(e) {
const warehouseId = e.currentTarget.dataset.id;
const warehouse = this.data.warehouses.find(w => w.id === warehouseId);
if (warehouse) {
this.setData({
editForm: {
id: warehouse.id || 0,
name: warehouse.name || '',
address: warehouse.address || '',
contact: warehouse.contact || '',
phone: warehouse.phone || '',
description: warehouse.description || '',
capacity: warehouse.capacity || 500,
longitude: warehouse.longitude || 102.833722,
latitude: warehouse.latitude || 24.880095,
status: warehouse.status || 'open'
},
currentTab: 'edit'
});
}
},
// 提交编辑仓库表单
async submitEditForm() {
this.setData({
errorMessage: '',
successMessage: ''
});
if (!this.validateEditForm()) {
return;
}
this.setData({
loading: true
});
try {
// 使用updateWarehouse更新仓库信息
await warehouseService_1.default.updateWarehouse(this.data.editForm.id, this.data.editForm);
this.setData({
loading: false,
successMessage: '仓库更新成功',
currentTab: 'list'
});
// 重新加载仓库列表
this.loadWarehouses();
(0, helpers_1.showToast)('仓库更新成功');
}
catch (error) {
console.error('更新仓库失败:', error);
this.setData({
loading: false,
errorMessage: '更新仓库失败,请重试'
});
}
},
// 验证编辑表单
validateEditForm() {
const { name, address, contact, phone } = this.data.editForm;
if (!name.trim()) {
this.setData({
errorMessage: '请输入仓库名称'
});
return false;
}
if (!address.trim()) {
this.setData({
errorMessage: '请输入仓库地址'
});
return false;
}
if (!contact?.trim()) {
this.setData({
errorMessage: '请输入联系人'
});
return false;
}
if (!phone?.trim()) {
this.setData({
errorMessage: '请输入联系电话'
});
return false;
}
return true;
},
// 删除仓库
async deleteWarehouse(e) {
const warehouseId = e.currentTarget.dataset.id;
const warehouseName = e.currentTarget.dataset.name;
wx.showModal({
title: '确认删除',
content: `确定要删除仓库"${warehouseName}"吗?此操作不可恢复。`,
confirmText: '删除',
confirmColor: '#ff4757',
cancelText: '取消',
success: async (res) => {
if (res.confirm) {
try {
await warehouseService_1.default.deleteWarehouse(warehouseId);
(0, helpers_1.showToast)('仓库删除成功');
// 重新加载仓库列表
this.loadWarehouses();
}
catch (error) {
console.error('删除仓库失败:', error);
(0, helpers_1.showToast)('删除仓库失败');
}
}
}
});
},
// 获取仓库状态文本
getWarehouseStatusText(status) {
const statusMap = {
'open': '营业中',
'closed': '已关闭',
'maintenance': '维护中'
};
return statusMap[status || 'open'] || '未知状态';
},
// 获取仓库库存状态
getWarehouseInventoryStatus(currentStock, capacity) {
const percentage = (currentStock / capacity) * 100;
if (percentage >= 90)
return '库存充足';
if (percentage >= 60)
return '库存正常';
if (percentage >= 30)
return '库存偏低';
return '库存不足';
},
// 获取库存状态对应的颜色
getInventoryStatusColor(currentStock, capacity) {
const percentage = (currentStock / capacity) * 100;
if (percentage >= 90)
return '#52c41a'; // 绿色
if (percentage >= 60)
return '#1890ff'; // 蓝色
if (percentage >= 30)
return '#faad14'; // 橙色
return '#f5222d'; // 红色
},
// 下拉刷新
onPullDownRefresh() {
this.loadWarehouses().finally(() => {
wx.stopPullDownRefresh();
});
},
// 清除错误信息
clearError() {
this.setData({
errorMessage: ''
});
},
// 清除成功信息
clearSuccess() {
this.setData({
successMessage: ''
});
},
/**
* 返回上一页
*/
goBack() {
wx.navigateBack();
}
});