feat: show import recovery actions

This commit is contained in:
ogt
2026-06-25 18:54:32 +08:00
parent 45da965702
commit a260ea9e4f
4 changed files with 39 additions and 4 deletions

View File

@@ -275,7 +275,7 @@
jobs.forEach(job => {
const tr = document.createElement('tr');
const fileName = job.drive_file_name || '未記錄檔名';
const errorMsg = job.display_error_message || job.error_message || '—';
const actionHint = buildImportActionHint(job);
const isRunning = job.status === 'downloading' || job.status === 'importing';
tr.innerHTML = `
@@ -296,7 +296,7 @@
</td>
<td><span class="ai-jobtable__time">${formatTime(job.started_at)}</span></td>
<td><span class="ai-jobtable__time">${formatTime(job.completed_at)}</span></td>
<td class="ai-jobtable__error">${escapeHtml(errorMsg)}</td>
<td class="ai-jobtable__error">${escapeHtml(actionHint)}</td>
<td class="text-center">
${isRunning
? `<button class="btn btn-sm btn-outline-danger" onclick="failJob(${job.id})" title="取消任務"><i class="fas fa-times"></i></button>`
@@ -307,6 +307,31 @@
});
}
function buildImportActionHint(job) {
const status = String(job?.status || '');
const raw = String(job?.display_error_message || job?.error_message || '').trim();
const text = raw.toLowerCase();
if (status === 'completed') {
return '已更新業績資料,可回到今日作戰看建議。';
}
if (status === 'downloading' || status === 'importing' || status === 'pending') {
return '匯入進行中,完成後會更新日報與今日作戰。';
}
if (status === 'failed') {
if (text.includes('google drive') || raw.includes('雲端') || raw.includes('授權')) {
return '重新確認 Google Drive 授權,確認後再執行立即匯入。';
}
if (raw.includes('格式') || raw.includes('日期') || raw.includes('商品') || raw.includes('業績') || text.includes('excel')) {
return '改用當日業績明細檔,確認包含日期、商品與業績金額後重新匯入。';
}
if (raw.includes('同步') || raw.includes('未完整') || raw.includes('重啟')) {
return '重新匯入最新檔案;若重複失敗,請通知維護人員檢查同步流程。';
}
return '檢查檔案後重新匯入;若重複失敗,請通知維護人員。';
}
return raw || '等待系統更新任務狀態。';
}
// ───── 工具 ─────
function escapeHtml(text) {
if (!text) return '';