fix: stabilize selected batch submit state

This commit is contained in:
2026-04-30 16:45:14 +08:00
parent b308b49368
commit 3992d4c325
2 changed files with 382 additions and 1 deletions
+36 -1
View File
@@ -139,6 +139,7 @@ export function createMarketController(options: CreateMarketControllerOptions) {
const toolbarHandlers = {
onExport: async () => {
syncSelectionStateFromDom();
const exportTarget = readToolbarExportTarget(toolbar);
if (!exportTarget.target) {
setToolbarExportStatus(toolbar, exportTarget.error ?? "导出配置无效");
@@ -164,6 +165,7 @@ export function createMarketController(options: CreateMarketControllerOptions) {
}
},
onSubmitBatch: async () => {
syncSelectionStateFromDom();
const exportTarget = readToolbarExportTarget(toolbar);
if (!exportTarget.target) {
setToolbarExportStatus(toolbar, exportTarget.error ?? "导出配置无效");
@@ -182,8 +184,15 @@ export function createMarketController(options: CreateMarketControllerOptions) {
setToolbarBusyState(toolbar, true);
try {
const hasSelectedAuthors = selectedAuthorIds.size > 0;
const records = filterRecordsBySelection(
await exportRecords(exportTarget.target, "提交中")
await exportRecords(
exportTarget.target,
hasSelectedAuthors ? "提交已选达人中" : "提交中",
{
showDetailedProgress: !hasSelectedAuthors
}
)
);
const authState = await getAuthState();
if (!authState.isAuthenticated) {
@@ -457,6 +466,32 @@ export function createMarketController(options: CreateMarketControllerOptions) {
syncMarketSelectionState(table, selectedAuthorIds);
}
function syncSelectionStateFromDom(): void {
const rowSelectionCheckboxes = Array.from(
options.document.querySelectorAll('[data-market-selection-checkbox="row"]')
).filter(
(element): element is HTMLInputElement => element instanceof HTMLInputElement
);
if (rowSelectionCheckboxes.length === 0) {
return;
}
rowSelectionCheckboxes.forEach((checkbox) => {
const authorId = checkbox.dataset.marketSelectionAuthorId?.trim();
if (!authorId) {
return;
}
if (checkbox.checked) {
selectedAuthorIds.add(authorId);
} else {
selectedAuthorIds.delete(authorId);
}
});
refreshSelectionControls();
}
function toggleSortFromHeader(field: MarketSortState["field"]): void {
activeSort = getNextSortState(activeSort, field);
applyCurrentView();