添加管理员逻辑
This commit is contained in:
@@ -148,12 +148,16 @@ export class DataModule {
|
||||
this.updateMarkers(updatedMarkers);
|
||||
} else {
|
||||
// 创建新的用户标记点
|
||||
const userInfo = this.pageContext.data.userInfo;
|
||||
const userRole = userInfo?.role || 'employee';
|
||||
const iconPath = userRole === 'ADMIN' ? '/images/crown.png' : '/images/truck.png';
|
||||
|
||||
const newUserMarker = {
|
||||
id: targetUserId,
|
||||
title: markerTitle,
|
||||
longitude: longitude,
|
||||
latitude: latitude,
|
||||
iconPath: '/images/trucks.png',
|
||||
iconPath: iconPath,
|
||||
width: 40,
|
||||
height: 40,
|
||||
zIndex: targetUserId === -1 ? 99 : 98 // 当前用户层级更高
|
||||
|
@@ -1,6 +1,6 @@
|
||||
// 员工模块 - 处理所有员工(管理员和货运人员)管理、位置跟踪、交互
|
||||
import employeeService from '../../../services/employeeService';
|
||||
import { Role } from '../../../utils/roleUtils';
|
||||
|
||||
// getApp是微信小程序全局函数,无需导入
|
||||
|
||||
import { showToast } from '../../../utils/helpers';
|
||||
@@ -30,37 +30,7 @@ export class EmployeeModule {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取员工角色对应的图标
|
||||
*/
|
||||
private getEmployeeIcon(role: string): string {
|
||||
console.log(`获取员工图标,角色: ${role}`);
|
||||
|
||||
// 根据角色使用不同的图标
|
||||
let iconPath = '';
|
||||
|
||||
switch (role) {
|
||||
case Role.ADMIN:
|
||||
// 管理员使用皇冠图标
|
||||
iconPath = '/images/crown.png';
|
||||
console.log('使用管理员图标(👑)');
|
||||
break;
|
||||
case Role.DELIVERY_PERSON:
|
||||
// 货运人员使用货车图标
|
||||
iconPath = '/images/truck.png';
|
||||
console.log('使用货运人员图标(🚚)');
|
||||
break;
|
||||
default:
|
||||
// 默认使用货车图标
|
||||
iconPath = '/images/truck.png';
|
||||
console.log('使用默认图标(🚚)');
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(`最终使用图标路径: ${iconPath}`);
|
||||
|
||||
return iconPath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示货运人员详情面板
|
||||
|
@@ -1,8 +1,7 @@
|
||||
// 位置模块 - 处理位置追踪、位置更新和地图标记点更新
|
||||
import { DataModule } from './dataModule';
|
||||
import { showToast } from '../../../utils/helpers';
|
||||
import locationTrackingService from '../../../services/locationTrackingService';
|
||||
import { OnlineUserInfo } from '../../../services/locationTrackingService';
|
||||
import { DataModule } from './dataModule';
|
||||
import locationTrackingService from '../../../services/locationTrackingService';
|
||||
|
||||
// 位置模块接口定义
|
||||
export interface LocationModule {
|
||||
@@ -10,21 +9,15 @@ export interface LocationModule {
|
||||
cleanup(): void;
|
||||
startRealTimeTracking(): Promise<void>;
|
||||
stopRealTimeTracking(): Promise<void>;
|
||||
updateEmployeeLocation(employeeId: number, location: { longitude: number, latitude: number }): Promise<void>;
|
||||
}
|
||||
|
||||
export class LocationModule {
|
||||
private pageContext: any;
|
||||
private dataModule: DataModule;
|
||||
private isTracking: boolean;
|
||||
|
||||
constructor(pageContext: any, dataModule: DataModule) {
|
||||
this.pageContext = pageContext;
|
||||
constructor(_pageContext: any, dataModule: DataModule) {
|
||||
this.dataModule = dataModule;
|
||||
this.isTracking = false;
|
||||
|
||||
// 绑定回调方法
|
||||
this.handleLocationUpdates = this.handleLocationUpdates.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,10 +26,28 @@ export class LocationModule {
|
||||
async initialize(): Promise<void> {
|
||||
console.log('位置模块初始化');
|
||||
|
||||
// 订阅位置更新
|
||||
this.subscribeToLocationUpdates();
|
||||
// 注册位置更新回调,当位置追踪服务有更新时自动刷新地图标记
|
||||
this.setupLocationUpdateCallback();
|
||||
|
||||
console.log('✅ 位置模块初始化完成');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置位置更新回调
|
||||
*/
|
||||
private setupLocationUpdateCallback(): void {
|
||||
console.log('📝 [LocationModule] 设置位置更新回调');
|
||||
|
||||
console.log('位置模块初始化完成');
|
||||
// 注册位置更新回调
|
||||
locationTrackingService.subscribeToLocationUpdates((onlineUsers) => {
|
||||
console.log('🔔 [LocationModule] 收到位置更新通知');
|
||||
console.log('👥 [LocationModule] 在线用户数量:', onlineUsers.length);
|
||||
|
||||
// 调用updateEmployeeMarkers方法更新地图标记
|
||||
this.updateEmployeeMarkers(onlineUsers);
|
||||
});
|
||||
|
||||
console.log('✅ [LocationModule] 位置更新回调设置完成');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,16 +55,15 @@ export class LocationModule {
|
||||
*/
|
||||
cleanup(): void {
|
||||
console.log('清理位置模块');
|
||||
|
||||
// 取消位置更新订阅
|
||||
this.unsubscribeFromLocationUpdates();
|
||||
|
||||
|
||||
// 停止实时跟踪
|
||||
if (this.isTracking) {
|
||||
this.stopRealTimeTracking().catch(error => {
|
||||
console.error('停止实时跟踪失败:', error);
|
||||
});
|
||||
}
|
||||
|
||||
console.log('✅ 位置模块清理完成');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,8 +77,8 @@ export class LocationModule {
|
||||
throw new Error('用户信息获取失败');
|
||||
}
|
||||
|
||||
// 启动位置跟踪订阅
|
||||
await locationTrackingService.startTrackingAfterSignIn();
|
||||
// 启动位置跟踪订阅(WebSocket连接)
|
||||
await locationTrackingService.startTracking();
|
||||
|
||||
this.isTracking = true;
|
||||
showToast('已开始实时跟踪');
|
||||
@@ -104,74 +114,13 @@ export class LocationModule {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新员工位置
|
||||
*/
|
||||
async updateEmployeeLocation(employeeId: number, location: { longitude: number, latitude: number }): Promise<void> {
|
||||
try {
|
||||
console.log(`员工 ${employeeId} 位置更新:`, location);
|
||||
|
||||
// 通过locationTrackingService更新位置
|
||||
await locationTrackingService.updateUserLocation(location);
|
||||
|
||||
console.log(`员工 ${employeeId} 位置更新完成`);
|
||||
} catch (error) {
|
||||
console.error('更新员工位置失败:', error);
|
||||
showToast('更新位置失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅位置更新
|
||||
*/
|
||||
private subscribeToLocationUpdates(): void {
|
||||
console.log('订阅位置更新');
|
||||
locationTrackingService.subscribeToLocationUpdates(this.handleLocationUpdates);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订阅位置更新
|
||||
*/
|
||||
private unsubscribeFromLocationUpdates(): void {
|
||||
console.log('取消订阅位置更新');
|
||||
locationTrackingService.unsubscribeFromLocationUpdates(this.handleLocationUpdates);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理位置更新回调
|
||||
*/
|
||||
private handleLocationUpdates(locationData: any): void {
|
||||
console.log('🔔 [LocationModule] 收到位置更新回调');
|
||||
console.log('📊 [LocationModule] 回调数据类型:', locationData.type || '未知类型');
|
||||
console.log('📋 [LocationModule] 回调数据内容:', JSON.stringify(locationData, null, 2));
|
||||
|
||||
if (locationData.type === 'onlineUserList' && locationData.users) {
|
||||
// 处理在线用户列表更新
|
||||
console.log('👥 [LocationModule] 处理在线用户列表,用户数量:', locationData.users.length);
|
||||
this.updateEmployeeMarkers(locationData.users);
|
||||
} else if (Array.isArray(locationData)) {
|
||||
// 处理位置更新数组(旧格式)
|
||||
console.log('📋 [LocationModule] 处理位置更新数组,用户数量:', locationData.length);
|
||||
this.updateEmployeeMarkers(locationData);
|
||||
} else if (locationData.userId && locationData.latitude && locationData.longitude) {
|
||||
// 处理单个用户位置更新
|
||||
console.log('👤 [LocationModule] 处理单个用户位置更新:', locationData.userId);
|
||||
this.updateSingleEmployeeMarker(locationData);
|
||||
} else {
|
||||
console.warn('❌ [LocationModule] 未知的位置数据格式:', locationData);
|
||||
}
|
||||
|
||||
console.log('🏁 [LocationModule] 位置更新回调处理完成');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新员工标记点
|
||||
*/
|
||||
private updateEmployeeMarkers(onlineUsers: any[]): void {
|
||||
public updateEmployeeMarkers(onlineUsers: any[]): void {
|
||||
console.log('📍 [LocationModule] 开始更新员工标记点');
|
||||
console.log('👥 [LocationModule] 传入用户数量:', onlineUsers.length);
|
||||
console.log('📋 [LocationModule] 用户数据示例:', JSON.stringify(onlineUsers[0], null, 2));
|
||||
|
||||
// 获取地图模块来更新标记点
|
||||
const mapModule = this.dataModule.getMapModule();
|
||||
@@ -180,8 +129,13 @@ export class LocationModule {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前地图上的所有标记点
|
||||
const { markers } = this.dataModule.getData();
|
||||
const currentEmployeeMarkers = markers.filter((marker: any) => marker.type === 'employee');
|
||||
console.log('🗺️ [LocationModule] 当前地图上员工标记点数量:', currentEmployeeMarkers.length);
|
||||
|
||||
// 为每个在线用户创建标记点
|
||||
const employeeMarkers = onlineUsers.map((user, index) => {
|
||||
const newEmployeeMarkers = onlineUsers.map((user, index) => {
|
||||
console.log(`🔍 [LocationModule] 处理第 ${index + 1} 个用户:`, user.userId || '未知ID');
|
||||
|
||||
// 获取用户角色信息
|
||||
@@ -215,55 +169,94 @@ export class LocationModule {
|
||||
return employeeMarker;
|
||||
});
|
||||
|
||||
console.log('📍 [LocationModule] 生成标记点数量:', employeeMarkers.length);
|
||||
console.log('📋 [LocationModule] 标记点数据示例:', JSON.stringify(employeeMarkers[0], null, 2));
|
||||
console.log('📍 [LocationModule] 新生成标记点数量:', newEmployeeMarkers.length);
|
||||
|
||||
// 调用地图模块更新员工标记点
|
||||
mapModule.updateEmployeeMarkers(employeeMarkers);
|
||||
// 对比新旧标记点,精确更新
|
||||
this.updateMarkersPrecisely(mapModule, currentEmployeeMarkers, newEmployeeMarkers);
|
||||
|
||||
console.log('✅ [LocationModule] 员工标记点更新完成');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新单个员工标记点
|
||||
* 精确更新标记点 - 通过对比新旧标记点来添加、更新和删除
|
||||
*/
|
||||
private updateSingleEmployeeMarker(locationUpdate: any): void {
|
||||
console.log('更新单个员工标记点:', locationUpdate.userId);
|
||||
private updateMarkersPrecisely(mapModule: any, currentMarkers: any[], newMarkers: any[]): void {
|
||||
console.log('🎯 [LocationModule] 开始精确更新标记点');
|
||||
|
||||
// 获取地图模块
|
||||
const mapModule = this.dataModule.getMapModule();
|
||||
if (!mapModule) {
|
||||
console.error('地图模块未找到,无法更新员工标记点');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取用户角色信息
|
||||
const userRole = this.getUserRole(locationUpdate.userId);
|
||||
|
||||
// 创建单个员工标记点
|
||||
const employeeMarker = {
|
||||
id: 10000 + locationUpdate.userId,
|
||||
type: 'employee',
|
||||
title: `员工${locationUpdate.userId}`,
|
||||
longitude: locationUpdate.longitude,
|
||||
latitude: locationUpdate.latitude,
|
||||
iconPath: this.getEmployeeIcon(locationUpdate.userId, userRole),
|
||||
width: 32,
|
||||
height: 32,
|
||||
zIndex: 30,
|
||||
data: {
|
||||
userId: locationUpdate.userId,
|
||||
role: userRole,
|
||||
lastUpdateTime: locationUpdate.timestamp || Date.now()
|
||||
// 创建用户ID到标记点的映射
|
||||
const currentMarkerMap = new Map();
|
||||
currentMarkers.forEach(marker => {
|
||||
if (marker.data && marker.data.userId) {
|
||||
currentMarkerMap.set(marker.data.userId, marker);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// 调用地图模块更新单个标记点
|
||||
mapModule.updateSingleEmployeeMarker(employeeMarker);
|
||||
const newMarkerMap = new Map();
|
||||
newMarkers.forEach(marker => {
|
||||
if (marker.data && marker.data.userId) {
|
||||
newMarkerMap.set(marker.data.userId, marker);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('单个员工标记点更新完成');
|
||||
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] 精确更新标记点完成');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户角色
|
||||
*/
|
||||
@@ -281,12 +274,14 @@ export class LocationModule {
|
||||
/**
|
||||
* 获取员工图标
|
||||
*/
|
||||
private getEmployeeIcon(userId: number, userRole: string): string {
|
||||
private getEmployeeIcon(_userId: number, userRole: string): string {
|
||||
// 根据用户角色返回不同的图标
|
||||
if (userRole === 'ADMIN') {
|
||||
return '/images/crown.png'; // 管理员图标
|
||||
} else if (userRole === 'DRIVER') {
|
||||
return '/images/truck.png'; // 司机图标
|
||||
} else {
|
||||
return '/images/trucks.png'; // 货运人员图标
|
||||
return '👤'; // 普通员工图标(表情符号)
|
||||
}
|
||||
}
|
||||
}
|
@@ -183,6 +183,71 @@ export class LoginModule {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理签退流程
|
||||
*/
|
||||
public async handleSignOut(): Promise<boolean> {
|
||||
try {
|
||||
// 显示加载中提示
|
||||
wx.showLoading({
|
||||
title: '签退中...',
|
||||
});
|
||||
|
||||
// 调用签退接口
|
||||
const signOutResult = await userService.signOut();
|
||||
|
||||
wx.hideLoading();
|
||||
|
||||
if (signOutResult.success) {
|
||||
console.log('签退成功:', signOutResult);
|
||||
wx.showToast({
|
||||
title: '签退成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
|
||||
// 停止位置追踪服务
|
||||
try {
|
||||
await locationTrackingService.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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理签到流程
|
||||
*/
|
||||
@@ -248,37 +313,11 @@ export class LoginModule {
|
||||
}
|
||||
}
|
||||
|
||||
// 启动位置追踪服务
|
||||
// 启动位置追踪服务(WebSocket连接)
|
||||
try {
|
||||
// 先启动位置追踪服务
|
||||
await locationTrackingService.startTrackingAfterSignIn();
|
||||
// 启动位置追踪服务(建立WebSocket连接)
|
||||
await locationTrackingService.startTracking();
|
||||
console.log('位置追踪服务已启动');
|
||||
|
||||
// 然后调用位置模块的实时跟踪功能
|
||||
const locationModule = this.dataModule.getLocationModule();
|
||||
if (locationModule) {
|
||||
await locationModule.startRealTimeTracking();
|
||||
console.log('位置模块实时跟踪已启动');
|
||||
}
|
||||
|
||||
// 订阅位置更新回调,采用统一方式更新所有用户位置
|
||||
locationTrackingService.subscribeToLocationUpdates((onlineUsers) => {
|
||||
console.log('🚚 位置更新回调 - 在线用户列表已更新,用户数量:', onlineUsers.length);
|
||||
|
||||
// 统一更新所有在线用户的位置标记点
|
||||
onlineUsers.forEach(user => {
|
||||
if (user.lastLocation) {
|
||||
console.log(`📍 更新用户 ${user.userId} 标记点位置:`, user.lastLocation);
|
||||
// 统一调用数据模块更新用户标记点位置
|
||||
this.dataModule.updateUserMarkerPosition(
|
||||
user.lastLocation.longitude,
|
||||
user.lastLocation.latitude,
|
||||
user.userId
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
} catch (trackingError) {
|
||||
console.warn('启动位置追踪失败,但不影响签到:', trackingError);
|
||||
}
|
||||
@@ -355,23 +394,6 @@ export class LoginModule {
|
||||
userInfo.role !== 'GUEST'
|
||||
);
|
||||
|
||||
// 调试信息:打印不满足条件的原因
|
||||
if (!result) {
|
||||
console.log('签到按钮不显示原因:');
|
||||
if (!authStatus.hasWxCode) console.log(' - 未获取微信code');
|
||||
if (authStatus.userStatus === 'signed_in') console.log(' - 用户状态为已签到');
|
||||
if (authStatus.userStatus === 'unregistered') console.log(' - 用户状态为未注册');
|
||||
if (userInfo === null) console.log(' - 用户信息为空');
|
||||
if (userInfo && userInfo.role === 'GUEST') console.log(' - 用户角色为游客');
|
||||
console.log('当前状态:', {
|
||||
hasWxCode: authStatus.hasWxCode,
|
||||
userStatus: authStatus.userStatus,
|
||||
userInfo: userInfo ? { role: userInfo.role } : null
|
||||
});
|
||||
} else {
|
||||
console.log('签到按钮显示条件满足');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -392,21 +414,7 @@ export class LoginModule {
|
||||
userInfo.role === 'GUEST'
|
||||
);
|
||||
|
||||
// 调试信息:打印不满足条件的原因
|
||||
if (!result) {
|
||||
console.log('注册按钮不显示原因:');
|
||||
if (!authStatus.hasWxCode) console.log(' - 未获取微信code');
|
||||
if (authStatus.userStatus !== 'unregistered') console.log(` - 用户状态为${authStatus.userStatus},不是未注册`);
|
||||
if (userInfo === null) console.log(' - 用户信息为空');
|
||||
if (userInfo && userInfo.role !== 'GUEST') console.log(` - 用户角色为${userInfo.role},不是游客`);
|
||||
console.log('当前状态:', {
|
||||
hasWxCode: authStatus.hasWxCode,
|
||||
userStatus: authStatus.userStatus,
|
||||
userInfo: userInfo ? { role: userInfo.role } : null
|
||||
});
|
||||
} else {
|
||||
console.log('注册按钮显示条件满足');
|
||||
}
|
||||
// 调试信息已删除
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -23,13 +23,13 @@ export interface MainPageModule {
|
||||
|
||||
export class MainPageModule {
|
||||
private pageContext: any;
|
||||
private dataModule: DataModule;
|
||||
private loginModule: LoginModule;
|
||||
private mapModule: MapModule;
|
||||
private orderModule: OrderModule;
|
||||
private warehouseModule: WarehouseModule;
|
||||
private employeeModule: EmployeeModule;
|
||||
private locationModule: LocationModule;
|
||||
private dataModule: DataModule;
|
||||
|
||||
constructor(pageContext: any) {
|
||||
this.pageContext = pageContext;
|
||||
@@ -198,13 +198,15 @@ export class MainPageModule {
|
||||
* 重置用户标记点
|
||||
*/
|
||||
private resetUserMarker(): void {
|
||||
const { markers } = this.pageContext.data;
|
||||
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: any) => {
|
||||
if (marker.id === -1) {
|
||||
return {
|
||||
...marker,
|
||||
iconPath: '/images/trucks.png'
|
||||
iconPath: iconPath
|
||||
};
|
||||
}
|
||||
return marker;
|
||||
@@ -334,6 +336,19 @@ export class MainPageModule {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理资源
|
||||
*/
|
||||
cleanup(): void {
|
||||
console.log('清理主页面模块资源');
|
||||
|
||||
// 清理位置模块
|
||||
this.locationModule.cleanup();
|
||||
|
||||
// 这里可以添加其他需要清理的资源
|
||||
console.log('✅ 主页面模块清理完成');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理错误
|
||||
*/
|
||||
|
@@ -171,55 +171,17 @@ export class MapModule {
|
||||
|
||||
const markers: Marker[] = [];
|
||||
|
||||
// 获取用户位置
|
||||
const userLocation = this.pageContext.data.userLocation;
|
||||
if (userLocation && userLocation.longitude && userLocation.latitude) {
|
||||
// 添加用户位置标记点
|
||||
markers.push({
|
||||
id: -1,
|
||||
title: '用户位置',
|
||||
longitude: userLocation.longitude,
|
||||
latitude: userLocation.latitude,
|
||||
iconPath: '/images/trucks.png',
|
||||
width: 40,
|
||||
height: 40,
|
||||
zIndex: 99
|
||||
});
|
||||
|
||||
console.log('已添加用户位置标记点');
|
||||
}
|
||||
// 地图自带用户位置显示功能,无需手动添加用户位置标记点
|
||||
|
||||
return markers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户标记图标为用户头像
|
||||
* 注意:由于地图自带用户位置显示功能,此方法已不再需要
|
||||
*/
|
||||
updateUserMarkerIcon(): void {
|
||||
const { authStatus, userInfo, markers } = this.pageContext.data;
|
||||
|
||||
if (!authStatus.hasWxCode || !userInfo) {
|
||||
console.warn('未登录或用户信息为空,无法更新头像');
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用默认头像
|
||||
const avatarUrl = '/images/trucks.png';
|
||||
|
||||
const updatedMarkers = markers.map((marker: Marker) => {
|
||||
if (marker.id === -1) {
|
||||
return {
|
||||
...marker,
|
||||
iconPath: avatarUrl
|
||||
};
|
||||
}
|
||||
return marker;
|
||||
});
|
||||
|
||||
// 更新数据模块中的标记点
|
||||
this.dataModule.updateMarkers(updatedMarkers);
|
||||
|
||||
console.log('用户头像已更新');
|
||||
console.log('地图自带用户位置显示功能,无需更新用户标记图标');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,6 +206,91 @@ export class MapModule {
|
||||
console.log('员工标记点更新完成,总标记点数量:', updatedMarkers.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有员工标记点
|
||||
*/
|
||||
clearEmployeeMarkers(): void {
|
||||
console.log('开始清除所有员工标记点');
|
||||
|
||||
const { markers } = this.pageContext.data;
|
||||
|
||||
// 过滤掉员工标记点,只保留其他类型的标记点
|
||||
const filteredMarkers = markers.filter((marker: any) =>
|
||||
marker.type !== 'employee'
|
||||
);
|
||||
|
||||
// 更新数据模块中的标记点
|
||||
this.dataModule.updateMarkers(filteredMarkers);
|
||||
|
||||
console.log('员工标记点清除完成,剩余标记点数量:', filteredMarkers.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除单个员工标记点
|
||||
*/
|
||||
removeEmployeeMarker(markerId: number): void {
|
||||
console.log('删除单个员工标记点:', markerId);
|
||||
|
||||
const { markers } = this.pageContext.data;
|
||||
|
||||
// 只删除员工类型的标记点,避免误删其他类型标记点
|
||||
const filteredMarkers = markers.filter((marker: any) =>
|
||||
!(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: Marker): void {
|
||||
console.log('添加单个员工标记点:', employeeMarker.id);
|
||||
|
||||
// 确保标记点类型为员工
|
||||
const markerWithType = {
|
||||
...employeeMarker,
|
||||
type: 'employee'
|
||||
};
|
||||
|
||||
const { markers } = this.pageContext.data;
|
||||
|
||||
// 检查是否已存在相同ID的标记点
|
||||
const existingIndex = markers.findIndex((marker: any) =>
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新单个员工标记点
|
||||
*/
|
||||
|
Reference in New Issue
Block a user