feat: 完成前端业务闭环与后端联调

This commit is contained in:
2026-08-24 23:37:56 +08:00
parent c59e36f933
commit 9ad572907b
175 changed files with 10711 additions and 1740 deletions
+20 -10
View File
@@ -1,15 +1,6 @@
import { resolveRuntimeMode } from '@/utils/runtime-config.js'
import { AUTH_VERIFICATION_OPERATION } from '@/utils/auth/verification.js'
import { session } from '@/utils/session.js'
export const requireRemoteAuth = () => {
if (resolveRuntimeMode() !== 'remote') {
const error = new Error('当前为本地预览模式,真实认证服务未启用')
error.code = 'AUTH_REMOTE_REQUIRED'
throw error
}
}
export const assertAuthVerificationOperation = (operationCode) => {
if (!Object.values(AUTH_VERIFICATION_OPERATION).includes(operationCode)) {
throw new TypeError('认证动作不属于当前认证合同')
@@ -34,9 +25,28 @@ export const assertPasswordHash = (passwordHash) => {
return passwordHash
}
export const normalizeOptionalReferralCode = (referralCode) => {
if (referralCode === undefined || referralCode === null || referralCode === '') return ''
if (typeof referralCode !== 'string') throw new TypeError('推荐码必须是字符串')
const normalized = referralCode.trim()
if (!/^[A-Za-z0-9_-]{4,64}$/.test(normalized)) {
throw new TypeError('推荐码格式无效')
}
return normalized
}
export const assertWechatAuthorizationCode = (authorizationCode) => {
if (typeof authorizationCode !== 'string' || !authorizationCode.trim()) {
throw new TypeError('微信授权未返回有效临时票据')
}
return authorizationCode.trim()
}
export const saveLogin = (loginResult) => {
const token = loginResult?.access_token
if (!token) throw new Error('登录响应未包含会话令牌')
if (typeof token !== 'string' || !token || token.trim() !== token) {
throw new Error('登录响应未包含有效的会话令牌')
}
session.saveToken(token)
return loginResult
}