feat: sanitize system import prompts

This commit is contained in:
ogt
2026-06-25 18:58:23 +08:00
parent a260ea9e4f
commit e2b28b4b69
4 changed files with 47 additions and 16 deletions

View File

@@ -189,16 +189,39 @@ function triggerBackup() {
window.location.href = data.download_url;
}
} else {
alert('錯誤: ' + data.message);
alert('備份沒有完成:' + toImportActionMessage(data.message));
}
})
.catch(error => {
console.error('Error:', error);
alert('備份請求失敗,請檢查日誌。');
alert('備份連線失敗,請稍後重試;若重複失敗請通知維護人員。');
});
}
}
function toImportActionMessage(message) {
const raw = String(message || '').trim();
const text = raw.toLowerCase();
if (!raw) return '請稍後重試;若重複失敗請通知維護人員。';
if (text.includes('google drive') || raw.includes('雲端') || raw.includes('授權')) {
return '請重新確認 Google Drive 授權或雲端檔案權限後再匯入。';
}
if (raw.includes('欄位') || raw.includes('格式') || raw.includes('日期') || text.includes('excel')) {
return '請改用正確的業績報表,確認包含日期、商品與業績金額後重新匯入。';
}
if (
text.includes('database') ||
text.includes('sql') ||
text.includes('table') ||
text.includes('snapshot') ||
text.includes('monthly') ||
raw.includes('資料庫')
) {
return '業績資料處理未完整完成,請重新匯入最新檔案;若重複失敗請通知維護人員。';
}
return raw;
}
function uploadSalesReport() {
const fileInput = document.getElementById('salesReportFile');
const file = fileInput.files[0];
@@ -209,7 +232,7 @@ function uploadSalesReport() {
}
if (!file.name.includes('即時業績') || !file.name.includes('全月')) {
if (!confirm('檔案名稱似乎不符合「即時業績(全月)」的格式,確定要繼續匯入嗎?\n系統會嘗試辨識檔案內容並更新業績資料。')) {
if (!confirm('檔名不像「即時業績(全月)」報表,確定要繼續匯入嗎?\n系統會嘗試辨識內容並更新業績資料。')) {
return;
}
} else if (!confirm('確定要匯入此份業績報表嗎?\n匯入後會更新月度業績判斷供成長分析與報表使用。')) {
@@ -234,19 +257,15 @@ function uploadSalesReport() {
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
if (data.table === 'realtime_sales_monthly') {
alert('業績報表匯入成功!\n共 ' + data.rows + ' 筆資料已更新,可回到分析頁確認結果。');
} else {
alert('匯入操作完成。\n系統偵測到資料落點與預期不同請確認月度分析是否已更新。\n共寫入 ' + data.rows + ' 筆資料。');
}
alert('業績報表匯入成功!\n共 ' + Number(data.rows || 0).toLocaleString() + ' 筆資料已更新,可回到成長分析確認結果。');
fileInput.value = '';
} else {
alert('匯入失敗: ' + data.message);
alert('匯入沒有完成:' + toImportActionMessage(data.message));
}
})
.catch(error => {
console.error('Error:', error);
alert('發生系統錯誤,請檢查日誌');
alert('匯入連線逾時,請稍後查看分析頁是否更新;若沒有更新請重新匯入。');
})
.finally(() => {
btn.innerHTML = originalText;
@@ -285,15 +304,15 @@ function uploadExcel() {
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
alert('匯入成功!\n共寫入 ' + data.rows + ' 筆資料,可回到分析頁確認結果。');
alert('匯入成功!\n共更新 ' + Number(data.rows || 0).toLocaleString() + ' 筆資料,可回到分析頁確認結果。');
fileInput.value = '';
} else {
alert('匯入失敗: ' + data.message);
alert('匯入沒有完成:' + toImportActionMessage(data.message));
}
})
.catch(error => {
console.error('Error:', error);
alert('發生系統錯誤,請檢查日誌');
alert('匯入連線逾時,請稍後查看分析頁是否更新;若沒有更新請重新匯入。');
})
.finally(() => {
btn.innerHTML = originalText;
@@ -337,7 +356,7 @@ function uploadMonthlySummary() {
alert('匯入完成:' + data.message);
fileInput.value = '';
} else {
alert('匯入失敗: ' + data.message);
alert('匯入沒有完成:' + toImportActionMessage(data.message));
}
})
.catch(error => {