修改完成

This commit is contained in:
2026-08-21 17:06:08 +08:00
parent 55da9a9e8a
commit 76af4cc492
10 changed files with 212 additions and 199 deletions
+2 -79
View File
@@ -4,14 +4,6 @@ const AuthPageUtil = {
slideX: 0,
slideToken: '',
slideCaptchaViewportCleanup: null,
referralInviteSessionKey: 'pendingReferralInviteCode',
getSessionStorage() {
if (typeof sessionStorage !== 'undefined') return sessionStorage;
if (typeof window !== 'undefined' && window.sessionStorage) return window.sessionStorage;
return null;
},
normalizeReferralInviteCode(inviteCode) {
return String(inviteCode || '').trim();
},
@@ -31,82 +23,13 @@ const AuthPageUtil = {
try {
const params = new Params(query || '');
return this.normalizeReferralInviteCode(
params.get('inviteCode') || params.get('referralCode') || '',
params.get('inviteCode') || '',
);
} catch (error) {
return '';
}
},
setPendingReferralInviteCode(inviteCode) {
const code = this.normalizeReferralInviteCode(inviteCode);
const storage = this.getSessionStorage();
if (code && storage) {
storage.setItem(this.referralInviteSessionKey, code);
}
return code;
},
getPendingReferralInviteCode() {
const storage = this.getSessionStorage();
if (!storage) return '';
return this.normalizeReferralInviteCode(storage.getItem(this.referralInviteSessionKey));
},
clearPendingReferralInviteCode() {
const storage = this.getSessionStorage();
if (storage) storage.removeItem(this.referralInviteSessionKey);
},
captureReferralInviteFromUrl(search) {
const code = this.getReferralInviteCodeFromUrl(search);
if (code) {
this.setPendingReferralInviteCode(code);
}
return code;
},
bindPendingReferralInviteCode() {
const inviteCode = this.getPendingReferralInviteCode();
if (!inviteCode) {
return Promise.resolve({ skipped: true, reason: 'empty' });
}
if (
typeof ApiClient === 'undefined' ||
!ApiClient.API ||
!ApiClient.API.referralBind ||
typeof ApiClient.post !== 'function'
) {
return Promise.resolve({ skipped: true, reason: 'missing-api' });
}
if (typeof ApiClient.token === 'function' && !ApiClient.token()) {
return Promise.resolve({ skipped: true, reason: 'unauthenticated' });
}
return ApiClient.post(ApiClient.API.referralBind, { inviteCode })
.then((res) => {
const isSuccess =
typeof ApiClient.isSuccess === 'function'
? ApiClient.isSuccess(res)
: !!(res && (res.success === true || Number(res.code) === 0 || Number(res.code) === 200));
if (isSuccess) {
this.clearPendingReferralInviteCode();
return { skipped: false, success: true, res };
}
return { skipped: false, success: false, res };
})
.catch((error) => ({ skipped: false, success: false, error }));
},
isPhone(phone) {
return /^1[3-9]\d{9}$/.test(String(phone || '').trim());
},
@@ -133,7 +56,7 @@ const AuthPageUtil = {
}
return 'captcha';
})
.catch(() => 'captcha');
.catch(() => 'slide');
},
buildSmsParams(options = {}) {