refactor(client):优化设备管理与登录逻辑
- 移除冗余的日志记录器声明 - 简化设备心跳接口,合并注册与更新逻辑 - 调整设备数量限制检查逻辑,提高代码可读性 - 修改默认设备数量限制从3台调整为1台- 更新客户端登出提示文案- 固定启动窗口尺寸并移除延迟启动逻辑 - 调整设备移除时的消息提示内容
This commit is contained in:
@@ -185,16 +185,13 @@ async function handleLoginSuccess(data: { token: string; permissions?: string; e
|
||||
os: navigator.platform
|
||||
})
|
||||
SSEManager.connect()
|
||||
|
||||
|
||||
// 根据不同场景显示提示
|
||||
const accountExpired = vipExpireTime.value && new Date() > vipExpireTime.value
|
||||
const deviceExpired = deviceTrialExpired.value
|
||||
const isPaid = accountType.value === 'paid'
|
||||
|
||||
if (isPaid) {
|
||||
// 场景5: 付费用户
|
||||
ElMessage.success('登录成功')
|
||||
} else if (deviceExpired && accountExpired) {
|
||||
if (deviceExpired && accountExpired) {
|
||||
// 场景4: 试用已到期,请订阅
|
||||
trialExpiredType.value = 'both'
|
||||
showTrialExpiredDialog.value = true
|
||||
@@ -206,9 +203,6 @@ async function handleLoginSuccess(data: { token: string; permissions?: string; e
|
||||
// 场景2: 设备试用已到期,请更换设备或订阅
|
||||
trialExpiredType.value = 'device'
|
||||
showTrialExpiredDialog.value = true
|
||||
} else {
|
||||
// 场景1: 允许使用
|
||||
ElMessage.success('登录成功')
|
||||
}
|
||||
} catch (e: any) {
|
||||
isAuthenticated.value = false
|
||||
@@ -234,7 +228,7 @@ function clearLocalAuth() {
|
||||
async function logout() {
|
||||
try {
|
||||
const deviceId = getClientIdFromToken()
|
||||
if (deviceId) await deviceApi.offline({ deviceId, username: currentUsername.value })
|
||||
if (deviceId) await deviceApi.remove({ deviceId, username: currentUsername.value })
|
||||
} catch (error) {
|
||||
console.warn('离线通知失败:', error)
|
||||
}
|
||||
@@ -253,7 +247,6 @@ async function handleUserClick() {
|
||||
cancelButtonText: '取消'
|
||||
})
|
||||
await logout()
|
||||
ElMessage.success('已退出登录')
|
||||
} catch {}
|
||||
}
|
||||
|
||||
@@ -366,7 +359,7 @@ const SSEManager = {
|
||||
break
|
||||
case 'DEVICE_REMOVED':
|
||||
clearLocalAuth()
|
||||
ElMessage.warning('您的设备已被移除,请重新登录')
|
||||
ElMessage.warning('会话已失效,请重新登录')
|
||||
break
|
||||
case 'FORCE_LOGOUT':
|
||||
logout()
|
||||
|
||||
Reference in New Issue
Block a user