拆分腾讯会话纯函数与序列化逻辑
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { getLoginTypeLabel } from './session-browser-config.js'
|
||||
|
||||
export const SESSION_TTL_MS = 30 * 60 * 1000
|
||||
|
||||
export function resolveTencentSessionExpiresAt(session, nowMs = Date.now(), sessionTtlMs = SESSION_TTL_MS) {
|
||||
const autoCloseAt = Number(session?.autoCloseAt || 0)
|
||||
if (autoCloseAt > 0) {
|
||||
return autoCloseAt
|
||||
}
|
||||
|
||||
return nowMs + sessionTtlMs
|
||||
}
|
||||
|
||||
export function shouldRefreshLoggedInPresentation(hostState) {
|
||||
const loginText = String(hostState?.loginText || '').trim()
|
||||
|
||||
return Boolean(hostState?.unloginVisible || !hostState?.loginedVisible || !loginText)
|
||||
}
|
||||
|
||||
export function resolveSessionStatus({ hostState, qrState, credentialReady, activityInfo }) {
|
||||
if (hostState.loginedVisible || credentialReady) {
|
||||
if (credentialReady && activityInfo?.role?.ready) {
|
||||
return 'ready_to_redeem'
|
||||
}
|
||||
|
||||
return 'logged_in'
|
||||
}
|
||||
|
||||
if (qrState.expired) {
|
||||
return 'expired'
|
||||
}
|
||||
|
||||
if (qrState.scanned) {
|
||||
return 'scanned'
|
||||
}
|
||||
|
||||
return 'waiting_scan'
|
||||
}
|
||||
|
||||
export function resolveSessionNotice({
|
||||
hostState,
|
||||
qrState,
|
||||
credentialReady,
|
||||
activityInfo,
|
||||
loginType,
|
||||
}) {
|
||||
const loginTypeLabel = getLoginTypeLabel(loginType)
|
||||
|
||||
if (credentialReady) {
|
||||
if (activityInfo?.role?.ready && activityInfo.role.roleName) {
|
||||
return `登录已完成,当前角色 ${activityInfo.role.roleName}`
|
||||
}
|
||||
|
||||
return '登录已完成,正在同步角色信息'
|
||||
}
|
||||
|
||||
if (hostState.loginedVisible) {
|
||||
return '页面已识别登录态'
|
||||
}
|
||||
|
||||
if (qrState.expired) {
|
||||
return '二维码已失效,准备刷新'
|
||||
}
|
||||
|
||||
if (qrState.scanned) {
|
||||
return '二维码已扫描,请在手机上确认登录'
|
||||
}
|
||||
|
||||
return `请使用${loginTypeLabel}扫码登录`
|
||||
}
|
||||
|
||||
export function hasRedeemCredential(cookieMap) {
|
||||
return Boolean(cookieMap.openid && cookieMap.access_token && cookieMap.appid)
|
||||
}
|
||||
Reference in New Issue
Block a user