caixianzhi pc接口修改完成

This commit is contained in:
rain
2026-06-08 17:31:30 +08:00
parent 3a2081f395
commit 7f7fd61ec0
10 changed files with 1737 additions and 12 deletions
+14
View File
@@ -9,8 +9,17 @@ const ApiClient = {
authLogout: '/api/web/auth/logout',
authRegister: '/api/web/auth/register',
authSmsCode: '/api/web/auth/sms/code',
authWechatOpen: '/api/web/auth/binding/wechat_open',
authVerifyConfig: '/api/web/auth/verify-config',
authSlideCaptcha: '/api/web/auth/slide-captcha',
authSlideCaptchaVerify: '/api/web/auth/slide-captcha/verify',
authForgotPasswordSmsCode: '/api/web/auth/forgot-password/sms-code',
authForgotPasswordReset: '/api/web/auth/forgot-password/reset',
authSocialLogin: '/api/web/auth/social-login',
authSocialCallback: '/api/web/auth/social-callback',
authSocialBind: '/api/web/auth/social-bind',
authSocialBindPhone: '/api/web/auth/social-bind-phone',
authSocialBindPhoneSmsCode: '/api/web/auth/social-bind-phone/sms-code',
webConfigList: '/api/web/config/list',
referralShareInfo: '/api/web/referral/share-info',
referralSummary: '/api/web/referral/summary',
@@ -18,6 +27,7 @@ const ApiClient = {
referralRebateList: '/api/web/referral/rebate-list',
referralBindPreview: '/api/web/referral/bind-preview',
referralBind: '/api/web/referral/bind',
accountInfo: '/api/web/account/info',
accountProfile: '/api/web/account/profile',
accountProfileAvatar: '/api/web/account/profile/avatar',
expertConfig: '/api/web/expert/config',
@@ -83,6 +93,10 @@ const ApiClient = {
);
},
get CLIENT_ID() {
return this.clientId;
},
get tenantId() {
return (
(window.CURRENT_CONFIG && window.CURRENT_CONFIG.TENANT_ID) ||
+65 -3
View File
@@ -2,6 +2,7 @@ const AuthPageUtil = {
smsTimers: {},
slideUuid: '',
slideX: 0,
slideToken: '',
isPhone(phone) {
return /^1[3-9]\d{9}$/.test(String(phone || '').trim());
@@ -15,7 +16,7 @@ const AuthPageUtil = {
loadVerifyType() {
return ApiClient.get(ApiClient.API.authVerifyConfig, {}, { publicRequest: true })
.then((res) => {
const data = (res && res.data) || {};
const data = (res && res.data) || res || {};
const yes = (value) =>
value === true || value === 1 || value === '1' || String(value).toLowerCase() === 'true';
if (
@@ -32,12 +33,13 @@ const AuthPageUtil = {
.catch(() => 'captcha');
},
sendSmsCode(options) {
buildSmsParams(options = {}) {
const params = {
phoneNumber: options.phoneNumber,
};
if (options.verifyType === 'slide') {
params.verifyType = 'slide';
params.slideToken = options.slideToken || this.slideToken;
params.slideUuid = options.slideUuid || this.slideUuid;
params.slideX = options.slideX || this.slideX;
}
@@ -46,7 +48,23 @@ const AuthPageUtil = {
params.code = options.code || '';
params.uuid = options.uuid || '';
}
return ApiClient.get(ApiClient.API.authSmsCode, params, { publicRequest: true });
return params;
},
sendSmsCode(options) {
return ApiClient.get(ApiClient.API.authSmsCode, this.buildSmsParams(options), {
publicRequest: true,
});
},
sendForgotPasswordSmsCode(options) {
return ApiClient.get(ApiClient.API.authForgotPasswordSmsCode, this.buildSmsParams(options), {
publicRequest: true,
});
},
getImageCaptcha() {
return ApiClient.get(ApiClient.API.authCode, {}, { publicRequest: true });
},
installSlideCaptchaTenantHeader() {
@@ -138,6 +156,50 @@ const AuthPageUtil = {
});
return window.__slideCaptchaLoading;
},
openSlideCaptcha(options = {}) {
this.installSlideCaptchaTenantHeader();
this.loadSlideCaptchaScript()
.then((SlideCaptcha) => {
SlideCaptcha.open({
title: options.title || '安全验证',
subtitle: options.subtitle || '拖动滑块完成验证',
apiBase: ApiClient.baseUrl || '',
tenantId: ApiClient.tenantId || '000000',
headers: ApiClient.publicHeaders(),
onSuccess: (result) => {
const data = result || {};
const nested = data.data || {};
this.slideToken =
data.slideToken || data.token || data.verifyToken ||
nested.slideToken || nested.token || nested.verifyToken || '';
this.slideUuid = data.slideUuid || data.uuid || nested.slideUuid || nested.uuid || '';
this.slideX = Number(data.slideX || data.x || nested.slideX || nested.x || 0) || 0;
if (!this.slideToken && !this.slideUuid) {
if (typeof options.onError === 'function') {
options.onError(new Error('滑动验证未返回凭证,请重试'));
}
return;
}
if (typeof options.onSuccess === 'function') {
options.onSuccess({
slideToken: this.slideToken,
slideUuid: this.slideUuid,
slideX: this.slideX,
});
}
},
onCancel: options.onCancel,
onError: options.onError,
});
})
.catch((error) => {
if (typeof options.onError === 'function') options.onError(error);
});
},
};
if (typeof window !== 'undefined') {
+228
View File
@@ -254,6 +254,8 @@ const CommonUtil = {
loadPageConfig(options = {}) {
if (typeof ApiClient === 'undefined') return;
this.installUnifiedPagination();
this.installWechatLoginEntry();
this.installWechatAccountBindEntry();
const loadHomeData = options.home !== false && this.isHomePageDom();
const request = loadHomeData ? this.loadHomePageData() : this.loadBasePageData(options);
this.applyCaiExpertListLabels();
@@ -270,6 +272,8 @@ const CommonUtil = {
this.processAndRenderAds(data.adList, options.adPositions);
}
this.applyCaiExpertListLabels();
this.installWechatLoginEntry();
this.installWechatAccountBindEntry();
if (options.links !== false) this.loadLinks();
if (typeof options.onSuccess === 'function') options.onSuccess(result);
})
@@ -278,6 +282,230 @@ const CommonUtil = {
});
},
installWechatLoginEntry() {
if (typeof window === 'undefined' || window.__WECHAT_LOGIN_ENTRY_INSTALLED__) return;
const $entry = this.$('.wxdl');
if (!$entry.length || typeof ApiClient === 'undefined') return;
window.__WECHAT_LOGIN_ENTRY_INSTALLED__ = true;
$entry.find('a').attr({
href: 'javascript:void(0)',
title: '微信登录',
});
$entry.on('click.wechatLogin', 'a, .wx_Box', (event) => {
event.preventDefault();
event.stopPropagation();
this.startWechatLogin();
});
},
getWechatLoginDomain() {
if (typeof window === 'undefined' || !window.location || window.location.protocol === 'file:') {
return window.CURRENT_CONFIG && window.CURRENT_CONFIG.SITE_DOMAIN
? window.CURRENT_CONFIG.SITE_DOMAIN
: 'http://47.108.24.205:9100';
}
return window.location.origin;
},
extractWechatAuthUrl(res) {
const data = res && res.data;
if (typeof data === 'string') return data;
if (data && typeof data === 'object') {
return data.url || data.authUrl || data.authorizeUrl || data.redirectUrl || data.loginUrl || '';
}
return '';
},
startWechatLogin() {
const $ = this.$;
const layer = typeof layui !== 'undefined' && layui.layer;
const $agreement = $('#checkbox, #agreementCheckbox').first();
if ($agreement.length && !$agreement.prop('checked')) {
if (layer) layer.msg('请先阅读并同意用户协议和隐私政策', { icon: 2 });
return;
}
const $loading = $('#loadingOverlay');
const $button = $('.wxdl');
$loading.addClass('is-active');
$button.addClass('is-loading');
ApiClient.get(
ApiClient.API.authWechatOpen,
{ domain: this.getWechatLoginDomain() },
{
publicRequest: true,
headers: { clientid: ApiClient.CLIENT_ID },
}
)
.then((res) => {
if (!ApiClient.isSuccess(res)) {
throw new Error((res && res.msg) || '微信授权地址获取失败');
}
const authUrl = this.extractWechatAuthUrl(res);
if (!authUrl) throw new Error('后端未返回微信授权地址');
window.location.href = authUrl;
})
.catch((error) => {
const message = error.message || '微信登录暂不可用,请稍后再试';
if (layer) layer.msg(message, { icon: 2 });
else alert(message);
})
.finally(() => {
$loading.removeClass('is-active');
$button.removeClass('is-loading');
});
},
installWechatAccountBindEntry() {
if (typeof window === 'undefined') return;
const button = document.getElementById('wechat-bind-button');
if (!button || typeof ApiClient === 'undefined') return;
this.normalizeWechatAccountBindPanel();
if (window.__WECHAT_ACCOUNT_BIND_ENTRY_INSTALLED__) return;
window.__WECHAT_ACCOUNT_BIND_ENTRY_INSTALLED__ = true;
button.setAttribute('title', '绑定微信');
button.addEventListener(
'click',
(event) => {
event.preventDefault();
event.stopPropagation();
if (event.stopImmediatePropagation) event.stopImmediatePropagation();
this.startWechatAccountBind();
},
true
);
this.observeWechatAccountBindPanel();
},
isWechatAccountBindPanelBound() {
const $ = this.$;
const descText = ($('#wechat-bind-desc').text() || '').trim();
const buttonText = ($('#wechat-bind-button').text() || '').trim();
return (
this.hasWechatAccountBindSuccessMark() ||
$('#wechat-bind-card').hasClass('is-bound') ||
descText.indexOf('已绑定') > -1 ||
buttonText.indexOf('已绑定') > -1
);
},
hasWechatAccountBindSuccessMark() {
if (typeof window === 'undefined') return false;
try {
return sessionStorage.getItem('wechatAccountBindSuccess') === '1';
} catch (e) {
return false;
}
},
applyWechatAccountBindBoundPanel() {
const $button = this.$('#wechat-bind-button');
if (!$button.length) return;
this.$('#wechat-bind-desc').text('微信已绑定');
this.$('#wechat-bind-card').removeClass('is-pending is-ready').addClass('is-bound');
$button
.text('已绑定')
.attr('title', '微信已绑定')
.removeClass('is-pending')
.addClass('is-bound')
.prop('disabled', true);
},
normalizeWechatAccountBindPanel() {
const $button = this.$('#wechat-bind-button');
if (!$button.length) return;
if (this.hasWechatAccountBindSuccessMark()) {
this.applyWechatAccountBindBoundPanel();
return;
}
if (this.isWechatAccountBindPanelBound()) return;
this.$('#wechat-bind-desc').text('未绑定微信');
this.$('#wechat-bind-card').removeClass('is-pending').addClass('is-ready');
$button
.text('绑定微信')
.attr('title', '绑定微信')
.removeClass('is-bound is-pending')
.prop('disabled', false);
},
observeWechatAccountBindPanel() {
if (typeof window === 'undefined' || window.__WECHAT_ACCOUNT_BIND_OBSERVER__) return;
const target = document.getElementById('wechat-bind-card') || document.getElementById('wechat-bind-button');
if (!target || typeof MutationObserver === 'undefined') return;
window.__WECHAT_ACCOUNT_BIND_OBSERVER__ = new MutationObserver(() => {
window.clearTimeout(window.__WECHAT_ACCOUNT_BIND_NORMALIZE_TIMER__);
window.__WECHAT_ACCOUNT_BIND_NORMALIZE_TIMER__ = window.setTimeout(() => {
this.normalizeWechatAccountBindPanel();
}, 0);
});
window.__WECHAT_ACCOUNT_BIND_OBSERVER__.observe(target, {
attributes: true,
childList: true,
subtree: true,
});
},
rememberWechatAccountBindMode() {
if (typeof window === 'undefined') return;
const returnUrl =
`${window.location.pathname}${window.location.search}${window.location.hash}` || '/html/usercenter.html';
const pairs = {
wechatSocialMode: 'account_bind',
wechatSocialReturnUrl: returnUrl,
wechatSocialStartedAt: String(Date.now()),
};
Object.keys(pairs).forEach((key) => {
try {
sessionStorage.setItem(key, pairs[key]);
} catch (e) {}
try {
localStorage.setItem(key, pairs[key]);
} catch (e) {}
});
},
startWechatAccountBind() {
const layer = typeof layui !== 'undefined' && layui.layer;
const token = typeof ApiClient !== 'undefined' && ApiClient.token ? ApiClient.token() : '';
if (!token) {
if (layer) layer.msg('请先登录后再绑定微信', { icon: 2 });
return;
}
const $button = this.$('#wechat-bind-button');
this.rememberWechatAccountBindMode();
$button.addClass('is-loading').prop('disabled', true);
ApiClient.get(ApiClient.API.authWechatOpen, { domain: this.getWechatLoginDomain() })
.then((res) => {
if (!ApiClient.isSuccess(res)) {
throw new Error((res && res.msg) || '微信授权地址获取失败');
}
const authUrl = this.extractWechatAuthUrl(res);
if (!authUrl) throw new Error('后端未返回微信授权地址');
window.location.href = authUrl;
})
.catch((error) => {
const message = error.message || '微信绑定暂不可用,请稍后再试';
if (layer) layer.msg(message, { icon: 2 });
else alert(message);
})
.finally(() => {
$button.removeClass('is-loading').prop('disabled', false);
});
},
installUnifiedPagination() {
if (typeof window === 'undefined' || typeof document === 'undefined') return;
this.injectPaginationStyles();