fix(user-center): reuse balance withdrawal modal

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Fable 5 committed 2026-08-06 14:33:24 +08:00
1 parent 50236b07fa
commit d86125b130
6 files changed
+65 -141

No files matched your search

+6 -3
View File
@@ -905,9 +905,10 @@
});
}
function initWithdraw() {
var modal = document.querySelector('[data-aksrt-withdraw-modal]');
if (!modal) return;
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;
@@ -1002,6 +1003,8 @@
});
}
window.AKSRTWithdrawInit = initWithdraw;
function bootAssets() {
initSignin();
initSigninGoto();
+1 -91
View File
@@ -163,97 +163,6 @@
});
});
}
var withdrawModal = root.querySelector('[data-aksrt-commission-withdraw-modal]') || document.querySelector('[data-aksrt-commission-withdraw-modal]');
var withdrawForm = withdrawModal && withdrawModal.querySelector('[data-aksrt-commission-withdraw-form]');
var withdrawTip = withdrawModal && withdrawModal.querySelector('[data-aksrt-commission-withdraw-tip]');
var withdrawSubmit = withdrawModal && withdrawModal.querySelector('[data-aksrt-commission-withdraw-submit]');
var lastWithdrawTrigger = null;
var withdrawBusy = false;
function setWithdrawTip(text, error) {
if (!withdrawTip) return;
withdrawTip.textContent = text || '';
withdrawTip.classList.toggle('is-error', !!error);
}
function setWithdrawBusy(isBusy) {
withdrawBusy = isBusy;
if (withdrawSubmit) withdrawSubmit.disabled = isBusy;
}
function getWithdrawFocusable() {
return Array.prototype.slice.call(withdrawModal.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));
}
function closeWithdrawModal() {
if (!withdrawModal || withdrawModal.hidden) return;
withdrawModal.hidden = true;
document.body.classList.remove('uc-modal-open');
if (lastWithdrawTrigger && typeof lastWithdrawTrigger.focus === 'function') {
lastWithdrawTrigger.focus();
}
}
if (withdrawModal && withdrawForm) {
document.querySelectorAll('[data-aksrt-commission-withdraw-open]').forEach(function (button) {
button.addEventListener('click', function () {
lastWithdrawTrigger = button;
withdrawModal.hidden = false;
document.body.classList.add('uc-modal-open');
window.requestAnimationFrame(function () {
var amountInput = withdrawForm.querySelector('[data-aksrt-commission-withdraw-amount]');
if (amountInput) amountInput.focus();
});
});
});
withdrawModal.querySelectorAll('[data-aksrt-commission-withdraw-close]').forEach(function (button) {
button.addEventListener('click', closeWithdrawModal);
});
document.addEventListener('keydown', function (event) {
if (withdrawModal.hidden) return;
if (event.key === 'Escape') {
event.preventDefault();
closeWithdrawModal();
return;
}
if (event.key !== 'Tab') return;
var focusable = getWithdrawFocusable();
if (!focusable.length) return;
var first = focusable[0];
var last = focusable[focusable.length - 1];
if (event.shiftKey && document.activeElement === first) {
event.preventDefault();
last.focus();
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault();
first.focus();
}
});
withdrawForm.addEventListener('submit', function (event) {
event.preventDefault();
if (withdrawBusy) return;
var values = new FormData(withdrawForm);
var amount = Number(values.get('amount') || 0);
var minimum = Number(root.getAttribute('data-min-amount') || 50);
var account = String(values.get('account_info') || '').trim();
if (amount < minimum) { setWithdrawTip('提现金额未达到最低额度', true); return; }
if (!account) { setWithdrawTip('请填写收款账户信息', true); return; }
setWithdrawTip('正在提交...', false);
setWithdrawBusy(true);
fetch(rest + '/pay/balance/withdraw', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': data.restNonce || data.nonce || '' }, body: JSON.stringify({ amount: amount, method: values.get('method') || 'alipay', account_info: account }) }).then(function (response) {
return response.json().catch(function () { return {}; }).then(function (json) { return { ok: response.ok, json: json }; });
}).then(function (result) {
if (!result.ok || !result.json || !result.json.success) { setWithdrawBusy(false); setWithdrawTip((result.json && result.json.message) || '提现申请失败', true); return; }
setWithdrawTip('提现申请已提交', false);
if (result.json.data && typeof result.json.data.wallet_balance !== 'undefined') {
var balanceEl = root.querySelector('[data-aksrt-revenue-balance]');
if (balanceEl) balanceEl.textContent = Number(result.json.data.wallet_balance).toFixed(2);
}
withdrawForm.reset();
setWithdrawBusy(false);
closeWithdrawModal();
reloadRevenuePanel().catch(function () {
if (typeof showToast === 'function') showToast('提现已提交,但收益数据刷新失败');
});
}).catch(function () { setWithdrawBusy(false); setWithdrawTip('网络错误,请稍后重试', true); });
});
}
}
function initRewardNavigation(root, rest, data) {
@@ -278,6 +187,7 @@
current.replaceWith(next);
window.history.pushState({}, '', targetUrl);
window.AKSRTRevenueCenterInit(next);
if (typeof window.AKSRTWithdrawInit === 'function') window.AKSRTWithdrawInit();
});
}).catch(function () {
if (typeof showToast === 'function') showToast('加载失败,请重试');