Update App.jsx via upload script - 2026-10-21 14:50:34
This commit is contained in:
parent
ab707c5ece
commit
afdfb434cd
41
App.jsx
41
App.jsx
|
|
@ -249,6 +249,7 @@ const COUNTRIES = [
|
|||
|
||||
const COUNTRY_BY_NAME = Object.fromEntries(COUNTRIES.map(c => [c.name, c]));
|
||||
|
||||
const SAVE_KEY_LABEL = { 'crm:customers': '客户', 'crm:products': '产品', 'crm:quotes': '报价单', 'crm:sellerProfiles': '卖方信息', 'crm:certifications': '授权', 'crm:productCategories': '产品分组', 'crm:packingLists': '箱单', 'crm:catalogDocs': '产品目录', 'crm:jmsLines': 'Just My Socks', 'crm:backPanelTemplates': '后板图模板', 'crm:suppliers': '供应商', 'crm:webDetailTemplates': '模板', 'crm:webAssets': '网站图片', 'crm:webNews': '近期动态' };
|
||||
const STORAGE_KEYS = { customers: 'crm:customers', products: 'crm:products', quotes: 'crm:quotes', sellerProfiles: 'crm:sellerProfiles', certifications: 'crm:certifications', productCategories: 'crm:productCategories', packingLists: 'crm:packingLists', catalogDocs: 'crm:catalogDocs', jmsLines: 'crm:jmsLines', backPanelTemplates: 'crm:backPanelTemplates', suppliers: 'crm:suppliers', webDetailTemplates: 'crm:webDetailTemplates', webAssets: 'crm:webAssets', webNews: 'crm:webNews' };
|
||||
|
||||
const blankCustomer = () => ({
|
||||
|
|
@ -2301,6 +2302,9 @@ export { LoginScreen, MainApp };
|
|||
function MainApp({ username, onLogout }) {
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [loadError, setLoadError] = useState('');
|
||||
// 保存出错:版本冲突(别的页面改过)或网络 / 服务器错误,都要让人看见,不能悄悄丢修改
|
||||
const [saveIssue, setSaveIssue] = useState(null); // { conflict, message }
|
||||
const reportSaveError = (e) => setSaveIssue(prev => (prev && prev.conflict) ? prev : { conflict: !!(e && e.conflict), message: (e && e.message) || '未知错误', key: e && e.key });
|
||||
const [customers, setCustomers] = useState([]);
|
||||
const [products, setProducts] = useState([]);
|
||||
const [view, setView] = useState('monitor');
|
||||
|
|
@ -2442,20 +2446,20 @@ function MainApp({ username, onLogout }) {
|
|||
setLoaded(true);
|
||||
})();
|
||||
}, []);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.customers, JSON.stringify(customers)).catch(() => {}); }, [customers, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.products, JSON.stringify(products)).catch(() => {}); }, [products, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.quotes, JSON.stringify(quotes)).catch(() => {}); }, [quotes, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.sellerProfiles, JSON.stringify(sellerProfiles)).catch(() => {}); }, [sellerProfiles, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.certifications, JSON.stringify(certifications)).catch(() => {}); }, [certifications, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.productCategories, JSON.stringify(productCategories)).catch(() => {}); }, [productCategories, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.packingLists, JSON.stringify(packingLists)).catch(() => {}); }, [packingLists, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.catalogDocs, JSON.stringify(catalogDocs)).catch(() => {}); }, [catalogDocs, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.jmsLines, JSON.stringify(jmsLines)).catch(() => {}); }, [jmsLines, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.backPanelTemplates, JSON.stringify(backPanelTemplates)).catch(() => {}); }, [backPanelTemplates, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.suppliers, JSON.stringify(suppliers)).catch(() => {}); }, [suppliers, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webDetailTemplates, JSON.stringify(webDetailTemplates)).catch(() => {}); }, [webDetailTemplates, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webAssets, JSON.stringify(webAssets)).catch(() => {}); }, [webAssets, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webNews, JSON.stringify(webNews)).catch(() => {}); }, [webNews, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.customers, JSON.stringify(customers)).catch(reportSaveError); }, [customers, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.products, JSON.stringify(products)).catch(reportSaveError); }, [products, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.quotes, JSON.stringify(quotes)).catch(reportSaveError); }, [quotes, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.sellerProfiles, JSON.stringify(sellerProfiles)).catch(reportSaveError); }, [sellerProfiles, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.certifications, JSON.stringify(certifications)).catch(reportSaveError); }, [certifications, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.productCategories, JSON.stringify(productCategories)).catch(reportSaveError); }, [productCategories, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.packingLists, JSON.stringify(packingLists)).catch(reportSaveError); }, [packingLists, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.catalogDocs, JSON.stringify(catalogDocs)).catch(reportSaveError); }, [catalogDocs, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.jmsLines, JSON.stringify(jmsLines)).catch(reportSaveError); }, [jmsLines, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.backPanelTemplates, JSON.stringify(backPanelTemplates)).catch(reportSaveError); }, [backPanelTemplates, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.suppliers, JSON.stringify(suppliers)).catch(reportSaveError); }, [suppliers, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webDetailTemplates, JSON.stringify(webDetailTemplates)).catch(reportSaveError); }, [webDetailTemplates, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webAssets, JSON.stringify(webAssets)).catch(reportSaveError); }, [webAssets, loaded]);
|
||||
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webNews, JSON.stringify(webNews)).catch(reportSaveError); }, [webNews, loaded]);
|
||||
|
||||
function notify(msg) { setToast(msg); setTimeout(() => setToast(''), 2200); }
|
||||
|
||||
|
|
@ -3558,6 +3562,15 @@ function MainApp({ username, onLogout }) {
|
|||
return (
|
||||
<div className="crm-root">
|
||||
<Styles />
|
||||
{saveIssue && (
|
||||
<div style={{ position: 'fixed', top: 0, left: 0, right: 0, zIndex: 9999, background: saveIssue.conflict ? '#b42318' : '#b54708', color: '#fff', padding: '10px 16px', display: 'flex', gap: 12, alignItems: 'center', justifyContent: 'center', flexWrap: 'wrap', fontSize: 13.5, boxShadow: '0 2px 10px rgba(0,0,0,.2)' }}>
|
||||
<span>{saveIssue.conflict
|
||||
? `这份数据(${SAVE_KEY_LABEL[saveIssue.key] || saveIssue.key || '数据'})已经在别的页面或设备上改过。为了不互相覆盖,这个页面之后的修改没有保存,请刷新页面后再改。`
|
||||
: `保存失败:${saveIssue.message}。刚才的修改可能没存上,请检查网络后刷新页面确认。`}</span>
|
||||
<button className="btn btn-sm" style={{ background: '#fff', color: '#111' }} onClick={() => window.location.reload()}>刷新页面</button>
|
||||
{!saveIssue.conflict && <button className="btn btn-sm btn-ghost" style={{ color: '#fff' }} onClick={() => setSaveIssue(null)}>关闭</button>}
|
||||
</div>
|
||||
)}
|
||||
<div className="crm-shell">
|
||||
|
||||
<div className="crm-topbar-mobile">
|
||||
|
|
|
|||
Loading…
Reference in New Issue