diff --git a/storage.js b/storage.js index 61d252c..5ce3110 100644 --- a/storage.js +++ b/storage.js @@ -77,8 +77,9 @@ async function pump(key) { // 还没存上的修改:正在发送 / 排队中的键,以及最近一次保存失败的键(保存成功后自动清掉) const failed = {}; +let uploadsInFlight = 0; // 正在上传的文件(图片、附件) export function hasUnsavedChanges() { - return Object.values(saveState).some((st) => st.running || st.next) || Object.keys(failed).length > 0; + return uploadsInFlight > 0 || Object.values(saveState).some((st) => st.running || st.next) || Object.keys(failed).length > 0; } export function storageSet(key, value) { @@ -92,6 +93,10 @@ export function storageSet(key, value) { // 上传一个与客户相关的沟通附件(文件本身存到磁盘,元数据由调用方存进客户记录) export async function uploadFile(customerId, file) { + uploadsInFlight++; + try { return await uploadFileNow(customerId, file); } finally { uploadsInFlight--; } +} +async function uploadFileNow(customerId, file) { const fd = new FormData(); fd.append('file', file); const res = await fetch(`/api/uploads/${encodeURIComponent(customerId)}`, {