地址路径修改
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
// 管理员模块 - 专门处理管理员相关功能
|
||||
import { showToast } from '../../utils/helpers';
|
||||
|
||||
import { DataModule } from './dataModule';
|
||||
|
||||
export class AdminModule {
|
||||
private pageContext: any;
|
||||
|
||||
private dataModule: DataModule;
|
||||
|
||||
constructor(pageContext: any, dataModule: DataModule) {
|
||||
this.pageContext = pageContext;
|
||||
constructor(_pageContext: any, dataModule: DataModule) {
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
|
||||
@@ -24,7 +23,7 @@ export class AdminModule {
|
||||
/**
|
||||
* 显示管理员详情面板
|
||||
*/
|
||||
private showAdminPanel(admin: any, position: { x: number, y: number }): void {
|
||||
private showAdminPanel(admin: any, _position: { x: number, y: number }): void {
|
||||
console.log('显示管理员详情面板:', admin);
|
||||
|
||||
// 设置当前管理员
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { UserInfo, Marker } from '../../../types';
|
||||
import { avatarCache } from '../../../utils/avatarCache';
|
||||
|
||||
/**
|
||||
* 页面数据管理模块
|
||||
@@ -80,16 +81,48 @@ export class DataModule {
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
public updateUserInfo(userInfo: UserInfo | null): void {
|
||||
public async updateUserInfo(userInfo: UserInfo | null): Promise<void> {
|
||||
if (!userInfo) {
|
||||
this.pageContext.setData({
|
||||
userInfo: null,
|
||||
isLoggedIn: false
|
||||
});
|
||||
|
||||
// 更新按钮显示状态
|
||||
if (this.pageContext.updateButtonDisplayStatus) {
|
||||
this.pageContext.updateButtonDisplayStatus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理头像缓存
|
||||
const processedUserInfo = { ...userInfo };
|
||||
if (userInfo.avatarPath) {
|
||||
try {
|
||||
// 只有在用户已签到的情况下才使用头像缓存
|
||||
const app = getApp<any>();
|
||||
const isSignedIn = app.globalData.userInfo && app.globalData.userInfo.status === 'signed_in';
|
||||
|
||||
if (isSignedIn) {
|
||||
processedUserInfo.avatarPath = await avatarCache.getAvatarPath(userInfo.avatarPath);
|
||||
} else {
|
||||
// 未签到状态,直接使用原始路径
|
||||
processedUserInfo.avatarPath = userInfo.avatarPath;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('处理用户头像缓存失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
this.pageContext.setData({
|
||||
userInfo,
|
||||
isLoggedIn: !!userInfo
|
||||
userInfo: processedUserInfo,
|
||||
isLoggedIn: true
|
||||
});
|
||||
|
||||
// 更新按钮显示状态
|
||||
if (this.pageContext.updateButtonDisplayStatus) {
|
||||
this.pageContext.updateButtonDisplayStatus();
|
||||
}
|
||||
if (this.pageContext.updateButtonDisplayStatus) {
|
||||
this.pageContext.updateButtonDisplayStatus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,8 +193,32 @@ export class DataModule {
|
||||
/**
|
||||
* 设置当前选中货运人员
|
||||
*/
|
||||
public setCurrentDeliveryPerson(person: any): void {
|
||||
this.pageContext.setData({ currentDeliveryPerson: person });
|
||||
public async setCurrentDeliveryPerson(person: any): Promise<void> {
|
||||
if (!person) {
|
||||
this.pageContext.setData({ currentDeliveryPerson: null });
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理头像缓存
|
||||
const processedPerson = { ...person };
|
||||
if (person.avatarPath) {
|
||||
try {
|
||||
// 只有在用户已签到的情况下才使用头像缓存
|
||||
const app = getApp<any>();
|
||||
const isSignedIn = app.globalData.userInfo && app.globalData.userInfo.status === 'signed_in';
|
||||
|
||||
if (isSignedIn) {
|
||||
processedPerson.avatarPath = await avatarCache.getAvatarPath(person.avatarPath);
|
||||
} else {
|
||||
// 未签到状态,直接使用原始路径
|
||||
processedPerson.avatarPath = person.avatarPath;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('处理货运人员头像缓存失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
this.pageContext.setData({ currentDeliveryPerson: processedPerson });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
// 货运人员模块 - 专门处理货运人员相关功能
|
||||
import { showToast } from '../../utils/helpers';
|
||||
|
||||
import { DataModule } from './dataModule';
|
||||
|
||||
export class DeliveryPersonModule {
|
||||
private pageContext: any;
|
||||
|
||||
private dataModule: DataModule;
|
||||
|
||||
constructor(pageContext: any, dataModule: DataModule) {
|
||||
this.pageContext = pageContext;
|
||||
constructor(_pageContext: any, dataModule: DataModule) {
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
|
||||
@@ -24,7 +23,7 @@ export class DeliveryPersonModule {
|
||||
/**
|
||||
* 显示货运人员详情面板
|
||||
*/
|
||||
private showDeliveryPersonPanel(deliveryPerson: any, position: { x: number, y: number }): void {
|
||||
private showDeliveryPersonPanel(deliveryPerson: any, _position: { x: number, y: number }): void {
|
||||
console.log('显示货运人员详情面板:', deliveryPerson);
|
||||
|
||||
// 设置当前货运人员
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
// 员工模块 - 处理所有员工(管理员和货运人员)的通用功能
|
||||
import { showToast } from '../../../utils/helpers';
|
||||
import { DataModule } from './dataModule';
|
||||
import employeeService from '../../../services/employeeService';
|
||||
import { API_BASE_URL } from '../../../services/apiService';
|
||||
|
||||
export class EmployeeModule {
|
||||
private pageContext: any;
|
||||
|
||||
private dataModule: DataModule;
|
||||
|
||||
constructor(pageContext: any, dataModule: DataModule) {
|
||||
this.pageContext = pageContext;
|
||||
constructor(_pageContext: any, dataModule: DataModule) {
|
||||
this.dataModule = dataModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理员工标记点点击 - 通用处理逻辑
|
||||
*/
|
||||
onEmployeeMarkerClick(employee: any, position: { x: number, y: number }): void {
|
||||
onEmployeeMarkerClick(employee: any, _position: { x: number, y: number }): void {
|
||||
console.log('员工被点击:', employee);
|
||||
|
||||
// 设置当前员工
|
||||
@@ -73,7 +72,31 @@ export class EmployeeModule {
|
||||
try {
|
||||
console.log('开始加载所有员工数据');
|
||||
const employees = await employeeService.getEmployees();
|
||||
console.log('员工数据加载完成:', employees);
|
||||
console.log('员工数据加载完成,共', employees.length, '名员工');
|
||||
|
||||
// 打印每个员工的基本信息
|
||||
console.log('=== 员工列表详细信息 ===');
|
||||
employees.forEach((employee, index) => {
|
||||
console.log(`员工 ${index + 1}:`);
|
||||
console.log(` - ID: ${employee.id}`);
|
||||
console.log(` - 姓名: ${employee.name || '未设置'}`);
|
||||
console.log(` - 电话: ${employee.phone || '未设置'}`);
|
||||
console.log(` - 角色: ${employee.role || '未设置'}`);
|
||||
|
||||
// 处理头像路径:使用avatarPath转换为完整URL
|
||||
let avatarFullUrl = '未设置';
|
||||
if (employee.avatarPath) {
|
||||
avatarFullUrl = `${API_BASE_URL}${employee.avatarPath}`;
|
||||
console.log(` - 头像路径: ${employee.avatarPath}`);
|
||||
console.log(` - 完整头像URL: ${avatarFullUrl}`);
|
||||
} else {
|
||||
console.log(` - 头像URL: 未设置`);
|
||||
}
|
||||
|
||||
console.log(` - 头像缩略图: ${employee.avatarThumbnail || '未设置'}`);
|
||||
console.log('---');
|
||||
});
|
||||
console.log('=== 员工列表打印完成 ===');
|
||||
|
||||
// 这里可以添加员工数据处理逻辑,比如更新到dataModule
|
||||
// this.dataModule.updateEmployees(employees);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import { showToast } from '../../../utils/helpers';
|
||||
import { DataModule } from './dataModule';
|
||||
import locationTrackingService from '../../../services/locationTrackingService';
|
||||
import { avatarCache } from '../../../utils/avatarCache';
|
||||
import { API_BASE_URL } from '../../../services/apiService';
|
||||
|
||||
// 位置模块接口定义
|
||||
export interface LocationModule {
|
||||
@@ -39,12 +41,16 @@ export class LocationModule {
|
||||
console.log('📝 [LocationModule] 设置位置更新回调');
|
||||
|
||||
// 注册位置更新回调
|
||||
locationTrackingService.subscribeToLocationUpdates((onlineUsers) => {
|
||||
locationTrackingService.subscribeToLocationUpdates(async (onlineUsers) => {
|
||||
console.log('🔔 [LocationModule] 收到位置更新通知');
|
||||
console.log('👥 [LocationModule] 在线用户数量:', onlineUsers.length);
|
||||
|
||||
// 调用updateEmployeeMarkers方法更新地图标记
|
||||
this.updateEmployeeMarkers(onlineUsers);
|
||||
try {
|
||||
await this.updateEmployeeMarkers(onlineUsers);
|
||||
} catch (error) {
|
||||
console.error('更新员工标记点失败:', error);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('✅ [LocationModule] 位置更新回调设置完成');
|
||||
@@ -118,7 +124,7 @@ export class LocationModule {
|
||||
/**
|
||||
* 更新员工标记点
|
||||
*/
|
||||
public updateEmployeeMarkers(onlineUsers: any[]): void {
|
||||
public async updateEmployeeMarkers(onlineUsers: any[]): Promise<void> {
|
||||
console.log('📍 [LocationModule] 开始更新员工标记点');
|
||||
console.log('👥 [LocationModule] 传入用户数量:', onlineUsers.length);
|
||||
|
||||
@@ -135,7 +141,7 @@ export class LocationModule {
|
||||
console.log('🗺️ [LocationModule] 当前地图上员工标记点数量:', currentEmployeeMarkers.length);
|
||||
|
||||
// 为每个在线用户创建标记点
|
||||
const newEmployeeMarkers = onlineUsers.map((user, index) => {
|
||||
const newEmployeeMarkers = await Promise.all(onlineUsers.map(async (user, index) => {
|
||||
console.log(`🔍 [LocationModule] 处理第 ${index + 1} 个用户:`, user.userId || '未知ID');
|
||||
|
||||
// 获取用户角色信息
|
||||
@@ -149,25 +155,33 @@ export class LocationModule {
|
||||
console.log(`📡 [LocationModule] 用户 ${index + 1} 位置: ${latitude}, ${longitude}`);
|
||||
console.log(`👤 [LocationModule] 用户 ${index + 1} 信息: ${user.userName || '未知用户'} (${userRole})`);
|
||||
|
||||
// 获取员工图标
|
||||
const iconPath = await this.getEmployeeIcon(user.userId, userRole, user);
|
||||
|
||||
const employeeMarker = {
|
||||
id: 10000 + user.userId, // 避免ID冲突
|
||||
type: 'employee',
|
||||
title: user.userName || `员工${user.userId}`,
|
||||
longitude: longitude,
|
||||
latitude: latitude,
|
||||
iconPath: this.getEmployeeIcon(user.userId, userRole),
|
||||
iconPath: iconPath,
|
||||
width: 32,
|
||||
height: 32,
|
||||
zIndex: 30,
|
||||
data: {
|
||||
userId: user.userId,
|
||||
role: userRole,
|
||||
lastUpdateTime: lastUpdateTime
|
||||
lastUpdateTime: lastUpdateTime,
|
||||
currentLocation: {
|
||||
address: user.address || '位置信息获取中...',
|
||||
longitude: longitude,
|
||||
latitude: latitude
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return employeeMarker;
|
||||
});
|
||||
}));
|
||||
|
||||
console.log('📍 [LocationModule] 新生成标记点数量:', newEmployeeMarkers.length);
|
||||
|
||||
@@ -274,14 +288,59 @@ export class LocationModule {
|
||||
/**
|
||||
* 获取员工图标
|
||||
*/
|
||||
private getEmployeeIcon(_userId: number, userRole: string): string {
|
||||
// 根据用户角色返回不同的图标
|
||||
private async getEmployeeIcon(userId: number, userRole: string, userData?: any): Promise<string> {
|
||||
console.log(`🔍 [LocationModule] 获取用户 ${userId} (${userRole}) 的图标`);
|
||||
|
||||
// 优先使用传入的用户数据中的头像信息
|
||||
if (userData) {
|
||||
// 尝试使用avatarPath(相对路径)
|
||||
if (userData.avatarPath) {
|
||||
console.log(`📸 [LocationModule] 使用用户数据中的avatarPath: ${userData.avatarPath}`);
|
||||
const fullAvatarUrl = `${API_BASE_URL}${userData.avatarPath}`;
|
||||
return await avatarCache.getAvatarPath(fullAvatarUrl);
|
||||
}
|
||||
|
||||
// 尝试使用avatarUrl(完整URL)
|
||||
if (userData.avatarUrl) {
|
||||
console.log(`📸 [LocationModule] 使用用户数据中的avatarUrl: ${userData.avatarUrl}`);
|
||||
return await avatarCache.getAvatarPath(userData.avatarUrl);
|
||||
}
|
||||
|
||||
// 尝试使用avatar(兼容字段)
|
||||
if (userData.avatar) {
|
||||
console.log(`📸 [LocationModule] 使用用户数据中的avatar: ${userData.avatar}`);
|
||||
return await avatarCache.getAvatarPath(userData.avatar);
|
||||
}
|
||||
}
|
||||
|
||||
// 其次尝试从全局数据获取当前用户的头像
|
||||
const app = getApp<any>();
|
||||
if (app.globalData.userInfo && app.globalData.userInfo.id === userId) {
|
||||
if (app.globalData.userInfo.avatarUrl) {
|
||||
console.log(`📸 [LocationModule] 使用全局数据中的avatarPath: ${app.globalData.userInfo.avatarPath}`);
|
||||
const fullAvatarUrl = `${API_BASE_URL}${app.globalData.userInfo.avatarPath}`;
|
||||
return await avatarCache.getAvatarPath(fullAvatarUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// 最后尝试从页面数据获取用户信息
|
||||
const userInfo = this.dataModule.getData().userInfo;
|
||||
if (userInfo && userInfo.id === userId) {
|
||||
if (userInfo.avatarPath) {
|
||||
console.log(`📸 [LocationModule] 使用页面数据中的avatarPath: ${userInfo.avatarPath}`);
|
||||
const fullAvatarUrl = `${API_BASE_URL}${userInfo.avatarPath}`;
|
||||
return await avatarCache.getAvatarPath(fullAvatarUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果所有头像获取都失败,使用默认图标
|
||||
console.log(`⚠️ [LocationModule] 用户 ${userId} 没有头像数据,使用默认图标`);
|
||||
if (userRole === 'ADMIN') {
|
||||
return '/images/crown.png'; // 管理员图标
|
||||
return '/images/crown.png'; // 使用现有的皇冠图标作为管理员图标
|
||||
} else if (userRole === 'DRIVER') {
|
||||
return '/images/truck.png'; // 司机图标
|
||||
return '/images/truck.png'; // 使用现有的卡车图标作为司机图标
|
||||
} else {
|
||||
return '/images/truck.png'; // 普通员工也使用货运图标
|
||||
return '/images/user-avatar.png'; // 使用现有的用户头像作为普通员工图标
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,10 @@ import { showToast } from '../../../utils/helpers';
|
||||
import { UserInfo } from '../../../types';
|
||||
import userService from '../../../services/userService';
|
||||
import locationTrackingService from '../../../services/locationTrackingService';
|
||||
import employeeService from '../../../services/employeeService';
|
||||
import { avatarCache } from '../../../utils/avatarCache';
|
||||
import { DataModule } from './dataModule';
|
||||
import { API_BASE_URL } from '../../../services/apiService';
|
||||
|
||||
export class LoginModule {
|
||||
private dataModule: DataModule;
|
||||
@@ -25,8 +28,8 @@ export class LoginModule {
|
||||
/**
|
||||
* 登录成功后更新页面状态
|
||||
*/
|
||||
public updatePageAfterLogin(userInfo: UserInfo): void {
|
||||
this.dataModule.updateUserInfo(userInfo);
|
||||
public async updatePageAfterLogin(userInfo: UserInfo): Promise<void> {
|
||||
await this.dataModule.updateUserInfo(userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +110,7 @@ export class LoginModule {
|
||||
const result = await userService.wxLogin();
|
||||
if (result.success && result.userInfo) {
|
||||
// 登录成功,更新页面状态
|
||||
this.updatePageAfterLogin(result.userInfo);
|
||||
await this.updatePageAfterLogin(result.userInfo);
|
||||
console.log('手动登录成功');
|
||||
return true;
|
||||
}
|
||||
@@ -297,7 +300,7 @@ export class LoginModule {
|
||||
name: signInResult.employeeInfo.name,
|
||||
phone: signInResult.employeeInfo.phone
|
||||
};
|
||||
this.updatePageAfterLogin(app.globalData.userInfo);
|
||||
await this.updatePageAfterLogin(app.globalData.userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,15 +316,6 @@ export class LoginModule {
|
||||
}
|
||||
}
|
||||
|
||||
// 启动位置追踪服务(WebSocket连接)
|
||||
try {
|
||||
// 启动位置追踪服务(建立WebSocket连接)
|
||||
await locationTrackingService.startTracking();
|
||||
console.log('位置追踪服务已启动');
|
||||
} catch (trackingError) {
|
||||
console.warn('启动位置追踪失败,但不影响签到:', trackingError);
|
||||
}
|
||||
|
||||
// 加载业务数据(所有登录用户)
|
||||
try {
|
||||
console.log('用户签到成功,开始加载业务数据');
|
||||
@@ -350,6 +344,25 @@ export class LoginModule {
|
||||
}
|
||||
}
|
||||
|
||||
// 预加载所有必要的头像并等待完成
|
||||
try {
|
||||
console.log('开始预加载所有必要的头像');
|
||||
await this.preloadAllAvatars();
|
||||
console.log('所有头像预加载完成');
|
||||
} catch (avatarError) {
|
||||
console.warn('头像预加载失败,但不影响签到:', avatarError);
|
||||
}
|
||||
|
||||
// 启动位置追踪服务(WebSocket连接)- 在所有必要数据加载和头像预加载完成后启动
|
||||
try {
|
||||
console.log('所有必要数据加载和头像预加载完成,开始启动位置追踪服务');
|
||||
// 启动位置追踪服务(建立WebSocket连接)
|
||||
await locationTrackingService.startTracking();
|
||||
console.log('位置追踪服务已启动');
|
||||
} catch (trackingError) {
|
||||
console.warn('启动位置追踪失败,但不影响签到:', trackingError);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
console.warn('签到失败:', signInResult.message);
|
||||
@@ -510,4 +523,59 @@ export class LoginModule {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载所有必要的头像
|
||||
*/
|
||||
private async preloadAllAvatars(): Promise<void> {
|
||||
console.log('🔄 [LoginModule] 开始收集需要预加载的头像URL');
|
||||
|
||||
const avatarUrls: string[] = [];
|
||||
|
||||
// 1. 当前用户的头像
|
||||
const app = getApp<any>();
|
||||
if (app.globalData.userInfo && app.globalData.userInfo.avatarPath) {
|
||||
const fullAvatarUrl = `${API_BASE_URL}${app.globalData.userInfo.avatarPath}`;
|
||||
avatarUrls.push(fullAvatarUrl);
|
||||
console.log(`👤 [LoginModule] 添加当前用户头像: ${fullAvatarUrl}`);
|
||||
}
|
||||
|
||||
// 2. 员工列表中的头像(如果是管理员)
|
||||
if (app.globalData.userInfo && app.globalData.userInfo.role === 'ADMIN') {
|
||||
try {
|
||||
// 获取员工数据
|
||||
const mainPageModule = this.pageContext.data.mainPageModule;
|
||||
if (mainPageModule && mainPageModule.getEmployeeModule) {
|
||||
// 直接调用员工服务获取员工数据
|
||||
const employees = await employeeService.getEmployees();
|
||||
|
||||
console.log(`📋 [LoginModule] 获取到 ${employees.length} 名员工数据`);
|
||||
|
||||
// 处理员工头像路径
|
||||
employees.forEach((employee, index) => {
|
||||
if (employee.avatarPath) {
|
||||
// 将相对路径转换为完整URL
|
||||
const fullAvatarUrl = `${API_BASE_URL}${employee.avatarPath}`;
|
||||
avatarUrls.push(fullAvatarUrl);
|
||||
console.log(`👥 [LoginModule] 添加员工 ${index + 1} 头像: ${fullAvatarUrl}`);
|
||||
} else {
|
||||
console.log(`ℹ️ [LoginModule] 员工 ${index + 1} 没有设置头像`);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('获取员工数据失败,跳过员工头像预加载:', error);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`📊 [LoginModule] 总共需要预加载 ${avatarUrls.length} 个头像`);
|
||||
|
||||
if (avatarUrls.length > 0) {
|
||||
// 等待所有头像预加载完成
|
||||
await avatarCache.preloadAvatarsAndWait(avatarUrls);
|
||||
console.log('✅ [LoginModule] 所有头像预加载完成');
|
||||
} else {
|
||||
console.log('ℹ️ [LoginModule] 没有需要预加载的头像');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user