feat: 建立组件化模板预览基线并规划可视化编辑

This commit is contained in:
que01 committed 2026-10-09 12:32:24 +08:00
1 parent c5af790554
commit 0b14b5a814
46 files changed
+1880 -427

No files matched your search

+11 -6
View File
@@ -7,6 +7,12 @@ export function brandSlug() {
}
return BRAND_SLUG;
}
function isEditorPreview() {
return (
process.env.TARO_ENV === "h5" &&
new URLSearchParams(window.location.search).get("editor") === "1"
);
}
export const tokenKey = () => `customerToken:${brandSlug()}`;
export function hasSession() {
return Boolean(Taro.getStorageSync<string>(tokenKey()));
@@ -16,9 +22,10 @@ export async function request<T>(
options: { method?: "GET" | "POST"; data?: unknown; customer?: boolean } = {},
): Promise<T> {
const context = path.startsWith("/public/") || path.startsWith("/customer/session/wechat");
const query = context
? `${path.includes("?") ? "&" : "?"}brandSlug=${encodeURIComponent(brandSlug())}`
: "";
const query =
context && !(isEditorPreview() && path === "/public/workspace")
? `${path.includes("?") ? "&" : "?"}brandSlug=${encodeURIComponent(brandSlug())}`
: "";
const response = await Taro.request<T & { error?: { message?: string; requestId?: string } }>({
url: API_BASE_URL.replace(/\/$/, "") + path + query,
method: options.method || "GET",
@@ -38,9 +45,7 @@ export async function request<T>(
}
export async function loadWorkspace() {
const data = await request<RuntimeWorkspace>("/public/workspace");
const editorPreview =
process.env.TARO_ENV === "h5" &&
new URLSearchParams(window.location.search).get("editor") === "1";
const editorPreview = isEditorPreview();
if (!editorPreview && data.publication?.status !== "published") throw new Error("品牌尚未发布");
if (!editorPreview && data.brand.visualTemplateKey !== TEMPLATE_KEY)
throw new Error("该品牌使用其他模板,请选择匹配的模板预览地址");