地址路径修改
This commit is contained in:
472
dist/pages/index/index.js
vendored
Normal file
472
dist/pages/index/index.js
vendored
Normal file
@@ -0,0 +1,472 @@
|
||||
"use strict";
|
||||
// index.ts
|
||||
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 mainPageModule_1 = require("./modules/mainPageModule");
|
||||
// 主页面组件
|
||||
Component({
|
||||
data: {
|
||||
longitude: 116.397428,
|
||||
latitude: 39.90923,
|
||||
scale: 16,
|
||||
markers: [],
|
||||
userInfo: null,
|
||||
authStatus: {
|
||||
hasWxCode: false,
|
||||
userStatus: 'unknown'
|
||||
},
|
||||
showUserPanel: false,
|
||||
showOrderPanel: false,
|
||||
currentOrder: null,
|
||||
currentDeliveryPerson: null,
|
||||
currentWarehouse: null,
|
||||
currentPanelPosition: { x: 0, y: 0 },
|
||||
polyline: null,
|
||||
pendingOrders: [],
|
||||
currentRoute: null,
|
||||
showRoute: false,
|
||||
routeDistance: 0,
|
||||
routeDuration: 0,
|
||||
showWarehouseModal: false,
|
||||
showDeliveryPersonModal: false,
|
||||
warehouseModalState: 'bottom',
|
||||
deliveryPersonModalState: 'bottom',
|
||||
showSignOutButton: false,
|
||||
showSignInButton: false,
|
||||
showRegisterButton: false,
|
||||
showAuthButton: true,
|
||||
// mainPageModule: null as MainPageModule | null
|
||||
},
|
||||
lifetimes: {
|
||||
attached() {
|
||||
console.log('index page attached');
|
||||
this.initPage();
|
||||
},
|
||||
detached() {
|
||||
console.log('index page detached');
|
||||
// 清理资源
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.cleanup();
|
||||
}
|
||||
},
|
||||
// show() {
|
||||
// console.log('index page show');
|
||||
// // 页面显示时调用主页面模块的onShow方法
|
||||
// if (this.data.mainPageModule) {
|
||||
// this.data.mainPageModule.onShow();
|
||||
// }
|
||||
// },
|
||||
// hide() {
|
||||
// console.log('index page hide');
|
||||
// // 页面隐藏时调用主页面模块的onHide方法
|
||||
// if (this.data.mainPageModule) {
|
||||
// this.data.mainPageModule.onHide();
|
||||
// }
|
||||
// }
|
||||
},
|
||||
methods: {
|
||||
// 处理货运人员底部弹窗关闭
|
||||
onDeliveryPersonModalClose() {
|
||||
this.setData({
|
||||
showDeliveryPersonModal: false
|
||||
});
|
||||
},
|
||||
// 处理仓库底部弹窗关闭
|
||||
onWarehouseModalClose() {
|
||||
this.setData({
|
||||
showWarehouseModal: false
|
||||
});
|
||||
},
|
||||
// 初始化页面
|
||||
async initPage() {
|
||||
// 初始化主页面模块
|
||||
this.setData({
|
||||
mainPageModule: new mainPageModule_1.MainPageModule(this)
|
||||
});
|
||||
// 异步检查登录状态
|
||||
await this.checkAndUpdateLoginStatus();
|
||||
},
|
||||
// 异步检查并更新登录状态
|
||||
async checkAndUpdateLoginStatus() {
|
||||
try {
|
||||
// 获取登录模块
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
// 显示加载状态
|
||||
wx.showLoading({
|
||||
title: '检查登录状态...',
|
||||
mask: true
|
||||
});
|
||||
// 异步检查登录状态
|
||||
const isLoggedIn = await this.asyncCheckLoginStatus(loginModule);
|
||||
if (isLoggedIn) {
|
||||
// 已登录状态 - 按钮状态会在refreshPageAfterLogin中统一更新
|
||||
console.log('✅ 登录检查成功,等待统一页面刷新');
|
||||
}
|
||||
else {
|
||||
// 未登录状态
|
||||
this.setData({
|
||||
userInfo: null,
|
||||
'authStatus.hasWxCode': false,
|
||||
'authStatus.userStatus': 'unknown',
|
||||
// 初始化按钮显示状态
|
||||
showSignInButton: false,
|
||||
showRegisterButton: false,
|
||||
showAuthButton: true
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('检查登录状态失败:', error);
|
||||
// 出错时设置为未登录状态
|
||||
this.setData({
|
||||
userInfo: null,
|
||||
'authStatus.hasWxCode': false,
|
||||
'authStatus.userStatus': 'unknown',
|
||||
showSignInButton: false,
|
||||
showRegisterButton: false,
|
||||
showAuthButton: true
|
||||
});
|
||||
console.log('❌ 登录检查失败,重置为未登录状态');
|
||||
console.log(' - authStatus.hasWxCode 设置为 false');
|
||||
console.log(' - showRegisterButton 设置为 false');
|
||||
}
|
||||
finally {
|
||||
wx.hideLoading();
|
||||
}
|
||||
},
|
||||
// 异步检查登录状态
|
||||
async asyncCheckLoginStatus(loginModule) {
|
||||
getApp();
|
||||
const app = getApp();
|
||||
// 首先检查本地是否有登录状态
|
||||
if (app.globalData.isLoggedIn && app.globalData.userInfo) {
|
||||
// 本地已有登录状态,此时可以安全获取用户状态(因为有token)
|
||||
const userStatus = await loginModule.determineUserStatus(app.globalData.userInfo);
|
||||
// 更新页面状态
|
||||
this.setData({
|
||||
userInfo: app.globalData.userInfo,
|
||||
'authStatus.hasWxCode': true,
|
||||
'authStatus.userStatus': userStatus
|
||||
});
|
||||
console.log('✅ 使用本地登录状态,用户状态已更新:', userStatus);
|
||||
// 登录成功后统一刷新页面
|
||||
this.refreshPageAfterLogin();
|
||||
return true;
|
||||
}
|
||||
// 如果本地没有登录状态,尝试执行静默登录
|
||||
try {
|
||||
const loginResult = await userService_1.default.wxLogin();
|
||||
if (loginResult.success && loginResult.userInfo) {
|
||||
const app = getApp();
|
||||
// 登录成功,更新全局用户信息
|
||||
app.globalData.userInfo = loginResult.userInfo;
|
||||
app.globalData.isLoggedIn = true;
|
||||
// 登录成功后,此时已经有token,可以安全获取用户状态
|
||||
const userStatus = await loginModule.determineUserStatus(loginResult.userInfo);
|
||||
// 更新页面状态
|
||||
this.setData({
|
||||
userInfo: loginResult.userInfo,
|
||||
'authStatus.hasWxCode': true,
|
||||
'authStatus.userStatus': userStatus
|
||||
});
|
||||
console.log('✅ 静默登录成功,用户状态已更新:', userStatus);
|
||||
// === 全局登录流程完成,登录成功 ===
|
||||
// 统一在此处执行一次完整的页面刷新
|
||||
this.refreshPageAfterLogin();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.warn('静默登录失败:', error);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
// 更新按钮显示状态
|
||||
updateButtonDisplayStatus() {
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
const showSignInButton = loginModule.shouldShowSignInButton();
|
||||
const showRegisterButton = loginModule.shouldShowRegisterButton();
|
||||
// 签退按钮显示逻辑:已签到用户显示签退按钮
|
||||
const showSignOutButton = this.data.authStatus && this.data.authStatus.userStatus === 'signed_in';
|
||||
console.log('🔄 更新按钮显示状态:');
|
||||
console.log(' - showSignInButton:', showSignInButton);
|
||||
console.log(' - showRegisterButton:', showRegisterButton);
|
||||
console.log(' - showSignOutButton:', showSignOutButton);
|
||||
console.log(' - 当前用户状态:', this.data.authStatus ? this.data.authStatus.userStatus : 'undefined');
|
||||
console.log(' - 当前hasWxCode:', this.data.authStatus ? this.data.authStatus.hasWxCode : 'undefined');
|
||||
this.setData({
|
||||
showSignInButton,
|
||||
showRegisterButton,
|
||||
showSignOutButton
|
||||
});
|
||||
console.log('✅ 按钮状态已更新到页面');
|
||||
},
|
||||
// 登录成功后统一刷新页面
|
||||
async refreshPageAfterLogin() {
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
getApp();
|
||||
console.log('🔄 === 全局登录流程完成,执行统一页面刷新 ===');
|
||||
// 1. 更新页面登录状态
|
||||
const app = getApp();
|
||||
loginModule.updatePageAfterLogin(app.globalData.userInfo);
|
||||
// 2. 更新按钮显示状态
|
||||
this.updateButtonDisplayStatus();
|
||||
// 3. 初始化主页面模块
|
||||
await this.data.mainPageModule.onLoad();
|
||||
// 4. 登录成功后只加载公开数据(仓库等),不加载业务数据
|
||||
// 业务数据(员工位置等)只有在用户签到后才应该加载
|
||||
if (app.globalData.isLoggedIn && this.data.authStatus.userStatus === 'signed_in') {
|
||||
console.log('🔍 登录成功,开始加载公开数据...');
|
||||
await this.data.mainPageModule.loadPublicData();
|
||||
console.log('✅ 公开数据加载完成');
|
||||
}
|
||||
console.log('✅ 统一页面刷新完成');
|
||||
},
|
||||
// 处理仓库底部弹窗状态变化
|
||||
onWarehouseModalStateChange(e) {
|
||||
const state = e.detail.state;
|
||||
this.setData({ warehouseModalState: state });
|
||||
},
|
||||
// 处理货运人员底部弹窗状态变化
|
||||
onDeliveryPersonModalStateChange(e) {
|
||||
const state = e.detail.state;
|
||||
this.setData({ deliveryPersonModalState: state });
|
||||
},
|
||||
// 处理签到 - 已迁移到LoginModule
|
||||
async handleSignIn() {
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
const success = await loginModule.handleSignIn();
|
||||
if (success) {
|
||||
// 更新按钮显示状态
|
||||
this.updateButtonDisplayStatus();
|
||||
// 刷新页面数据
|
||||
await this.data.mainPageModule.refreshAllData();
|
||||
}
|
||||
},
|
||||
// 处理授权登录 - 已迁移到LoginModule
|
||||
async handleAuthLogin() {
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
const success = await loginModule.handleAuthLogin();
|
||||
if (success) {
|
||||
const app = getApp();
|
||||
const userStatus = loginModule.determineUserStatus(app.globalData.userInfo);
|
||||
this.setData({
|
||||
userInfo: app.globalData.userInfo,
|
||||
'authStatus.hasWxCode': true,
|
||||
'authStatus.userStatus': userStatus
|
||||
});
|
||||
console.log('✅ 手动登录成功,authStatus.hasWxCode 设置为 true');
|
||||
console.log('✅ 用户状态已更新:', userStatus);
|
||||
// === 全局登录流程完成,登录成功 ===
|
||||
// 统一在此处执行一次完整的页面刷新
|
||||
this.refreshPageAfterLogin();
|
||||
}
|
||||
},
|
||||
// 处理签退 - 已迁移到LoginModule
|
||||
async handleSignOut() {
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
const success = await loginModule.handleSignOut();
|
||||
if (success) {
|
||||
// 更新按钮显示状态
|
||||
this.updateButtonDisplayStatus();
|
||||
// 刷新页面数据
|
||||
await this.data.mainPageModule.refreshAllData();
|
||||
}
|
||||
},
|
||||
// 处理绑定按钮点击
|
||||
handleRegister() {
|
||||
console.log('用户点击绑定按钮');
|
||||
// 跳转到绑定页面
|
||||
wx.navigateTo({
|
||||
url: '/pages/apply/apply'
|
||||
});
|
||||
},
|
||||
// 显示员工账号绑定表单 - 跳转到独立页面
|
||||
showApplyForm() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/apply/apply'
|
||||
});
|
||||
},
|
||||
// 跳转到管理员页面
|
||||
goToAdminPage() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/admin/admin'
|
||||
});
|
||||
},
|
||||
// 跳转到员工管理页面
|
||||
goToEmployeeManagement() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/employee/employee'
|
||||
});
|
||||
},
|
||||
// 阻止事件冒泡
|
||||
stopPropagation(e) {
|
||||
if (e && typeof e.stopPropagation === 'function') {
|
||||
e.stopPropagation();
|
||||
}
|
||||
},
|
||||
// 获取性别文本表示
|
||||
getGenderText(gender) {
|
||||
if (gender === 1)
|
||||
return '男';
|
||||
if (gender === 2)
|
||||
return '女';
|
||||
return '未知';
|
||||
},
|
||||
// 格式化坐标对
|
||||
formatCoordinatePair(longitude, latitude) {
|
||||
return `${longitude.toFixed(6)}, ${latitude.toFixed(6)}`;
|
||||
},
|
||||
// 用户登出
|
||||
userLogout() {
|
||||
if (this.data.mainPageModule) {
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
loginModule.logout();
|
||||
// 更新页面状态
|
||||
this.setData({
|
||||
isLoggedIn: false,
|
||||
userInfo: null
|
||||
});
|
||||
// 更新按钮显示状态
|
||||
this.updateButtonDisplayStatus();
|
||||
}
|
||||
},
|
||||
// 显示用户面板
|
||||
showUserPanel() {
|
||||
this.setData({ showUserPanel: true });
|
||||
},
|
||||
// 跳转到管理界面(基于用户角色)
|
||||
goToManagementPage() {
|
||||
if (this.data.userInfo && this.data.userInfo.role) {
|
||||
if (this.data.userInfo.role === 'ADMIN') {
|
||||
// 管理员跳转到管理员界面 - 使用navigateTo保持当前页面状态
|
||||
wx.navigateTo({
|
||||
url: '/pages/staff/admin-dashboard'
|
||||
});
|
||||
}
|
||||
else {
|
||||
// 员工跳转到员工界面 - 使用navigateTo保持当前页面状态
|
||||
wx.navigateTo({
|
||||
url: '/pages/staff/employee-dashboard'
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 未登录用户显示用户面板
|
||||
this.setData({ showUserPanel: true });
|
||||
}
|
||||
},
|
||||
// 隐藏用户面板
|
||||
hideUserPanel() {
|
||||
this.setData({ showUserPanel: false });
|
||||
},
|
||||
// 隐藏所有面板
|
||||
hideAllPanels() {
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.hideAllPanels();
|
||||
}
|
||||
},
|
||||
// 重置标记点状态
|
||||
resetMarkers() {
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.resetMarkers();
|
||||
}
|
||||
},
|
||||
// 地图点击事件
|
||||
onMapTap(e) {
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.onMapTap(e);
|
||||
}
|
||||
},
|
||||
// 标记点点击事件
|
||||
onMarkerTap(e) {
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.onMarkerTap(e);
|
||||
}
|
||||
},
|
||||
// 分配订单
|
||||
async assignOrder(orderId, deliveryPersonId) {
|
||||
if (this.data.mainPageModule) {
|
||||
const orderModule = this.data.mainPageModule.getOrderModule();
|
||||
await orderModule.assignOrder(orderId, deliveryPersonId);
|
||||
}
|
||||
},
|
||||
// 更新订单状态
|
||||
async updateOrderStatus(orderId, status) {
|
||||
if (this.data.mainPageModule) {
|
||||
const orderModule = this.data.mainPageModule.getOrderModule();
|
||||
await orderModule.updateOrderStatus(orderId, status);
|
||||
}
|
||||
},
|
||||
// 展开仓库面板
|
||||
expandWarehousePanel() {
|
||||
if (this.data.mainPageModule) {
|
||||
const warehouseModule = this.data.mainPageModule.getWarehouseModule();
|
||||
warehouseModule.expandWarehousePanel();
|
||||
}
|
||||
},
|
||||
// 收起仓库面板
|
||||
collapseWarehousePanel() {
|
||||
if (this.data.mainPageModule) {
|
||||
const warehouseModule = this.data.mainPageModule.getWarehouseModule();
|
||||
warehouseModule.collapseWarehousePanel();
|
||||
}
|
||||
},
|
||||
// 展开员工面板
|
||||
expandDeliveryPersonPanel() {
|
||||
if (this.data.mainPageModule) {
|
||||
const employeeModule = this.data.mainPageModule.getEmployeeModule();
|
||||
employeeModule.expandDeliveryPersonPanel();
|
||||
}
|
||||
},
|
||||
// 收起员工面板
|
||||
collapseDeliveryPersonPanel() {
|
||||
if (this.data.mainPageModule) {
|
||||
const employeeModule = this.data.mainPageModule.getEmployeeModule();
|
||||
employeeModule.collapseDeliveryPersonPanel();
|
||||
}
|
||||
},
|
||||
// 刷新所有数据
|
||||
async refreshAllData() {
|
||||
if (this.data.mainPageModule) {
|
||||
await this.data.mainPageModule.refreshAllData();
|
||||
}
|
||||
},
|
||||
// 开始定位(处理地图控制按钮点击)
|
||||
async startLocation() {
|
||||
if (this.data.mainPageModule) {
|
||||
const mapModule = this.data.mainPageModule.getMapModule();
|
||||
await mapModule.startLocation();
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
59
dist/pages/index/modules/adminModule.js
vendored
Normal file
59
dist/pages/index/modules/adminModule.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
// 管理员模块 - 专门处理管理员相关功能
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AdminModule = void 0;
|
||||
class AdminModule {
|
||||
constructor(_pageContext, dataModule) {
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
/**
|
||||
* 处理管理员标记点点击
|
||||
*/
|
||||
onAdminMarkerClick(admin, position) {
|
||||
console.log('管理员被点击:', admin);
|
||||
// 显示管理员详情面板
|
||||
this.showAdminPanel(admin, position);
|
||||
}
|
||||
/**
|
||||
* 显示管理员详情面板
|
||||
*/
|
||||
showAdminPanel(admin, _position) {
|
||||
console.log('显示管理员详情面板:', admin);
|
||||
// 设置当前管理员
|
||||
this.dataModule.setCurrentDeliveryPerson(admin);
|
||||
// 显示面板
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'bottom');
|
||||
}
|
||||
/**
|
||||
* 隐藏管理员详情面板
|
||||
*/
|
||||
hideAdminPanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(false);
|
||||
this.dataModule.setCurrentDeliveryPerson(null);
|
||||
}
|
||||
/**
|
||||
* 展开管理员详情面板
|
||||
*/
|
||||
expandAdminPanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'full');
|
||||
}
|
||||
/**
|
||||
* 收起管理员详情面板
|
||||
*/
|
||||
collapseAdminPanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'bottom');
|
||||
}
|
||||
/**
|
||||
* 获取管理员信息摘要
|
||||
*/
|
||||
getAdminSummary(admin) {
|
||||
return `${admin.name || '管理员'} - ${admin.role || 'ADMIN'}`;
|
||||
}
|
||||
/**
|
||||
* 清理资源
|
||||
*/
|
||||
cleanup() {
|
||||
console.log('清理管理员模块资源');
|
||||
}
|
||||
}
|
||||
exports.AdminModule = AdminModule;
|
||||
254
dist/pages/index/modules/dataModule.js
vendored
Normal file
254
dist/pages/index/modules/dataModule.js
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DataModule = void 0;
|
||||
/**
|
||||
* 页面数据管理模块
|
||||
* 负责管理index页面的所有数据状态
|
||||
*/
|
||||
class DataModule {
|
||||
constructor(pageContext) {
|
||||
this.pageContext = pageContext;
|
||||
}
|
||||
/**
|
||||
* 初始化页面数据
|
||||
*/
|
||||
async initializeData() {
|
||||
// 检查是否已静默登录,如果是则尝试获取真实位置
|
||||
let initialLongitude = 102.833722;
|
||||
let initialLatitude = 24.880095;
|
||||
const app = getApp();
|
||||
if (app.globalData.isLoggedIn) {
|
||||
try {
|
||||
// 导入地图服务
|
||||
const mapService = require('../../../services/mapService').default;
|
||||
const location = await mapService.getCurrentLocation();
|
||||
if (location && !isNaN(location.latitude) && !isNaN(location.longitude)) {
|
||||
initialLongitude = location.longitude;
|
||||
initialLatitude = location.latitude;
|
||||
console.log('[DATA MODULE] 静默登录后使用真实位置:', location);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.warn('[DATA MODULE] 获取真实位置失败,使用默认位置:', error);
|
||||
}
|
||||
}
|
||||
this.pageContext.setData({
|
||||
// 地图相关数据
|
||||
longitude: initialLongitude,
|
||||
latitude: initialLatitude,
|
||||
scale: 13,
|
||||
markers: [],
|
||||
polyline: null,
|
||||
showRoute: false,
|
||||
routeDistance: 0,
|
||||
routeDuration: 0,
|
||||
currentRoute: null,
|
||||
// 用户相关数据
|
||||
userInfo: null,
|
||||
isLoggedIn: false,
|
||||
showUserPanel: false,
|
||||
// 订单相关数据
|
||||
pendingOrders: [],
|
||||
showOrderPanel: false,
|
||||
currentOrder: null,
|
||||
// 货运人员相关数据
|
||||
showDeliveryPersonModal: false,
|
||||
deliveryPersonModalState: 'bottom',
|
||||
currentDeliveryPerson: null,
|
||||
// 仓库相关数据
|
||||
showWarehouseModal: false,
|
||||
warehouseModalState: 'bottom',
|
||||
currentWarehouse: null,
|
||||
// 面板位置数据
|
||||
currentPanelPosition: { x: 0, y: 0 },
|
||||
// 对话框相关数据
|
||||
showNickNameDialog: false,
|
||||
tempNickName: ''
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
updateUserInfo(userInfo) {
|
||||
this.pageContext.setData({
|
||||
userInfo,
|
||||
isLoggedIn: !!userInfo
|
||||
});
|
||||
// 更新按钮显示状态
|
||||
if (this.pageContext.updateButtonDisplayStatus) {
|
||||
this.pageContext.updateButtonDisplayStatus();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置登录状态
|
||||
*/
|
||||
setLoginStatus(isLoggedIn) {
|
||||
this.pageContext.setData({
|
||||
isLoggedIn
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 设置地图缩放级别
|
||||
*/
|
||||
setMapScale(scale) {
|
||||
this.pageContext.setData({
|
||||
scale
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 更新用户位置信息
|
||||
*/
|
||||
updateUserLocation(latitude, longitude) {
|
||||
this.pageContext.setData({
|
||||
latitude,
|
||||
longitude
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 更新地图标记点
|
||||
*/
|
||||
updateMarkers(markers) {
|
||||
// 验证每个标记点的坐标
|
||||
const validatedMarkers = markers.map((marker) => {
|
||||
// 检查经纬度是否为有效数字
|
||||
if (isNaN(marker.longitude) || isNaN(marker.latitude)) {
|
||||
// 为无效坐标设置默认值
|
||||
return {
|
||||
...marker,
|
||||
longitude: 102.833722, // 默认经度
|
||||
latitude: 24.880095 // 默认纬度
|
||||
};
|
||||
}
|
||||
else {
|
||||
return marker;
|
||||
}
|
||||
});
|
||||
// 执行更新
|
||||
this.pageContext.setData({ markers: validatedMarkers });
|
||||
}
|
||||
/**
|
||||
* 更新待分配订单列表
|
||||
*/
|
||||
updatePendingOrders(orders) {
|
||||
this.pageContext.setData({ pendingOrders: orders });
|
||||
}
|
||||
/**
|
||||
* 设置当前选中订单
|
||||
*/
|
||||
setCurrentOrder(order) {
|
||||
this.pageContext.setData({ currentOrder: order });
|
||||
}
|
||||
/**
|
||||
* 设置当前选中货运人员
|
||||
*/
|
||||
setCurrentDeliveryPerson(person) {
|
||||
this.pageContext.setData({ currentDeliveryPerson: person });
|
||||
}
|
||||
/**
|
||||
* 设置当前选中仓库
|
||||
*/
|
||||
setCurrentWarehouse(warehouse) {
|
||||
this.pageContext.setData({ currentWarehouse: warehouse });
|
||||
}
|
||||
/**
|
||||
* 设置面板位置
|
||||
*/
|
||||
setPanelPosition(position) {
|
||||
this.pageContext.setData({ currentPanelPosition: position });
|
||||
}
|
||||
/**
|
||||
* 显示/隐藏用户面板
|
||||
*/
|
||||
toggleUserPanel(show) {
|
||||
this.pageContext.setData({ showUserPanel: show });
|
||||
}
|
||||
/**
|
||||
* 显示/隐藏订单面板
|
||||
*/
|
||||
toggleOrderPanel(show) {
|
||||
this.pageContext.setData({ showOrderPanel: show });
|
||||
}
|
||||
/**
|
||||
* 显示/隐藏仓库弹窗
|
||||
*/
|
||||
toggleWarehouseModal(show, state = 'bottom') {
|
||||
this.pageContext.setData({
|
||||
showWarehouseModal: show,
|
||||
warehouseModalState: state
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 显示/隐藏货运人员弹窗
|
||||
*/
|
||||
toggleDeliveryPersonModal(show, state = 'bottom') {
|
||||
this.pageContext.setData({
|
||||
showDeliveryPersonModal: show,
|
||||
deliveryPersonModalState: state
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 显示/隐藏昵称修改对话框
|
||||
*/
|
||||
toggleNickNameDialog(show, tempNickName = '') {
|
||||
this.pageContext.setData({
|
||||
showNickNameDialog: show,
|
||||
tempNickName
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 更新路线信息
|
||||
*/
|
||||
updateRouteInfo(polyline, distance, duration) {
|
||||
this.pageContext.setData({
|
||||
polyline,
|
||||
routeDistance: distance,
|
||||
routeDuration: duration,
|
||||
showRoute: true
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 清除路线信息
|
||||
*/
|
||||
clearRouteInfo() {
|
||||
this.pageContext.setData({
|
||||
polyline: null,
|
||||
showRoute: false,
|
||||
routeDistance: 0,
|
||||
routeDuration: 0,
|
||||
currentRoute: null
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取当前数据状态
|
||||
*/
|
||||
getData() {
|
||||
return this.pageContext.data;
|
||||
}
|
||||
/**
|
||||
* 重置所有数据到初始状态
|
||||
*/
|
||||
resetAllData() {
|
||||
this.initializeData();
|
||||
}
|
||||
/**
|
||||
* 获取位置模块(用于其他模块访问位置模块)
|
||||
*/
|
||||
getLocationModule() {
|
||||
// 通过页面上下文获取位置模块
|
||||
if (this.pageContext.data.mainPageModule) {
|
||||
return this.pageContext.data.mainPageModule.getLocationModule();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 获取地图模块(用于其他模块访问地图模块)
|
||||
*/
|
||||
getMapModule() {
|
||||
// 通过页面上下文获取地图模块
|
||||
if (this.pageContext.data.mainPageModule) {
|
||||
return this.pageContext.data.mainPageModule.getMapModule();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.DataModule = DataModule;
|
||||
108
dist/pages/index/modules/deliveryPersonModule.js
vendored
Normal file
108
dist/pages/index/modules/deliveryPersonModule.js
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
"use strict";
|
||||
// 货运人员模块 - 专门处理货运人员相关功能
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DeliveryPersonModule = void 0;
|
||||
class DeliveryPersonModule {
|
||||
constructor(_pageContext, dataModule) {
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
/**
|
||||
* 处理货运人员标记点点击
|
||||
*/
|
||||
onDeliveryPersonMarkerClick(deliveryPerson, position) {
|
||||
console.log('货运人员被点击:', deliveryPerson);
|
||||
// 显示货运人员详情面板(包含订单列表)
|
||||
this.showDeliveryPersonPanel(deliveryPerson, position);
|
||||
}
|
||||
/**
|
||||
* 显示货运人员详情面板
|
||||
*/
|
||||
showDeliveryPersonPanel(deliveryPerson, _position) {
|
||||
console.log('显示货运人员详情面板:', deliveryPerson);
|
||||
// 设置当前货运人员
|
||||
this.dataModule.setCurrentDeliveryPerson(deliveryPerson);
|
||||
// 显示面板
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'bottom');
|
||||
}
|
||||
/**
|
||||
* 隐藏货运人员详情面板
|
||||
*/
|
||||
hideDeliveryPersonPanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(false);
|
||||
this.dataModule.setCurrentDeliveryPerson(null);
|
||||
}
|
||||
/**
|
||||
* 展开货运人员详情面板
|
||||
*/
|
||||
expandDeliveryPersonPanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'full');
|
||||
}
|
||||
/**
|
||||
* 收起货运人员详情面板
|
||||
*/
|
||||
collapseDeliveryPersonPanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'bottom');
|
||||
}
|
||||
/**
|
||||
* 获取货运人员信息摘要
|
||||
*/
|
||||
getDeliveryPersonSummary(deliveryPerson) {
|
||||
return `${deliveryPerson.name || '货运人员'} - ${deliveryPerson.role || 'DRIVER'}`;
|
||||
}
|
||||
/**
|
||||
* 获取货运人员状态文本
|
||||
*/
|
||||
getDeliveryPersonStatusText(status) {
|
||||
const statusMap = {
|
||||
'idle': '空闲',
|
||||
'busy': '忙碌',
|
||||
'offline': '离线'
|
||||
};
|
||||
return statusMap[status] || status;
|
||||
}
|
||||
/**
|
||||
* 获取货运人员状态颜色
|
||||
*/
|
||||
getDeliveryPersonStatusColor(status) {
|
||||
switch (status) {
|
||||
case 'idle':
|
||||
return '#52c41a'; // 绿色
|
||||
case 'busy':
|
||||
return '#faad14'; // 橙色
|
||||
case 'offline':
|
||||
return '#d9d9d9'; // 灰色
|
||||
default:
|
||||
return '#d9d9d9'; // 灰色
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取货运人员当前订单信息
|
||||
*/
|
||||
getCurrentOrderInfo(person) {
|
||||
if (!person.currentOrder) {
|
||||
return '暂无订单';
|
||||
}
|
||||
const order = person.currentOrder;
|
||||
return `订单 #${order.id} - ${this.getOrderStatusText(order.status)}`;
|
||||
}
|
||||
/**
|
||||
* 获取订单状态文本
|
||||
*/
|
||||
getOrderStatusText(status) {
|
||||
const statusMap = {
|
||||
'pending': '未分配',
|
||||
'assigned': '已分配',
|
||||
'in_transit': '配送中',
|
||||
'delivered': '已完成',
|
||||
'cancelled': '已取消'
|
||||
};
|
||||
return statusMap[status] || status;
|
||||
}
|
||||
/**
|
||||
* 清理资源
|
||||
*/
|
||||
cleanup() {
|
||||
console.log('清理货运人员模块资源');
|
||||
}
|
||||
}
|
||||
exports.DeliveryPersonModule = DeliveryPersonModule;
|
||||
81
dist/pages/index/modules/employeeModule.js
vendored
Normal file
81
dist/pages/index/modules/employeeModule.js
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EmployeeModule = void 0;
|
||||
const employeeService_1 = __importDefault(require("../../../services/employeeService"));
|
||||
class EmployeeModule {
|
||||
constructor(_pageContext, dataModule) {
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
/**
|
||||
* 处理员工标记点点击 - 通用处理逻辑
|
||||
*/
|
||||
onEmployeeMarkerClick(employee, _position) {
|
||||
console.log('员工被点击:', employee);
|
||||
// 设置当前员工
|
||||
this.dataModule.setCurrentDeliveryPerson(employee);
|
||||
// 显示面板
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'bottom');
|
||||
}
|
||||
/**
|
||||
* 隐藏员工详情面板
|
||||
*/
|
||||
hideEmployeePanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(false);
|
||||
this.dataModule.setCurrentDeliveryPerson(null);
|
||||
}
|
||||
/**
|
||||
* 展开员工详情面板
|
||||
*/
|
||||
expandEmployeePanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'full');
|
||||
}
|
||||
/**
|
||||
* 收起员工详情面板
|
||||
*/
|
||||
collapseEmployeePanel() {
|
||||
this.dataModule.toggleDeliveryPersonModal(true, 'bottom');
|
||||
}
|
||||
/**
|
||||
* 获取员工信息摘要
|
||||
*/
|
||||
getEmployeeSummary(employee) {
|
||||
return `${employee.name || '员工'} - ${employee.role || '未知角色'}`;
|
||||
}
|
||||
/**
|
||||
* 获取员工状态文本
|
||||
*/
|
||||
getEmployeeStatusText(status) {
|
||||
const statusMap = {
|
||||
'idle': '空闲',
|
||||
'busy': '忙碌',
|
||||
'offline': '离线'
|
||||
};
|
||||
return statusMap[status] || status;
|
||||
}
|
||||
/**
|
||||
* 加载所有员工数据
|
||||
*/
|
||||
async loadAllEmployees() {
|
||||
try {
|
||||
console.log('开始加载所有员工数据');
|
||||
const employees = await employeeService_1.default.getEmployees();
|
||||
console.log('员工数据加载完成:', employees);
|
||||
// 这里可以添加员工数据处理逻辑,比如更新到dataModule
|
||||
// this.dataModule.updateEmployees(employees);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('加载员工数据失败:', error);
|
||||
throw error; // 重新抛出错误,让调用方处理
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 清理资源
|
||||
*/
|
||||
cleanup() {
|
||||
console.log('清理员工模块资源');
|
||||
}
|
||||
}
|
||||
exports.EmployeeModule = EmployeeModule;
|
||||
265
dist/pages/index/modules/locationModule.js
vendored
Normal file
265
dist/pages/index/modules/locationModule.js
vendored
Normal file
@@ -0,0 +1,265 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LocationModule = void 0;
|
||||
// 位置模块 - 处理位置追踪、位置更新和地图标记点更新
|
||||
const helpers_1 = require("../../../utils/helpers");
|
||||
const locationTrackingService_1 = __importDefault(require("../../../services/locationTrackingService"));
|
||||
class LocationModule {
|
||||
constructor(_pageContext, dataModule) {
|
||||
this.dataModule = dataModule;
|
||||
this.isTracking = false;
|
||||
}
|
||||
/**
|
||||
* 初始化位置模块
|
||||
*/
|
||||
async initialize() {
|
||||
console.log('位置模块初始化');
|
||||
// 注册位置更新回调,当位置追踪服务有更新时自动刷新地图标记
|
||||
this.setupLocationUpdateCallback();
|
||||
console.log('✅ 位置模块初始化完成');
|
||||
}
|
||||
/**
|
||||
* 设置位置更新回调
|
||||
*/
|
||||
setupLocationUpdateCallback() {
|
||||
console.log('📝 [LocationModule] 设置位置更新回调');
|
||||
// 注册位置更新回调
|
||||
locationTrackingService_1.default.subscribeToLocationUpdates(async (onlineUsers) => {
|
||||
console.log('🔔 [LocationModule] 收到位置更新通知');
|
||||
console.log('👥 [LocationModule] 在线用户数量:', onlineUsers.length);
|
||||
// 调用updateEmployeeMarkers方法更新地图标记
|
||||
try {
|
||||
await this.updateEmployeeMarkers(onlineUsers);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('更新员工标记点失败:', error);
|
||||
}
|
||||
});
|
||||
console.log('✅ [LocationModule] 位置更新回调设置完成');
|
||||
}
|
||||
/**
|
||||
* 清理位置模块
|
||||
*/
|
||||
cleanup() {
|
||||
console.log('清理位置模块');
|
||||
// 停止实时跟踪
|
||||
if (this.isTracking) {
|
||||
this.stopRealTimeTracking().catch(error => {
|
||||
console.error('停止实时跟踪失败:', error);
|
||||
});
|
||||
}
|
||||
console.log('✅ 位置模块清理完成');
|
||||
}
|
||||
/**
|
||||
* 开始实时跟踪位置
|
||||
*/
|
||||
async startRealTimeTracking() {
|
||||
try {
|
||||
// 获取当前用户信息
|
||||
const userInfo = this.dataModule.getData().userInfo;
|
||||
if (!userInfo || !userInfo.id) {
|
||||
throw new Error('用户信息获取失败');
|
||||
}
|
||||
// 启动位置跟踪订阅(WebSocket连接)
|
||||
await locationTrackingService_1.default.startTracking();
|
||||
this.isTracking = true;
|
||||
(0, helpers_1.showToast)('已开始实时跟踪');
|
||||
console.log('开始实时跟踪位置');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('开始实时跟踪失败:', error);
|
||||
(0, helpers_1.showToast)('开始实时跟踪失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 停止实时跟踪位置
|
||||
*/
|
||||
async stopRealTimeTracking() {
|
||||
try {
|
||||
// 获取当前用户信息
|
||||
const userInfo = this.dataModule.getData().userInfo;
|
||||
if (!userInfo || !userInfo.id) {
|
||||
throw new Error('用户信息获取失败');
|
||||
}
|
||||
// 停止位置跟踪
|
||||
await locationTrackingService_1.default.stopTracking();
|
||||
this.isTracking = false;
|
||||
(0, helpers_1.showToast)('已停止实时跟踪');
|
||||
console.log('停止实时跟踪位置');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('停止实时跟踪失败:', error);
|
||||
(0, helpers_1.showToast)('停止实时跟踪失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 更新员工标记点
|
||||
*/
|
||||
async updateEmployeeMarkers(onlineUsers) {
|
||||
console.log('📍 [LocationModule] 开始更新员工标记点');
|
||||
console.log('👥 [LocationModule] 传入用户数量:', onlineUsers.length);
|
||||
// 获取地图模块来更新标记点
|
||||
const mapModule = this.dataModule.getMapModule();
|
||||
if (!mapModule) {
|
||||
console.error('地图模块未找到,无法更新员工标记点');
|
||||
return;
|
||||
}
|
||||
// 获取当前地图上的所有标记点
|
||||
const { markers } = this.dataModule.getData();
|
||||
const currentEmployeeMarkers = markers.filter((marker) => marker.type === 'employee');
|
||||
console.log('🗺️ [LocationModule] 当前地图上员工标记点数量:', currentEmployeeMarkers.length);
|
||||
// 为每个在线用户创建标记点
|
||||
const newEmployeeMarkers = await Promise.all(onlineUsers.map(async (user, index) => {
|
||||
console.log(`🔍 [LocationModule] 处理第 ${index + 1} 个用户:`, user.userId || '未知ID');
|
||||
// 获取用户角色信息
|
||||
const userRole = user.role || this.getUserRole(user.userId);
|
||||
// 解析位置信息(支持多种格式)
|
||||
const longitude = user.longitude || (user.lastLocation && user.lastLocation.longitude) || 0;
|
||||
const latitude = user.latitude || (user.lastLocation && user.lastLocation.latitude) || 0;
|
||||
const lastUpdateTime = user.lastUpdateTime || Date.now();
|
||||
console.log(`📡 [LocationModule] 用户 ${index + 1} 位置: ${latitude}, ${longitude}`);
|
||||
console.log(`👤 [LocationModule] 用户 ${index + 1} 信息: ${user.userName || '未知用户'} (${userRole})`);
|
||||
// 获取员工图标
|
||||
const iconPath = await this.getEmployeeIcon(user.userId, userRole);
|
||||
const employeeMarker = {
|
||||
id: 10000 + user.userId, // 避免ID冲突
|
||||
type: 'employee',
|
||||
title: user.userName || `员工${user.userId}`,
|
||||
longitude: longitude,
|
||||
latitude: latitude,
|
||||
iconPath: iconPath,
|
||||
width: 32,
|
||||
height: 32,
|
||||
zIndex: 30,
|
||||
data: {
|
||||
userId: user.userId,
|
||||
role: userRole,
|
||||
lastUpdateTime: lastUpdateTime
|
||||
}
|
||||
};
|
||||
return employeeMarker;
|
||||
}));
|
||||
console.log('📍 [LocationModule] 新生成标记点数量:', newEmployeeMarkers.length);
|
||||
// 对比新旧标记点,精确更新
|
||||
this.updateMarkersPrecisely(mapModule, currentEmployeeMarkers, newEmployeeMarkers);
|
||||
console.log('✅ [LocationModule] 员工标记点更新完成');
|
||||
}
|
||||
/**
|
||||
* 精确更新标记点 - 通过对比新旧标记点来添加、更新和删除
|
||||
*/
|
||||
updateMarkersPrecisely(mapModule, currentMarkers, newMarkers) {
|
||||
console.log('🎯 [LocationModule] 开始精确更新标记点');
|
||||
// 创建用户ID到标记点的映射
|
||||
const currentMarkerMap = new Map();
|
||||
currentMarkers.forEach(marker => {
|
||||
if (marker.data && marker.data.userId) {
|
||||
currentMarkerMap.set(marker.data.userId, marker);
|
||||
}
|
||||
});
|
||||
const newMarkerMap = new Map();
|
||||
newMarkers.forEach(marker => {
|
||||
if (marker.data && marker.data.userId) {
|
||||
newMarkerMap.set(marker.data.userId, marker);
|
||||
}
|
||||
});
|
||||
console.log('📊 [LocationModule] 当前标记点用户ID:', Array.from(currentMarkerMap.keys()));
|
||||
console.log('📊 [LocationModule] 新标记点用户ID:', Array.from(newMarkerMap.keys()));
|
||||
// 找出需要删除的标记点(在当前但不在新的)
|
||||
const markersToRemove = currentMarkers.filter(marker => {
|
||||
if (marker.data && marker.data.userId) {
|
||||
return !newMarkerMap.has(marker.data.userId);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// 找出需要添加的标记点(在新的但不在当前的)
|
||||
const markersToAdd = newMarkers.filter(marker => {
|
||||
if (marker.data && marker.data.userId) {
|
||||
return !currentMarkerMap.has(marker.data.userId);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// 找出需要更新的标记点(位置或信息有变化)
|
||||
const markersToUpdate = newMarkers.filter(marker => {
|
||||
if (marker.data && marker.data.userId) {
|
||||
const currentMarker = currentMarkerMap.get(marker.data.userId);
|
||||
if (currentMarker) {
|
||||
// 检查位置是否变化
|
||||
return currentMarker.longitude !== marker.longitude ||
|
||||
currentMarker.latitude !== marker.latitude ||
|
||||
currentMarker.title !== marker.title ||
|
||||
currentMarker.iconPath !== marker.iconPath;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
console.log(`🗑️ [LocationModule] 需要删除的标记点数量: ${markersToRemove.length}`);
|
||||
console.log(`➕ [LocationModule] 需要添加的标记点数量: ${markersToAdd.length}`);
|
||||
console.log(`🔄 [LocationModule] 需要更新的标记点数量: ${markersToUpdate.length}`);
|
||||
// 执行删除操作
|
||||
markersToRemove.forEach(marker => {
|
||||
console.log(`🗑️ [LocationModule] 删除标记点: 用户 ${marker.data.userId}`);
|
||||
mapModule.removeEmployeeMarker(marker.id);
|
||||
});
|
||||
// 执行添加操作
|
||||
markersToAdd.forEach(marker => {
|
||||
console.log(`➕ [LocationModule] 添加标记点: 用户 ${marker.data.userId}`);
|
||||
mapModule.addEmployeeMarker(marker);
|
||||
});
|
||||
// 执行更新操作
|
||||
markersToUpdate.forEach(marker => {
|
||||
console.log(`🔄 [LocationModule] 更新标记点: 用户 ${marker.data.userId}`);
|
||||
mapModule.updateSingleEmployeeMarker(marker);
|
||||
});
|
||||
console.log('🎯 [LocationModule] 精确更新标记点完成');
|
||||
}
|
||||
/**
|
||||
* 获取用户角色
|
||||
*/
|
||||
getUserRole(userId) {
|
||||
// 从数据模块获取用户信息
|
||||
const userInfo = this.dataModule.getData().userInfo;
|
||||
if (userInfo && userInfo.id === userId) {
|
||||
return userInfo.role || 'employee';
|
||||
}
|
||||
// 如果是其他用户,默认为货运人员
|
||||
return 'employee';
|
||||
}
|
||||
/**
|
||||
* 获取员工图标
|
||||
*/
|
||||
async getEmployeeIcon(userId, userRole) {
|
||||
// 首先尝试获取用户头像URL
|
||||
const userInfo = this.dataModule.getData().userInfo;
|
||||
// 如果是当前用户,使用当前用户的头像
|
||||
if (userInfo && userInfo.id === userId && userInfo.avatarUrl) {
|
||||
return userInfo.avatarUrl;
|
||||
}
|
||||
// 对于其他用户,尝试从员工服务获取头像URL
|
||||
try {
|
||||
const employeeService = require('../../services/employeeService').default;
|
||||
const avatarUrl = await employeeService.getAvatarUrl(userId);
|
||||
if (avatarUrl) {
|
||||
return avatarUrl;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.warn(`获取用户 ${userId} 的头像失败:`, error);
|
||||
}
|
||||
// 如果获取头像失败,使用默认图标
|
||||
if (userRole === 'ADMIN') {
|
||||
return '/images/crown.png'; // 管理员图标
|
||||
}
|
||||
else if (userRole === 'DRIVER') {
|
||||
return '/images/truck.png'; // 司机图标
|
||||
}
|
||||
else {
|
||||
return '/images/truck.png'; // 普通员工也使用货运图标
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.LocationModule = LocationModule;
|
||||
482
dist/pages/index/modules/loginModule.js
vendored
Normal file
482
dist/pages/index/modules/loginModule.js
vendored
Normal file
@@ -0,0 +1,482 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LoginModule = void 0;
|
||||
// 登录模块 - 处理用户登录、授权、用户信息管理
|
||||
const helpers_1 = require("../../../utils/helpers");
|
||||
const userService_1 = __importDefault(require("../../../services/userService"));
|
||||
const locationTrackingService_1 = __importDefault(require("../../../services/locationTrackingService"));
|
||||
class LoginModule {
|
||||
constructor(pageContext, dataModule) {
|
||||
this.pageContext = pageContext;
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
/**
|
||||
* 处理用户信息
|
||||
*/
|
||||
async processUserInfo(userInfo) {
|
||||
// 直接返回用户信息,不进行额外处理
|
||||
return userInfo;
|
||||
}
|
||||
/**
|
||||
* 登录成功后更新页面状态
|
||||
*/
|
||||
updatePageAfterLogin(userInfo) {
|
||||
this.dataModule.updateUserInfo(userInfo);
|
||||
}
|
||||
/**
|
||||
* 检查登录状态
|
||||
*/
|
||||
checkLoginStatus() {
|
||||
const globalUserInfo = userService_1.default.getGlobalUserInfo();
|
||||
if (globalUserInfo) {
|
||||
this.dataModule.updateUserInfo(globalUserInfo);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 用户退出登录
|
||||
*/
|
||||
async logout() {
|
||||
try {
|
||||
// 停止位置追踪服务
|
||||
try {
|
||||
await locationTrackingService_1.default.stopTracking();
|
||||
console.log('位置追踪服务已停止');
|
||||
}
|
||||
catch (trackingError) {
|
||||
console.warn('停止位置追踪失败,但不影响退出登录:', trackingError);
|
||||
}
|
||||
// 注意:这里不调用userService.logout(),因为服务器端的logout接口会删除token
|
||||
// 而用户只是签退不接单,不是完全退出应用,需要保持token有效
|
||||
console.log('用户已退出登录(本地签退,保持token有效)');
|
||||
(0, helpers_1.showToast)('已退出登录');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('退出登录失败:', error);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 显示手动登录模态框:如果静默登录失败后,让用户尝试手动登录
|
||||
*/
|
||||
async showManualLoginModal() {
|
||||
console.log('显示手动登录模态框');
|
||||
return new Promise((resolve) => {
|
||||
wx.showModal({
|
||||
title: '手动登录',
|
||||
content: '静默登录失败,请手动登录以使用完整功能',
|
||||
confirmText: '手动登录',
|
||||
cancelText: '暂不',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
// 用户点击确定,执行手动登录
|
||||
console.log('用户选择手动登录');
|
||||
const success = await this.performLogin();
|
||||
if (!success) {
|
||||
// 登录失败,再次提供选项
|
||||
this.handleLoginFailure(resolve);
|
||||
}
|
||||
else {
|
||||
resolve(success);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 用户取消登录,显示关闭小程序选项
|
||||
console.log('用户选择暂不登录');
|
||||
this.showCloseAppOption(resolve);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 执行登录流程 - 调用userService的登录方法
|
||||
* 静默登录失败后,只专注于登录本身,不涉及绑定、签到等复杂逻辑
|
||||
*/
|
||||
async performLogin() {
|
||||
try {
|
||||
// 执行微信登录
|
||||
const result = await userService_1.default.wxLogin();
|
||||
if (result.success && result.userInfo) {
|
||||
// 登录成功,更新页面状态
|
||||
this.updatePageAfterLogin(result.userInfo);
|
||||
console.log('手动登录成功');
|
||||
return true;
|
||||
}
|
||||
console.log('手动登录失败');
|
||||
return false;
|
||||
}
|
||||
catch (error) {
|
||||
console.error('执行登录流程失败:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 处理登录失败的情况
|
||||
*/
|
||||
async handleLoginFailure(resolve) {
|
||||
console.log('登录失败,显示重试选项');
|
||||
wx.showModal({
|
||||
title: '登录失败',
|
||||
content: '登录遇到问题,是否重试?',
|
||||
confirmText: '重新登录',
|
||||
cancelText: '取消并关闭',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
console.log('用户选择重新登录');
|
||||
const success = await this.performLogin();
|
||||
if (!success) {
|
||||
// 再次登录失败,递归调用以避免嵌套过深
|
||||
this.handleLoginFailure(resolve);
|
||||
}
|
||||
else {
|
||||
resolve(success);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('用户选择取消并关闭小程序');
|
||||
wx.showToast({
|
||||
title: '即将退出小程序',
|
||||
icon: 'none',
|
||||
duration: 1500,
|
||||
complete: () => {
|
||||
setTimeout(() => {
|
||||
// 使用类型断言解决类型问题
|
||||
wx.exitMiniProgram();
|
||||
}, 1500);
|
||||
}
|
||||
});
|
||||
resolve(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 显示关闭小程序选项
|
||||
*/
|
||||
showCloseAppOption(resolve) {
|
||||
console.log('显示关闭小程序选项');
|
||||
wx.showModal({
|
||||
title: '确认退出',
|
||||
content: '不登录将无法使用完整功能,是否退出小程序?',
|
||||
confirmText: '退出小程序',
|
||||
cancelText: '留在页面',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
console.log('用户确认退出小程序');
|
||||
// 使用类型断言解决类型问题
|
||||
wx.exitMiniProgram();
|
||||
resolve(false);
|
||||
}
|
||||
else {
|
||||
console.log('用户选择留在页面');
|
||||
resolve(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 处理签退流程
|
||||
*/
|
||||
async handleSignOut() {
|
||||
try {
|
||||
// 显示加载中提示
|
||||
wx.showLoading({
|
||||
title: '签退中...',
|
||||
});
|
||||
// 调用签退接口
|
||||
const signOutResult = await userService_1.default.signOut();
|
||||
wx.hideLoading();
|
||||
if (signOutResult.success) {
|
||||
console.log('签退成功:', signOutResult);
|
||||
wx.showToast({
|
||||
title: '签退成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
// 停止位置追踪服务
|
||||
try {
|
||||
await locationTrackingService_1.default.stopTracking();
|
||||
console.log('位置追踪服务已停止');
|
||||
}
|
||||
catch (trackingError) {
|
||||
console.warn('停止位置追踪失败,但不影响签退:', trackingError);
|
||||
}
|
||||
// 设置用户状态为已签退
|
||||
if (this.pageContext && this.pageContext.setData) {
|
||||
this.pageContext.setData({
|
||||
'authStatus.userStatus': 'signed_out'
|
||||
});
|
||||
// 更新按钮显示状态
|
||||
if (this.pageContext.updateButtonDisplayStatus) {
|
||||
this.pageContext.updateButtonDisplayStatus();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
console.warn('签退失败:', signOutResult.message);
|
||||
wx.showToast({
|
||||
title: signOutResult.message || '签退失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('签退过程中发生错误:', error);
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '签退失败,请重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 处理签到流程
|
||||
*/
|
||||
async handleSignIn() {
|
||||
try {
|
||||
// 显示加载中提示
|
||||
wx.showLoading({
|
||||
title: '签到中...',
|
||||
});
|
||||
// 先获取地图位置和当前时间
|
||||
let initialLocation;
|
||||
try {
|
||||
const location = await locationTrackingService_1.default.getCurrentLocation();
|
||||
// 使用秒级时间戳(除以1000取整)
|
||||
initialLocation = {
|
||||
latitude: location.latitude,
|
||||
longitude: location.longitude,
|
||||
timestamp: Math.floor(Date.now() / 1000)
|
||||
};
|
||||
console.log('获取到签到位置数据:', initialLocation);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取位置失败:', error);
|
||||
throw new Error('获取位置失败,请检查位置权限设置');
|
||||
}
|
||||
// 调用实际的签到接口,传递位置数据
|
||||
const signInResult = await userService_1.default.signIn(initialLocation);
|
||||
wx.hideLoading();
|
||||
if (signInResult.success) {
|
||||
console.log('签到成功:', signInResult);
|
||||
wx.showToast({
|
||||
title: '签到成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
// 更新用户信息
|
||||
if (signInResult.employeeInfo) {
|
||||
// 将员工信息合并到用户信息中
|
||||
const app = getApp();
|
||||
if (app.globalData.userInfo) {
|
||||
app.globalData.userInfo = {
|
||||
...app.globalData.userInfo,
|
||||
name: signInResult.employeeInfo.name,
|
||||
phone: signInResult.employeeInfo.phone
|
||||
};
|
||||
this.updatePageAfterLogin(app.globalData.userInfo);
|
||||
}
|
||||
}
|
||||
// 设置用户状态为已签到
|
||||
if (this.pageContext && this.pageContext.setData) {
|
||||
this.pageContext.setData({
|
||||
'authStatus.userStatus': 'signed_in'
|
||||
});
|
||||
// 更新按钮显示状态
|
||||
if (this.pageContext.updateButtonDisplayStatus) {
|
||||
this.pageContext.updateButtonDisplayStatus();
|
||||
}
|
||||
}
|
||||
// 启动位置追踪服务(WebSocket连接)
|
||||
try {
|
||||
// 启动位置追踪服务(建立WebSocket连接)
|
||||
await locationTrackingService_1.default.startTracking();
|
||||
console.log('位置追踪服务已启动');
|
||||
}
|
||||
catch (trackingError) {
|
||||
console.warn('启动位置追踪失败,但不影响签到:', trackingError);
|
||||
}
|
||||
// 加载业务数据(所有登录用户)
|
||||
try {
|
||||
console.log('用户签到成功,开始加载业务数据');
|
||||
// 获取主页面模块并加载业务数据
|
||||
const mainPageModule = this.pageContext.data.mainPageModule;
|
||||
if (mainPageModule && mainPageModule.loadBusinessData) {
|
||||
await mainPageModule.loadBusinessData();
|
||||
console.log('业务数据加载完成');
|
||||
}
|
||||
}
|
||||
catch (businessError) {
|
||||
console.warn('加载业务数据失败,但不影响签到:', businessError);
|
||||
}
|
||||
// 如果是管理员用户,加载员工数据
|
||||
if (signInResult.employeeInfo && signInResult.employeeInfo.role === 'ADMIN') {
|
||||
try {
|
||||
console.log('管理员用户签到成功,开始加载员工数据');
|
||||
// 获取主页面模块并加载员工数据
|
||||
const mainPageModule = this.pageContext.data.mainPageModule;
|
||||
if (mainPageModule && mainPageModule.loadEmployeeData) {
|
||||
await mainPageModule.loadEmployeeData();
|
||||
console.log('员工数据加载完成');
|
||||
}
|
||||
}
|
||||
catch (employeeError) {
|
||||
console.warn('加载员工数据失败,但不影响签到:', employeeError);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
console.warn('签到失败:', signInResult.message);
|
||||
wx.showToast({
|
||||
title: signInResult.message || '签到失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('签到过程中发生错误:', error);
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '签到失败,请重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 处理授权登录流程
|
||||
*/
|
||||
async handleAuthLogin() {
|
||||
try {
|
||||
const success = await this.showManualLoginModal();
|
||||
if (success) {
|
||||
console.log('手动登录成功');
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
console.log('用户取消手动登录');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('手动登录过程中发生错误:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 判断用户是否为游客(已登录但信息不完整)
|
||||
*/
|
||||
isTourist() {
|
||||
const app = getApp();
|
||||
// 游客定义:已登录但没有完善基本信息(姓名和电话)的用户
|
||||
if (app.globalData.isLoggedIn && app.globalData.userInfo) {
|
||||
const userInfo = app.globalData.userInfo;
|
||||
return !userInfo.name || !userInfo.phone;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 计算是否显示签到按钮(基于用户状态和角色)
|
||||
*/
|
||||
shouldShowSignInButton() {
|
||||
// 从页面上下文中获取数据
|
||||
const pageData = this.dataModule.getData();
|
||||
const authStatus = pageData.authStatus || {};
|
||||
const userInfo = pageData.userInfo;
|
||||
// 显示条件:已获取微信code、用户状态不是已签到、且用户不是游客(已绑定用户)
|
||||
const result = (authStatus.hasWxCode &&
|
||||
(authStatus.userStatus === 'registered' || authStatus.userStatus === 'signed_out') &&
|
||||
userInfo !== null &&
|
||||
userInfo.role !== 'GUEST');
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 计算是否显示注册按钮(基于用户状态和角色)
|
||||
*/
|
||||
shouldShowRegisterButton() {
|
||||
// 从页面上下文中获取数据
|
||||
const pageData = this.dataModule.getData();
|
||||
const authStatus = pageData.authStatus || {};
|
||||
const userInfo = pageData.userInfo;
|
||||
// 显示条件:已获取微信code、用户状态为未绑定、且用户是游客
|
||||
const result = (authStatus.hasWxCode &&
|
||||
authStatus.userStatus === 'unregistered' &&
|
||||
userInfo !== null &&
|
||||
userInfo.role === 'GUEST');
|
||||
// 调试信息已删除
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 根据用户信息确定用户状态(从服务器获取真实状态)
|
||||
*/
|
||||
async determineUserStatus(userInfo) {
|
||||
if (!userInfo)
|
||||
return 'signed_out';
|
||||
try {
|
||||
// 从服务器获取用户真实状态
|
||||
const serverStatus = await this.getUserStatusFromServer();
|
||||
if (serverStatus) {
|
||||
console.log('从服务器获取的用户状态:', serverStatus);
|
||||
return serverStatus;
|
||||
}
|
||||
// 如果服务器获取失败,使用本地逻辑作为降级方案
|
||||
console.warn('服务器状态获取失败,使用本地逻辑判断');
|
||||
const isRegistered = userInfo.name && userInfo.phone;
|
||||
return isRegistered ? 'registered' : 'unregistered';
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取用户状态失败:', error);
|
||||
// 网络错误时使用本地逻辑
|
||||
const isRegistered = userInfo.name && userInfo.phone;
|
||||
return isRegistered ? 'registered' : 'unregistered';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 从服务器获取用户签到状态
|
||||
*/
|
||||
async getUserStatusFromServer() {
|
||||
try {
|
||||
// 调用服务器接口获取用户状态
|
||||
const response = await userService_1.default.getUserStatus();
|
||||
// 如果返回null,表示服务器接口不存在
|
||||
if (response === null) {
|
||||
console.log('服务器状态接口不存在,跳过服务器状态获取');
|
||||
return null;
|
||||
}
|
||||
if (response && response.status) {
|
||||
// 根据服务器返回的状态映射到前端状态
|
||||
switch (response.status) {
|
||||
case 'signed_in':
|
||||
return 'signed_in';
|
||||
case 'signed_out':
|
||||
return 'signed_out';
|
||||
case 'registered':
|
||||
return 'registered';
|
||||
case 'unregistered':
|
||||
return 'unregistered';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取服务器状态失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.LoginModule = LoginModule;
|
||||
330
dist/pages/index/modules/mainPageModule.js
vendored
Normal file
330
dist/pages/index/modules/mainPageModule.js
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MainPageModule = void 0;
|
||||
// 主页面模块 - 协调各个子模块,处理页面生命周期和事件分发
|
||||
const loginModule_1 = require("./loginModule");
|
||||
const mapModule_1 = require("./mapModule");
|
||||
const orderModule_1 = require("./orderModule");
|
||||
const warehouseModule_1 = require("./warehouseModule");
|
||||
const employeeModule_1 = require("./employeeModule");
|
||||
const adminModule_1 = require("./adminModule");
|
||||
const deliveryPersonModule_1 = require("./deliveryPersonModule");
|
||||
const locationModule_1 = require("./locationModule");
|
||||
const dataModule_1 = require("./dataModule");
|
||||
const helpers_1 = require("../../../utils/helpers");
|
||||
class MainPageModule {
|
||||
constructor(pageContext) {
|
||||
this.pageContext = pageContext;
|
||||
// 初始化各个子模块
|
||||
this.dataModule = new dataModule_1.DataModule(pageContext);
|
||||
this.loginModule = new loginModule_1.LoginModule(pageContext, this.dataModule);
|
||||
this.mapModule = new mapModule_1.MapModule(pageContext, this.dataModule);
|
||||
this.orderModule = new orderModule_1.OrderModule(pageContext, this.dataModule);
|
||||
this.warehouseModule = new warehouseModule_1.WarehouseModule(pageContext, this.dataModule);
|
||||
this.employeeModule = new employeeModule_1.EmployeeModule(this.pageContext, this.dataModule);
|
||||
this.adminModule = new adminModule_1.AdminModule(this.pageContext, this.dataModule);
|
||||
this.deliveryPersonModule = new deliveryPersonModule_1.DeliveryPersonModule(this.pageContext, this.dataModule);
|
||||
this.locationModule = new locationModule_1.LocationModule(pageContext, this.dataModule);
|
||||
}
|
||||
/**
|
||||
* 页面初始化
|
||||
*/
|
||||
async onLoad() {
|
||||
console.log('主页面模块初始化');
|
||||
try {
|
||||
// 初始化应用
|
||||
await this.initApp();
|
||||
// 初始化位置模块
|
||||
await this.locationModule.initialize();
|
||||
// 加载地图数据
|
||||
await this.loadAllData();
|
||||
console.log('主页面初始化完成');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('页面初始化失败:', error);
|
||||
(0, helpers_1.showToast)('页面初始化失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 页面显示
|
||||
*/
|
||||
onShow() {
|
||||
console.log('主页面显示');
|
||||
// 检查是否需要刷新数据
|
||||
this.refreshDataIfNeeded();
|
||||
}
|
||||
/**
|
||||
* 页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
console.log('主页面隐藏');
|
||||
// 清理位置模块
|
||||
this.locationModule.cleanup();
|
||||
}
|
||||
/**
|
||||
* 初始化应用
|
||||
*/
|
||||
async initApp() {
|
||||
// 初始化数据
|
||||
await this.dataModule.initializeData();
|
||||
console.log('应用初始化');
|
||||
}
|
||||
/**
|
||||
* 加载所有数据
|
||||
*/
|
||||
async loadAllData() {
|
||||
try {
|
||||
// 初始化地图
|
||||
await this.mapModule.initMap();
|
||||
// 加载公开数据(不需要登录)
|
||||
await this.loadPublicData();
|
||||
// 业务数据(订单和员工数据)在用户签到后单独加载
|
||||
console.log('公开数据加载完成,业务数据将在用户签到后加载');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('加载数据失败:', error);
|
||||
(0, helpers_1.showToast)('数据加载失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 加载公开数据(不需要登录)
|
||||
*/
|
||||
async loadPublicData() {
|
||||
console.log('加载公开数据');
|
||||
try {
|
||||
// 加载仓库数据(公开数据,不需要登录)
|
||||
await this.warehouseModule.loadWarehouses();
|
||||
console.log('公开数据加载完成');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('加载公开数据失败:', error);
|
||||
// 公开数据加载失败不影响主要功能,只记录日志
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 加载业务数据(仅在用户签到后调用)
|
||||
*/
|
||||
async loadBusinessData() {
|
||||
console.log('加载业务数据');
|
||||
try {
|
||||
// 加载待处理订单(所有登录用户都可以看到)
|
||||
await this.orderModule.loadPendingOrders();
|
||||
console.log('业务数据加载完成');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('加载业务数据失败:', error);
|
||||
throw error; // 重新抛出错误,让调用方处理
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 加载员工数据(仅在管理员签到后调用)
|
||||
*/
|
||||
async loadEmployeeData() {
|
||||
console.log('加载员工数据');
|
||||
try {
|
||||
// 获取用户信息
|
||||
const app = getApp();
|
||||
const userInfo = app.globalData.userInfo;
|
||||
// 只有管理员才加载员工列表
|
||||
if (userInfo && userInfo.role === 'ADMIN') {
|
||||
console.log('管理员用户,加载员工列表');
|
||||
await this.employeeModule.loadAllEmployees();
|
||||
console.log('员工数据加载完成');
|
||||
}
|
||||
else {
|
||||
console.log('非管理员用户,跳过员工列表加载');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('加载员工数据失败:', error);
|
||||
throw error; // 重新抛出错误,让调用方处理
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检查是否需要刷新数据
|
||||
*/
|
||||
refreshDataIfNeeded() {
|
||||
// 这里可以添加数据刷新逻辑
|
||||
// 例如:检查上次刷新时间,如果超过一定时间则重新加载数据
|
||||
console.log('检查数据刷新');
|
||||
}
|
||||
/**
|
||||
* 处理登出
|
||||
*/
|
||||
onLogout() {
|
||||
console.log('用户登出');
|
||||
// 清除业务数据
|
||||
this.clearBusinessData();
|
||||
// 重置用户标记点图标
|
||||
this.resetUserMarker();
|
||||
(0, helpers_1.showToast)('已登出');
|
||||
}
|
||||
/**
|
||||
* 清除业务数据
|
||||
*/
|
||||
clearBusinessData() {
|
||||
this.dataModule.updatePendingOrders([]);
|
||||
const filteredMarkers = this.pageContext.data.markers.filter((marker) => marker.type !== 'warehouse' && marker.type !== 'employee');
|
||||
this.dataModule.updateMarkers(filteredMarkers);
|
||||
}
|
||||
/**
|
||||
* 重置用户标记点
|
||||
*/
|
||||
resetUserMarker() {
|
||||
const { markers, userInfo } = this.pageContext.data;
|
||||
const userRole = userInfo?.role || 'employee';
|
||||
const iconPath = userRole === 'ADMIN' ? '/images/crown.png' : '/images/truck.png';
|
||||
const updatedMarkers = markers.map((marker) => {
|
||||
if (marker.id === -1) {
|
||||
return {
|
||||
...marker,
|
||||
iconPath: iconPath
|
||||
};
|
||||
}
|
||||
return marker;
|
||||
});
|
||||
this.dataModule.updateMarkers(updatedMarkers);
|
||||
}
|
||||
/**
|
||||
* 隐藏所有面板
|
||||
*/
|
||||
hideAllPanels() {
|
||||
this.dataModule.toggleUserPanel(false);
|
||||
this.dataModule.toggleOrderPanel(false);
|
||||
this.dataModule.toggleWarehouseModal(false);
|
||||
this.dataModule.toggleDeliveryPersonModal(false);
|
||||
}
|
||||
/**
|
||||
* 重置标记点状态
|
||||
*/
|
||||
resetMarkers() {
|
||||
// 这里可以添加标记点状态重置逻辑
|
||||
console.log('重置标记点状态');
|
||||
}
|
||||
/**
|
||||
* 分发地图点击事件
|
||||
*/
|
||||
onMapTap(e) {
|
||||
this.mapModule.onMapTap(e);
|
||||
}
|
||||
/**
|
||||
* 分发标记点点击事件
|
||||
*/
|
||||
onMarkerTap(e) {
|
||||
const markerId = e.markerId;
|
||||
const { markers } = this.pageContext.data;
|
||||
// 找到被点击的标记点
|
||||
const marker = markers.find((m) => m.id === markerId);
|
||||
if (!marker) {
|
||||
console.warn('未找到标记点:', markerId);
|
||||
return;
|
||||
}
|
||||
// 根据标记点类型分发到不同的模块
|
||||
switch (marker.type) {
|
||||
case 'warehouse':
|
||||
this.warehouseModule.onWarehouseMarkerClick(marker.data, e);
|
||||
break;
|
||||
case 'employee':
|
||||
// 员工标记点点击 - 根据角色分发到不同模块
|
||||
if (marker.data.role === 'ADMIN') {
|
||||
// 管理员 - 由adminModule处理
|
||||
this.adminModule.onAdminMarkerClick(marker.data, e);
|
||||
}
|
||||
else {
|
||||
// 货运人员 - 由deliveryPersonModule处理(包含订单列表)
|
||||
this.deliveryPersonModule.onDeliveryPersonMarkerClick(marker.data, e);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.mapModule.onMarkerTap(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取登录模块
|
||||
*/
|
||||
getLoginModule() {
|
||||
return this.loginModule;
|
||||
}
|
||||
/**
|
||||
* 获取地图模块
|
||||
*/
|
||||
getMapModule() {
|
||||
return this.mapModule;
|
||||
}
|
||||
/**
|
||||
* 获取订单模块
|
||||
*/
|
||||
getOrderModule() {
|
||||
return this.orderModule;
|
||||
}
|
||||
/**
|
||||
* 获取仓库模块
|
||||
*/
|
||||
getWarehouseModule() {
|
||||
return this.warehouseModule;
|
||||
}
|
||||
/**
|
||||
* 获取员工模块
|
||||
*/
|
||||
getEmployeeModule() {
|
||||
return this.employeeModule;
|
||||
}
|
||||
/**
|
||||
* 获取管理员模块
|
||||
*/
|
||||
getAdminModule() {
|
||||
return this.adminModule;
|
||||
}
|
||||
/**
|
||||
* 获取位置模块
|
||||
*/
|
||||
getLocationModule() {
|
||||
return this.locationModule;
|
||||
}
|
||||
/**
|
||||
* 刷新所有数据
|
||||
*/
|
||||
async refreshAllData() {
|
||||
console.log('刷新所有数据');
|
||||
try {
|
||||
// 刷新公开数据(不需要登录)
|
||||
await this.loadPublicData();
|
||||
// 检查是否已登录,只有已登录用户才能刷新业务数据
|
||||
const app = getApp();
|
||||
if (app.globalData.isLoggedIn) {
|
||||
await this.loadBusinessData();
|
||||
(0, helpers_1.showToast)('数据刷新成功');
|
||||
}
|
||||
else {
|
||||
console.log('用户未登录,无法刷新业务数据');
|
||||
(0, helpers_1.showToast)('公开数据已刷新,请登录以刷新业务数据');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('刷新数据失败:', error);
|
||||
(0, helpers_1.showToast)('刷新数据失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 清理资源
|
||||
*/
|
||||
cleanup() {
|
||||
console.log('清理主页面模块资源');
|
||||
// 清理位置模块
|
||||
this.locationModule.cleanup();
|
||||
// 清理员工和管理员模块
|
||||
this.employeeModule.cleanup();
|
||||
this.adminModule.cleanup();
|
||||
// 这里可以添加其他需要清理的资源
|
||||
console.log('✅ 主页面模块清理完成');
|
||||
}
|
||||
/**
|
||||
* 处理错误
|
||||
*/
|
||||
handleError(error, context) {
|
||||
console.error(`在 ${context} 中发生错误:`, error);
|
||||
(0, helpers_1.showToast)(`操作失败: ${context}`);
|
||||
}
|
||||
}
|
||||
exports.MainPageModule = MainPageModule;
|
||||
292
dist/pages/index/modules/mapModule.js
vendored
Normal file
292
dist/pages/index/modules/mapModule.js
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MapModule = void 0;
|
||||
// 地图模块 - 处理地图显示、定位、标记点管理
|
||||
const mapService_1 = __importDefault(require("../../../services/mapService"));
|
||||
const userService_1 = __importDefault(require("../../../services/userService"));
|
||||
const helpers_1 = require("../../../utils/helpers");
|
||||
class MapModule {
|
||||
constructor(pageContext, dataModule) {
|
||||
this.pageContext = pageContext;
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
/**
|
||||
* 初始化地图数据
|
||||
*/
|
||||
async initMap() {
|
||||
try {
|
||||
// 检查并请求位置权限
|
||||
await this.checkAndRequestLocationPermission();
|
||||
// 加载地图数据
|
||||
this.loadMapData();
|
||||
}
|
||||
catch (error) {
|
||||
console.error('初始化地图失败:', error);
|
||||
(0, helpers_1.showToast)('地图初始化失败,请重试');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检查并请求位置权限
|
||||
*/
|
||||
async checkAndRequestLocationPermission() {
|
||||
try {
|
||||
// 检查位置权限
|
||||
const hasPermission = await userService_1.default.checkLocationPermission();
|
||||
if (hasPermission) {
|
||||
// 已授权,开始定位
|
||||
await this.startLocation();
|
||||
}
|
||||
else {
|
||||
// 未授权,请求权限
|
||||
const permissionGranted = await userService_1.default.requestLocationPermission();
|
||||
if (permissionGranted) {
|
||||
await this.startLocation();
|
||||
}
|
||||
else {
|
||||
// 授权失败,使用默认位置
|
||||
this.setDefaultLocation();
|
||||
(0, helpers_1.showToast)('已使用默认位置');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('检查位置权限失败:', error);
|
||||
this.setDefaultLocation();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 开始定位
|
||||
*/
|
||||
async startLocation() {
|
||||
try {
|
||||
console.log('[MAP MODULE] 开始获取用户位置...');
|
||||
const location = await mapService_1.default.getCurrentLocation();
|
||||
console.log('[MAP MODULE] 获取位置成功,原始坐标:', location);
|
||||
console.log('[MAP MODULE] 详细位置信息:');
|
||||
console.log(`- 经度: ${location.longitude}`);
|
||||
console.log(`- 纬度: ${location.latitude}`);
|
||||
console.log(`- 精度: ${location.accuracy}`);
|
||||
console.log(`- 速度: ${location.speed}`);
|
||||
// 验证获取的坐标是否有效
|
||||
if (isNaN(location.latitude) || isNaN(location.longitude)) {
|
||||
console.error('[MAP MODULE] 获取的位置坐标无效:', location);
|
||||
this.setDefaultLocation();
|
||||
(0, helpers_1.showToast)('获取的位置无效,已使用默认位置');
|
||||
return;
|
||||
}
|
||||
// 强制重置地图视角到用户位置
|
||||
// 1. 更新用户位置
|
||||
this.dataModule.updateUserLocation(location.latitude, location.longitude);
|
||||
// 2. 重置地图缩放级别到15(详细级别)
|
||||
this.dataModule.setMapScale(15);
|
||||
// 3. 添加地图动画效果,让视角平滑回到用户位置
|
||||
this.animateMapToUserLocation(location.latitude, location.longitude);
|
||||
console.log('[MAP MODULE] 定位成功,坐标已更新,视角已重置:', location);
|
||||
(0, helpers_1.showToast)('已定位到您的位置');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('[MAP MODULE] 定位失败:', error);
|
||||
this.setDefaultLocation();
|
||||
(0, helpers_1.showToast)('定位失败,已使用默认位置');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置默认位置
|
||||
*/
|
||||
setDefaultLocation() {
|
||||
const defaultLatitude = 24.880095;
|
||||
const defaultLongitude = 102.833722;
|
||||
// 更新数据模块中的位置信息和缩放级别
|
||||
this.dataModule.updateUserLocation(defaultLatitude, defaultLongitude);
|
||||
this.dataModule.setMapScale(13);
|
||||
// 动画效果回到默认位置
|
||||
this.animateMapToUserLocation(defaultLatitude, defaultLongitude);
|
||||
console.log('[MAP MODULE] 默认位置设置完成');
|
||||
}
|
||||
/**
|
||||
* 动画效果将地图视角平滑移动到用户位置
|
||||
*/
|
||||
animateMapToUserLocation(latitude, longitude) {
|
||||
// 使用微信小程序的MapContext.moveToLocation方法实现地图移动
|
||||
const mapContext = wx.createMapContext('myMap', this.pageContext);
|
||||
// 先设置地图中心点
|
||||
this.pageContext.setData({
|
||||
latitude: latitude,
|
||||
longitude: longitude
|
||||
});
|
||||
// 使用moveToLocation方法平滑移动地图视角
|
||||
mapContext.moveToLocation({
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
success: () => {
|
||||
console.log('[MAP MODULE] 地图视角移动成功,位置:', { latitude, longitude });
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('[MAP MODULE] 地图视角移动失败:', err);
|
||||
// 如果moveToLocation失败,直接设置中心点
|
||||
this.pageContext.setData({
|
||||
latitude: latitude,
|
||||
longitude: longitude
|
||||
});
|
||||
}
|
||||
});
|
||||
console.log('[MAP MODULE] 地图视角动画已启动,移动到位置:', { latitude, longitude });
|
||||
}
|
||||
/**
|
||||
* 加载地图数据(仓库和货运人员)
|
||||
*/
|
||||
loadMapData() {
|
||||
// 这里会调用具体的服务来获取数据
|
||||
// 目前使用模拟数据
|
||||
const markers = this.generateInitialMarkers();
|
||||
// 更新数据模块中的标记点
|
||||
this.dataModule.updateMarkers(markers);
|
||||
console.log('地图数据加载完成');
|
||||
}
|
||||
/**
|
||||
* 生成初始标记点
|
||||
*/
|
||||
generateInitialMarkers() {
|
||||
console.log('生成初始标记点');
|
||||
const markers = [];
|
||||
// 地图自带用户位置显示功能,无需手动添加用户位置标记点
|
||||
return markers;
|
||||
}
|
||||
/**
|
||||
* 更新用户标记图标为用户头像
|
||||
* 注意:由于地图自带用户位置显示功能,此方法已不再需要
|
||||
*/
|
||||
updateUserMarkerIcon() {
|
||||
console.log('地图自带用户位置显示功能,无需更新用户标记图标');
|
||||
}
|
||||
/**
|
||||
* 更新员工标记点
|
||||
*/
|
||||
updateEmployeeMarkers(employeeMarkers) {
|
||||
console.log('开始更新员工标记点,数量:', employeeMarkers.length);
|
||||
const { markers } = this.pageContext.data;
|
||||
// 过滤掉现有的员工标记点
|
||||
const filteredMarkers = markers.filter((marker) => marker.type !== 'employee');
|
||||
// 合并标记点
|
||||
const updatedMarkers = [...filteredMarkers, ...employeeMarkers];
|
||||
// 更新数据模块中的标记点
|
||||
this.dataModule.updateMarkers(updatedMarkers);
|
||||
console.log('员工标记点更新完成,总标记点数量:', updatedMarkers.length);
|
||||
}
|
||||
/**
|
||||
* 清除所有员工标记点
|
||||
*/
|
||||
clearEmployeeMarkers() {
|
||||
console.log('开始清除所有员工标记点');
|
||||
const { markers } = this.pageContext.data;
|
||||
// 过滤掉员工标记点,只保留其他类型的标记点
|
||||
const filteredMarkers = markers.filter((marker) => marker.type !== 'employee');
|
||||
// 更新数据模块中的标记点
|
||||
this.dataModule.updateMarkers(filteredMarkers);
|
||||
console.log('员工标记点清除完成,剩余标记点数量:', filteredMarkers.length);
|
||||
}
|
||||
/**
|
||||
* 删除单个员工标记点
|
||||
*/
|
||||
removeEmployeeMarker(markerId) {
|
||||
console.log('删除单个员工标记点:', markerId);
|
||||
const { markers } = this.pageContext.data;
|
||||
// 只删除员工类型的标记点,避免误删其他类型标记点
|
||||
const filteredMarkers = markers.filter((marker) => !(marker.id === markerId && marker.type === 'employee'));
|
||||
// 检查是否真的删除了标记点
|
||||
const originalCount = markers.length;
|
||||
const newCount = filteredMarkers.length;
|
||||
if (originalCount === newCount) {
|
||||
console.warn('未找到员工标记点,可能标记点不存在或不是员工类型:', markerId);
|
||||
}
|
||||
else {
|
||||
console.log('成功删除员工标记点:', markerId);
|
||||
}
|
||||
// 更新数据模块中的标记点
|
||||
this.dataModule.updateMarkers(filteredMarkers);
|
||||
console.log('单个员工标记点删除完成,剩余标记点数量:', filteredMarkers.length);
|
||||
}
|
||||
/**
|
||||
* 添加单个员工标记点
|
||||
*/
|
||||
addEmployeeMarker(employeeMarker) {
|
||||
console.log('添加单个员工标记点:', employeeMarker.id);
|
||||
// 确保标记点类型为员工
|
||||
const markerWithType = {
|
||||
...employeeMarker,
|
||||
type: 'employee'
|
||||
};
|
||||
const { markers } = this.pageContext.data;
|
||||
// 检查是否已存在相同ID的标记点
|
||||
const existingIndex = markers.findIndex((marker) => marker.id === markerWithType.id && marker.type === 'employee');
|
||||
let updatedMarkers;
|
||||
if (existingIndex !== -1) {
|
||||
// 如果已存在相同ID的员工标记点,则更新
|
||||
updatedMarkers = [...markers];
|
||||
updatedMarkers[existingIndex] = markerWithType;
|
||||
console.log('员工标记点已存在,执行更新操作');
|
||||
}
|
||||
else {
|
||||
// 如果不存在,则添加新的员工标记点
|
||||
updatedMarkers = [...markers, markerWithType];
|
||||
console.log('员工标记点不存在,执行添加操作');
|
||||
}
|
||||
// 更新数据模块中的标记点
|
||||
this.dataModule.updateMarkers(updatedMarkers);
|
||||
console.log('单个员工标记点添加完成,总标记点数量:', updatedMarkers.length);
|
||||
}
|
||||
/**
|
||||
* 更新单个员工标记点
|
||||
*/
|
||||
updateSingleEmployeeMarker(employeeMarker) {
|
||||
console.log('更新单个员工标记点:', employeeMarker.id);
|
||||
const { markers } = this.pageContext.data;
|
||||
// 查找现有的员工标记点
|
||||
const markerIndex = markers.findIndex((marker) => marker.type === 'employee' && marker.id === employeeMarker.id);
|
||||
let updatedMarkers;
|
||||
if (markerIndex !== -1) {
|
||||
// 更新现有的标记点
|
||||
updatedMarkers = [...markers];
|
||||
updatedMarkers[markerIndex] = employeeMarker;
|
||||
}
|
||||
else {
|
||||
// 添加新的标记点
|
||||
updatedMarkers = [...markers, employeeMarker];
|
||||
}
|
||||
// 更新数据模块中的标记点
|
||||
this.dataModule.updateMarkers(updatedMarkers);
|
||||
console.log('单个员工标记点更新完成');
|
||||
}
|
||||
/**
|
||||
* 处理地图点击事件
|
||||
*/
|
||||
onMapTap(e) {
|
||||
console.log('地图被点击:', e);
|
||||
// 可以在这里添加地图点击的处理逻辑
|
||||
}
|
||||
/**
|
||||
* 处理标记点点击事件
|
||||
*/
|
||||
onMarkerTap(e) {
|
||||
const markerId = e.markerId;
|
||||
console.log('标记点被点击:', markerId);
|
||||
// 根据标记点ID处理不同的点击逻辑
|
||||
this.handleMarkerClick(markerId);
|
||||
}
|
||||
/**
|
||||
* 处理标记点点击
|
||||
*/
|
||||
handleMarkerClick(markerId) {
|
||||
// 这里可以根据标记点ID进行不同的处理
|
||||
// 例如:显示订单详情、货运人员信息等
|
||||
if (markerId === -1) {
|
||||
// 用户位置标记
|
||||
this.pageContext.showUserPanel();
|
||||
}
|
||||
// 可以添加其他标记点的处理逻辑
|
||||
}
|
||||
}
|
||||
exports.MapModule = MapModule;
|
||||
234
dist/pages/index/modules/orderModule.js
vendored
Normal file
234
dist/pages/index/modules/orderModule.js
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OrderModule = void 0;
|
||||
const orderService_1 = __importDefault(require("../../../services/orderService"));
|
||||
const helpers_1 = require("../../../utils/helpers");
|
||||
class OrderModule {
|
||||
constructor(pageContext, dataModule) {
|
||||
this.pageContext = pageContext;
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
/**
|
||||
* 加载待处理订单
|
||||
*/
|
||||
async loadPendingOrders() {
|
||||
try {
|
||||
this.pageContext.setData({
|
||||
loadingOrders: true
|
||||
});
|
||||
const orders = await orderService_1.default.getPendingOrders();
|
||||
this.dataModule.updatePendingOrders(orders);
|
||||
// 更新地图标记点
|
||||
// this.updateOrderMarkers();
|
||||
}
|
||||
catch (error) {
|
||||
console.error('加载订单失败:', error);
|
||||
(0, helpers_1.showToast)('加载订单失败');
|
||||
}
|
||||
finally {
|
||||
this.pageContext.setData({
|
||||
loadingOrders: false
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 显示订单详情面板
|
||||
*/
|
||||
showOrderPanel(order, position) {
|
||||
// 关闭其他面板
|
||||
this.pageContext.hideAllPanels();
|
||||
// 更新数据模块中的当前订单和面板状态
|
||||
this.dataModule.setCurrentOrder(order);
|
||||
this.dataModule.setPanelPosition(position);
|
||||
this.dataModule.toggleOrderPanel(true);
|
||||
// 规划订单路线
|
||||
this.planOrderRoute(order);
|
||||
}
|
||||
/**
|
||||
* 隐藏订单详情面板
|
||||
*/
|
||||
hideOrderPanel() {
|
||||
// 更新数据模块中的面板状态
|
||||
this.dataModule.toggleOrderPanel(false);
|
||||
this.dataModule.setCurrentOrder(null);
|
||||
// 同时取消路线显示
|
||||
this.cancelRoute();
|
||||
// 重置标记点状态
|
||||
this.pageContext.resetMarkers();
|
||||
}
|
||||
/**
|
||||
* 规划订单路线
|
||||
*/
|
||||
async planOrderRoute(order) {
|
||||
try {
|
||||
const origin = `${order.startPoint.longitude},${order.startPoint.latitude}`;
|
||||
const destination = `${order.endPoint.longitude},${order.endPoint.latitude}`;
|
||||
console.log(`开始规划路线: 起点=${origin}, 终点=${destination}`);
|
||||
// 这里应该调用地图服务的路线规划功能
|
||||
// 目前先模拟一个简单的路线规划结果
|
||||
const routeResult = {
|
||||
distance: 1500, // 1.5公里
|
||||
duration: 300, // 5分钟
|
||||
polyline: null // 路线数据
|
||||
};
|
||||
console.log('路线规划结果:', routeResult);
|
||||
// 显示距离和时长信息
|
||||
if (routeResult.distance > 0 || routeResult.duration > 0) {
|
||||
const distanceStr = this.formatDistance(routeResult.distance);
|
||||
const durationStr = this.formatDuration(routeResult.duration);
|
||||
(0, helpers_1.showToast)(`距离: ${distanceStr}, 预计时间: ${durationStr}`);
|
||||
}
|
||||
// 更新数据模块中的路线信息
|
||||
this.dataModule.updateRouteInfo(routeResult.polyline, routeResult.distance, routeResult.duration);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('路线规划失败:', error);
|
||||
(0, helpers_1.showToast)('路线规划失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 取消路线显示
|
||||
*/
|
||||
cancelRoute() {
|
||||
// 清除数据模块中的路线信息
|
||||
this.dataModule.clearRouteInfo();
|
||||
}
|
||||
/**
|
||||
* 分配订单给货运人员
|
||||
*/
|
||||
async assignOrder(orderId, deliveryPersonId) {
|
||||
try {
|
||||
const result = await orderService_1.default.assignOrder(orderId, deliveryPersonId);
|
||||
if (result.success) {
|
||||
(0, helpers_1.showToast)('订单分配成功');
|
||||
// 刷新订单列表
|
||||
await this.loadPendingOrders();
|
||||
// 刷新货运人员状态
|
||||
// TODO this.dataModule.notifyDeliveryPersonsUpdated();
|
||||
}
|
||||
else {
|
||||
(0, helpers_1.showToast)(result.message || '订单分配失败');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('分配订单失败:', error);
|
||||
(0, helpers_1.showToast)('订单分配失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 更新订单状态
|
||||
*/
|
||||
async updateOrderStatus(orderId, status) {
|
||||
try {
|
||||
const result = await orderService_1.default.updateOrderStatus(orderId, status);
|
||||
if (result.success) {
|
||||
(0, helpers_1.showToast)('订单状态已更新');
|
||||
// 刷新订单列表
|
||||
await this.loadPendingOrders();
|
||||
// 刷新货运人员状态
|
||||
// this.dataModule.notifyDeliveryPersonsUpdated();
|
||||
}
|
||||
else {
|
||||
(0, helpers_1.showToast)(result.message || '订单状态更新失败');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('更新订单状态失败:', error);
|
||||
(0, helpers_1.showToast)('订单状态更新失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除订单
|
||||
*/
|
||||
async deleteOrder(orderId) {
|
||||
try {
|
||||
// 确认删除操作
|
||||
const confirmResult = await new Promise((resolve) => {
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除这个订单吗?此操作不可恢复。',
|
||||
success: (res) => {
|
||||
resolve(res.confirm);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!confirmResult) {
|
||||
return; // 用户取消删除
|
||||
}
|
||||
await orderService_1.default.deleteOrder(orderId);
|
||||
(0, helpers_1.showToast)('订单已删除');
|
||||
// 刷新订单列表
|
||||
await this.loadPendingOrders();
|
||||
// 刷新货运人员状态
|
||||
// this.dataModule.notifyDeliveryPersonsUpdated();
|
||||
// 如果当前正在查看被删除的订单,关闭订单面板
|
||||
//TODO
|
||||
// const currentOrder = this.dataModule.getCurrentOrder();
|
||||
// if (currentOrder && currentOrder.id === orderId) {
|
||||
// this.hideOrderPanel();
|
||||
// }
|
||||
}
|
||||
catch (error) {
|
||||
console.error('删除订单失败:', error);
|
||||
(0, helpers_1.showToast)('删除订单失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 格式化距离
|
||||
*/
|
||||
formatDistance(distance) {
|
||||
if (distance < 1000) {
|
||||
return `${distance}米`;
|
||||
}
|
||||
else {
|
||||
return `${(distance / 1000).toFixed(1)}公里`;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 格式化时长
|
||||
*/
|
||||
formatDuration(duration) {
|
||||
const minutes = Math.floor(duration / 60);
|
||||
const seconds = duration % 60;
|
||||
if (minutes > 0) {
|
||||
return `${minutes}分${seconds}秒`;
|
||||
}
|
||||
else {
|
||||
return `${seconds}秒`;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取订单状态文本
|
||||
*/
|
||||
getOrderStatusText(status) {
|
||||
const statusMap = {
|
||||
'pending': '未分配',
|
||||
'assigned': '已分配',
|
||||
'in_transit': '配送中',
|
||||
'delivered': '已完成',
|
||||
'cancelled': '已取消'
|
||||
};
|
||||
return statusMap[status] || status;
|
||||
}
|
||||
/**
|
||||
* 获取订单状态对应的图标
|
||||
*/
|
||||
getOrderStatusIcon(status) {
|
||||
switch (status) {
|
||||
case 'pending':
|
||||
return '/images/order-pending.png';
|
||||
case 'assigned':
|
||||
return '/images/order-assigned.png';
|
||||
case 'in_transit':
|
||||
return '/images/order-transit.png';
|
||||
case 'delivered':
|
||||
return '/images/order-delivered.png';
|
||||
default:
|
||||
return '/images/order-pending.png';
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.OrderModule = OrderModule;
|
||||
213
dist/pages/index/modules/warehouseModule.js
vendored
Normal file
213
dist/pages/index/modules/warehouseModule.js
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WarehouseModule = void 0;
|
||||
// 仓库模块 - 处理仓库管理、显示、交互
|
||||
const warehouseService_1 = __importDefault(require("../../../services/warehouseService"));
|
||||
const helpers_1 = require("../../../utils/helpers");
|
||||
class WarehouseModule {
|
||||
constructor(pageContext, dataModule) {
|
||||
this.lastLoadTime = 0;
|
||||
this.isLoading = false;
|
||||
this.loadPromise = null;
|
||||
this.pageContext = pageContext;
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
/**
|
||||
* 加载仓库数据(带缓存和防抖机制)
|
||||
*/
|
||||
async loadWarehouses(forceRefresh = false) {
|
||||
// 防抖机制:如果正在加载,返回同一个Promise
|
||||
if (this.isLoading && this.loadPromise && !forceRefresh) {
|
||||
return this.loadPromise;
|
||||
}
|
||||
// 缓存机制:5分钟内不重复加载相同数据
|
||||
const now = Date.now();
|
||||
const cacheTime = 5 * 60 * 1000; // 5分钟缓存
|
||||
if (!forceRefresh && now - this.lastLoadTime < cacheTime) {
|
||||
console.log('使用缓存的仓库数据');
|
||||
return;
|
||||
}
|
||||
this.isLoading = true;
|
||||
this.loadPromise = (async () => {
|
||||
try {
|
||||
const warehouses = await warehouseService_1.default.getWarehouses();
|
||||
// 更新地图标记点
|
||||
this.updateWarehouseMarkers(warehouses);
|
||||
this.lastLoadTime = Date.now();
|
||||
console.log('仓库数据加载完成,数量:', warehouses.length);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('加载仓库数据失败:', error);
|
||||
(0, helpers_1.showToast)('加载仓库数据失败');
|
||||
}
|
||||
finally {
|
||||
this.isLoading = false;
|
||||
this.loadPromise = null;
|
||||
}
|
||||
})();
|
||||
return this.loadPromise;
|
||||
}
|
||||
/**
|
||||
* 更新仓库标记点
|
||||
*/
|
||||
updateWarehouseMarkers(warehouses) {
|
||||
const { markers } = this.pageContext.data;
|
||||
// 移除现有的仓库标记点
|
||||
const filteredMarkers = markers.filter((marker) => marker.type !== 'warehouse');
|
||||
// 添加新的仓库标记点
|
||||
const warehouseMarkers = warehouses.map((warehouse, index) => {
|
||||
// 验证仓库坐标是否有效
|
||||
let validLongitude = warehouse.longitude;
|
||||
let validLatitude = warehouse.latitude;
|
||||
if (isNaN(validLongitude) || isNaN(validLatitude)) {
|
||||
validLongitude = 102.833722; // 默认经度
|
||||
validLatitude = 24.880095; // 默认纬度
|
||||
}
|
||||
return {
|
||||
id: 1000 + index, // 仓库标记点ID从1000开始
|
||||
longitude: validLongitude,
|
||||
latitude: validLatitude,
|
||||
iconPath: '/images/warehouse.png',
|
||||
width: 24,
|
||||
height: 24,
|
||||
zIndex: 10,
|
||||
type: 'warehouse',
|
||||
data: warehouse
|
||||
};
|
||||
});
|
||||
// 更新数据模块中的标记点
|
||||
const allMarkers = [...filteredMarkers, ...warehouseMarkers];
|
||||
this.dataModule.updateMarkers(allMarkers);
|
||||
}
|
||||
/**
|
||||
* 显示仓库详情面板
|
||||
*/
|
||||
showWarehousePanel(warehouse, position) {
|
||||
// 关闭其他面板
|
||||
this.pageContext.hideAllPanels();
|
||||
// 更新数据模块中的当前仓库和面板状态
|
||||
this.dataModule.setCurrentWarehouse(warehouse);
|
||||
this.dataModule.setPanelPosition(position);
|
||||
this.dataModule.toggleWarehouseModal(true, 'bottom');
|
||||
}
|
||||
/**
|
||||
* 隐藏仓库详情面板
|
||||
*/
|
||||
hideWarehousePanel() {
|
||||
// 更新数据模块中的面板状态
|
||||
this.dataModule.toggleWarehouseModal(false);
|
||||
this.dataModule.setCurrentWarehouse(null);
|
||||
}
|
||||
/**
|
||||
* 展开仓库详情面板
|
||||
*/
|
||||
expandWarehousePanel() {
|
||||
this.dataModule.toggleWarehouseModal(true, 'full');
|
||||
}
|
||||
/**
|
||||
* 收起仓库详情面板
|
||||
*/
|
||||
collapseWarehousePanel() {
|
||||
this.dataModule.toggleWarehouseModal(true, 'bottom');
|
||||
}
|
||||
/**
|
||||
* 处理仓库标记点点击
|
||||
*/
|
||||
onWarehouseMarkerClick(warehouse, position) {
|
||||
console.log('仓库被点击:', warehouse);
|
||||
// 显示仓库详情面板
|
||||
this.showWarehousePanel(warehouse, position);
|
||||
}
|
||||
/**
|
||||
* 获取仓库库存状态
|
||||
*/
|
||||
getWarehouseInventoryStatus(warehouse) {
|
||||
const capacity = warehouse.capacity || 100;
|
||||
const currentStock = warehouse.currentStock || 0;
|
||||
const percentage = (currentStock / capacity) * 100;
|
||||
if (percentage >= 80) {
|
||||
return 'high';
|
||||
}
|
||||
else if (percentage >= 50) {
|
||||
return 'medium';
|
||||
}
|
||||
else {
|
||||
return 'low';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取仓库库存状态文本
|
||||
*/
|
||||
getWarehouseInventoryStatusText(warehouse) {
|
||||
const status = this.getWarehouseInventoryStatus(warehouse);
|
||||
switch (status) {
|
||||
case 'high':
|
||||
return '库存充足';
|
||||
case 'medium':
|
||||
return '库存适中';
|
||||
case 'low':
|
||||
return '库存不足';
|
||||
default:
|
||||
return '未知状态';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取仓库库存状态颜色
|
||||
*/
|
||||
getWarehouseInventoryStatusColor(warehouse) {
|
||||
const status = this.getWarehouseInventoryStatus(warehouse);
|
||||
switch (status) {
|
||||
case 'high':
|
||||
return '#52c41a'; // 绿色
|
||||
case 'medium':
|
||||
return '#faad14'; // 橙色
|
||||
case 'low':
|
||||
return '#f5222d'; // 红色
|
||||
default:
|
||||
return '#d9d9d9'; // 灰色
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 创建新仓库
|
||||
*/
|
||||
async createWarehouse(warehouseData) {
|
||||
try {
|
||||
await warehouseService_1.default.createWarehouse(warehouseData);
|
||||
(0, helpers_1.showToast)('仓库创建成功');
|
||||
console.log('新仓库创建成功:', warehouseData);
|
||||
// 不需要重新加载仓库数据,因为仓库数据变化不频繁
|
||||
// 用户可以通过手动刷新来获取最新数据
|
||||
}
|
||||
catch (error) {
|
||||
console.error('创建仓库失败:', error);
|
||||
(0, helpers_1.showToast)('创建仓库失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除仓库
|
||||
*/
|
||||
async deleteWarehouse(warehouseId) {
|
||||
try {
|
||||
await warehouseService_1.default.deleteWarehouse(warehouseId);
|
||||
(0, helpers_1.showToast)('仓库删除成功');
|
||||
console.log(`仓库 ${warehouseId} 已删除`);
|
||||
// 不需要重新加载仓库数据,因为仓库数据变化不频繁
|
||||
// 用户可以通过手动刷新来获取最新数据
|
||||
}
|
||||
catch (error) {
|
||||
console.error('删除仓库失败:', error);
|
||||
(0, helpers_1.showToast)('删除仓库失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 强制刷新仓库数据(忽略缓存)
|
||||
*/
|
||||
async forceRefreshWarehouses() {
|
||||
console.log('强制刷新仓库数据');
|
||||
return this.loadWarehouses(true);
|
||||
}
|
||||
}
|
||||
exports.WarehouseModule = WarehouseModule;
|
||||
Reference in New Issue
Block a user