diff --git a/frontend/index.html b/frontend/index.html index 8c3bee8..c67be98 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -695,7 +695,8 @@
- +
@@ -1173,7 +1174,7 @@
- + diff --git a/frontend/js/main.js b/frontend/js/main.js index 49defaf..25c01fa 100644 --- a/frontend/js/main.js +++ b/frontend/js/main.js @@ -61,6 +61,7 @@ function canDelete() { } document.addEventListener("DOMContentLoaded", function () { + console.log("CRM System Main JS v3.5 Loaded - " + new Date().toLocaleString()); // 登录守卫 const token = localStorage.getItem("crmToken"); if (!token && !window.location.pathname.endsWith("login.html")) { @@ -3248,16 +3249,52 @@ document.addEventListener("DOMContentLoaded", function () { continue; } + // Helper to convert file to base64 with retry + const fileToBase64 = async (f, attempt = 1) => { + try { + return await new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(reader.result); + reader.onerror = () => reject(reader.error || new Error("FileReader error")); + reader.onabort = () => reject(new Error("File read aborted")); + reader.readAsDataURL(f); + }); + } catch (err) { + if (attempt < 3 && err.name === "NotReadableError") { + console.warn(`Retrying ${f.name} read due to NotReadableError (attempt ${attempt})...`); + await new Promise(r => setTimeout(r, 200 * attempt)); + return fileToBase64(f, attempt + 1); + } + throw err; + } + }; + try { - const base64 = await new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onload = () => resolve(reader.result); - reader.onerror = (error) => reject(error); - reader.readAsDataURL(file); - }); + console.log(`[v3.5] Processing ${file.name} (${file.size} bytes)...`); + const base64 = await fileToBase64(file); newBase64Images.push(base64); + console.log(`Successfully converted ${file.name}`); } catch (error) { - console.error(`Error converting file ${file.name} to base64:`, error); + console.error(`Primary method failed for ${file.name}:`, error); + + // Fallback: arrayBuffer + try { + console.log(`Trying arrayBuffer fallback for ${file.name}...`); + const buffer = await file.arrayBuffer(); + const bytes = new Uint8Array(buffer); + let binary = ""; + const chunkSize = 8192; + for (let i = 0; i < bytes.length; i += chunkSize) { + const chunk = bytes.slice(i, i + chunkSize); + binary += String.fromCharCode.apply(null, chunk); + } + const b64 = `data:${file.type};base64,${btoa(binary)}`; + newBase64Images.push(b64); + console.log(`Fallback successful for ${file.name}`); + } catch (fallbackError) { + console.error(`Both methods failed for ${file.name}:`, fallbackError); + alert(`无法读取文件 "${file.name}"。\n这种情况通常是浏览器或系统文件锁定导致的。\n\n建议尝试:\n1. 刷新页面后再试\n2. 使用浏览器的“无痕模式”\n3. 确认文件没有被其他软件打开`); + } } } diff --git a/frontend/uploads/screenshots/bd232714-58ac-472b-b3d0-18e7e768afe0.jpg b/frontend/uploads/screenshots/bd232714-58ac-472b-b3d0-18e7e768afe0.jpg new file mode 100644 index 0000000..102b30c Binary files /dev/null and b/frontend/uploads/screenshots/bd232714-58ac-472b-b3d0-18e7e768afe0.jpg differ