用户在线状态处理
This commit is contained in:
@@ -142,30 +142,36 @@ export class LocationModule {
|
||||
* 处理位置更新回调
|
||||
*/
|
||||
private handleLocationUpdates(locationData: any): void {
|
||||
console.log('收到位置更新回调:', locationData);
|
||||
console.log('🔔 [LocationModule] 收到位置更新回调');
|
||||
console.log('📊 [LocationModule] 回调数据类型:', locationData.type || '未知类型');
|
||||
console.log('📋 [LocationModule] 回调数据内容:', JSON.stringify(locationData, null, 2));
|
||||
|
||||
if (locationData.type === 'onlineUserList' && locationData.users) {
|
||||
// 处理在线用户列表更新
|
||||
console.log('处理在线用户列表,用户数量:', locationData.users.length);
|
||||
console.log('👥 [LocationModule] 处理在线用户列表,用户数量:', locationData.users.length);
|
||||
this.updateEmployeeMarkers(locationData.users);
|
||||
} else if (Array.isArray(locationData)) {
|
||||
// 处理位置更新数组(旧格式)
|
||||
console.log('处理位置更新数组,用户数量:', locationData.length);
|
||||
console.log('📋 [LocationModule] 处理位置更新数组,用户数量:', locationData.length);
|
||||
this.updateEmployeeMarkers(locationData);
|
||||
} else if (locationData.userId && locationData.latitude && locationData.longitude) {
|
||||
// 处理单个用户位置更新
|
||||
console.log('处理单个用户位置更新:', locationData.userId);
|
||||
console.log('👤 [LocationModule] 处理单个用户位置更新:', locationData.userId);
|
||||
this.updateSingleEmployeeMarker(locationData);
|
||||
} else {
|
||||
console.warn('未知的位置数据格式:', locationData);
|
||||
console.warn('❌ [LocationModule] 未知的位置数据格式:', locationData);
|
||||
}
|
||||
|
||||
console.log('🏁 [LocationModule] 位置更新回调处理完成');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新员工标记点
|
||||
*/
|
||||
private updateEmployeeMarkers(onlineUsers: any[]): void {
|
||||
console.log('开始更新员工标记点,在线用户数量:', onlineUsers.length);
|
||||
console.log('📍 [LocationModule] 开始更新员工标记点');
|
||||
console.log('👥 [LocationModule] 传入用户数量:', onlineUsers.length);
|
||||
console.log('📋 [LocationModule] 用户数据示例:', JSON.stringify(onlineUsers[0], null, 2));
|
||||
|
||||
// 获取地图模块来更新标记点
|
||||
const mapModule = this.dataModule.getMapModule();
|
||||
@@ -175,7 +181,9 @@ export class LocationModule {
|
||||
}
|
||||
|
||||
// 为每个在线用户创建标记点
|
||||
const employeeMarkers = onlineUsers.map(user => {
|
||||
const employeeMarkers = onlineUsers.map((user, index) => {
|
||||
console.log(`🔍 [LocationModule] 处理第 ${index + 1} 个用户:`, user.userId || '未知ID');
|
||||
|
||||
// 获取用户角色信息
|
||||
const userRole = user.role || this.getUserRole(user.userId);
|
||||
|
||||
@@ -184,6 +192,9 @@ export class LocationModule {
|
||||
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 employeeMarker = {
|
||||
id: 10000 + user.userId, // 避免ID冲突
|
||||
type: 'employee',
|
||||
@@ -204,10 +215,13 @@ export class LocationModule {
|
||||
return employeeMarker;
|
||||
});
|
||||
|
||||
console.log('📍 [LocationModule] 生成标记点数量:', employeeMarkers.length);
|
||||
console.log('📋 [LocationModule] 标记点数据示例:', JSON.stringify(employeeMarkers[0], null, 2));
|
||||
|
||||
// 调用地图模块更新员工标记点
|
||||
mapModule.updateEmployeeMarkers(employeeMarkers);
|
||||
|
||||
console.log(`成功更新了 ${employeeMarkers.length} 个员工标记点`);
|
||||
console.log('✅ [LocationModule] 员工标记点更新完成');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -193,8 +193,24 @@ export class LoginModule {
|
||||
title: '签到中...',
|
||||
});
|
||||
|
||||
// 调用实际的签到接口
|
||||
const signInResult = await userService.signIn();
|
||||
// 先获取地图位置和当前时间
|
||||
let initialLocation: { latitude: number; longitude: number; timestamp: number };
|
||||
try {
|
||||
const location = await locationTrackingService.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.signIn(initialLocation);
|
||||
|
||||
wx.hideLoading();
|
||||
|
||||
|
Reference in New Issue
Block a user