后台「积分配置 → 自定义货币名称」改名后,用户中心仍有大量硬编码 「积分」:做任务赚积分 / 购买积分 / 签到领积分、积分记录 / 积分任务、 每日可免费获取 XX 积分、我的积分、积分+1、创作中心积分收益等。 get_currency_name() 早已存在且可用,问题只是这些文案没有走它。 本PR 全部替换,无双路、无迁移: 服务端渲染(用户中心 renderers) - credits-balance.php:购买/做任务赚/签到领 + 整个购买弹窗 - profile-credits.php:积分记录 / 积分任务 页签 - credits-points-tasks.php:每日上限三态与空态 - sidebar-creator.php / profile-creator.php:积分收益 - transfer-modal.php:积分转账提示 - Signin.php:签到详情弹窗(我的积分 / 奖励 tooltip / 积分+N) - VipServiceModal.php:我的积分 / 积分兑换会员 - download-permission-card.php:购买价格 客户端渲染(JS 无法调用 PHP,注入 currencyName 到 aksrtData) - signin.js:签到状态行「已签到 N 天 +1」 - credits.js:转账标题/金额标签 + 购买提示 toast - cms-download.js:积分不足视图、我的积分 入口、余额不足文案 - pay-vip.js:积分兑换会员入口(优先 catalog.currency_name) - order-center.js:订单行单位回退 契约测试同步改为断言模板构造而非死字符串,并新增两例: 改名后跟随、未注入时回退「积分」。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
204 lines
7.2 KiB
JavaScript
204 lines
7.2 KiB
JavaScript
/**
|
|
* AKSRT global sign-in controller.
|
|
*
|
|
* All sign-in buttons share one REST request, captcha and toast flow.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
if (!window.aksrtData) {
|
|
return;
|
|
}
|
|
|
|
var signinBusy = false;
|
|
var refreshSequence = 0;
|
|
|
|
// 自定义货币名称(后台「积分配置 → 自定义货币名称」)由服务端注入,
|
|
// 状态行文案必须跟随它,否则改名后这里仍显示「积分」。
|
|
function currencyName() {
|
|
return (window.aksrtData && window.aksrtData.currencyName) || '积分';
|
|
}
|
|
|
|
function api(path, options) {
|
|
return window.AksrtRequest.request(path, options || {}).then(function (response) {
|
|
return {
|
|
ok: response.ok,
|
|
status: response.status,
|
|
json: response.json || {}
|
|
};
|
|
}).catch(function (error) {
|
|
var response = error && error.response ? error.response : {};
|
|
return {
|
|
ok: false,
|
|
status: error && error.status ? error.status : (response.status || 0),
|
|
json: error && error.json ? error.json : (response.json || { message: error && error.message })
|
|
};
|
|
});
|
|
}
|
|
|
|
function initSignin() {
|
|
var buttons = Array.prototype.slice.call(document.querySelectorAll('[data-signin-btn]'));
|
|
var freshButtons = buttons.filter(function (button) {
|
|
return button.dataset.aksrtSigninInitialized !== '1';
|
|
});
|
|
if (!freshButtons.length) return;
|
|
|
|
freshButtons.forEach(function (button) {
|
|
button.dataset.aksrtSigninInitialized = '1';
|
|
});
|
|
|
|
function statuses() {
|
|
return document.querySelectorAll('[data-signin-status]');
|
|
}
|
|
|
|
function currentButtons() {
|
|
return document.querySelectorAll('[data-signin-btn]');
|
|
}
|
|
|
|
function setStatus(text) {
|
|
statuses().forEach(function (status) {
|
|
status.textContent = text;
|
|
});
|
|
}
|
|
|
|
function setStatusHtml(html) {
|
|
statuses().forEach(function (status) {
|
|
status.innerHTML = html;
|
|
});
|
|
}
|
|
|
|
// 签到成功后,入口按钮就地替换为「已签到」详情弹窗触发链接
|
|
// (参考主题:.initiate-checkin → details_link 的替换行为)。
|
|
function swapButtonsToDetailsLink() {
|
|
var url = window.aksrtData && window.aksrtData.signinDetailsUrl;
|
|
if (!url) return;
|
|
currentButtons().forEach(function (button) {
|
|
var label = button.querySelector('[data-signin-label]');
|
|
if (label) {
|
|
label.textContent = button.getAttribute('data-signin-done-label') || '已签到';
|
|
label.removeAttribute('data-signin-label');
|
|
}
|
|
var link = document.createElement('a');
|
|
link.href = 'javascript:;';
|
|
link.className = (button.className || '') + ' checkin-details-link';
|
|
link.setAttribute('data-aksrt-modal', 'remote');
|
|
link.setAttribute('data-aksrt-modal-url', url);
|
|
link.setAttribute('data-aksrt-modal-class', 'aksrt-checkin-details-modal modal-mini');
|
|
link.setAttribute('data-aksrt-modal-height', '240');
|
|
link.setAttribute('data-aksrt-modal-mobile-bottom', 'true');
|
|
link.setAttribute('data-aksrt-modal-cache', 'false');
|
|
link.innerHTML = button.innerHTML;
|
|
if (link.classList.contains('uc-header__signin-btn')) link.classList.add('is-done');
|
|
button.replaceWith(link);
|
|
});
|
|
}
|
|
|
|
function refresh() {
|
|
if (signinBusy) return;
|
|
var sequence = ++refreshSequence;
|
|
api('/signin/today').then(function (result) {
|
|
// A status read started before a click must not overwrite its result.
|
|
if (signinBusy || sequence !== refreshSequence) return;
|
|
if (!result.ok) {
|
|
var message = (result.json && result.json.message) || '签到状态加载失败 (HTTP ' + result.status + ')';
|
|
setStatus(message);
|
|
notyf(message, 'danger');
|
|
return;
|
|
}
|
|
|
|
var data = result.json;
|
|
if (!data.enabled) {
|
|
setStatus('签到功能未启用');
|
|
currentButtons().forEach(function (button) {
|
|
button.disabled = true;
|
|
button.setAttribute('disabled', '');
|
|
button.setAttribute('aria-disabled', 'true');
|
|
});
|
|
return;
|
|
}
|
|
if (data.signed) {
|
|
setStatusHtml('已签到 <strong>' + data.streak + '</strong> 天 +' + data.reward_today + ' ' + currencyName());
|
|
swapButtonsToDetailsLink();
|
|
return;
|
|
}
|
|
setStatusHtml('连续 <strong>' + data.streak + '</strong> 天,+' + data.reward_if_signin + ' ' + currencyName());
|
|
});
|
|
}
|
|
|
|
function captchaMount() {
|
|
return document.querySelector('[data-signin-captcha]');
|
|
}
|
|
|
|
freshButtons.forEach(function (button) {
|
|
button.addEventListener('click', function (event) {
|
|
event.preventDefault();
|
|
if (signinBusy || button.disabled) return;
|
|
|
|
signinBusy = true;
|
|
++refreshSequence;
|
|
var originalHtml = button.innerHTML;
|
|
button.disabled = true;
|
|
button.setAttribute('disabled', '');
|
|
button.setAttribute('aria-busy', 'true');
|
|
button.innerHTML = '<i class="loading mr6" aria-hidden="true"></i><text>请稍后</text>';
|
|
|
|
function restoreButton() {
|
|
button.innerHTML = originalHtml;
|
|
button.disabled = false;
|
|
button.removeAttribute('disabled');
|
|
button.removeAttribute('aria-busy');
|
|
}
|
|
|
|
var captchaRequired = !!window.aksrtData.captchaSignin;
|
|
var captcha = window.AKSRTCaptcha;
|
|
var mount = captchaMount();
|
|
|
|
Promise.resolve().then(function () {
|
|
if (captchaRequired && (!captcha || !mount)) {
|
|
throw new Error('人机验证未正确加载,请刷新页面后重试');
|
|
}
|
|
return captchaRequired ? captcha.run('signin', mount) : {};
|
|
}).then(function (payload) {
|
|
if (payload === null) throw new Error('已取消验证');
|
|
notyf('正在签到,请稍后...', 'load', '', 'aksrt-balance-signin-toast');
|
|
return api('/signin', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ captcha: payload })
|
|
});
|
|
}).then(function (result) {
|
|
if (!result.ok) throw new Error(result.json.message || '签到失败');
|
|
|
|
restoreButton();
|
|
notyf(result.json.message || '签到成功', 'success', 5, 'aksrt-balance-signin-toast');
|
|
document.querySelectorAll('[data-credits-value]').forEach(function (element) {
|
|
element.textContent = Number(result.json.balance || 0).toLocaleString();
|
|
element.title = element.textContent;
|
|
});
|
|
setStatusHtml('已签到 <strong>' + result.json.streak + '</strong> 天 +' + result.json.reward + ' ' + currencyName());
|
|
swapButtonsToDetailsLink();
|
|
}).catch(function (error) {
|
|
restoreButton();
|
|
notyf((error && error.message) || '签到失败,请稍后重试', 'danger', 5, 'aksrt-balance-signin-toast');
|
|
}).finally(function () {
|
|
signinBusy = false;
|
|
if (captcha && mount) captcha.reset('signin', mount);
|
|
});
|
|
});
|
|
});
|
|
|
|
refresh();
|
|
}
|
|
|
|
function boot() {
|
|
if (!window.AksrtRequest) return;
|
|
jQuery(document).off('auto_fun.aksrt-signin').on('auto_fun.aksrt-signin', initSignin);
|
|
initSignin();
|
|
}
|
|
|
|
if (typeof tbquire === 'function') {
|
|
tbquire(['main'], boot);
|
|
} else {
|
|
boot();
|
|
}
|
|
})();
|