fix: stabilize selected batch submit state
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user