功能迭代
This commit is contained in:
1 parent
9df10ca806
commit
5fc7d4564c
11 files changed
+227
-11
No files matched your search
@@ -30,11 +30,20 @@ type ProductTemplate = {
|
||||
/** 模板名称。 */ templateName: string;
|
||||
/** 模板用途说明。 */ description: string;
|
||||
/** 模板英文富文本内容。 */ templateContent: string;
|
||||
/** 模板关联推荐产品业务编号。 */ relatedProductCodes: string[];
|
||||
/** 发布状态。 */ status: string;
|
||||
/** 排序值。 */ sortNo: number;
|
||||
/** 更新时间毫秒时间戳。 */ updateTime?: number;
|
||||
};
|
||||
|
||||
type ProductOption = {
|
||||
/** 产品业务编号。 */ productCode: string;
|
||||
/** 产品英文名称。 */ productName: string;
|
||||
/** 产品型号。 */ model?: string;
|
||||
/** 产品封面图片地址。 */ coverMediaUrl?: string;
|
||||
/** 发布状态。 */ status: string;
|
||||
};
|
||||
|
||||
type MediaItem = {
|
||||
/** 素材业务编号。 */ mediaCode: string;
|
||||
/** 素材访问地址。 */ url: string;
|
||||
@@ -47,6 +56,7 @@ const emptyTemplate: ProductTemplate = {
|
||||
templateName: "",
|
||||
description: "",
|
||||
templateContent: "<p></p>",
|
||||
relatedProductCodes: [],
|
||||
status: "DRAFT",
|
||||
sortNo: 30,
|
||||
};
|
||||
@@ -54,6 +64,7 @@ const emptyTemplate: ProductTemplate = {
|
||||
/** 产品公共详情模板列表和编辑页面。 */
|
||||
export default function ProductTemplateManager() {
|
||||
const [items, setItems] = useState<ProductTemplate[]>([]);
|
||||
const [products, setProducts] = useState<ProductOption[]>([]);
|
||||
const [editing, setEditing] = useState<ProductTemplate | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
@@ -72,10 +83,12 @@ export default function ProductTemplateManager() {
|
||||
const loadTemplates = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await apiPost("/products/templates/list", {
|
||||
siteCode: SITE,
|
||||
});
|
||||
setItems(data.items || []);
|
||||
const [data, productData] = await Promise.all([
|
||||
apiPost("/products/templates/list", { siteCode: SITE }),
|
||||
apiPost("/products/list", { siteCode: SITE, pageNo: 1, pageSize: 100 }),
|
||||
]);
|
||||
setItems((data.items || []).map((item: ProductTemplate) => ({ ...item, relatedProductCodes: item.relatedProductCodes || [] })));
|
||||
setProducts(productData.items || []);
|
||||
} catch (error) {
|
||||
setNotice(error instanceof Error ? error.message : "模板加载失败");
|
||||
} finally {
|
||||
@@ -106,6 +119,7 @@ export default function ProductTemplateManager() {
|
||||
templateName: editing.templateName,
|
||||
description: editing.description,
|
||||
templateContent: editor.getHTML(),
|
||||
relatedProductCodes: editing.relatedProductCodes || [],
|
||||
status: editing.status,
|
||||
sortNo: editing.sortNo,
|
||||
});
|
||||
@@ -247,6 +261,30 @@ export default function ProductTemplateManager() {
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
<section className="edit-section">
|
||||
<div className="section-head">
|
||||
<h2>关联推荐产品</h2>
|
||||
<span>已选择 {editing.relatedProductCodes?.length || 0} / 12</span>
|
||||
</div>
|
||||
<p className="template-editor-tip">
|
||||
使用该模板的产品详情页底部将统一展示所选产品;未选择时按当前产品分类自动推荐。
|
||||
</p>
|
||||
<div className="template-related-products">
|
||||
{products.filter((product) => product.status === "PUBLISHED").map((product) => {
|
||||
const checked = (editing.relatedProductCodes || []).includes(product.productCode);
|
||||
return <label className={checked ? "selected" : ""} key={product.productCode}>
|
||||
{product.coverMediaUrl ? <img src={assetUrl(product.coverMediaUrl)} alt={product.productName}/> : <span className="product-image-empty"><ImageIcon size={18}/></span>}
|
||||
<span><strong>{product.productName}</strong><small>{product.model || product.productCode}</small></span>
|
||||
<input type="checkbox" checked={checked} disabled={!checked && (editing.relatedProductCodes?.length || 0) >= 12} onChange={() => setEditing({
|
||||
...editing,
|
||||
relatedProductCodes: checked
|
||||
? editing.relatedProductCodes.filter((code) => code !== product.productCode)
|
||||
: [...(editing.relatedProductCodes || []), product.productCode],
|
||||
})}/>
|
||||
</label>;
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
<section className="edit-section">
|
||||
<div className="section-head">
|
||||
<h2>公共富文本内容</h2>
|
||||
|
||||
@@ -3966,3 +3966,53 @@ header p {
|
||||
min-width: 30px;
|
||||
}
|
||||
}
|
||||
.template-related-products {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
max-height: 430px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.template-related-products label {
|
||||
align-items: center;
|
||||
border: 1px solid #dce4e1;
|
||||
cursor: pointer;
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
grid-template-columns: 54px 1fr auto;
|
||||
padding: 9px;
|
||||
}
|
||||
|
||||
.template-related-products label.selected {
|
||||
background: #edf6f3;
|
||||
border-color: #14735f;
|
||||
}
|
||||
|
||||
.template-related-products img,
|
||||
.template-related-products .product-image-empty {
|
||||
align-items: center;
|
||||
background: #f4f6f5;
|
||||
display: flex;
|
||||
height: 54px;
|
||||
justify-content: center;
|
||||
object-fit: contain;
|
||||
width: 54px;
|
||||
}
|
||||
|
||||
.template-related-products label > span:nth-child(2) {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.template-related-products strong,
|
||||
.template-related-products small {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.template-related-products { grid-template-columns: 1fr; }
|
||||
}
|
||||
Reference in new issue
Block a user