Files
airz-uniapp/services/agreements-route.uts
T

21 lines
1.3 KiB
Plaintext
Raw Normal View History

// 主包共享协议路由与会话守卫,账户分包不依赖融资分包。
export function agreementScope(code: string): string {
if (code == 'terms') return 'account-terms'
if (code == 'privacy') return 'account-privacy'
if (code == 'document-use') return 'documents'
if (code == 'data-authorization') return 'data'
return ''
}
export function agreementVersionValid(value: string): boolean { return /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(value) }
export function agreementRecordIdValid(value: string): boolean {
return /^[1-9][0-9]{0,18}$/.test(value) && !(value.length == 19 && value > '9223372036854775807')
}
export function agreementRoute(code: string, version: string = ''): string {
if (agreementScope(code).length == 0 || (version.length > 0 && !agreementVersionValid(version))) return ''
return '/pages/agreement/agreement?code=' + code + (version.length > 0 ? '&version=' + encodeURIComponent(version) : '')
}
export const optionalConsentScope = (scope: string): boolean => scope == 'documents' || scope == 'data'
export function sameConsentSession(token: string, userId: string, currentToken: string, currentUserId: string): boolean {
return token.length > 0 && userId.length > 0 && token == currentToken && userId == currentUserId
}