From c616822cd6fb3cf572c07dbf0935c54edecb2714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Tue, 28 Jul 2026 10:37:49 +0800 Subject: [PATCH] Add files via upload --- web/static/i18n/en-US.json | 1 + web/static/i18n/zh-CN.json | 1 + web/static/js/assets.js | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/web/static/i18n/en-US.json b/web/static/i18n/en-US.json index b98c1d85..4913c5f8 100644 --- a/web/static/i18n/en-US.json +++ b/web/static/i18n/en-US.json @@ -1106,6 +1106,7 @@ "importValidRows": "Import valid rows", "importValidRowsCount": "Import {{count}} valid rows", "importPreviewSummary": "{{total}} rows: {{valid}} valid, {{invalid}} need attention", + "importBackendRowError": "Excel row {{row}} (submitted valid asset #{{index}}): {{message}}", "previewLimited": "Showing the first 100 rows; all {{count}} rows will be processed", "fileTypeInvalid": "Only .xlsx and .csv files are supported", "fileTooLarge": "The file must not exceed 100 MB", diff --git a/web/static/i18n/zh-CN.json b/web/static/i18n/zh-CN.json index e86e2deb..4176005a 100644 --- a/web/static/i18n/zh-CN.json +++ b/web/static/i18n/zh-CN.json @@ -1094,6 +1094,7 @@ "importValidRows": "导入有效数据", "importValidRowsCount": "导入 {{count}} 条有效数据", "importPreviewSummary": "共 {{total}} 行,{{valid}} 行有效,{{invalid}} 行需修正", + "importBackendRowError": "Excel 第 {{row}} 行(提交有效数据第 {{index}} 条):{{message}}", "previewLimited": "仅展示前 100 行;提交时将处理全部 {{count}} 行", "fileTypeInvalid": "仅支持 .xlsx 和 .csv 文件", "fileTooLarge": "文件不能超过 100 MB", diff --git a/web/static/js/assets.js b/web/static/js/assets.js index 3619d163..a41db34d 100644 --- a/web/static/js/assets.js +++ b/web/static/js/assets.js @@ -358,7 +358,8 @@ function renderAssetImportPreview() { async function submitAssetImport() { if (assetPageState.importBusy) return; - const assets = assetPageState.importRows.filter(row => !row.error).map(row => row.asset); + const validRows = assetPageState.importRows.filter(row => !row.error); + const assets = validRows.map(row => row.asset); if (!assets.length) return; setAssetImportError(''); setAssetImportBusy(true); @@ -367,7 +368,7 @@ async function submitAssetImport() { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ assets, source: 'manual-import', source_query: assetPageState.importFileName }) }); - if (!response.ok) throw new Error(await assetEditorResponseError(response)); + if (!response.ok) throw new Error(formatAssetImportSubmitError(await assetEditorResponseError(response), validRows)); const result = await response.json(); const invalid = assetPageState.importRows.length - assets.length; closeAssetImport(true); @@ -384,6 +385,20 @@ async function submitAssetImport() { } } +function formatAssetImportSubmitError(message, validRows) { + const text = String(message || '').trim(); + const match = text.match(/^第\s*(\d+)\s*个资产无效[::]\s*(.+)$/); + if (!match) return text; + const assetNumber = Number(match[1]); + const row = Array.isArray(validRows) ? validRows[assetNumber - 1] : null; + if (!row || !row.rowNumber) return text; + return assetT('assets.importBackendRowError', `Excel 第 ${row.rowNumber} 行(提交有效数据第 ${assetNumber} 条): ${match[2]}`, { + row: row.rowNumber, + index: assetNumber, + message: match[2] + }); +} + async function loadAssetOverview() { try { const response = await apiFetch('/api/assets/stats?days=' + assetOverviewDays);