- Always render the checkbox column and bulk bar; disable with a reason instead of hiding when settlement is off or the page has no pending rows - Replace the batch-settle button with a bulk action select (settle / delete) plus apply, matching the charge cards and invite codes pages - Add per-row delete for pending records and Revenue::delete_pending(), guarded by status = 'pending' so settled ledger-backed rows are never removed - Report done / failed counts for bulk settle and delete Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
81 lines
3.0 KiB
JavaScript
81 lines
3.0 KiB
JavaScript
/** 创作分成:勾选计数、全选、批量操作(结算 / 删除)、二次确认 + 防重复提交。仅本页入队。 */
|
|
(function () {
|
|
'use strict';
|
|
|
|
var root = document.querySelector('.aksrt-income-page');
|
|
if (!root) return;
|
|
|
|
var checkAll = root.querySelector('[data-aksrt-income-check-all]');
|
|
var checks = Array.from(root.querySelectorAll('[data-aksrt-income-check]'));
|
|
var bulkAction = root.querySelector('[data-aksrt-income-bulk-action]');
|
|
var bulkSubmit = root.querySelector('[data-aksrt-income-bulk-submit]');
|
|
var selected = root.querySelector('[data-aksrt-income-selected]');
|
|
var emptyText = selected ? selected.textContent : '';
|
|
|
|
function checkedCount() {
|
|
return checks.filter(function (box) { return box.checked; }).length;
|
|
}
|
|
|
|
function sync() {
|
|
var count = checkedCount();
|
|
if (bulkSubmit) bulkSubmit.disabled = count === 0 || !bulkAction || bulkAction.value === '';
|
|
if (selected) {
|
|
selected.textContent = count > 0 ? '已选 ' + count + ' 条' : emptyText;
|
|
selected.classList.toggle('is-active', count > 0);
|
|
}
|
|
if (checkAll && !checkAll.disabled) {
|
|
checkAll.checked = count > 0 && count === checks.length;
|
|
checkAll.indeterminate = count > 0 && count < checks.length;
|
|
}
|
|
}
|
|
|
|
if (checkAll) {
|
|
checkAll.addEventListener('change', function () {
|
|
checks.forEach(function (box) { box.checked = checkAll.checked; });
|
|
sync();
|
|
});
|
|
}
|
|
checks.forEach(function (box) { box.addEventListener('change', sync); });
|
|
if (bulkAction) bulkAction.addEventListener('change', sync);
|
|
sync();
|
|
|
|
/** 单行表单的确认文案在 form 上;批量表单按所选操作取 option 上的文案。 */
|
|
function confirmMessage(form) {
|
|
if (bulkAction && form.contains(bulkAction)) {
|
|
var option = bulkAction.selectedOptions[0];
|
|
return option ? option.getAttribute('data-confirm') : '';
|
|
}
|
|
return form.getAttribute('data-aksrt-confirm');
|
|
}
|
|
|
|
root.addEventListener('submit', function (event) {
|
|
var form = event.target.closest('form');
|
|
if (!form) return;
|
|
if (form.dataset.submitting) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
var message = confirmMessage(form);
|
|
if (message && !window.confirm(message.replace('{count}', String(checkedCount())))) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
if (form.method.toLowerCase() !== 'post') return;
|
|
form.dataset.submitting = '1';
|
|
// 延后禁用:同步禁用 submit 按钮会让部分浏览器丢掉这次提交。
|
|
setTimeout(function () {
|
|
form.querySelectorAll('button[type="submit"]').forEach(function (button) { button.disabled = true; });
|
|
}, 0);
|
|
});
|
|
|
|
// bfcache 返回时恢复按钮与勾选计数,避免整页停在禁用态。
|
|
window.addEventListener('pageshow', function (event) {
|
|
if (!event.persisted) return;
|
|
root.querySelectorAll('form[data-submitting]').forEach(function (form) {
|
|
delete form.dataset.submitting;
|
|
form.querySelectorAll('button[type="submit"]').forEach(function (button) { button.disabled = false; });
|
|
});
|
|
sync();
|
|
});
|
|
})();
|