fix: 修复预览成功页与记录页运行时报错
This commit is contained in:
1 parent
fd2e970d8b
commit
541304a763
4 files changed
+31
-8
No files matched your search
@@ -8,8 +8,8 @@ import { TemplateAssetContext } from "./taro-web-components.jsx";
|
|||||||
|
|
||||||
function pageContent({ workspace, page }) {
|
function pageContent({ workspace, page }) {
|
||||||
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
||||||
if (page === "records") return <Records workspace={workspace} />;
|
if (page === "records") return <Records workspace={workspace} preview />;
|
||||||
if (page === "success") return <Success workspace={workspace} />;
|
if (page === "success") return <Success workspace={workspace} preview />;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,20 @@ const labels: Record<string, string> = {
|
|||||||
converted: "已转化",
|
converted: "已转化",
|
||||||
closed: "已关闭",
|
closed: "已关闭",
|
||||||
};
|
};
|
||||||
export function Records({ workspace }: { workspace: RuntimeWorkspace }) {
|
export function Records({
|
||||||
|
workspace,
|
||||||
|
preview = false,
|
||||||
|
}: {
|
||||||
|
workspace: RuntimeWorkspace;
|
||||||
|
preview?: boolean;
|
||||||
|
}) {
|
||||||
const [records, setRecords] = useState<RecordItem[]>([]);
|
const [records, setRecords] = useState<RecordItem[]>([]);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [authenticated, setAuthenticated] = useState(hasSession());
|
const [authenticated, setAuthenticated] = useState(preview ? false : hasSession());
|
||||||
const p = presentation(workspace, "records");
|
const p = presentation(workspace, "records");
|
||||||
const load = useCallback(() => {
|
const load = useCallback(() => {
|
||||||
|
if (preview) return;
|
||||||
if (!hasSession()) {
|
if (!hasSession()) {
|
||||||
setAuthenticated(false);
|
setAuthenticated(false);
|
||||||
setRecords([]);
|
setRecords([]);
|
||||||
@@ -46,7 +53,7 @@ export function Records({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
setAuthenticated(hasSession());
|
setAuthenticated(hasSession());
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, []);
|
}, [preview]);
|
||||||
useDidShow(load);
|
useDidShow(load);
|
||||||
return (
|
return (
|
||||||
<View className="records-page">
|
<View className="records-page">
|
||||||
|
|||||||
@@ -4,10 +4,18 @@ import type { RuntimeWorkspace } from "@personal-brand/types";
|
|||||||
import { presentation, object, text } from "../runtime/content";
|
import { presentation, object, text } from "../runtime/content";
|
||||||
import { brandSlug } from "../runtime/api";
|
import { brandSlug } from "../runtime/api";
|
||||||
import { navigate } from "../runtime/navigation";
|
import { navigate } from "../runtime/navigation";
|
||||||
export function Success({ workspace }: { workspace: RuntimeWorkspace }) {
|
export function Success({
|
||||||
|
workspace,
|
||||||
|
preview = false,
|
||||||
|
}: {
|
||||||
|
workspace: RuntimeWorkspace;
|
||||||
|
preview?: boolean;
|
||||||
|
}) {
|
||||||
const p = presentation(workspace, "success");
|
const p = presentation(workspace, "success");
|
||||||
const result = object(Taro.getStorageSync<unknown>(`latestInquiry:${brandSlug()}`));
|
const submitted =
|
||||||
if (!text(result.id))
|
preview ||
|
||||||
|
Boolean(text(object(Taro.getStorageSync<unknown>(`latestInquiry:${brandSlug()}`)).id));
|
||||||
|
if (!submitted)
|
||||||
return (
|
return (
|
||||||
<View className="runtime-state">
|
<View className="runtime-state">
|
||||||
尚未提交咨询<Button onClick={() => navigate("inquiry")}>填写需求</Button>
|
尚未提交咨询<Button onClick={() => navigate("inquiry")}>填写需求</Button>
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ const templateContent = {
|
|||||||
{ key: "service", page: "service", label: "出摊服务" },
|
{ key: "service", page: "service", label: "出摊服务" },
|
||||||
{ key: "detail", page: "detail", label: "详情页" },
|
{ key: "detail", page: "detail", label: "详情页" },
|
||||||
{ key: "inquiry", page: "inquiry", label: "定制/咨询" },
|
{ key: "inquiry", page: "inquiry", label: "定制/咨询" },
|
||||||
|
{ key: "success", page: "success", label: "提交成功页" },
|
||||||
|
{ key: "records", page: "records", label: "记录页" },
|
||||||
],
|
],
|
||||||
assetSlots: [],
|
assetSlots: [],
|
||||||
trustContentTypes: [
|
trustContentTypes: [
|
||||||
@@ -413,6 +415,12 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
|||||||
await page.getByRole("button", { name: "浏览页面" }).click();
|
await page.getByRole("button", { name: "浏览页面" }).click();
|
||||||
await preview.locator(".inquiry-form input").first().fill("预览访客");
|
await preview.locator(".inquiry-form input").first().fill("预览访客");
|
||||||
await expect(preview.locator(".inquiry-form input").first()).toHaveValue("预览访客");
|
await expect(preview.locator(".inquiry-form input").first()).toHaveValue("预览访客");
|
||||||
|
await page.getByText("提交成功页", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".success-page")).toBeVisible();
|
||||||
|
await expect(preview.locator(".success-page")).toContainText("已收到你的需求");
|
||||||
|
await page.getByText("记录页", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".records-page")).toBeVisible();
|
||||||
|
await expect(preview.locator(".records-page")).toContainText("请在微信小程序内登录查看");
|
||||||
await page.getByRole("button", { name: "点选编辑" }).click();
|
await page.getByRole("button", { name: "点选编辑" }).click();
|
||||||
await page.getByText("套餐餐品", { exact: true }).click();
|
await page.getByText("套餐餐品", { exact: true }).click();
|
||||||
await expect
|
await expect
|
||||||
|
|||||||
Reference in new issue
Block a user