feat: 新增 Taro 模板双端运行与独立 Web 预览
This commit is contained in:
1 parent
f4061a24bd
commit
7e8fc01fba
48 files changed
+11576
-12
No files matched your search
@@ -0,0 +1,90 @@
|
||||
import type {
|
||||
RuntimeOffering,
|
||||
RuntimeWorkspace,
|
||||
RuntimeTrustItem,
|
||||
RuntimeInquiryField,
|
||||
} from "@personal-brand/types";
|
||||
export type Presentation = Record<string, string>;
|
||||
export function text(value: unknown): string {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
export function object(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" && !Array.isArray(value)
|
||||
? (value as Record<string, unknown>)
|
||||
: {};
|
||||
}
|
||||
export function rows(value: unknown): Record<string, string>[] {
|
||||
return Array.isArray(value)
|
||||
? value
|
||||
.filter(
|
||||
(item): item is Record<string, string> =>
|
||||
Boolean(item) && typeof item === "object" && !Array.isArray(item),
|
||||
)
|
||||
.map((item) =>
|
||||
Object.fromEntries(Object.entries(item).map(([key, value]) => [key, text(value)])),
|
||||
)
|
||||
: [];
|
||||
}
|
||||
export function brandText(workspace: RuntimeWorkspace, key: string) {
|
||||
return text(workspace.brand[key]);
|
||||
}
|
||||
export function presentation(workspace: RuntimeWorkspace, page: string): Presentation {
|
||||
return object(object(workspace.brand.visualPresentation)[page]) as Presentation;
|
||||
}
|
||||
export function slot(workspace: RuntimeWorkspace, type: string): RuntimeTrustItem | undefined {
|
||||
const items = workspace.trustItems.filter((item) => item.type === type);
|
||||
return items.find((item) => Object.keys(item.config).length > 0) || items[0];
|
||||
}
|
||||
export type Offering = RuntimeOffering & {
|
||||
image: string;
|
||||
desc: string;
|
||||
priceRange: string;
|
||||
category: string;
|
||||
area: string;
|
||||
series: string;
|
||||
keywords: string[];
|
||||
details: RuntimeOffering["presentation"]["details"];
|
||||
};
|
||||
export function offering(item: RuntimeOffering): Offering {
|
||||
return {
|
||||
...item,
|
||||
image: item.presentation.heroImage || item.coverUrl || "",
|
||||
desc: item.summary || "",
|
||||
priceRange: item.priceText || "沟通报价",
|
||||
category: item.presentation.categoryLabel,
|
||||
area: text(item.presentation.area),
|
||||
series: text(item.presentation.series),
|
||||
keywords: item.presentation.keywords,
|
||||
details: item.presentation.details,
|
||||
};
|
||||
}
|
||||
export type Values = Record<string, string | string[]>;
|
||||
export function visibleFields(fields: RuntimeInquiryField[], values: Values) {
|
||||
return fields.filter((field) =>
|
||||
(field.visibleWhen || []).every((rule) => {
|
||||
const value = values[rule.field];
|
||||
switch (rule.operator) {
|
||||
case "exists":
|
||||
return Array.isArray(value) ? value.length > 0 : Boolean(value);
|
||||
case "equals":
|
||||
return value === rule.value;
|
||||
case "not-equals":
|
||||
return value !== rule.value;
|
||||
case "in":
|
||||
return (
|
||||
Array.isArray(rule.value) && typeof value === "string" && rule.value.includes(value)
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
export function missingField(fields: RuntimeInquiryField[], values: Values) {
|
||||
return visibleFields(fields, values).find(
|
||||
(field) =>
|
||||
field.required &&
|
||||
(!values[field.key] ||
|
||||
(Array.isArray(values[field.key])
|
||||
? values[field.key].length === 0
|
||||
: !(values[field.key] as string).trim())),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user