feat: 完善后台可视化模板编辑与区域绑定
This commit is contained in:
1 parent
0b14b5a814
commit
5b85fe769f
18 files changed
+1620
-239
No files matched your search
@@ -23,6 +23,33 @@ const brand = {
|
||||
visualPresentation: { home: { stallTitle: "原服务地点", worksTitle: "原餐品标题" } },
|
||||
},
|
||||
};
|
||||
const adminOffering = {
|
||||
id: "menu-fixture",
|
||||
kind: "service",
|
||||
name: "家庭聚餐定制",
|
||||
summary: "为同学聚餐、家庭聚会提供常见的私房菜定制。",
|
||||
description: "餐品详情",
|
||||
priceText: "88.88",
|
||||
coverUrl: brand.avatarUrl,
|
||||
isEnabled: true,
|
||||
sortOrder: 0,
|
||||
config: { categoryLabel: "业务提供项" },
|
||||
};
|
||||
const adminTrust = {
|
||||
id: "schedule-fixture",
|
||||
type: "schedule",
|
||||
title: "出摊安排",
|
||||
summary: "工作日安排",
|
||||
content: "周末安排",
|
||||
sortOrder: 0,
|
||||
isPublished: true,
|
||||
config: {
|
||||
weekdayLabel: "周一至周五",
|
||||
weekdayDetail: "东门附近",
|
||||
weekendLabel: "周六至周日",
|
||||
weekendDetail: "周末晚间出摊",
|
||||
},
|
||||
};
|
||||
const runtimeWorkspace = {
|
||||
schemaVersion: "1.0.0",
|
||||
publication: { status: "published", version: 1 },
|
||||
@@ -37,16 +64,20 @@ const runtimeWorkspace = {
|
||||
navigation: { tabs: [] },
|
||||
offerings: [
|
||||
{
|
||||
id: "menu-fixture",
|
||||
name: "家庭聚餐定制",
|
||||
summary: "为同学聚餐、家庭聚会提供常见的私房菜定制。",
|
||||
priceText: "88.88",
|
||||
coverUrl: brand.avatarUrl,
|
||||
presentation: { categoryLabel: "业务提供项", keywords: [], details: [] },
|
||||
id: adminOffering.id,
|
||||
name: adminOffering.name,
|
||||
summary: adminOffering.summary,
|
||||
priceText: adminOffering.priceText,
|
||||
coverUrl: adminOffering.coverUrl,
|
||||
presentation: {
|
||||
categoryLabel: "业务提供项",
|
||||
keywords: [],
|
||||
details: { background: "餐品详情", designConcept: "", crafts: [], materialsList: [] },
|
||||
},
|
||||
},
|
||||
],
|
||||
inquiryForms: [],
|
||||
trustItems: [],
|
||||
trustItems: [{ ...adminTrust }],
|
||||
trustPresentation: {},
|
||||
capabilities: [],
|
||||
theme: { colors: {} },
|
||||
@@ -56,11 +87,88 @@ const templateContent = {
|
||||
navigation: [
|
||||
{ key: "home", page: "home", label: "首页" },
|
||||
{ key: "offerings", page: "offerings", label: "套餐餐品" },
|
||||
{ key: "service", page: "service", label: "出摊服务" },
|
||||
{ key: "detail", page: "detail", label: "详情页" },
|
||||
],
|
||||
assetSlots: [],
|
||||
trustContentTypes: [],
|
||||
trustContentTypes: [
|
||||
{
|
||||
type: "schedule",
|
||||
label: "每周出摊安排",
|
||||
adminFields: { title: "安排标题", summary: "安排摘要", content: "安排正文" },
|
||||
hideStandardFields: ["summary", "content"],
|
||||
pages: ["service"],
|
||||
configFields: [
|
||||
{
|
||||
key: "weekdayLabel",
|
||||
binding: "trust.config.weekdayLabel",
|
||||
label: "工作日标题",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekdayDetail",
|
||||
binding: "trust.config.weekdayDetail",
|
||||
label: "工作日地点",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekendLabel",
|
||||
binding: "trust.config.weekendLabel",
|
||||
label: "周末标题",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekendDetail",
|
||||
binding: "trust.config.weekendDetail",
|
||||
label: "周末地点",
|
||||
input: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
admin: {
|
||||
sections: [
|
||||
{
|
||||
key: "detailCopy",
|
||||
title: "餐品说明",
|
||||
description: "编辑详情页说明",
|
||||
page: "detail",
|
||||
target: "brand",
|
||||
previewTargets: [{ key: "acheng-campus-food.detail.detailCopy", label: "餐品说明" }],
|
||||
fields: [
|
||||
{
|
||||
key: "priceLabel",
|
||||
binding: "brand.config.visualPresentation.detail.priceLabel",
|
||||
label: "价格标题",
|
||||
input: "text",
|
||||
previewTarget: "acheng-campus-food.detail.detailCopy",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "offering-card",
|
||||
title: "餐品卡片",
|
||||
description: "编辑单条餐品",
|
||||
page: "offerings",
|
||||
target: "offering",
|
||||
previewTargets: [{ key: "acheng-campus-food.offerings.item", label: "餐品卡片" }],
|
||||
fields: [
|
||||
{
|
||||
key: "name",
|
||||
binding: "offering.name",
|
||||
label: "餐品名称",
|
||||
input: "text",
|
||||
previewTarget: "acheng-campus-food.offerings.item",
|
||||
},
|
||||
{
|
||||
key: "summary",
|
||||
binding: "offering.summary",
|
||||
label: "餐品简介",
|
||||
input: "textarea",
|
||||
previewTarget: "acheng-campus-food.offerings.item",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "home",
|
||||
title: "首页内容",
|
||||
@@ -125,6 +233,32 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
return route.fulfill({ json: brand });
|
||||
}
|
||||
if (url.pathname === "/admin/config/brand") return route.fulfill({ json: brand });
|
||||
if (url.pathname === "/admin/workspace/offerings")
|
||||
return route.fulfill({ json: [adminOffering] });
|
||||
if (
|
||||
url.pathname === `/admin/workspace/offerings/${adminOffering.id}` &&
|
||||
request.method() === "PATCH"
|
||||
) {
|
||||
Object.assign(adminOffering, request.postDataJSON());
|
||||
Object.assign(runtimeWorkspace.offerings[0], {
|
||||
name: adminOffering.name,
|
||||
summary: adminOffering.summary,
|
||||
});
|
||||
return route.fulfill({ json: adminOffering });
|
||||
}
|
||||
if (url.pathname === "/admin/config/trust-content")
|
||||
return route.fulfill({ json: [adminTrust] });
|
||||
if (
|
||||
url.pathname === `/admin/config/trust-content/${adminTrust.id}` &&
|
||||
request.method() === "PATCH"
|
||||
) {
|
||||
Object.assign(adminTrust, request.postDataJSON());
|
||||
Object.assign(runtimeWorkspace.trustItems[0], {
|
||||
title: adminTrust.title,
|
||||
config: adminTrust.config,
|
||||
});
|
||||
return route.fulfill({ json: adminTrust });
|
||||
}
|
||||
if (url.pathname === "/admin/workspace")
|
||||
return route.fulfill({
|
||||
json: { brand, installations: [], fields: [], offerings: [], forms: [], templateContent },
|
||||
@@ -185,11 +319,56 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
await expect(preview.locator(".notice-title")).toContainText("后台草稿地点");
|
||||
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||
await expect(preview.locator('[data-editor-target="food.home.location"]')).toHaveClass(
|
||||
/editor-target-selected/,
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-target",
|
||||
"food.home.location",
|
||||
);
|
||||
await page.getByRole("button", { name: "浏览页面" }).click();
|
||||
await preview.locator(".food-home .actions button").nth(1).click();
|
||||
await expect(page.getByText("招牌餐品标题")).toHaveCount(0);
|
||||
await page.getByRole("button", { name: "点选编辑" }).click();
|
||||
await preview.locator('[data-editor-target="food.home.location"]').click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-target",
|
||||
"food.home.location",
|
||||
);
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await expect(preview.locator(".offering-card")).toHaveCount(1);
|
||||
await preview.locator('[data-editor-target="acheng-campus-food.offerings.item"]').click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-record-id",
|
||||
adminOffering.id,
|
||||
);
|
||||
await page.getByLabel("餐品名称").fill("编辑后的家庭餐");
|
||||
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => adminOffering.name).toBe("编辑后的家庭餐");
|
||||
await page.reload();
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
|
||||
await page.getByText("出摊服务", { exact: true }).click();
|
||||
await preview.locator('[data-editor-target="trust:schedule"]').click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-record-id",
|
||||
adminTrust.id,
|
||||
);
|
||||
await page.getByLabel("工作日标题").fill("周一到周五营业");
|
||||
await expect(preview.locator(".schedule-card")).toContainText("周一到周五营业");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => adminTrust.config.weekdayLabel).toBe("周一到周五营业");
|
||||
await page.reload();
|
||||
await page.getByText("出摊服务", { exact: true }).click();
|
||||
await expect(preview.locator(".schedule-card")).toContainText("周一到周五营业");
|
||||
await page.getByText("详情页", { exact: true }).click();
|
||||
await preview.locator('[data-editor-target="acheng-campus-food.detail.detailCopy"]').click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-target",
|
||||
"acheng-campus-food.detail.detailCopy",
|
||||
);
|
||||
await expect(page.getByLabel("价格标题")).toBeVisible();
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview.locator(".dish-media img").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
@@ -216,3 +395,129 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1600, height: 900 });
|
||||
const editorialBrand = {
|
||||
...structuredClone(brand),
|
||||
templateKey: "personal",
|
||||
config: {
|
||||
visualTemplateKey: "linjing-editorial",
|
||||
founder: "林境主理人",
|
||||
title: "建筑设计师",
|
||||
heroImage: "/assets/tab/home.png",
|
||||
homeHero: { title: "林境作品" },
|
||||
},
|
||||
};
|
||||
const editorialWorkspace = {
|
||||
...structuredClone(runtimeWorkspace),
|
||||
brand: {
|
||||
...structuredClone(runtimeWorkspace.brand),
|
||||
...editorialBrand,
|
||||
founder: "林境主理人",
|
||||
title: "建筑设计师",
|
||||
heroImage: "/assets/tab/home.png",
|
||||
homeHero: { title: "林境作品" },
|
||||
},
|
||||
offerings: [],
|
||||
trustItems: [],
|
||||
};
|
||||
const editorialContent = {
|
||||
displayName: "林境模板",
|
||||
navigation: [
|
||||
{ key: "home", page: "home", label: "首页" },
|
||||
{ key: "profile", page: "profile", label: "主理人与我" },
|
||||
],
|
||||
assetSlots: [],
|
||||
trustContentTypes: [],
|
||||
admin: {
|
||||
sections: [
|
||||
{
|
||||
key: "home",
|
||||
title: "首页主视觉",
|
||||
page: "home",
|
||||
target: "brand",
|
||||
previewTargets: [{ key: "editorial.home.hero", label: "首页主视觉" }],
|
||||
fields: [
|
||||
{
|
||||
key: "heroTitle",
|
||||
binding: "brand.config.homeHero.title",
|
||||
label: "首页标题",
|
||||
input: "text",
|
||||
previewTarget: "editorial.home.hero",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "identity",
|
||||
title: "主理人与联系方式",
|
||||
page: "profile",
|
||||
target: "brand",
|
||||
previewTargets: [
|
||||
{ key: "linjing-editorial.profile.identity", label: "主理人与联系方式" },
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
key: "founder",
|
||||
binding: "brand.config.founder",
|
||||
label: "主理人姓名",
|
||||
input: "text",
|
||||
previewTarget: "linjing-editorial.profile.identity",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
await page.route("**/api/**", (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const path = url.pathname.replace(/^\/api/, "");
|
||||
if (path === "/admin/session/login")
|
||||
return route.fulfill({
|
||||
json: { token: "fixture-token", displayName: "测试管理员", role: "owner" },
|
||||
});
|
||||
if (path === "/admin/brands")
|
||||
return route.fulfill({
|
||||
json: [{ id: editorialBrand.id, role: "owner", brand: editorialBrand }],
|
||||
});
|
||||
if (path === "/admin/config/brand") return route.fulfill({ json: editorialBrand });
|
||||
if (path === "/public/templates/personal")
|
||||
return route.fulfill({
|
||||
json: { name: "个人品牌", description: "林境模板", serviceCategories: [] },
|
||||
});
|
||||
if (path === "/admin/workspace")
|
||||
return route.fulfill({
|
||||
json: {
|
||||
brand: editorialBrand,
|
||||
installations: [],
|
||||
fields: [],
|
||||
offerings: [],
|
||||
forms: [],
|
||||
templateContent: editorialContent,
|
||||
},
|
||||
});
|
||||
if (path === "/admin/workspace/preview" || path === "/public/workspace")
|
||||
return route.fulfill({ json: editorialWorkspace });
|
||||
return route.fulfill({ json: {} });
|
||||
});
|
||||
await page.goto(adminOrigin + "/admin/brand");
|
||||
await page.getByLabel("账号").fill("admin");
|
||||
await page.getByLabel("密码").fill("fixture-password");
|
||||
await page.locator('button[type="submit"]').click();
|
||||
const preview = page.locator(".component-template-preview");
|
||||
await expect(preview.locator(".editorial-home")).toBeVisible();
|
||||
await expect(preview.locator(".hero-title")).toContainText("林境作品");
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview.locator(".hero-image").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
)
|
||||
.toBeGreaterThan(0);
|
||||
await preview.locator('[data-editor-target="editorial.home.hero"]').click();
|
||||
await expect(page.getByLabel("首页标题")).toBeVisible();
|
||||
await page.getByText("主理人与我", { exact: true }).click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||
await preview.locator('[data-editor-target="linjing-editorial.profile.identity"]').click();
|
||||
await expect(page.getByLabel("主理人姓名")).toBeVisible();
|
||||
await page.getByLabel("主理人姓名").fill("修改后的主理人");
|
||||
await expect(preview.locator(".editorial-profile .founder")).toContainText("修改后的主理人");
|
||||
});
|
||||
Reference in new issue
Block a user