添加管理员逻辑
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user