Update App.jsx via upload script - 2026-11-12 17:02:24
This commit is contained in:
parent
c271637b84
commit
5e116bf01b
91
App.jsx
91
App.jsx
|
|
@ -2184,6 +2184,12 @@ const Styles = () => (
|
||||||
.web-thumb.tall img { object-fit: cover; object-position: top; }
|
.web-thumb.tall img { object-fit: cover; object-position: top; }
|
||||||
.web-thumb-add { width: 88px; height: 88px; border: 1px dashed var(--line); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; color: var(--ink-soft); cursor: pointer; }
|
.web-thumb-add { width: 88px; height: 88px; border: 1px dashed var(--line); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; color: var(--ink-soft); cursor: pointer; }
|
||||||
.web-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; font-size: 11px; font-weight: 500; color: #1d7a3e; background: #dcf1e2; padding: 2px 8px; border-radius: 99px; }
|
.web-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; font-size: 11px; font-weight: 500; color: #1d7a3e; background: #dcf1e2; padding: 2px 8px; border-radius: 99px; }
|
||||||
|
.tpl-badge.bad { color: #b42318 !important; background: #fde4e1 !important; font-weight: 600; }
|
||||||
|
.tpl-warn { font-size: 12.5px; color: #b42318; background: #fef1ef; border: 1px solid #f5b5ac; border-radius: 8px; padding: 9px 12px; line-height: 1.6; }
|
||||||
|
.tpl-warn-link { background: none; border: 0; padding: 0; color: #b42318; text-decoration: underline; cursor: pointer; font: inherit; }
|
||||||
|
.btn.tpl-btn-bad { border-color: #d92d20 !important; color: #b42318 !important; background: #fef1ef !important; }
|
||||||
|
.btn.btn-primary.tpl-btn-bad { background: #d92d20 !important; color: #fff !important; }
|
||||||
|
.tpl-chip.bad { border-color: #d92d20 !important; background: #fef1ef !important; }
|
||||||
.tpl-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 6px; font-size: 11px; font-weight: 500; color: #1e4f8a; background: #e1ecf8; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
|
.tpl-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 6px; font-size: 11px; font-weight: 500; color: #1e4f8a; background: #e1ecf8; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
|
||||||
.web-tier-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
|
.web-tier-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
|
||||||
.web-tier-preview div { display: flex; justify-content: space-between; gap: 6px; font-size: 12.5px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-variant-numeric: tabular-nums; }
|
.web-tier-preview div { display: flex; justify-content: space-between; gap: 6px; font-size: 12.5px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-variant-numeric: tabular-nums; }
|
||||||
|
|
@ -4266,7 +4272,7 @@ function MainApp({ username, onLogout }) {
|
||||||
<div key={p.id} className="row" style={{ cursor: 'pointer', background: selectedProductId === p.id ? '#FAFBFC' : undefined }} onClick={() => { setProductDraft(null); setSelectedProductId(p.id); }}>
|
<div key={p.id} className="row" style={{ cursor: 'pointer', background: selectedProductId === p.id ? '#FAFBFC' : undefined }} onClick={() => { setProductDraft(null); setSelectedProductId(p.id); }}>
|
||||||
<div className="led-dot blue" />
|
<div className="led-dot blue" />
|
||||||
<div className="row-main">
|
<div className="row-main">
|
||||||
<div className="row-title">{p.name || '(未命名)'}</div>
|
<div className="row-title">{p.name || '(未命名)'}{tplConflict(p, webDetailTemplates) && <span className="tpl-badge bad" title="异常:一个型号只能关联一个模板">⚠ 多个模板</span>}</div>
|
||||||
<div className="row-sub">{categoryBreadcrumb(p, productCategories)}{p.brand ? ` · ${p.brand}` : ''}</div>
|
<div className="row-sub">{categoryBreadcrumb(p, productCategories)}{p.brand ? ` · ${p.brand}` : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
<ChevronRight size={15} color="var(--ink-soft)" />
|
<ChevronRight size={15} color="var(--ink-soft)" />
|
||||||
|
|
@ -7560,21 +7566,20 @@ function SiteNewsItem({ n, update, remove }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 一个型号只能关联一个模板:关联了多个(还存在的)模板的产品算异常,界面上标红
|
||||||
|
const tplIdsOf = (p, templates) => (Array.isArray(p && p.webDetailTemplateIds) ? p.webDetailTemplateIds : []).filter(id => !templates || templates.some(t => t.id === id));
|
||||||
|
const tplConflict = (p, templates) => tplIdsOf(p, templates).length > 1;
|
||||||
|
|
||||||
function DetailTemplatePicker({ draft, set, templates, setTemplates, products, onNotify }) {
|
function DetailTemplatePicker({ draft, set, templates, setTemplates, products, onNotify }) {
|
||||||
const [managerOpen, setManagerOpen] = useState(false);
|
const [managerOpen, setManagerOpen] = useState(false);
|
||||||
const selected = (Array.isArray(draft.webDetailTemplateIds) ? draft.webDetailTemplateIds : []).filter(id => templates.some(t => t.id === id));
|
const selected = (Array.isArray(draft.webDetailTemplateIds) ? draft.webDetailTemplateIds : []).filter(id => templates.some(t => t.id === id));
|
||||||
const toggle = (id) => set({ webDetailTemplateIds: selected.includes(id) ? selected.filter(x => x !== id) : [...selected, id] });
|
// 单选:点一个模板就换成这个模板;再点已选的就移除
|
||||||
const move = (idx, dir) => {
|
const toggle = (id) => set({ webDetailTemplateIds: selected.includes(id) ? selected.filter(x => x !== id) : [id] });
|
||||||
const j = idx + dir;
|
|
||||||
if (j < 0 || j >= selected.length) return;
|
|
||||||
const next = [...selected]; [next[idx], next[j]] = [next[j], next[idx]];
|
|
||||||
set({ webDetailTemplateIds: next });
|
|
||||||
};
|
|
||||||
const byId = (id) => templates.find(t => t.id === id);
|
const byId = (id) => templates.find(t => t.id === id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<span className="field-label">模板(主图模板接在网站主图后面;详情图片组、HTML 参数表显示在"产品详情图"下方;点一下添加,再点一下移除)</span>
|
<span className="field-label">模板(一个型号只能关联一个模板;点一下选中,再点一下移除)</span>
|
||||||
{templates.length === 0 ? (
|
{templates.length === 0 ? (
|
||||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>还没有模板。可以把公司介绍、工厂、认证、包装物流这类每个产品都要放的图片做成模板。</div>
|
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>还没有模板。可以把公司介绍、工厂、认证、包装物流这类每个产品都要放的图片做成模板。</div>
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -7583,7 +7588,7 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
|
||||||
const on = selected.includes(t.id);
|
const on = selected.includes(t.id);
|
||||||
const imgs = [...(t.mainImages || []), ...(t.images || [])];
|
const imgs = [...(t.mainImages || []), ...(t.images || [])];
|
||||||
return (
|
return (
|
||||||
<button type="button" key={t.id} onClick={() => toggle(t.id)} className={`tpl-chip${on ? ' on' : ''}`}>
|
<button type="button" key={t.id} onClick={() => toggle(t.id)} className={`tpl-chip${on ? ' on' : ''}${on && selected.length > 1 ? ' bad' : ''}`}>
|
||||||
{imgs[0] ? <img src={`/uploads/${t.id}/${imgs[0]}`} alt="" /> : <span className="tpl-chip-noimg">{tplHtmlsFilled(t).length ? <FileText size={14} /> : <ImageIcon size={14} />}</span>}
|
{imgs[0] ? <img src={`/uploads/${t.id}/${imgs[0]}`} alt="" /> : <span className="tpl-chip-noimg">{tplHtmlsFilled(t).length ? <FileText size={14} /> : <ImageIcon size={14} />}</span>}
|
||||||
<span>{on ? '✓ ' : '+ '}{t.name || '未命名模板'}<em>{tplSummary(t)}</em></span>
|
<span>{on ? '✓ ' : '+ '}{t.name || '未命名模板'}<em>{tplSummary(t)}</em></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -7592,22 +7597,15 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{selected.length > 1 && (
|
{selected.length > 1 && (
|
||||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', marginTop: 8 }}>
|
<div className="tpl-warn" style={{ marginTop: 8 }}>
|
||||||
显示顺序:
|
⚠ 异常:这个型号关联了 {selected.length} 个模板({selected.map(id => (byId(id) || {}).name || '未命名模板').join('、')}),只能保留一个。点要去掉的模板移除。
|
||||||
{selected.map((id, i) => (
|
|
||||||
<span key={id} style={{ marginRight: 10, whiteSpace: 'nowrap' }}>
|
|
||||||
{i + 1}. {(byId(id) || {}).name}
|
|
||||||
<button type="button" className="btn btn-sm btn-ghost" disabled={i === 0} onClick={() => move(i, -1)}>↑</button>
|
|
||||||
<button type="button" className="btn btn-sm btn-ghost" disabled={i === selected.length - 1} onClick={() => move(i, 1)}>↓</button>
|
|
||||||
</span>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div><button type="button" className="btn btn-sm" style={{ marginTop: 8 }} onClick={() => setManagerOpen(true)}><Edit2 size={12} />管理模板</button></div>
|
<div><button type="button" className="btn btn-sm" style={{ marginTop: 8 }} onClick={() => setManagerOpen(true)}><Edit2 size={12} />管理模板</button></div>
|
||||||
{managerOpen && (
|
{managerOpen && (
|
||||||
<DetailTemplateManager templates={templates} setTemplates={setTemplates} products={products} onNotify={onNotify}
|
<DetailTemplateManager templates={templates} setTemplates={setTemplates} products={products} onNotify={onNotify}
|
||||||
onClose={() => setManagerOpen(false)}
|
onClose={() => setManagerOpen(false)}
|
||||||
onCreated={(id) => set({ webDetailTemplateIds: [...selected, id] })} />
|
onCreated={(id) => set({ webDetailTemplateIds: [id] })} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -7624,6 +7622,10 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
|
||||||
const tq = norm(tplQ);
|
const tq = norm(tplQ);
|
||||||
const modelHits = (t) => (tq ? products.filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(t.id) && (norm(p.name).includes(tq) || norm(p.model).includes(tq))) : []);
|
const modelHits = (t) => (tq ? products.filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(t.id) && (norm(p.name).includes(tq) || norm(p.model).includes(tq))) : []);
|
||||||
const shownTemplates = tq ? templates.filter(t => norm(t.name).includes(tq) || modelHits(t).length) : templates;
|
const shownTemplates = tq ? templates.filter(t => norm(t.name).includes(tq) || modelHits(t).length) : templates;
|
||||||
|
// 异常:同一个型号出现在多个模板里
|
||||||
|
const conflicts = products.filter(p => tplConflict(p, templates));
|
||||||
|
const tplHasConflict = (id) => conflicts.some(p => p.webDetailTemplateIds.includes(id));
|
||||||
|
const tplName = (id) => ((templates.find(t => t.id === id) || {}).name || '未命名模板');
|
||||||
|
|
||||||
function addTemplate() {
|
function addTemplate() {
|
||||||
const t = { id: newTemplateId(), name: `新模板 ${templates.length + 1}`, kind: 'images', images: [] };
|
const t = { id: newTemplateId(), name: `新模板 ${templates.length + 1}`, kind: 'images', images: [] };
|
||||||
|
|
@ -7677,6 +7679,23 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
|
||||||
|
|
||||||
const body = (
|
const body = (
|
||||||
<div className="modal-body">
|
<div className="modal-body">
|
||||||
|
{conflicts.length > 0 && (
|
||||||
|
<div className="tpl-warn" style={{ marginBottom: 12 }}>
|
||||||
|
<b>⚠ 异常:{conflicts.length} 个型号同时出现在多个模板里(一个型号只能关联一个模板)</b>
|
||||||
|
<div style={{ marginTop: 4, display: 'grid', gap: 2 }}>
|
||||||
|
{conflicts.slice(0, 12).map(p => (
|
||||||
|
<div key={p.id}>
|
||||||
|
<span style={{ fontWeight: 600 }}>{p.name || p.model || '未命名'}</span>:
|
||||||
|
{tplIdsOf(p, templates).map((id, i) => (
|
||||||
|
<span key={id}>{i ? '、' : ''}<button type="button" className="tpl-warn-link" onClick={() => setActiveId(id)}>{tplName(id)}</button></span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{conflicts.length > 12 && <div>…还有 {conflicts.length - 12} 个,搜索型号可以找到</div>}
|
||||||
|
</div>
|
||||||
|
<div style={{ marginTop: 4, opacity: .85 }}>点模板名进入该模板,在"使用这个模板的产品"里取消多余的型号(标红的就是)。</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 10, flexWrap: 'wrap' }}>
|
<div style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 10, flexWrap: 'wrap' }}>
|
||||||
<div style={{ position: 'relative', flex: '1 1 260px', maxWidth: 420 }}>
|
<div style={{ position: 'relative', flex: '1 1 260px', maxWidth: 420 }}>
|
||||||
<Search size={14} style={{ position: 'absolute', left: 10, top: '50%', transform: 'translateY(-50%)', color: 'var(--ink-soft)' }} />
|
<Search size={14} style={{ position: 'absolute', left: 10, top: '50%', transform: 'translateY(-50%)', color: 'var(--ink-soft)' }} />
|
||||||
|
|
@ -7687,9 +7706,9 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
|
||||||
{shownTemplates.map(t => (
|
{shownTemplates.map(t => (
|
||||||
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}`} onClick={() => setActiveId(t.id)}
|
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}${tplHasConflict(t.id) ? ' tpl-btn-bad' : ''}`} onClick={() => setActiveId(t.id)}
|
||||||
title={syncStatus ? (syncStatus[t.id] === 'synced' ? '已同步到网站' : syncStatus[t.id] === 'new' ? '新模板,还没同步到网站' : '有修改,还没同步到网站') : ''}>
|
title={syncStatus ? (syncStatus[t.id] === 'synced' ? '已同步到网站' : syncStatus[t.id] === 'new' ? '新模板,还没同步到网站' : '有修改,还没同步到网站') : ''}>
|
||||||
{t.name || '未命名模板'}({tplSummary(t)}){t.webPage ? ` → ${sitePageLabel(t.webPage)}` : ''}
|
{tplHasConflict(t.id) && '⚠ '}{t.name || '未命名模板'}({tplSummary(t)}){t.webPage ? ` → ${sitePageLabel(t.webPage)}` : ''}
|
||||||
{tq && !norm(t.name).includes(tq) && (() => { const h = modelHits(t); return <span style={{ marginLeft: 6, fontSize: 11, opacity: .8 }}>含 {h.slice(0, 2).map(p => p.name || p.model).join('、')}{h.length > 2 ? ` 等 ${h.length} 个` : ''}</span>; })()}
|
{tq && !norm(t.name).includes(tq) && (() => { const h = modelHits(t); return <span style={{ marginLeft: 6, fontSize: 11, opacity: .8 }}>含 {h.slice(0, 2).map(p => p.name || p.model).join('、')}{h.length > 2 ? ` 等 ${h.length} 个` : ''}</span>; })()}
|
||||||
{syncStatus && <span aria-label={syncStatus[t.id] === 'synced' ? '已同步' : '未同步'} style={{ marginLeft: 6, display: 'inline-grid', placeItems: 'center', width: 16, height: 16, borderRadius: 4, fontSize: 11, fontWeight: 700, lineHeight: 1,
|
{syncStatus && <span aria-label={syncStatus[t.id] === 'synced' ? '已同步' : '未同步'} style={{ marginLeft: 6, display: 'inline-grid', placeItems: 'center', width: 16, height: 16, borderRadius: 4, fontSize: 11, fontWeight: 700, lineHeight: 1,
|
||||||
background: syncStatus[t.id] === 'synced' ? '#16a34a' : 'rgba(127,127,127,.25)', color: syncStatus[t.id] === 'synced' ? '#fff' : 'rgba(127,127,127,.9)' }}>✓</span>}
|
background: syncStatus[t.id] === 'synced' ? '#16a34a' : 'rgba(127,127,127,.25)', color: syncStatus[t.id] === 'synced' ? '#fff' : 'rgba(127,127,127,.9)' }}>✓</span>}
|
||||||
|
|
@ -7741,7 +7760,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
|
||||||
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
|
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
|
||||||
)}
|
)}
|
||||||
{(active.kind || 'images') === 'images' && <DetailHtmlBlocks tpl={active} update={(patch) => update(active.id, patch)} />}
|
{(active.kind || 'images') === 'images' && <DetailHtmlBlocks tpl={active} update={(patch) => update(active.id, patch)} />}
|
||||||
{setProducts && <TemplateProductMatcher tpl={active} products={products} setProducts={setProducts} onNotify={onNotify} />}
|
{setProducts && <TemplateProductMatcher tpl={active} templates={templates} products={products} setProducts={setProducts} onNotify={onNotify} />}
|
||||||
<TemplateModelPick tpl={active} products={products} update={(patch) => update(active.id, patch)} onNotify={onNotify} />
|
<TemplateModelPick tpl={active} products={products} update={(patch) => update(active.id, patch)} onNotify={onNotify} />
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 12.5, color: 'var(--ink-soft)' }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 12.5, color: 'var(--ink-soft)' }}>
|
||||||
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后约 3 分钟自动同步到网站` : '还没有产品使用这个模板'}</span>
|
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后约 3 分钟自动同步到网站` : '还没有产品使用这个模板'}</span>
|
||||||
|
|
@ -7799,7 +7818,7 @@ function TemplateCenter({ templates, setTemplates, products, setProducts, onNoti
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
|
function TemplateProductMatcher({ tpl, templates, products, setProducts, onNotify }) {
|
||||||
const [q, setQ] = useState('');
|
const [q, setQ] = useState('');
|
||||||
const [onlySel, setOnlySel] = useState(false);
|
const [onlySel, setOnlySel] = useState(false);
|
||||||
// 勾选型号后自动发布:产品打开"发布到网站",服务器停手约 3 分钟后自动更新网站(多次勾选合并成一次)
|
// 勾选型号后自动发布:产品打开"发布到网站",服务器停手约 3 分钟后自动更新网站(多次勾选合并成一次)
|
||||||
|
|
@ -7808,15 +7827,25 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
|
||||||
function scheduleDeploy() { setDeployMsg('已保存,约 3 分钟后自动更新网站'); }
|
function scheduleDeploy() { setDeployMsg('已保存,约 3 分钟后自动更新网站'); }
|
||||||
const uses = (p) => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id);
|
const uses = (p) => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id);
|
||||||
const label = (p) => p.name || p.model || '未命名';
|
const label = (p) => p.name || p.model || '未命名';
|
||||||
|
const others = (p) => tplIdsOf(p, templates).filter(id => id !== tpl.id);
|
||||||
|
const tplName = (id) => (((templates || []).find(t => t.id === id) || {}).name || '未命名模板');
|
||||||
const setUse = (ids, on) => {
|
const setUse = (ids, on) => {
|
||||||
|
// 一个型号只能关联一个模板:选中时,已经在别的模板里的型号会从那个模板移过来(先确认)
|
||||||
|
if (on) {
|
||||||
|
const moving = products.filter(p => ids.includes(p.id) && others(p).length);
|
||||||
|
if (moving.length && !window.confirm(moving.length === 1
|
||||||
|
? `"${label(moving[0])}"已经在模板"${others(moving[0]).map(tplName).join('、')}"里。\n一个型号只能关联一个模板,确定移到"${tpl.name || '当前模板'}"?`
|
||||||
|
: `其中 ${moving.length} 个型号已经在别的模板里(如 ${moving.slice(0, 3).map(label).join('、')})。\n一个型号只能关联一个模板,确定把它们都移到"${tpl.name || '当前模板'}"?`)) return;
|
||||||
|
}
|
||||||
const set = new Set(ids);
|
const set = new Set(ids);
|
||||||
setProducts(list => list.map(p => {
|
setProducts(list => list.map(p => {
|
||||||
if (!set.has(p.id)) return p;
|
if (!set.has(p.id)) return p;
|
||||||
const cur = Array.isArray(p.webDetailTemplateIds) ? p.webDetailTemplateIds : [];
|
const cur = Array.isArray(p.webDetailTemplateIds) ? p.webDetailTemplateIds : [];
|
||||||
const has = cur.includes(tpl.id);
|
const has = cur.includes(tpl.id);
|
||||||
if (on === has && (!on || p.publishToWeb)) return p;
|
if (!on && !has) return p;
|
||||||
|
if (on && has && cur.length === 1 && p.publishToWeb) return p;
|
||||||
// 选中 = 同时发布到网站;取消选中只移除模板,不会取消发布
|
// 选中 = 同时发布到网站;取消选中只移除模板,不会取消发布
|
||||||
return { ...p, webDetailTemplateIds: on ? (has ? cur : [...cur, tpl.id]) : cur.filter(x => x !== tpl.id), ...(on ? { publishToWeb: true } : {}) };
|
return { ...p, webDetailTemplateIds: on ? [tpl.id] : cur.filter(x => x !== tpl.id), ...(on ? { publishToWeb: true } : {}) };
|
||||||
}));
|
}));
|
||||||
scheduleDeploy();
|
scheduleDeploy();
|
||||||
};
|
};
|
||||||
|
|
@ -7863,9 +7892,13 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
|
||||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
|
||||||
{list.map(p => {
|
{list.map(p => {
|
||||||
const on = uses(p);
|
const on = uses(p);
|
||||||
|
const bad = on && others(p).length > 0;
|
||||||
|
const elsewhere = !on && others(p).length > 0;
|
||||||
return (
|
return (
|
||||||
<button type="button" key={p.id} className={`btn btn-sm${on ? ' btn-primary' : ''}`} onClick={() => setUse([p.id], !on)} title={p.publishToWeb ? '已发布到网站' : '未发布到网站'}>
|
<button type="button" key={p.id} className={`btn btn-sm${on ? ' btn-primary' : ''}${bad ? ' tpl-btn-bad' : ''}`} onClick={() => setUse([p.id], !on)}
|
||||||
{on ? '✓ ' : ''}{label(p)}{!p.publishToWeb && <span style={{ opacity: .55, marginLeft: 4, fontSize: 11 }}>未发布</span>}
|
title={bad ? `异常:还在模板"${others(p).map(tplName).join('、')}"里,一个型号只能关联一个模板` : elsewhere ? `已在模板"${others(p).map(tplName).join('、')}"里,选中会移到当前模板` : (p.publishToWeb ? '已发布到网站' : '未发布到网站')}>
|
||||||
|
{bad ? '⚠ ' : on ? '✓ ' : ''}{label(p)}{!p.publishToWeb && <span style={{ opacity: .55, marginLeft: 4, fontSize: 11 }}>未发布</span>}
|
||||||
|
{elsewhere && <span style={{ opacity: .6, marginLeft: 4, fontSize: 11 }}>在「{others(p).map(tplName).join('、')}」</span>}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
@ -9789,7 +9822,7 @@ function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categori
|
||||||
<>
|
<>
|
||||||
<div className="panel section-gap">
|
<div className="panel section-gap">
|
||||||
<div className="panel-header">
|
<div className="panel-header">
|
||||||
<div className="panel-title"><div className="led-dot blue" />{p.name || '(未命名)'}{p.publishToWeb && <span className="web-badge"><Globe size={11} />已发布到网站</span>}{usedTemplates.map(t => <span key={t.id} className="tpl-badge" title="使用的模板(模板管理里可修改)"><Layers size={11} />{t.name || '未命名模板'}</span>)}</div>
|
<div className="panel-title"><div className="led-dot blue" />{p.name || '(未命名)'}{p.publishToWeb && <span className="web-badge"><Globe size={11} />已发布到网站</span>}{usedTemplates.map(t => <span key={t.id} className={`tpl-badge${usedTemplates.length > 1 ? ' bad' : ''}`} title={usedTemplates.length > 1 ? '异常:一个型号只能关联一个模板' : '使用的模板(模板管理里可修改)'}><Layers size={11} />{t.name || '未命名模板'}</span>)}{usedTemplates.length > 1 && <span className="tpl-badge bad">⚠ 异常:关联了 {usedTemplates.length} 个模板</span>}</div>
|
||||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
|
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
|
||||||
{p.publishToWeb && <SiteDeployButton />}
|
{p.publishToWeb && <SiteDeployButton />}
|
||||||
<button className="btn btn-sm" onClick={onEdit}><Edit2 size={12} />编辑</button>
|
<button className="btn btn-sm" onClick={onEdit}><Edit2 size={12} />编辑</button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue