(fix):update credits toast
This commit is contained in:
+77
-82
@@ -37,42 +37,41 @@
|
||||
// ===== 签到 =====
|
||||
function initSignin() {
|
||||
var root = document.querySelector('[data-aksrt-signin]');
|
||||
if (!root) return;
|
||||
if (!root || root.dataset.aksrtSigninInitialized === '1') return;
|
||||
root.dataset.aksrtSigninInitialized = '1';
|
||||
var status = root.querySelector('[data-signin-status]');
|
||||
var btn = root.querySelector('[data-signin-btn]');
|
||||
var tip = root.querySelector('[data-signin-tip]');
|
||||
if (!btn) return;
|
||||
|
||||
function setStatus(text) { if (status) status.textContent = text; }
|
||||
function setStatusHtml(html) { if (status) status.innerHTML = html; }
|
||||
function setTip(text) { if (tip) tip.textContent = text; }
|
||||
|
||||
function refresh() {
|
||||
api('/signin/today').then(function (r) {
|
||||
if (!r.ok) {
|
||||
setStatus((r.json && r.json.message) || '加载失败 (HTTP ' + r.status + ')');
|
||||
var message = (r.json && r.json.message) || '签到状态加载失败 (HTTP ' + r.status + ')';
|
||||
setStatus(message);
|
||||
notyf(message, 'danger');
|
||||
return;
|
||||
}
|
||||
var j = r.json;
|
||||
if (!j.enabled) {
|
||||
setStatus('签到功能未启用');
|
||||
btn.disabled = true;
|
||||
setTip('');
|
||||
return;
|
||||
}
|
||||
if (j.signed) {
|
||||
setStatusHtml('已签到 <strong>' + j.streak + '</strong> 天 +' + j.reward_today);
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '已签到';
|
||||
setTip('');
|
||||
} else {
|
||||
setStatusHtml('连续 <strong>' + j.streak + '</strong> 天,+' + j.reward_if_signin);
|
||||
btn.disabled = false;
|
||||
setTip('');
|
||||
}
|
||||
}).catch(function (err) {
|
||||
if (window.console) console.error('[AKSRT Credits] /signin/today 请求失败:', err);
|
||||
setStatus('加载失败,请刷新重试');
|
||||
notyf('签到状态加载失败,请刷新重试', 'danger');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -128,36 +127,36 @@
|
||||
btn.addEventListener('click', function () {
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '…';
|
||||
setTip('');
|
||||
|
||||
triggerCaptcha(function () {
|
||||
doSignin();
|
||||
}, function (msg) {
|
||||
resetCaptcha();
|
||||
if (msg) setTip(msg);
|
||||
if (msg) notyf(msg, 'danger');
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '签到';
|
||||
});
|
||||
|
||||
function doSignin() {
|
||||
notyf('正在签到…', 'load', '', 'aksrt-balance-signin-toast');
|
||||
api('/signin', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ captcha: collectCaptcha() })
|
||||
}).then(function (r) {
|
||||
if (!r.ok) {
|
||||
resetCaptcha();
|
||||
setTip((r.json && r.json.message) || '签到失败');
|
||||
notyf((r.json && r.json.message) || '签到失败', 'danger', 5, 'aksrt-balance-signin-toast');
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '签到';
|
||||
return;
|
||||
}
|
||||
setTip('签到成功,获得 ' + r.json.reward + ' 积分(连续 ' + r.json.streak + ' 天)');
|
||||
notyf('签到成功,获得 ' + r.json.reward + ' 积分(连续 ' + r.json.streak + ' 天)', 'success', 5, 'aksrt-balance-signin-toast');
|
||||
var balanceEls = document.querySelectorAll('[data-credits-value]');
|
||||
balanceEls.forEach(function (el) { el.textContent = r.json.balance.toLocaleString(); });
|
||||
refresh();
|
||||
}).catch(function () {
|
||||
resetCaptcha();
|
||||
setTip('网络错误,请重试');
|
||||
notyf('网络错误,请重试', 'danger', 5, 'aksrt-balance-signin-toast');
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '签到';
|
||||
});
|
||||
@@ -170,6 +169,8 @@
|
||||
// Task-list "去签到" → scroll + click the real asset-card sign-in button.
|
||||
function initSigninGoto() {
|
||||
document.querySelectorAll('[data-aksrt-signin-goto]').forEach(function (el) {
|
||||
if (el.dataset.aksrtSigninGotoInitialized === '1') return;
|
||||
el.dataset.aksrtSigninGotoInitialized = '1';
|
||||
el.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
var root = document.querySelector('[data-aksrt-signin]');
|
||||
@@ -418,7 +419,10 @@
|
||||
}
|
||||
function closeModal(el) {
|
||||
if (!el) return;
|
||||
if (activePoll && typeof activePoll.abort === 'function') activePoll.abort();
|
||||
if (activePoll && typeof activePoll.abort === 'function') {
|
||||
activePoll.abort();
|
||||
notyf('已停止查询支付状态', 'warning', 3, 'aksrt-balance-charge-payment-toast');
|
||||
}
|
||||
activePoll = null;
|
||||
el.hidden = true;
|
||||
el.classList.remove('is-open');
|
||||
@@ -426,17 +430,25 @@
|
||||
document.body.classList.remove('uc-modal-open');
|
||||
}
|
||||
}
|
||||
function pollPaidOrder(orderNumber, setTip, tags) {
|
||||
function pollPaidOrder(orderNumber, tags) {
|
||||
var coordinator = window.AksrtVipPurchaseCoordinator;
|
||||
if (!orderNumber) return;
|
||||
notyf('等待支付结果…', 'load', '', 'aksrt-balance-charge-payment-toast');
|
||||
var handle = coordinator.poll(orderNumber, {
|
||||
tags: tags || ['credits', 'orders'],
|
||||
onTerminal: function (result) {
|
||||
activePoll = null;
|
||||
if (result.success) {
|
||||
if (typeof setTip === 'function') setTip('支付成功,正在刷新…');
|
||||
window.location.reload();
|
||||
notyf('支付成功,正在刷新…', 'success', 5, 'aksrt-balance-charge-payment-toast');
|
||||
window.setTimeout(function () { window.location.reload(); }, 800);
|
||||
return;
|
||||
}
|
||||
var message = result.data && result.data.message ? result.data.message : '支付未完成,请重试';
|
||||
notyf(message, 'danger', 5, 'aksrt-balance-charge-payment-toast');
|
||||
},
|
||||
onTimeout: function () {
|
||||
activePoll = null;
|
||||
notyf('支付状态暂未确认,请稍后在订单中心查看', 'danger', 5, 'aksrt-balance-charge-payment-toast');
|
||||
}
|
||||
});
|
||||
return handle;
|
||||
@@ -447,20 +459,12 @@
|
||||
if (!modal || modal.dataset.aksrtChargeInitialized === '1') return;
|
||||
modal.dataset.aksrtChargeInitialized = '1';
|
||||
var form = modal.querySelector('[data-aksrt-charge-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-charge-tip]');
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-charge-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
});
|
||||
modal.querySelectorAll('[data-aksrt-charge-close]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
if (activePoll && typeof activePoll.abort === 'function') activePoll.abort();
|
||||
activePoll = null;
|
||||
closeModal(modal);
|
||||
});
|
||||
});
|
||||
@@ -483,17 +487,17 @@
|
||||
pkg = 'custom';
|
||||
}
|
||||
if ((!pkg || pkg === 'custom') && !(custom > 0) && !pkgInput) {
|
||||
setTip('请选择或输入充值金额', true);
|
||||
notyf('请选择或输入充值金额', 'danger');
|
||||
return;
|
||||
}
|
||||
if (pkg === 'custom' && !(custom > 0)) {
|
||||
setTip('请输入有效充值金额', true);
|
||||
notyf('请输入有效充值金额', 'danger');
|
||||
return;
|
||||
}
|
||||
var methodEl = form.querySelector('input[name="payment_method"]:checked');
|
||||
var method = methodEl ? methodEl.value : 'alipay';
|
||||
busy = true;
|
||||
setTip('正在创建订单…');
|
||||
notyf('正在创建充值订单…', 'load', '', 'aksrt-balance-charge-toast');
|
||||
api('/pay/balance/charge', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
@@ -504,21 +508,21 @@
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '充值失败', true);
|
||||
notyf((r.json && r.json.message) || '充值失败', 'danger', 5, 'aksrt-balance-charge-toast');
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
if (data && data.redirect && (data.payment_url || data.qr_content)) {
|
||||
if (data.payment_url) window.open(data.payment_url, '_blank');
|
||||
setTip(data.message || '请完成支付,支付成功后将自动刷新。');
|
||||
if (data.order_number) activePoll = pollPaidOrder(data.order_number, setTip, ['credits', 'orders']);
|
||||
notyf(data.message || '请完成支付,支付成功后将自动刷新。', 'info', 5, 'aksrt-balance-charge-toast');
|
||||
if (data.order_number) activePoll = pollPaidOrder(data.order_number, ['credits', 'orders']);
|
||||
return;
|
||||
}
|
||||
setTip((data && data.message) || '充值成功,正在刷新…');
|
||||
window.location.reload();
|
||||
notyf((data && data.message) || '充值成功,正在刷新…', 'success', 5, 'aksrt-balance-charge-toast');
|
||||
window.setTimeout(function () { window.location.reload(); }, 800);
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
notyf('网络错误,请重试', 'danger', 5, 'aksrt-balance-charge-toast');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -528,7 +532,6 @@
|
||||
if (!modal || modal.dataset.aksrtTransferInitialized === '1') return;
|
||||
modal.dataset.aksrtTransferInitialized = '1';
|
||||
var form = modal.querySelector('[data-aksrt-transfer-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-transfer-tip]');
|
||||
var results = modal.querySelector('[data-aksrt-transfer-results]');
|
||||
var selected = modal.querySelector('[data-aksrt-transfer-selected]');
|
||||
var recipientInput = modal.querySelector('[data-aksrt-transfer-recipient]');
|
||||
@@ -540,11 +543,6 @@
|
||||
var pointsTransferMin = 1;
|
||||
var searchTimer = null;
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-transfer-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var type = btn.getAttribute('data-aksrt-transfer-open') || 'balance';
|
||||
@@ -566,7 +564,6 @@
|
||||
if (results) results.innerHTML = '';
|
||||
if (selected) selected.textContent = '';
|
||||
if (recipientInput) recipientInput.value = '';
|
||||
setTip('');
|
||||
openModal(modal);
|
||||
});
|
||||
});
|
||||
@@ -586,7 +583,10 @@
|
||||
api('/pay/transfer/search?s=' + encodeURIComponent(q)).then(function (r) {
|
||||
if (!results) return;
|
||||
results.innerHTML = '';
|
||||
if (!r.ok) return;
|
||||
if (!r.ok) {
|
||||
notyf((r.json && r.json.message) || '用户搜索失败', 'danger');
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
var users = (data && data.users) || [];
|
||||
if (!users.length) {
|
||||
@@ -618,47 +618,42 @@
|
||||
var amountEl = form.querySelector('[data-aksrt-transfer-amount]');
|
||||
var amount = amountEl ? amountEl.value : 0;
|
||||
if (!recipient) {
|
||||
setTip('请选择收款用户', true);
|
||||
notyf('请选择收款用户', 'danger');
|
||||
return;
|
||||
}
|
||||
if (!(parseFloat(amount) > 0) || (type === 'points' && (!Number.isInteger(Number(amount)) || Number(amount) < pointsTransferMin))) {
|
||||
setTip('请输入有效金额', true);
|
||||
notyf('请输入有效金额', 'danger');
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
setTip('正在转账…');
|
||||
notyf('正在转账…', 'load', '', 'aksrt-balance-transfer-toast');
|
||||
api('/pay/transfer', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ type: type, recipient: recipient, amount: amount })
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '转账失败', true);
|
||||
notyf((r.json && r.json.message) || '转账失败', 'danger', 5, 'aksrt-balance-transfer-toast');
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
setTip((data && data.message) || '转账成功,正在刷新…');
|
||||
window.location.reload();
|
||||
notyf((data && data.message) || '转账成功,正在刷新…', 'success', 5, 'aksrt-balance-transfer-toast');
|
||||
window.setTimeout(function () { window.location.reload(); }, 800);
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
notyf('网络错误,请重试', 'danger', 5, 'aksrt-balance-transfer-toast');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initPointsExchange() {
|
||||
var modal = document.querySelector('[data-aksrt-points-exchange-modal]');
|
||||
if (!modal) return;
|
||||
if (!modal || modal.dataset.aksrtPointsExchangeInitialized === '1') return;
|
||||
modal.dataset.aksrtPointsExchangeInitialized = '1';
|
||||
var form = modal.querySelector('[data-aksrt-points-exchange-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-points-exchange-tip]');
|
||||
var amountEl = form ? form.querySelector('[data-aksrt-points-exchange-amount]') : null;
|
||||
var preview = form ? form.querySelector('[data-aksrt-points-exchange-preview]') : null;
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-points-exchange-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
});
|
||||
@@ -681,42 +676,36 @@
|
||||
if (busy) return;
|
||||
var amount = amountEl ? Number(amountEl.value || '0') : 0;
|
||||
if (!Number.isInteger(amount) || !(amount > 0)) {
|
||||
setTip('请输入正整数余额', true);
|
||||
notyf('请输入正整数余额', 'danger');
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
setTip('正在兑换…');
|
||||
notyf('正在购买积分…', 'load', '', 'aksrt-balance-points-toast');
|
||||
api('/pay/balance/points-exchange', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ amount: amount })
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '购买失败', true);
|
||||
notyf((r.json && r.json.message) || '购买失败', 'danger', 5, 'aksrt-balance-points-toast');
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
setTip((data && data.message) || '购买成功,正在刷新…');
|
||||
window.location.reload();
|
||||
notyf((data && data.message) || '购买成功,正在刷新…', 'success', 5, 'aksrt-balance-points-toast');
|
||||
window.setTimeout(function () { window.location.reload(); }, 800);
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
notyf('网络错误,请重试', 'danger', 5, 'aksrt-balance-points-toast');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initWithdraw() {
|
||||
var modal = document.querySelector('[data-aksrt-withdraw-modal]');
|
||||
if (!modal || modal.dataset.aksrtWithdrawInitialized === '1') return;
|
||||
modal.dataset.aksrtWithdrawInitialized = '1';
|
||||
function initWithdraw() {
|
||||
var modal = document.querySelector('[data-aksrt-withdraw-modal]');
|
||||
if (!modal || modal.dataset.aksrtWithdrawInitialized === '1') return;
|
||||
modal.dataset.aksrtWithdrawInitialized = '1';
|
||||
var form = modal.querySelector('[data-aksrt-withdraw-form]');
|
||||
var tip = modal.querySelector('[data-aksrt-withdraw-tip]');
|
||||
var busy = false;
|
||||
function setTip(text, isError) {
|
||||
if (!tip) return;
|
||||
tip.textContent = text || '';
|
||||
tip.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
document.querySelectorAll('[data-aksrt-withdraw-open]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () { openModal(modal); });
|
||||
});
|
||||
@@ -738,38 +727,38 @@
|
||||
var method = methodEl ? methodEl.value : 'alipay';
|
||||
var account = accountEl ? String(accountEl.value || '').trim() : '';
|
||||
if (!Number.isInteger(amount) || !(amount > 0)) {
|
||||
setTip('提现金额必须为正整数', true);
|
||||
notyf('提现金额必须为正整数', 'danger');
|
||||
return;
|
||||
}
|
||||
if (amount < minAmount) {
|
||||
setTip('提现金额低于最低提现门槛', true);
|
||||
notyf('提现金额低于最低提现门槛', 'danger');
|
||||
return;
|
||||
}
|
||||
if (remainingCount <= 0) {
|
||||
setTip('当日提现次数已用尽', true);
|
||||
notyf('当日提现次数已用尽', 'danger');
|
||||
return;
|
||||
}
|
||||
if (amount > remainingAmount) {
|
||||
setTip('本次提现后将超出单日提现总额上限', true);
|
||||
notyf('本次提现后将超出单日提现总额上限', 'danger');
|
||||
return;
|
||||
}
|
||||
if (!account) {
|
||||
setTip('请填写收款账号信息', true);
|
||||
notyf('请填写收款账号信息', 'danger');
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
setTip('正在提交…');
|
||||
notyf('正在提交提现申请…', 'load', '', 'aksrt-balance-withdraw-toast');
|
||||
api('/earnings/withdrawals', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ amount: amount, method: method, account: account })
|
||||
}).then(function (r) {
|
||||
busy = false;
|
||||
if (!r.ok || (r.json && r.json.code && !r.json.success)) {
|
||||
setTip((r.json && r.json.message) || '提现失败', true);
|
||||
notyf((r.json && r.json.message) || '提现失败', 'danger', 5, 'aksrt-balance-withdraw-toast');
|
||||
return;
|
||||
}
|
||||
var data = (r.json && r.json.data) ? r.json.data : r.json;
|
||||
setTip((data && data.message) || '申请已提交');
|
||||
notyf((data && data.message) || '申请已提交', 'success', 5, 'aksrt-balance-withdraw-toast');
|
||||
closeModal(modal);
|
||||
var panel = modal.closest ? modal.closest('.dashboard-panel') : null;
|
||||
panel = panel || document.getElementById('panel-credits');
|
||||
@@ -785,7 +774,7 @@
|
||||
}
|
||||
}).catch(function () {
|
||||
busy = false;
|
||||
setTip('网络错误,请重试', true);
|
||||
notyf('网络错误,请重试', 'danger', 5, 'aksrt-balance-withdraw-toast');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -822,7 +811,8 @@
|
||||
|
||||
function initWithdrawHistory() {
|
||||
var modal = document.querySelector('[data-aksrt-withdraw-history-modal]');
|
||||
if (!modal) return;
|
||||
if (!modal || modal.dataset.aksrtWithdrawHistoryInitialized === '1') return;
|
||||
modal.dataset.aksrtWithdrawHistoryInitialized = '1';
|
||||
function open() { modal.hidden = false; document.body.classList.add('uc-modal-open'); }
|
||||
function close() { modal.hidden = true; document.body.classList.remove('uc-modal-open'); }
|
||||
document.querySelectorAll('[data-aksrt-withdraw-history-open]').forEach(function (btn) {
|
||||
@@ -838,7 +828,7 @@
|
||||
function bootAssets() {
|
||||
initSignin();
|
||||
initSigninGoto();
|
||||
initAffiliateRevenue();
|
||||
initAffiliateRevenue();
|
||||
initVipShop();
|
||||
initVipPointsExchange();
|
||||
initCardPass();
|
||||
@@ -858,8 +848,13 @@
|
||||
|
||||
if (window.AksrtFrontend && typeof window.AksrtFrontend.register === 'function') {
|
||||
window.AksrtFrontend.register('credits', function () {
|
||||
initSignin();
|
||||
initSigninGoto();
|
||||
initBalanceCharge();
|
||||
initTransfer();
|
||||
initPointsExchange();
|
||||
initWithdraw();
|
||||
initWithdrawHistory();
|
||||
initAssetTabs();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user