修改位置交互,修改代码逻辑
This commit is contained in:
@@ -1,61 +1,64 @@
|
||||
// index.ts
|
||||
|
||||
// 引入服务和工具函数
|
||||
import { UserInfo, Marker } from '../../types';
|
||||
import { showToast } from '../../utils/helpers';
|
||||
import userService from '../../services/userService';
|
||||
import locationTrackingService from '../../services/locationTrackingService';
|
||||
|
||||
// 引入模块
|
||||
// 引入主页面模块
|
||||
import { MainPageModule } from './modules/mainPageModule';
|
||||
|
||||
// 主页面组件
|
||||
Component({
|
||||
// 主页面组件接口定义
|
||||
interface IndexPageComponent {
|
||||
data: {
|
||||
// 地图中心点坐标
|
||||
longitude: 102.833722,
|
||||
latitude: 24.880095,
|
||||
scale: 13, // 地图缩放级别
|
||||
markers: [] as Marker[], // 地图标记点数组
|
||||
userInfo: null as UserInfo | null, // 用户信息
|
||||
// 用户认证状态(分离外部登录状态和用户二级状态)
|
||||
authStatus: {
|
||||
hasWxCode: false, // 是否已获取微信code(外部登录状态)
|
||||
userStatus: 'unknown' as 'unknown' | 'registered' | 'unregistered' | 'signed_in' | 'signed_out', // 用户二级状态
|
||||
},
|
||||
showUserPanel: false, // 是否显示用户信息面板
|
||||
showOrderPanel: false, // 是否显示订单详情面板
|
||||
currentOrder: null as any, // 当前选中的订单
|
||||
currentDeliveryPerson: null as any, // 当前选中的货运人员
|
||||
currentWarehouse: null as any, // 当前选中的仓库
|
||||
currentPanelPosition: { x: 0, y: 0 }, // 当前信息面板位置
|
||||
polyline: null as any, // 路线规划结果
|
||||
pendingOrders: [] as any[] ,// 待分配订单
|
||||
currentRoute: null as any, // 当前路线信息
|
||||
showRoute: false, // 是否显示路线
|
||||
routeDistance: 0, // 路线距离
|
||||
routeDuration: 0, // 路线预计时间
|
||||
|
||||
// 底部弹窗相关状态
|
||||
showWarehouseModal: false, // 仓库底部弹窗
|
||||
showDeliveryPersonModal: false, // 货运人员底部弹窗
|
||||
// 底部弹窗状态(bottom或full)
|
||||
warehouseModalState: 'bottom',
|
||||
deliveryPersonModalState: 'bottom',
|
||||
// 操作按钮显示状态(基于用户状态动态计算)
|
||||
mainPageModule: MainPageModule | null;
|
||||
// 核心UI状态
|
||||
showUserPanel: boolean;
|
||||
showOrderPanel: boolean;
|
||||
showDeliveryPersonModal: boolean;
|
||||
showWarehouseModal: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
showSignOutButton: false // 是否显示签退按钮
|
||||
// 主页面组件
|
||||
Component<IndexPageComponent>({
|
||||
data: {
|
||||
mainPageModule: null as MainPageModule | null,
|
||||
// 核心UI状态
|
||||
showUserPanel: false,
|
||||
showOrderPanel: false,
|
||||
showDeliveryPersonModal: false,
|
||||
showWarehouseModal: false
|
||||
},
|
||||
|
||||
lifetimes: {
|
||||
async attached() {
|
||||
// 组件挂载时初始化
|
||||
await this.initPage();
|
||||
attached() {
|
||||
console.log('index page attached');
|
||||
this.initPage();
|
||||
},
|
||||
|
||||
detached() {
|
||||
console.log('index page detached');
|
||||
// 清理资源
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.cleanup();
|
||||
}
|
||||
},
|
||||
|
||||
detached() {
|
||||
// 组件卸载时清理
|
||||
(this as any).mainPageModule = null;
|
||||
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();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -82,11 +85,14 @@ Component({
|
||||
const app = getApp<any>();
|
||||
|
||||
// 初始化主页面模块
|
||||
(this as any).mainPageModule = new MainPageModule(this);
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
this.setData({
|
||||
mainPageModule: new MainPageModule(this)
|
||||
});
|
||||
|
||||
// 设置globalData中的loginModule引用,用于废弃方法的重定向
|
||||
app.globalData.loginModule = loginModule;
|
||||
if (this.data.mainPageModule) {
|
||||
app.globalData.loginModule = this.data.mainPageModule.getLoginModule();
|
||||
}
|
||||
|
||||
// 异步检查登录状态
|
||||
await this.checkAndUpdateLoginStatus();
|
||||
@@ -95,9 +101,14 @@ Component({
|
||||
// 异步检查并更新登录状态
|
||||
async checkAndUpdateLoginStatus() {
|
||||
const app = getApp<any>();
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
|
||||
try {
|
||||
// 获取登录模块
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
// 显示加载状态
|
||||
wx.showLoading({
|
||||
title: '检查登录状态...',
|
||||
@@ -108,21 +119,8 @@ Component({
|
||||
const isLoggedIn = await this.asyncCheckLoginStatus(loginModule);
|
||||
|
||||
if (isLoggedIn) {
|
||||
// 已登录状态
|
||||
const userStatus = await loginModule.determineUserStatus(app.globalData.userInfo);
|
||||
this.setData({
|
||||
userInfo: app.globalData.userInfo,
|
||||
'authStatus.hasWxCode': true,
|
||||
'authStatus.userStatus': userStatus,
|
||||
// 初始化按钮显示状态
|
||||
showSignInButton: loginModule.shouldShowSignInButton(),
|
||||
showRegisterButton: loginModule.shouldShowRegisterButton(),
|
||||
showAuthButton: false
|
||||
});
|
||||
|
||||
// === 全局登录流程完成,登录成功 ===
|
||||
// 统一在此处执行一次完整的页面刷新
|
||||
this.refreshPageAfterLogin();
|
||||
// 已登录状态 - 按钮状态会在refreshPageAfterLogin中统一更新
|
||||
console.log('✅ 登录检查成功,等待统一页面刷新');
|
||||
} else {
|
||||
// 未登录状态
|
||||
this.setData({
|
||||
@@ -173,6 +171,9 @@ Component({
|
||||
|
||||
console.log('✅ 使用本地登录状态,用户状态已更新:', userStatus);
|
||||
|
||||
// 登录成功后统一刷新页面
|
||||
this.refreshPageAfterLogin();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -213,19 +214,24 @@ Component({
|
||||
|
||||
// 更新按钮显示状态
|
||||
updateButtonDisplayStatus() {
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
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.userStatus === 'signed_in';
|
||||
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.userStatus);
|
||||
console.log(' - 当前hasWxCode:', this.data.authStatus.hasWxCode);
|
||||
console.log(' - 当前用户状态:', this.data.authStatus ? this.data.authStatus.userStatus : 'undefined');
|
||||
console.log(' - 当前hasWxCode:', this.data.authStatus ? this.data.authStatus.hasWxCode : 'undefined');
|
||||
|
||||
this.setData({
|
||||
showSignInButton,
|
||||
@@ -238,7 +244,12 @@ Component({
|
||||
|
||||
// 登录成功后统一刷新页面
|
||||
async refreshPageAfterLogin() {
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
const app = getApp<any>();
|
||||
|
||||
console.log('🔄 === 全局登录流程完成,执行统一页面刷新 ===');
|
||||
@@ -250,13 +261,14 @@ Component({
|
||||
this.updateButtonDisplayStatus();
|
||||
|
||||
// 3. 初始化主页面模块
|
||||
await (this as any).mainPageModule.onLoad();
|
||||
await this.data.mainPageModule.onLoad();
|
||||
|
||||
// 4. 登录成功后主动加载业务数据(仓库、订单等)
|
||||
// 4. 登录成功后只加载公开数据(仓库等),不加载业务数据
|
||||
// 业务数据(员工位置等)只有在用户签到后才应该加载
|
||||
if (app.globalData.isLoggedIn) {
|
||||
console.log('🔍 登录成功,开始加载业务数据...');
|
||||
await (this as any).mainPageModule.refreshAllData();
|
||||
console.log('✅ 业务数据加载完成');
|
||||
console.log('🔍 登录成功,开始加载公开数据...');
|
||||
await this.data.mainPageModule.loadPublicData();
|
||||
console.log('✅ 公开数据加载完成');
|
||||
}
|
||||
|
||||
console.log('✅ 统一页面刷新完成');
|
||||
@@ -278,7 +290,12 @@ Component({
|
||||
|
||||
// 处理签到 - 已迁移到LoginModule
|
||||
async handleSignIn() {
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
const success = await loginModule.handleSignIn();
|
||||
|
||||
if (success) {
|
||||
@@ -286,18 +303,22 @@ Component({
|
||||
this.updateButtonDisplayStatus();
|
||||
|
||||
// 刷新页面数据
|
||||
await (this as any).mainPageModule.refreshAllData();
|
||||
await this.data.mainPageModule.refreshAllData();
|
||||
}
|
||||
},
|
||||
|
||||
// 处理授权登录 - 已迁移到LoginModule
|
||||
async handleAuthLogin() {
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
const success = await loginModule.handleAuthLogin();
|
||||
|
||||
if (success) {
|
||||
const app = getApp<any>();
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
const userStatus = loginModule.determineUserStatus(app.globalData.userInfo);
|
||||
this.setData({
|
||||
userInfo: app.globalData.userInfo,
|
||||
@@ -323,7 +344,11 @@ Component({
|
||||
});
|
||||
|
||||
// 调用loginModule的logout方法
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
if (!this.data.mainPageModule) {
|
||||
console.error('mainPageModule未初始化');
|
||||
return;
|
||||
}
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
await loginModule.logout();
|
||||
|
||||
// 更新页面状态
|
||||
@@ -364,10 +389,18 @@ Component({
|
||||
console.warn('调试信息 - 停止位置追踪失败:', trackingError);
|
||||
}
|
||||
|
||||
// 清除登录信息,防止自动重新登录
|
||||
console.log('调试信息 - 开始清除登录信息');
|
||||
const app = getApp<any>();
|
||||
app.doGlobalLogout();
|
||||
// 停止位置模块的实时跟踪
|
||||
try {
|
||||
if (this.data.mainPageModule) {
|
||||
const locationModule = this.data.mainPageModule.getLocationModule();
|
||||
if (locationModule) {
|
||||
await locationModule.stopRealTimeTracking();
|
||||
console.log('调试信息 - 位置模块实时跟踪已停止');
|
||||
}
|
||||
}
|
||||
} catch (trackingError) {
|
||||
console.warn('调试信息 - 停止位置模块实时跟踪失败:', trackingError);
|
||||
}
|
||||
|
||||
// 保存签退状态到本地存储,防止自动重新登录
|
||||
console.log('调试信息 - 保存签退状态到本地存储');
|
||||
@@ -377,13 +410,25 @@ Component({
|
||||
const savedStatus = wx.getStorageSync('userStatus');
|
||||
console.log('调试信息 - 验证保存的签退状态:', savedStatus);
|
||||
|
||||
// 更新用户状态为已签退
|
||||
// 更新用户状态为已签退(不调用doGlobalLogout,保持登录状态)
|
||||
this.setData({
|
||||
'authStatus.userStatus': 'signed_out',
|
||||
showSignOutButton: false,
|
||||
showSignInButton: true
|
||||
});
|
||||
|
||||
// 清除所有员工图标
|
||||
if (this.data.mainPageModule) {
|
||||
const employeeModule = this.data.mainPageModule.getEmployeeModule();
|
||||
if (employeeModule) {
|
||||
// 清除员工标记点
|
||||
const { markers } = this.data;
|
||||
const filteredMarkers = markers.filter((marker: any) => marker.type !== 'employee');
|
||||
this.setData({ markers: filteredMarkers });
|
||||
console.log('调试信息 - 已清除所有员工图标');
|
||||
}
|
||||
}
|
||||
|
||||
wx.hideLoading();
|
||||
showToast('签退成功');
|
||||
console.log('调试信息 - 用户签退完成');
|
||||
@@ -401,9 +446,25 @@ Component({
|
||||
});
|
||||
},
|
||||
|
||||
// 跳转到管理员页面
|
||||
goToAdminPage() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/admin/admin'
|
||||
});
|
||||
},
|
||||
|
||||
// 跳转到员工管理页面
|
||||
goToEmployeeManagement() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/employee/employee'
|
||||
});
|
||||
},
|
||||
|
||||
// 阻止事件冒泡
|
||||
stopPropagation(e: any) {
|
||||
e.stopPropagation();
|
||||
if (e && typeof e.stopPropagation === 'function') {
|
||||
e.stopPropagation();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -422,8 +483,8 @@ Component({
|
||||
|
||||
// 用户登出
|
||||
userLogout() {
|
||||
if ((this as any).mainPageModule) {
|
||||
const loginModule = (this as any).mainPageModule.getLoginModule();
|
||||
if (this.data.mainPageModule) {
|
||||
const loginModule = this.data.mainPageModule.getLoginModule();
|
||||
loginModule.logout();
|
||||
|
||||
// 更新页面状态
|
||||
@@ -449,91 +510,91 @@ Component({
|
||||
|
||||
// 隐藏所有面板
|
||||
hideAllPanels() {
|
||||
if ((this as any).mainPageModule) {
|
||||
(this as any).mainPageModule.hideAllPanels();
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.hideAllPanels();
|
||||
}
|
||||
},
|
||||
|
||||
// 重置标记点状态
|
||||
resetMarkers() {
|
||||
if ((this as any).mainPageModule) {
|
||||
(this as any).mainPageModule.resetMarkers();
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.resetMarkers();
|
||||
}
|
||||
},
|
||||
|
||||
// 地图点击事件
|
||||
onMapTap(e: any) {
|
||||
if ((this as any).mainPageModule) {
|
||||
(this as any).mainPageModule.onMapTap(e);
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.onMapTap(e);
|
||||
}
|
||||
},
|
||||
|
||||
// 标记点点击事件
|
||||
onMarkerTap(e: any) {
|
||||
if ((this as any).mainPageModule) {
|
||||
(this as any).mainPageModule.onMarkerTap(e);
|
||||
if (this.data.mainPageModule) {
|
||||
this.data.mainPageModule.onMarkerTap(e);
|
||||
}
|
||||
},
|
||||
|
||||
// 分配订单
|
||||
async assignOrder(orderId: number, deliveryPersonId: number) {
|
||||
if ((this as any).mainPageModule) {
|
||||
const orderModule = (this as any).mainPageModule.getOrderModule();
|
||||
if (this.data.mainPageModule) {
|
||||
const orderModule = this.data.mainPageModule.getOrderModule();
|
||||
await orderModule.assignOrder(orderId, deliveryPersonId);
|
||||
}
|
||||
},
|
||||
|
||||
// 更新订单状态
|
||||
async updateOrderStatus(orderId: number, status: 'pending' | 'assigned' | 'in_transit' | 'delivered') {
|
||||
if ((this as any).mainPageModule) {
|
||||
const orderModule = (this as any).mainPageModule.getOrderModule();
|
||||
if (this.data.mainPageModule) {
|
||||
const orderModule = this.data.mainPageModule.getOrderModule();
|
||||
await orderModule.updateOrderStatus(orderId, status);
|
||||
}
|
||||
},
|
||||
|
||||
// 展开仓库面板
|
||||
expandWarehousePanel() {
|
||||
if ((this as any).mainPageModule) {
|
||||
const warehouseModule = (this as any).mainPageModule.getWarehouseModule();
|
||||
if (this.data.mainPageModule) {
|
||||
const warehouseModule = this.data.mainPageModule.getWarehouseModule();
|
||||
warehouseModule.expandWarehousePanel();
|
||||
}
|
||||
},
|
||||
|
||||
// 收起仓库面板
|
||||
collapseWarehousePanel() {
|
||||
if ((this as any).mainPageModule) {
|
||||
const warehouseModule = (this as any).mainPageModule.getWarehouseModule();
|
||||
if (this.data.mainPageModule) {
|
||||
const warehouseModule = this.data.mainPageModule.getWarehouseModule();
|
||||
warehouseModule.collapseWarehousePanel();
|
||||
}
|
||||
},
|
||||
|
||||
// 展开货运人员面板
|
||||
// 展开员工面板
|
||||
expandDeliveryPersonPanel() {
|
||||
if ((this as any).mainPageModule) {
|
||||
const deliveryPersonModule = (this as any).mainPageModule.getDeliveryPersonModule();
|
||||
deliveryPersonModule.expandDeliveryPersonPanel();
|
||||
if (this.data.mainPageModule) {
|
||||
const employeeModule = this.data.mainPageModule.getEmployeeModule();
|
||||
employeeModule.expandDeliveryPersonPanel();
|
||||
}
|
||||
},
|
||||
|
||||
// 收起货运人员面板
|
||||
// 收起员工面板
|
||||
collapseDeliveryPersonPanel() {
|
||||
if ((this as any).mainPageModule) {
|
||||
const deliveryPersonModule = (this as any).mainPageModule.getDeliveryPersonModule();
|
||||
deliveryPersonModule.collapseDeliveryPersonPanel();
|
||||
if (this.data.mainPageModule) {
|
||||
const employeeModule = this.data.mainPageModule.getEmployeeModule();
|
||||
employeeModule.collapseDeliveryPersonPanel();
|
||||
}
|
||||
},
|
||||
|
||||
// 刷新所有数据
|
||||
async refreshAllData() {
|
||||
if ((this as any).mainPageModule) {
|
||||
await (this as any).mainPageModule.refreshAllData();
|
||||
if (this.data.mainPageModule) {
|
||||
await this.data.mainPageModule.refreshAllData();
|
||||
}
|
||||
},
|
||||
|
||||
// 开始定位(处理地图控制按钮点击)
|
||||
async startLocation() {
|
||||
if ((this as any).mainPageModule) {
|
||||
const mapModule = (this as any).mainPageModule.getMapModule();
|
||||
if (this.data.mainPageModule) {
|
||||
const mapModule = this.data.mainPageModule.getMapModule();
|
||||
await mapModule.startLocation();
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user