Update App.jsx via upload script - 2026-10-21 11:33:35
This commit is contained in:
parent
e3ca100b57
commit
b808a5c57e
50
App.jsx
50
App.jsx
|
|
@ -1545,6 +1545,8 @@ function normalizeProductTaxonomy(products, categories) {
|
|||
/* -------------------------------- storage ------------------------------ */
|
||||
|
||||
async function loadAll() {
|
||||
// 读取失败(服务器重启中、网络断了)和"还没有数据"必须区分:读取失败时绝不能把空列表当成真实数据再存回服务器
|
||||
const failed = [];
|
||||
let customers = [];
|
||||
let products = [];
|
||||
let quotes = [];
|
||||
|
|
@ -1556,65 +1558,66 @@ async function loadAll() {
|
|||
try {
|
||||
const c = await storageGet(STORAGE_KEYS.customers);
|
||||
if (c && c.value) customers = JSON.parse(c.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
try {
|
||||
const p = await storageGet(STORAGE_KEYS.products);
|
||||
if (p && p.value) products = JSON.parse(p.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
try {
|
||||
const q = await storageGet(STORAGE_KEYS.quotes);
|
||||
if (q && q.value) quotes = JSON.parse(q.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
try {
|
||||
const sp = await storageGet(STORAGE_KEYS.sellerProfiles);
|
||||
if (sp && sp.value) sellerProfiles = JSON.parse(sp.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
try {
|
||||
const cf = await storageGet(STORAGE_KEYS.certifications);
|
||||
if (cf && cf.value) certifications = JSON.parse(cf.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
try {
|
||||
const pc = await storageGet(STORAGE_KEYS.productCategories);
|
||||
if (pc && pc.value) productCategories = JSON.parse(pc.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
try {
|
||||
const pl = await storageGet(STORAGE_KEYS.packingLists);
|
||||
if (pl && pl.value) packingLists = JSON.parse(pl.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
try {
|
||||
const cd = await storageGet(STORAGE_KEYS.catalogDocs);
|
||||
if (cd && cd.value) catalogDocs = JSON.parse(cd.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
let jmsLines = [];
|
||||
try {
|
||||
const jl = await storageGet(STORAGE_KEYS.jmsLines);
|
||||
if (jl && jl.value) jmsLines = JSON.parse(jl.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
let backPanelTemplates = [];
|
||||
try {
|
||||
const bpt = await storageGet(STORAGE_KEYS.backPanelTemplates);
|
||||
if (bpt && bpt.value) backPanelTemplates = JSON.parse(bpt.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
let suppliers = [];
|
||||
try {
|
||||
const sup = await storageGet(STORAGE_KEYS.suppliers);
|
||||
if (sup && sup.value) suppliers = JSON.parse(sup.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
let webDetailTemplates = [];
|
||||
try {
|
||||
const wdt = await storageGet(STORAGE_KEYS.webDetailTemplates);
|
||||
if (wdt && wdt.value) webDetailTemplates = JSON.parse(wdt.value);
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
let webAssets = {};
|
||||
try {
|
||||
const wa = await storageGet(STORAGE_KEYS.webAssets);
|
||||
if (wa && wa.value) webAssets = JSON.parse(wa.value) || {};
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
let webNews = [];
|
||||
try {
|
||||
const wn = await storageGet(STORAGE_KEYS.webNews);
|
||||
if (wn && wn.value) webNews = JSON.parse(wn.value) || [];
|
||||
} catch (e) {}
|
||||
} catch (e) { if (!e.notFound) failed.push(e.message); }
|
||||
if (failed.length) { const err = new Error(failed[0]); err.loadFailed = true; throw err; }
|
||||
return { customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, webAssets, webNews };
|
||||
}
|
||||
|
||||
|
|
@ -2297,6 +2300,7 @@ export { LoginScreen, MainApp };
|
|||
|
||||
function MainApp({ username, onLogout }) {
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [loadError, setLoadError] = useState('');
|
||||
const [customers, setCustomers] = useState([]);
|
||||
const [products, setProducts] = useState([]);
|
||||
const [view, setView] = useState('monitor');
|
||||
|
|
@ -2406,7 +2410,12 @@ function MainApp({ username, onLogout }) {
|
|||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const data = await loadAll();
|
||||
let data;
|
||||
// 读取失败:停在错误页,不进入系统(loaded 保持 false,所以不会触发任何自动保存)
|
||||
for (let i = 0; i < 3 && !data; i++) {
|
||||
try { data = await loadAll(); }
|
||||
catch (e) { if (i < 2) await new Promise(r => setTimeout(r, 2000)); else { setLoadError(e.message || '读取失败'); return; } }
|
||||
}
|
||||
const normalized = normalizeProductTaxonomy(data.products, data.productCategories);
|
||||
setCustomers(data.customers);
|
||||
setProducts(normalized.products);
|
||||
|
|
@ -3527,6 +3536,17 @@ function MainApp({ username, onLogout }) {
|
|||
if (editingCertId === cert.id) setEditingCertId(null);
|
||||
}
|
||||
|
||||
if (!loaded && loadError) {
|
||||
return (
|
||||
<div className="crm-root" style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: 320, padding: 20 }}>
|
||||
<div style={{ maxWidth: 420, textAlign: 'center', fontSize: 14, lineHeight: 1.7 }}>
|
||||
<div style={{ fontWeight: 700, marginBottom: 6 }}>数据读取失败</div>
|
||||
<div style={{ color: 'var(--ink-soft)', marginBottom: 12 }}>服务器可能正在重启(刚部署完常见)。为了保护数据,这次没有进入系统,也没有保存任何内容。请稍等几秒后重新加载。<br /><span style={{ fontSize: 12 }}>{loadError}</span></div>
|
||||
<button className="btn btn-primary" onClick={() => window.location.reload()}>重新加载</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (!loaded) {
|
||||
return (
|
||||
<div className="crm-root" style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: 320 }}>
|
||||
|
|
|
|||
Loading…
Reference in New Issue