"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;