feat: 能力插件元数据与运行时消费闭环
This commit is contained in:
1 parent
076c6124c8
commit
bb0709b8cc
26 files changed
+2188
-267
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1,148 +1,34 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { Alert, Button, Card, Form, Input, Select, Table, Tag, message } from "antd";
|
||||
import type { CapabilityInstallation } from "@personal-brand/api-client";
|
||||
import { Card, Col, Empty, Row, Typography } from "antd";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { QueryState } from "../../components/QueryState.js";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
const statusLabels = { enabled: "已启用", disabled: "已停用", degraded: "降级" } as const;
|
||||
import { CapabilityCard } from "./components/CapabilityCard.js";
|
||||
import { useCapabilityQuery } from "./hooks/useCapabilityQueries.js";
|
||||
|
||||
export function CapabilitiesPage() {
|
||||
const queryClient = useQueryClient();
|
||||
const query = useQuery({
|
||||
queryKey: ["admin", "capabilities"],
|
||||
queryFn: () => createApiClient().listAdminCapabilities(),
|
||||
});
|
||||
const mutation = useMutation({
|
||||
mutationFn: ({
|
||||
key,
|
||||
values,
|
||||
}: {
|
||||
key: string;
|
||||
values: {
|
||||
capabilityVersion: string;
|
||||
status: CapabilityInstallation["status"];
|
||||
configText?: string;
|
||||
};
|
||||
}) =>
|
||||
createApiClient().updateAdminCapability(key, {
|
||||
capabilityVersion: values.capabilityVersion,
|
||||
status: values.status,
|
||||
config: values.configText ? (JSON.parse(values.configText) as Record<string, unknown>) : {},
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("能力配置已更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin", "capabilities"] });
|
||||
},
|
||||
onError: (error) => message.error(error instanceof Error ? error.message : "更新失败"),
|
||||
});
|
||||
const sampleMutation = useMutation({
|
||||
mutationFn: () => createApiClient().importAdminSampleContent(),
|
||||
onSuccess: (result) => message.success(`已导入 ${result.counts.offerings} 项示例业务`),
|
||||
onError: (error) => message.error(error instanceof Error ? error.message : "导入失败"),
|
||||
});
|
||||
if (query.isLoading) return <QueryState loading />;
|
||||
if (query.isError) return <QueryState error={query.error} />;
|
||||
const items = query.data ?? [];
|
||||
return (
|
||||
<div>
|
||||
<AdminPageHeader title="能力插件" description="管理当前模板声明的业务能力及其运行状态。" />
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message="能力状态会影响公开 Runtime Workspace;停用不会删除历史数据。"
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
<Button
|
||||
onClick={() => sampleMutation.mutate()}
|
||||
loading={sampleMutation.isPending}
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
导入门窗示例内容
|
||||
</Button>
|
||||
<Table
|
||||
rowKey="capabilityKey"
|
||||
dataSource={items}
|
||||
locale={{ emptyText: "当前还没有品牌级能力覆盖,系统将使用模板默认能力。" }}
|
||||
columns={[
|
||||
{ title: "能力", dataIndex: "capabilityKey" },
|
||||
{
|
||||
title: "来源",
|
||||
dataIndex: "source",
|
||||
render: (value: CapabilityInstallation["source"]) => (
|
||||
<Tag>{value === "brand" ? "品牌覆盖" : "模板默认"}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: "版本", dataIndex: "capabilityVersion" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
render: (value: CapabilityInstallation["status"]) => (
|
||||
<Tag
|
||||
color={value === "enabled" ? "green" : value === "degraded" ? "orange" : "default"}
|
||||
>
|
||||
{statusLabels[value]}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, record: CapabilityInstallation) => (
|
||||
<CapabilityEditor
|
||||
record={record}
|
||||
loading={mutation.isPending}
|
||||
onSubmit={(values) => mutation.mutate({ key: record.capabilityKey, values })}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const query = useCapabilityQuery();
|
||||
|
||||
function CapabilityEditor({
|
||||
record,
|
||||
loading,
|
||||
onSubmit,
|
||||
}: {
|
||||
record: CapabilityInstallation;
|
||||
loading: boolean;
|
||||
onSubmit: (values: {
|
||||
capabilityVersion: string;
|
||||
status: CapabilityInstallation["status"];
|
||||
configText?: string;
|
||||
}) => void;
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
return (
|
||||
<Card size="small" style={{ maxWidth: 420 }}>
|
||||
<Form
|
||||
form={form}
|
||||
layout="inline"
|
||||
initialValues={{
|
||||
capabilityVersion: record.capabilityVersion,
|
||||
status: record.status,
|
||||
configText: record.config ? JSON.stringify(record.config) : "",
|
||||
}}
|
||||
onFinish={onSubmit}
|
||||
>
|
||||
<Form.Item name="capabilityVersion" rules={[{ required: true, message: "请输入版本" }]}>
|
||||
<Input placeholder="版本" style={{ width: 100 }} />
|
||||
</Form.Item>
|
||||
<Form.Item name="status">
|
||||
<Select
|
||||
options={Object.entries(statusLabels).map(([value, label]) => ({ value, label }))}
|
||||
style={{ width: 100 }}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="configText">
|
||||
<Input placeholder="JSON 配置(可选)" style={{ width: 180 }} />
|
||||
</Form.Item>
|
||||
<Button type="primary" htmlType="submit" loading={loading}>
|
||||
保存
|
||||
</Button>
|
||||
</Form>
|
||||
</Card>
|
||||
<QueryState loading={query.isLoading} error={query.error} onRetry={() => void query.refetch()}>
|
||||
<AdminPageHeader
|
||||
title="能力管理"
|
||||
description="以经营者视角调整模板能力的开关与展示设置;保存后进入草稿,发布后生效。"
|
||||
/>
|
||||
{query.data?.length ? (
|
||||
<Row gutter={[16, 16]}>
|
||||
{query.data.map((capability) => (
|
||||
<Col key={capability.capabilityKey} xs={24} lg={12}>
|
||||
<CapabilityCard capability={capability} />
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
) : (
|
||||
<Card>
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="当前模板没有可配置能力。" />
|
||||
</Card>
|
||||
)}
|
||||
<Typography.Text type="secondary" style={{ display: "block", marginTop: 16 }}>
|
||||
技术信息仅用于排查问题,不作为运营判断依据。
|
||||
</Typography.Text>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import { Alert, Button, Card, Input, Switch, Tag, Typography } from "antd";
|
||||
import { useState } from "react";
|
||||
import { useCapabilityMutation } from "../hooks/useCapabilityQueries.js";
|
||||
import type { AdminCapability, CapabilityStatus } from "../types.js";
|
||||
import { CapabilityStatusControl, CapabilityStatusTag } from "./CapabilityStatusControl.js";
|
||||
|
||||
const sourceLabels = {
|
||||
brand: "品牌覆盖",
|
||||
template: "模板默认",
|
||||
} as const;
|
||||
|
||||
const disablePolicyLabels = {
|
||||
allowed: "该能力允许停用,保存后进入草稿。",
|
||||
disabled: "该能力为模板必需项,保存后进入草稿。",
|
||||
} as const;
|
||||
|
||||
const updatedTimeFormatter = new Intl.DateTimeFormat("zh-CN", {
|
||||
dateStyle: "short",
|
||||
timeStyle: "short",
|
||||
});
|
||||
|
||||
function readTextValue(value: unknown): string {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function readSwitchValue(value: unknown): boolean {
|
||||
return value === true;
|
||||
}
|
||||
|
||||
export function CapabilityCard({ capability }: { capability: AdminCapability }) {
|
||||
const [status, setStatus] = useState<CapabilityStatus>(capability.status);
|
||||
const [config, setConfig] = useState<Record<string, unknown>>(capability.config);
|
||||
const mutation = useCapabilityMutation();
|
||||
|
||||
const save = async () => {
|
||||
await mutation.mutateAsync({
|
||||
key: capability.capabilityKey,
|
||||
status,
|
||||
config,
|
||||
});
|
||||
};
|
||||
|
||||
const updateConfigValue = (key: string, value: unknown) =>
|
||||
setConfig((current) => ({ ...current, [key]: value }));
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={
|
||||
<span>
|
||||
{capability.displayName ?? "未命名能力"}
|
||||
<Tag style={{ marginLeft: 8 }}>{sourceLabels[capability.source]}</Tag>
|
||||
<CapabilityStatusTag status={status} />
|
||||
</span>
|
||||
}
|
||||
extra={
|
||||
<Button type="primary" loading={mutation.isPending} onClick={() => void save()}>
|
||||
保存草稿
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{mutation.isError ? (
|
||||
<Alert
|
||||
type="error"
|
||||
showIcon
|
||||
message="保存失败,已保留当前输入"
|
||||
description={
|
||||
mutation.error instanceof Error ? mutation.error.message : "请检查网络或稍后重试"
|
||||
}
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
) : null}
|
||||
{capability.description ? (
|
||||
<Typography.Paragraph>{capability.description}</Typography.Paragraph>
|
||||
) : null}
|
||||
{capability.impact ? (
|
||||
<Typography.Paragraph type="secondary">影响:{capability.impact}</Typography.Paragraph>
|
||||
) : null}
|
||||
<div style={{ display: "grid", gap: 12 }}>
|
||||
<div>
|
||||
<Typography.Text strong>运行状态</Typography.Text>
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<CapabilityStatusControl
|
||||
status={status}
|
||||
onChange={setStatus}
|
||||
disabled={mutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 0 }}>
|
||||
保存后进入草稿,发布后生效。
|
||||
</Typography.Paragraph>
|
||||
{status === "disabled" && capability.disablePolicy ? (
|
||||
<Typography.Paragraph type="warning" style={{ marginBottom: 0 }}>
|
||||
{disablePolicyLabels[capability.disablePolicy]}
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
</div>
|
||||
{capability.configFields?.length ? (
|
||||
<div>
|
||||
<Typography.Text strong>能力设置</Typography.Text>
|
||||
<div style={{ display: "grid", gap: 12, marginTop: 8 }}>
|
||||
{capability.configFields.map((field) => (
|
||||
<div key={field.key}>
|
||||
<Typography.Text>{field.label}</Typography.Text>
|
||||
{field.input === "switch" ? (
|
||||
<div>
|
||||
<Switch
|
||||
checked={readSwitchValue(config[field.key])}
|
||||
disabled={mutation.isPending}
|
||||
onChange={(checked) => updateConfigValue(field.key, checked)}
|
||||
/>
|
||||
</div>
|
||||
) : field.input === "textarea" ? (
|
||||
<Input.TextArea
|
||||
rows={3}
|
||||
value={readTextValue(config[field.key])}
|
||||
disabled={mutation.isPending}
|
||||
onChange={(event) => updateConfigValue(field.key, event.target.value)}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
value={readTextValue(config[field.key])}
|
||||
disabled={mutation.isPending}
|
||||
onChange={(event) => updateConfigValue(field.key, event.target.value)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
<Typography.Text type="secondary">
|
||||
{capability.source === "template"
|
||||
? "当前使用模板默认设置;修改后保存会创建品牌覆盖。"
|
||||
: "当前已创建品牌覆盖;修改后保存会更新草稿。"}
|
||||
{capability.updatedAt
|
||||
? ` 最近更新:${updatedTimeFormatter.format(new Date(capability.updatedAt))}`
|
||||
: ""}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Segmented, Space, Switch, Tag, Typography } from "antd";
|
||||
import type { CapabilityStatus } from "../types.js";
|
||||
|
||||
const statusLabels: Record<CapabilityStatus, string> = {
|
||||
enabled: "启用",
|
||||
disabled: "停用",
|
||||
degraded: "降级",
|
||||
};
|
||||
|
||||
const statusColors: Record<CapabilityStatus, string> = {
|
||||
enabled: "green",
|
||||
disabled: "default",
|
||||
degraded: "orange",
|
||||
};
|
||||
|
||||
export function CapabilityStatusTag({ status }: { status: CapabilityStatus }) {
|
||||
return <Tag color={statusColors[status]}>{statusLabels[status]}</Tag>;
|
||||
}
|
||||
|
||||
export function CapabilityStatusControl({
|
||||
status,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
status: CapabilityStatus;
|
||||
onChange: (status: CapabilityStatus) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const isDisabled = disabled === true;
|
||||
if (status === "degraded")
|
||||
return (
|
||||
<Segmented
|
||||
value={status}
|
||||
disabled={isDisabled}
|
||||
options={[
|
||||
{ value: "degraded", label: "降级" },
|
||||
{ value: "enabled", label: "启用" },
|
||||
{ value: "disabled", label: "停用" },
|
||||
]}
|
||||
onChange={(value) => onChange(value as CapabilityStatus)}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<Space>
|
||||
<Switch
|
||||
checked={status === "enabled"}
|
||||
disabled={isDisabled}
|
||||
onChange={(checked) => onChange(checked ? "enabled" : "disabled")}
|
||||
/>
|
||||
<Typography.Text type={status === "enabled" ? "success" : "secondary"}>
|
||||
{statusLabels[status]}
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { message } from "antd";
|
||||
import { createApiClient } from "../../../lib/api.js";
|
||||
import { readAdminCapability } from "../types.js";
|
||||
import type { CapabilityValues } from "../types.js";
|
||||
|
||||
export const capabilitiesQueryKey = ["admin", "capabilities"] as const;
|
||||
|
||||
export function useCapabilityQuery() {
|
||||
return useQuery({
|
||||
queryKey: capabilitiesQueryKey,
|
||||
queryFn: async () => {
|
||||
const response = await createApiClient().listAdminCapabilities();
|
||||
return response.map(readAdminCapability);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useCapabilityMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ key, ...values }: { key: string } & CapabilityValues) =>
|
||||
createApiClient().updateAdminCapability(key, {
|
||||
...values,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("能力已保存,进入草稿;发布后生效");
|
||||
void queryClient.invalidateQueries({ queryKey: capabilitiesQueryKey });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import type { CapabilityInstallation } from "@personal-brand/api-client";
|
||||
|
||||
export type CapabilityStatus = CapabilityInstallation["status"];
|
||||
|
||||
export type CapabilitySource = NonNullable<CapabilityInstallation["source"]>;
|
||||
|
||||
export interface CapabilityConfigField {
|
||||
key: string;
|
||||
label: string;
|
||||
input: string;
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
export interface AdminCapability {
|
||||
capabilityKey: string;
|
||||
capabilityVersion: string;
|
||||
status: CapabilityStatus;
|
||||
config: Record<string, unknown>;
|
||||
source: CapabilitySource;
|
||||
updatedAt?: string | null;
|
||||
displayName?: string | undefined;
|
||||
description?: string | undefined;
|
||||
impact?: string | undefined;
|
||||
optional?: boolean | undefined;
|
||||
disablePolicy?: "allowed" | "disabled" | undefined;
|
||||
configFields?: CapabilityConfigField[] | undefined;
|
||||
}
|
||||
|
||||
export interface CapabilityValues {
|
||||
status: CapabilityStatus;
|
||||
config: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export function isCapabilitySource(value: unknown): value is CapabilitySource {
|
||||
return value === "brand" || value === "template";
|
||||
}
|
||||
|
||||
export function readAdminCapability(value: CapabilityInstallation): AdminCapability {
|
||||
const { config, source, ...rest } = value;
|
||||
return {
|
||||
...rest,
|
||||
config: config ?? {},
|
||||
source: isCapabilitySource(source) ? source : "template",
|
||||
displayName: readOptionalString(value.displayName),
|
||||
description: readOptionalString(value.description),
|
||||
impact: readOptionalString(value.impact),
|
||||
optional: typeof value.optional === "boolean" ? value.optional : undefined,
|
||||
disablePolicy:
|
||||
value.disablePolicy === "allowed" || value.disablePolicy === "disabled"
|
||||
? value.disablePolicy
|
||||
: undefined,
|
||||
configFields: Array.isArray(value.configFields)
|
||||
? value.configFields.filter(isCapabilityConfigField)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function readOptionalString(value: unknown): string | undefined {
|
||||
return typeof value === "string" && value.trim() ? value : undefined;
|
||||
}
|
||||
|
||||
function isCapabilityConfigField(value: {
|
||||
key: string;
|
||||
label: string;
|
||||
input: string;
|
||||
required: boolean;
|
||||
}): value is CapabilityConfigField {
|
||||
const field = value;
|
||||
return (
|
||||
typeof field.key === "string" &&
|
||||
field.key.length > 0 &&
|
||||
typeof field.label === "string" &&
|
||||
field.label.length > 0 &&
|
||||
(field.input === "text" || field.input === "textarea" || field.input === "switch")
|
||||
);
|
||||
}
|
||||
@@ -25,6 +25,8 @@ import {
|
||||
} from "./admin.dto.js";
|
||||
import {
|
||||
capabilityRegistry,
|
||||
capabilityMetadata,
|
||||
validateCapabilityConfig,
|
||||
capabilityPlugins,
|
||||
getBrandTemplate,
|
||||
getTemplateSampleContent,
|
||||
@@ -102,10 +104,15 @@ class AdminWorkspaceController {
|
||||
]);
|
||||
const installed = new Map(installations.map((item) => [item.capabilityKey, item]));
|
||||
const template = getBrandTemplate(templateKey);
|
||||
return (template?.capabilities ?? [])
|
||||
.map((key) => capabilityRegistry[key])
|
||||
const optionalCapabilityKeys = Object.entries(capabilityRegistry)
|
||||
.filter(([, definition]) => "optional" in definition && definition.optional)
|
||||
.map(([key]) => key);
|
||||
return [...new Set([...(template?.capabilities ?? []), ...optionalCapabilityKeys])]
|
||||
.map((key) => capabilityRegistry[key as keyof typeof capabilityRegistry])
|
||||
.filter(Boolean)
|
||||
.map((definition) => {
|
||||
const item = installed.get(definition.key);
|
||||
const metadata = capabilityMetadata(definition.key);
|
||||
return {
|
||||
id: item?.id ?? null,
|
||||
capabilityKey: definition.key,
|
||||
@@ -113,6 +120,7 @@ class AdminWorkspaceController {
|
||||
status: item?.status ?? "enabled",
|
||||
config: item?.config ?? {},
|
||||
source: item ? "brand" : "template",
|
||||
...(metadata ?? {}),
|
||||
updatedAt: item?.updatedAt ?? null,
|
||||
};
|
||||
});
|
||||
@@ -249,18 +257,25 @@ class AdminWorkspaceController {
|
||||
const existing = await this.prisma.capabilityInstallation.findUnique({
|
||||
where: { brandId_capabilityKey: { brandId, capabilityKey: key } },
|
||||
});
|
||||
const definition = capabilityRegistry[key as keyof typeof capabilityRegistry];
|
||||
if (definition && "disablePolicy" in definition && definition.disablePolicy === "disabled")
|
||||
throw new BadRequestException("核心能力不可移除");
|
||||
const configErrors = validateCapabilityConfig(key as never, body.config);
|
||||
if (configErrors === null) throw new BadRequestException("能力配置字段无效");
|
||||
if (Object.keys(configErrors).length)
|
||||
throw new BadRequestException({ message: "能力配置字段无效", errors: configErrors });
|
||||
return this.prisma.$transaction(async (tx) => {
|
||||
const installation = await tx.capabilityInstallation.upsert({
|
||||
where: { brandId_capabilityKey: { brandId, capabilityKey: key } },
|
||||
create: {
|
||||
brandId,
|
||||
capabilityKey: key,
|
||||
capabilityVersion: body.capabilityVersion,
|
||||
capabilityVersion: definition?.version ?? "1.0.0",
|
||||
status: body.status,
|
||||
config: (body.config ?? {}) as Prisma.InputJsonValue,
|
||||
},
|
||||
update: {
|
||||
capabilityVersion: body.capabilityVersion,
|
||||
...(definition ? { capabilityVersion: definition.version } : {}),
|
||||
status: body.status,
|
||||
...(body.config === undefined ? {} : { config: body.config as Prisma.InputJsonValue }),
|
||||
},
|
||||
|
||||
@@ -108,7 +108,6 @@ export class InstallTemplateDto {
|
||||
}
|
||||
|
||||
export class UpdateCapabilityInstallationDto {
|
||||
@IsString() capabilityVersion!: string;
|
||||
@IsIn(["enabled", "disabled", "degraded"])
|
||||
status!: "enabled" | "disabled" | "degraded";
|
||||
@IsOptional() @IsObject() config?: Record<string, unknown>;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { BrandReleaseSnapshot } from "../../brand-release.service.js";
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import {
|
||||
capabilityMetadata,
|
||||
capabilityPlugins,
|
||||
defaultBrandTemplateKey,
|
||||
type BrandTemplateKey,
|
||||
@@ -100,20 +101,23 @@ export function assemblePublicWorkspace(input: {
|
||||
defaultBrandTemplateKey;
|
||||
const template = releaseSnapshot.templateDefinition ?? getBrandTemplate(templateKey);
|
||||
const capabilityData = asArray(releaseSnapshot.capabilities) as Array<Record<string, unknown>>;
|
||||
const capabilityRecord = (item: Record<string, unknown>, fallbackVersion = "1.0.0") => {
|
||||
const key = asString(item.capabilityKey) || asString(item.key);
|
||||
const metadata = capabilityMetadata(key as never);
|
||||
return {
|
||||
key,
|
||||
version: asString(item.capabilityVersion, fallbackVersion),
|
||||
status: capabilityStatus(item.status),
|
||||
config: asRecord(item.config),
|
||||
...(metadata ? { metadata: { ...metadata } } : {}),
|
||||
};
|
||||
};
|
||||
const capabilities = capabilityData.length
|
||||
? capabilityData.map((item) => ({
|
||||
key: asString(item.capabilityKey),
|
||||
version: asString(item.capabilityVersion, "1.0.0"),
|
||||
status: capabilityStatus(item.status),
|
||||
config: asRecord(item.config),
|
||||
}))
|
||||
? capabilityData.map((item) => capabilityRecord(item))
|
||||
: template
|
||||
? resolveCapabilities(template.capabilities).map((item) => ({
|
||||
key: item.key,
|
||||
version: item.version,
|
||||
status: "enabled" as const,
|
||||
config: {},
|
||||
}))
|
||||
? resolveCapabilities(template.capabilities).map((item) =>
|
||||
capabilityRecord({ ...item, config: {} }),
|
||||
)
|
||||
: [];
|
||||
const brandConfig = asRecord(brandData.config);
|
||||
const visualTemplateKey =
|
||||
@@ -183,7 +187,11 @@ export function assemblePublicWorkspace(input: {
|
||||
.filter((capability) => capability.status === "enabled")
|
||||
.map((capability) => capabilityPlugins[capability.key as keyof typeof capabilityPlugins])
|
||||
.filter(Boolean)
|
||||
.map((plugin) => ({ ...plugin, status: "enabled" as const, config: {} })),
|
||||
.map((plugin) => ({
|
||||
...plugin,
|
||||
status: "enabled" as const,
|
||||
config: capabilities.find((capability) => capability.key === plugin.key)?.config ?? {},
|
||||
})),
|
||||
theme: visualTemplate?.theme ?? {
|
||||
colors: { background: "#F7F5F1", foreground: "#252525", accent: "#8A6846" },
|
||||
},
|
||||
|
||||
@@ -4,13 +4,11 @@ import { BrandReleaseService } from "../../brand-release.service.js";
|
||||
import {
|
||||
defaultBrandTemplateKey,
|
||||
defaultVisualTemplateKey,
|
||||
brandTemplates,
|
||||
brandTemplateKeys,
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
isVisualTemplateCompatible,
|
||||
resolveCapabilities,
|
||||
visualTemplates,
|
||||
visualTemplateKeys,
|
||||
} from "@personal-brand/config";
|
||||
|
||||
@@ -78,8 +76,8 @@ export class PublicTemplateController {
|
||||
@Get()
|
||||
list(): unknown {
|
||||
return {
|
||||
industries: brandTemplateKeys.map((key) => brandTemplates[key]),
|
||||
visuals: visualTemplateKeys.map((key) => visualTemplates[key]),
|
||||
industries: brandTemplateKeys.map((key) => getBrandTemplate(key)),
|
||||
visuals: visualTemplateKeys.map((key) => getVisualTemplate(key)),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -991,6 +991,10 @@ test("health and public content are available without authentication", async ()
|
||||
assert.ok(Array.isArray(runtime.capabilities));
|
||||
assert.ok(runtime.theme.colors.background);
|
||||
assert.ok(Array.isArray(runtime.plugins));
|
||||
const inquiryPlugin = runtime.plugins.find((plugin) => plugin.key === "inquiry");
|
||||
assert.ok(inquiryPlugin);
|
||||
assert.deepEqual(inquiryPlugin.config, {});
|
||||
assert.deepEqual(inquiryPlugin.purposeBindings, ["inquiry"]);
|
||||
assert.equal(runtime.brand.founder, "阿成");
|
||||
assert.ok(runtime.offerings.every((item) => item.coverUrl));
|
||||
assert.ok(runtime.trustPresentation);
|
||||
@@ -1023,7 +1027,7 @@ test("visual template compatibility is enforced by catalog, preview, and brand s
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const compatibleSwitch = await request("/admin/config/brand", {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
@@ -1107,6 +1111,24 @@ test("public workspace uses brand-scoped capability installations and preserves
|
||||
version: "1.0.0",
|
||||
status: "disabled",
|
||||
config: { source: "integration-test" },
|
||||
metadata: {
|
||||
key: "inquiry",
|
||||
version: "1.0.0",
|
||||
displayName: "通用咨询",
|
||||
description: "接收客户的一对一合作咨询。",
|
||||
impact: "停用后所有通用咨询表单都无法提交。",
|
||||
optional: false,
|
||||
disablePolicy: "allowed",
|
||||
allowedPages: ["inquiry", "success"],
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
purposeBindings: ["inquiry"],
|
||||
entryNavigationKey: "inquiry",
|
||||
configFields: [
|
||||
{ key: "entryLabel", label: "入口文案", input: "text", required: false },
|
||||
{ key: "submitHint", label: "提交提示", input: "text", required: false },
|
||||
{ key: "disabledHint", label: "停用提示", input: "text", required: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
]);
|
||||
assert.notEqual(body.capabilities[0].status, "enabled");
|
||||
@@ -1118,21 +1140,38 @@ test("public workspace uses brand-scoped capability installations and preserves
|
||||
test("admin can update declared capability status with authorization and audit", async () => {
|
||||
const unauthorized = await request("/admin/workspace/capabilities/inquiry", {
|
||||
method: "PATCH",
|
||||
payload: { capabilityVersion: "1.0.0", status: "disabled" },
|
||||
payload: { status: "disabled" },
|
||||
});
|
||||
assert.equal(unauthorized.statusCode, 401);
|
||||
const customerForbidden = await request("/admin/workspace/capabilities/inquiry", {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
payload: { status: "disabled" },
|
||||
});
|
||||
assert.equal(customerForbidden.statusCode, 403);
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const updated = await request("/admin/workspace/capabilities/inquiry", {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
payload: { capabilityVersion: "1.0.0", status: "disabled", config: { mode: "manual" } },
|
||||
payload: { status: "disabled", config: { entryLabel: "合作咨询", disabledHint: "咨询已暂停" } },
|
||||
});
|
||||
assert.equal(updated.statusCode, 200);
|
||||
assert.equal(JSON.parse(updated.body).status, "disabled");
|
||||
assert.equal(JSON.parse(updated.body).capabilityVersion, "1.0.0");
|
||||
const invalidConfig = await request("/admin/workspace/capabilities/inquiry", {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
payload: { status: "disabled", config: { unknown: "字段" } },
|
||||
});
|
||||
assert.equal(invalidConfig.statusCode, 400);
|
||||
const saved = await prisma.capabilityInstallation.findUnique({
|
||||
where: { brandId_capabilityKey: { brandId, capabilityKey: "inquiry" } },
|
||||
});
|
||||
assert.deepEqual(saved?.config, { entryLabel: "合作咨询", disabledHint: "咨询已暂停" });
|
||||
const audit = await prisma.capabilityAuditLog.findFirst({
|
||||
where: { brandId, capabilityKey: "inquiry" },
|
||||
orderBy: { createdAt: "desc" },
|
||||
@@ -1148,7 +1187,7 @@ test("editor membership can manage brand content but cannot change system settin
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const identity = readIdentity(token);
|
||||
const membership = await prisma.brandMembership.findUnique({
|
||||
where: { adminUserId_brandId: { adminUserId: identity.subject, brandId } },
|
||||
@@ -1187,7 +1226,7 @@ test("owner can manage brand members without removing the final owner", async ()
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const identity = readIdentity(token);
|
||||
const members = await request("/admin/brands/members", {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
@@ -1273,6 +1312,8 @@ test("manually created member must change the initial password before normal use
|
||||
});
|
||||
|
||||
test("admin can install optional quote capability without industry-specific branching", async () => {
|
||||
const quoteListUser = await prisma.adminUser.findUniqueOrThrow({ where: { username: "admin" } });
|
||||
const quoteToken = signIdentity({ subject: quoteListUser.id, brandId, role: "admin" });
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
@@ -1281,13 +1322,25 @@ test("admin can install optional quote capability without industry-specific bran
|
||||
const response = await request("/admin/workspace/capabilities/quote-request", {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
payload: { capabilityVersion: "1.0.0", status: "enabled", config: { currency: "CNY" } },
|
||||
payload: { status: "enabled", config: { entryLabel: "获取报价", submitHint: "48 小时内回复" } },
|
||||
});
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.equal(JSON.parse(response.body).capabilityKey, "quote-request");
|
||||
assert.equal(JSON.parse(response.body).capabilityVersion, "1.0.0");
|
||||
const list = await request("/admin/workspace/capabilities", {
|
||||
headers: { authorization: `Bearer ${quoteToken}` },
|
||||
});
|
||||
assert.equal(
|
||||
JSON.parse(list.body).find((item) => item.capabilityKey === "quote-request")?.optional,
|
||||
true,
|
||||
);
|
||||
assert.equal((await publishReleaseForTests()).statusCode, 201);
|
||||
const workspace = await request("/public/workspace");
|
||||
assert.ok(JSON.parse(workspace.body).plugins.some((plugin) => plugin.key === "quote-request"));
|
||||
const quotePlugin = JSON.parse(workspace.body).plugins.find(
|
||||
(plugin) => plugin.key === "quote-request",
|
||||
);
|
||||
assert.ok(quotePlugin);
|
||||
assert.deepEqual(quotePlugin.config, { entryLabel: "获取报价", submitHint: "48 小时内回复" });
|
||||
await prisma.capabilityInstallation.deleteMany({
|
||||
where: { brandId, capabilityKey: "quote-request" },
|
||||
});
|
||||
@@ -1302,14 +1355,21 @@ test("admin capability list includes template defaults and brand overrides", asy
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const defaults = await request("/admin/workspace/capabilities", {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
});
|
||||
assert.equal(defaults.statusCode, 200);
|
||||
const defaultBody = JSON.parse(defaults.body);
|
||||
assert.ok(
|
||||
defaultBody.some((item) => item.capabilityKey === "inquiry" && item.source === "template"),
|
||||
defaultBody.some(
|
||||
(item) =>
|
||||
item.capabilityKey === "inquiry" &&
|
||||
item.source === "template" &&
|
||||
item.optional === false &&
|
||||
item.disablePolicy === "allowed" &&
|
||||
item.configFields?.some((field) => field.key === "entryLabel"),
|
||||
),
|
||||
);
|
||||
await prisma.capabilityInstallation.create({
|
||||
data: {
|
||||
@@ -1317,7 +1377,7 @@ test("admin capability list includes template defaults and brand overrides", asy
|
||||
capabilityKey: "inquiry",
|
||||
capabilityVersion: "1.0.0",
|
||||
status: "disabled",
|
||||
config: { mode: "manual" },
|
||||
config: { entryLabel: "品牌自定义咨询" },
|
||||
},
|
||||
});
|
||||
const overrides = await request("/admin/workspace/capabilities", {
|
||||
@@ -1326,7 +1386,7 @@ test("admin capability list includes template defaults and brand overrides", asy
|
||||
const override = JSON.parse(overrides.body).find((item) => item.capabilityKey === "inquiry");
|
||||
assert.equal(override.source, "brand");
|
||||
assert.equal(override.status, "disabled");
|
||||
assert.deepEqual(override.config, { mode: "manual" });
|
||||
assert.deepEqual(override.config, { entryLabel: "品牌自定义咨询" });
|
||||
await prisma.capabilityInstallation.deleteMany({ where: { brandId } });
|
||||
});
|
||||
|
||||
@@ -1339,7 +1399,7 @@ test("admin can install doors industry template through the shared runtime contr
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
try {
|
||||
const installed = await request("/admin/workspace/install", {
|
||||
method: "POST",
|
||||
@@ -1394,7 +1454,7 @@ test("admin can preview and import sample content idempotently", async () => {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const preview = await request("/admin/workspace/sample-content/preview", {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
});
|
||||
@@ -1474,7 +1534,7 @@ test("admin can install a template and public workspace exposes enabled configur
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const before = await request("/admin/workspace");
|
||||
assert.equal(before.statusCode, 401);
|
||||
const customerAccess = await request("/admin/workspace", {
|
||||
@@ -1625,7 +1685,7 @@ test("admin can customize workspace fields with brand isolation", async () => {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const install = await request("/admin/workspace/install", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
@@ -1677,7 +1737,7 @@ test("admin visual template selection is reflected in public runtime workspace",
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const before = await request("/public/workspace");
|
||||
assert.equal(before.statusCode, 200);
|
||||
const updated = await request("/admin/config/brand", {
|
||||
@@ -1935,7 +1995,7 @@ test("admin can create and version an inquiry form", async () => {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const offering = await prisma.offering.findFirst({ where: { brandId, isEnabled: true } });
|
||||
assert.ok(offering);
|
||||
const created = await request("/admin/workspace/forms", {
|
||||
@@ -2153,7 +2213,7 @@ test("admin rejects invalid dynamic inquiry field definitions", async () => {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const invalid = await request("/admin/workspace/forms", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
@@ -2170,7 +2230,7 @@ test("admin can manage offerings and public endpoint hides disabled offerings",
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const invalidConfig = await request("/admin/workspace/offerings", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
@@ -2248,7 +2308,7 @@ test("offering with an inquiry form cannot be deleted", async () => {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const offering = await prisma.offering.create({
|
||||
data: { brandId, kind: "service", name: `保护测试-${Date.now()}`, description: "测试" },
|
||||
});
|
||||
@@ -2283,7 +2343,7 @@ test("seeded admin can log in and read protected booking resources", async () =>
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
assert.equal(login.statusCode, 201);
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
assert.ok(token);
|
||||
|
||||
const count = await request("/admin/bookings/unread-count", {
|
||||
@@ -2312,7 +2372,7 @@ test("admin can list and switch only enabled brand memberships", async () => {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const brands = await request("/admin/brands", {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
});
|
||||
@@ -2405,7 +2465,7 @@ test("disabled brand membership blocks existing admin token", async () => {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const admin = await prisma.adminUser.findUnique({ where: { username: "admin" } });
|
||||
assert.ok(admin);
|
||||
const membership = await prisma.brandMembership.findUnique({
|
||||
@@ -2547,7 +2607,7 @@ test("admin can update user-facing brand presentation without replacing other co
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const brand = await prisma.brandProfile.findUnique({ where: { id: brandId } });
|
||||
assert.ok(brand);
|
||||
const originalConfig = brand.config;
|
||||
@@ -2583,7 +2643,7 @@ test("admin can manage trust content", async () => {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).token;
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
assert.equal((await request("/admin/config/trust-content")).statusCode, 401);
|
||||
assert.equal(
|
||||
(
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Button, Text, View } from "@tarojs/components";
|
||||
import type { ReactNode } from "react";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/types";
|
||||
import { pluginByKey, pluginConfigText } from "../runtime/plugins";
|
||||
import { navigate } from "../runtime/navigation";
|
||||
|
||||
export function CapabilityAction({
|
||||
workspace,
|
||||
pluginKey,
|
||||
params,
|
||||
presentationLabel,
|
||||
fallbackLabel,
|
||||
className,
|
||||
editorTarget,
|
||||
children,
|
||||
}: {
|
||||
workspace: RuntimeWorkspace;
|
||||
pluginKey: string;
|
||||
params?: Record<string, string>;
|
||||
presentationLabel?: string;
|
||||
fallbackLabel: string;
|
||||
className?: string;
|
||||
editorTarget?: string;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
const plugin = pluginByKey(workspace, pluginKey);
|
||||
const label = pluginConfigText(plugin, "entryLabel") || presentationLabel || fallbackLabel;
|
||||
if (plugin?.status !== "enabled")
|
||||
return (
|
||||
<View className={className} data-editor-target={editorTarget}>
|
||||
<Text>{pluginConfigText(plugin, "disabledHint") || `${fallbackLabel}暂不可用`}</Text>
|
||||
</View>
|
||||
);
|
||||
return (
|
||||
<Button
|
||||
className={className}
|
||||
data-editor-target={editorTarget}
|
||||
onClick={() => navigate("inquiry", params)}
|
||||
>
|
||||
{children ?? label}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import { missingField, visibleFields, presentation } from "../runtime/content";
|
||||
import type { Values } from "../runtime/content";
|
||||
import { ensureSession, request, brandSlug } from "../runtime/api";
|
||||
import { takeQuery, navigate } from "../runtime/navigation";
|
||||
import { inquiryPluginState, pluginConfigText, usableInquiryForms } from "../runtime/plugins";
|
||||
import "./forms.css";
|
||||
export function Inquiry({
|
||||
workspace,
|
||||
@@ -26,14 +27,16 @@ export function Inquiry({
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [offeringId, setOfferingId] = useState(router.params.offeringId || "");
|
||||
const forms = usableInquiryForms(workspace);
|
||||
const form: RuntimeInquiryForm | undefined =
|
||||
workspace.inquiryForms.find((form) => offeringId && form.targetId === offeringId) ||
|
||||
workspace.inquiryForms.find((form) => form.target === "brand");
|
||||
forms.find((form) => offeringId && form.targetId === offeringId) ||
|
||||
forms.find((form) => form.target === "brand");
|
||||
const [values, setValues] = useState<Values>({});
|
||||
const [error, setError] = useState("");
|
||||
const [sending, setSending] = useState(false);
|
||||
const busy = useRef(false);
|
||||
const p = presentation(workspace, "inquiry");
|
||||
const inquiryPlugin = inquiryPluginState(workspace);
|
||||
const compactFieldKeys = new Set(["people", "date", "budget", "delivery"]);
|
||||
const compactForm = Boolean(form?.fields.some((field) => compactFieldKeys.has(field.key)));
|
||||
useDidShow(() => {
|
||||
@@ -89,7 +92,12 @@ export function Inquiry({
|
||||
<Text className="form-title">{p.title || "提交咨询"}</Text>
|
||||
<Text className="form-subtitle">{p.subtitle}</Text>
|
||||
</View>
|
||||
{!form ? (
|
||||
{!inquiryPlugin.enabled && form?.purpose !== "quote-request" ? (
|
||||
<View className="records-empty">
|
||||
<Text>{inquiryPlugin.disabledHint}</Text>
|
||||
<Button onClick={() => navigate("records")}>查看咨询记录</Button>
|
||||
</View>
|
||||
) : !form ? (
|
||||
<View className="form-error">尚未配置可用的咨询表单</View>
|
||||
) : (
|
||||
<View className="inquiry-form">
|
||||
@@ -197,6 +205,11 @@ export function Inquiry({
|
||||
{error}
|
||||
</View>
|
||||
)}
|
||||
{pluginConfigText(inquiryPlugin.plugin, "submitHint") && (
|
||||
<Text className="form-subtitle">
|
||||
{pluginConfigText(inquiryPlugin.plugin, "submitHint")}
|
||||
</Text>
|
||||
)}
|
||||
<Button
|
||||
className="submit-button"
|
||||
disabled={sending}
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { RuntimeWorkspace } from "@personal-brand/types";
|
||||
import { ensureSession, hasSession, request } from "../runtime/api";
|
||||
import { navigate } from "../runtime/navigation";
|
||||
import { presentation } from "../runtime/content";
|
||||
import { inquiryPluginState } from "../runtime/plugins";
|
||||
import "./forms.css";
|
||||
type RecordItem = {
|
||||
id: string;
|
||||
@@ -37,6 +38,7 @@ export function Records({
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [authenticated, setAuthenticated] = useState(preview ? false : hasSession());
|
||||
const p = presentation(workspace, "records");
|
||||
const inquiryPlugin = inquiryPluginState(workspace);
|
||||
const load = useCallback(() => {
|
||||
if (preview) return;
|
||||
if (!hasSession()) {
|
||||
@@ -58,7 +60,14 @@ export function Records({
|
||||
return (
|
||||
<View className="records-page">
|
||||
<Text className="form-title">{p.title || "我的咨询记录"}</Text>
|
||||
<Button onClick={() => navigate("inquiry")}>{p.createAction || "新增咨询"}</Button>
|
||||
{inquiryPlugin.enabled ? (
|
||||
<Button onClick={() => navigate("inquiry")}>{p.createAction || "新增咨询"}</Button>
|
||||
) : (
|
||||
<View className="records-empty">
|
||||
<Text>{inquiryPlugin.disabledHint}</Text>
|
||||
<Text className="form-subtitle">暂无可发起的咨询入口</Text>
|
||||
</View>
|
||||
)}
|
||||
{loading ? (
|
||||
<View className="runtime-state">正在加载…</View>
|
||||
) : error ? (
|
||||
@@ -94,7 +103,9 @@ export function Records({
|
||||
<View className="records-empty">
|
||||
<Text>{p.emptyTitle || "还没有咨询记录"}</Text>
|
||||
<Text className="form-subtitle">{p.emptyDescription}</Text>
|
||||
<Button onClick={() => navigate("inquiry")}>{p.emptyAction || "开始咨询"}</Button>
|
||||
{inquiryPlugin.enabled && (
|
||||
<Button onClick={() => navigate("inquiry")}>{p.emptyAction || "开始咨询"}</Button>
|
||||
)}
|
||||
</View>
|
||||
) : (
|
||||
records.map((item) => (
|
||||
|
||||
@@ -47,8 +47,6 @@ export async function loadWorkspace() {
|
||||
const data = await request<RuntimeWorkspace>("/public/workspace");
|
||||
const editorPreview = isEditorPreview();
|
||||
if (!editorPreview && data.publication?.status !== "published") throw new Error("品牌尚未发布");
|
||||
if (!editorPreview && data.brand.visualTemplateKey !== TEMPLATE_KEY)
|
||||
throw new Error("该品牌使用其他模板,请选择匹配的模板预览地址");
|
||||
return {
|
||||
...data,
|
||||
brand: data.brand ?? {},
|
||||
@@ -59,6 +57,7 @@ export async function loadWorkspace() {
|
||||
trustPresentation: data.trustPresentation ?? {},
|
||||
capabilities: data.capabilities ?? [],
|
||||
theme: data.theme ?? { colors: {} },
|
||||
plugins: data.plugins ?? [],
|
||||
};
|
||||
}
|
||||
export async function ensureSession() {
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import type { RuntimeInquiryForm, RuntimeWorkspace } from "@personal-brand/types";
|
||||
|
||||
export type RuntimePluginStatus = "enabled" | "disabled" | "degraded";
|
||||
|
||||
type RuntimePlugin = {
|
||||
key: string;
|
||||
displayName?: string;
|
||||
status: RuntimePluginStatus;
|
||||
config: Record<string, unknown>;
|
||||
purpose?: string;
|
||||
purposeBindings?: readonly string[];
|
||||
configFields?: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
input: string;
|
||||
required: boolean;
|
||||
}>;
|
||||
};
|
||||
|
||||
function pluginList(workspace: RuntimeWorkspace): RuntimePlugin[] {
|
||||
const plugins = (workspace as { plugins?: unknown }).plugins;
|
||||
if (!Array.isArray(plugins)) return [];
|
||||
return plugins.filter((plugin): plugin is RuntimePlugin => {
|
||||
if (!plugin || typeof plugin !== "object" || Array.isArray(plugin)) return false;
|
||||
const candidate = plugin as Partial<RuntimePlugin>;
|
||||
return (
|
||||
typeof candidate.key === "string" &&
|
||||
(candidate.status === "enabled" ||
|
||||
candidate.status === "disabled" ||
|
||||
candidate.status === "degraded") &&
|
||||
Boolean(candidate.config) &&
|
||||
typeof candidate.config === "object" &&
|
||||
!Array.isArray(candidate.config)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function pluginByKey(workspace: RuntimeWorkspace, key: string) {
|
||||
return pluginList(workspace).find((plugin) => plugin.key === key);
|
||||
}
|
||||
|
||||
export function pluginByPurpose(workspace: RuntimeWorkspace, purpose: string) {
|
||||
return pluginList(workspace).find(
|
||||
(plugin) => plugin.purpose === purpose || plugin.purposeBindings?.includes(purpose),
|
||||
);
|
||||
}
|
||||
|
||||
export function enabledPluginByKey(workspace: RuntimeWorkspace, key: string) {
|
||||
const plugin = pluginByKey(workspace, key);
|
||||
return plugin?.status === "enabled" ? plugin : undefined;
|
||||
}
|
||||
|
||||
export function enabledPluginByPurpose(workspace: RuntimeWorkspace, purpose: string) {
|
||||
const plugin = pluginByPurpose(workspace, purpose);
|
||||
return plugin?.status === "enabled" ? plugin : undefined;
|
||||
}
|
||||
|
||||
export function pluginConfigText(plugin: RuntimePlugin | undefined, key: string) {
|
||||
const value = plugin?.config[key];
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
export function pluginStateText(workspace: RuntimeWorkspace, key: string, configKey: string) {
|
||||
const plugin = pluginByKey(workspace, key);
|
||||
const value = plugin?.config[configKey];
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
export function inquiryFormAvailability(
|
||||
workspace: RuntimeWorkspace,
|
||||
form: RuntimeInquiryForm | undefined,
|
||||
) {
|
||||
const plugin = pluginByKey(
|
||||
workspace,
|
||||
form?.purpose === "quote-request" ? "quote-request" : "inquiry",
|
||||
);
|
||||
return {
|
||||
status: plugin?.status,
|
||||
disabledHint: pluginConfigText(plugin, "disabledHint"),
|
||||
};
|
||||
}
|
||||
|
||||
export function isPluginUsable(status: RuntimePluginStatus | undefined) {
|
||||
return status === "enabled";
|
||||
}
|
||||
|
||||
export function usableInquiryForms(workspace: RuntimeWorkspace) {
|
||||
return workspace.inquiryForms.filter((form) => {
|
||||
const { status } = inquiryFormAvailability(workspace, form);
|
||||
return isPluginUsable(status);
|
||||
});
|
||||
}
|
||||
|
||||
export function inquiryPluginState(workspace: RuntimeWorkspace) {
|
||||
const plugin = pluginByKey(workspace, "inquiry");
|
||||
return {
|
||||
plugin,
|
||||
enabled: plugin?.status === "enabled",
|
||||
disabledHint: pluginConfigText(plugin, "disabledHint") || "咨询功能暂不可用",
|
||||
};
|
||||
}
|
||||
@@ -8,13 +8,7 @@ const renderers = import.meta.glob<{
|
||||
}>("../../../../packages/template-*/taro/index.tsx", { eager: true });
|
||||
|
||||
export function TemplatePage(props: TemplateProps) {
|
||||
const config = props.workspace.brand.config;
|
||||
const visualTemplateKey =
|
||||
config && typeof config === "object" && !Array.isArray(config)
|
||||
? (config as Record<string, unknown>).visualTemplateKey
|
||||
: undefined;
|
||||
const templateKey = typeof visualTemplateKey === "string" ? visualTemplateKey : TEMPLATE_KEY;
|
||||
const suffix = `/template-${templateKey}/taro/index.tsx`;
|
||||
const suffix = `/template-${TEMPLATE_KEY}/taro/index.tsx`;
|
||||
const rendererModule = Object.entries(renderers).find(([path]) => path.endsWith(suffix))?.[1];
|
||||
if (!rendererModule)
|
||||
return <div className="runtime-state">当前模板没有可用的 H5 预览 renderer</div>;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# 0024 Capability 产品元数据契约
|
||||
|
||||
## Context
|
||||
|
||||
Capability 之前只有技术 key 和状态,Admin 难以判断能力是否可选、停用影响和入口配置。插件配置也存在硬编码 `{}` 的问题,且客户端曾要求提交 `capabilityVersion`,容易让服务端版本被错误覆盖。
|
||||
|
||||
## Decision
|
||||
|
||||
- `capabilityRegistry` 是产品元数据、禁用策略、允许页面、依赖模块、用途绑定和入口导航的唯一来源。`offerings` 是不可移除的核心能力;`inquiry` 核心能力允许停用;`quote-request` 是可选能力。
|
||||
- 咨询和报价能力只声明 `entryLabel`、`submitHint`、`disabledHint` 三个文本配置字段。服务端按注册表白名单校验,不接受未声明字段。
|
||||
- Admin 读写契约返回元数据与配置字段声明;更新接口只接受状态和配置,`capabilityVersion` 由服务端按当前注册表派生。
|
||||
- Runtime Workspace 的 capabilities 与 plugins 输出品牌级配置。已发布快照读取发布时能力记录,草稿变更只进入 Admin 预览,直到重新发布。
|
||||
|
||||
## Alternatives
|
||||
|
||||
- 在每个行业模板中重复能力元数据:会造成同一能力多份定义。
|
||||
- 允许客户端提交版本:可能导致品牌记录与平台契约漂移。
|
||||
- 继续把配置写入硬编码 `{}`:无法支撑可运营入口和提示文案。
|
||||
|
||||
## Consequences
|
||||
|
||||
- 新增能力时必须同步注册表元数据、配置字段和集成回归。
|
||||
- 未声明元数据的能力在 Runtime 中只保留技术状态,不会伪装成可配置产品能力。
|
||||
- 停用 `inquiry` 会阻止对应表单提交;移除 `quote-request` 后报价表单不再可用。
|
||||
|
||||
## Migration Plan
|
||||
|
||||
1. 旧品牌记录继续保留原 `capabilityVersion`,下一次 Admin 更新由服务端派生为注册表版本。
|
||||
2. 已存在的能力配置继续进入发布快照;未声明字段需要在下一次保存时按新校验清理。
|
||||
@@ -72,9 +72,11 @@
|
||||
- [x] Runtime Workspace 优先读取品牌级能力安装记录,并保留模板默认能力回退。
|
||||
- [x] 能力状态统一输出为 `enabled`、`disabled` 或 `degraded`,并保留能力配置。
|
||||
- [x] 集成测试覆盖品牌级能力安装读取、状态保留和配置隔离。
|
||||
- [ ] 增加 Admin 能力启用 / 停用写接口、DTO、权限、审计和状态转换测试。
|
||||
- [x] 增加 Admin 能力列表与状态更新接口,校验模板声明、品牌隔离和状态枚举。
|
||||
- [x] 增加能力变更审计日志和授权 / 审计集成测试。
|
||||
- [x] 建立 Capability 产品元数据、可选策略、用途绑定和受控配置字段契约。
|
||||
- [x] Admin 更新能力时由服务端注册表派生 `capabilityVersion`,并拒绝未声明配置字段。
|
||||
- [x] Runtime Workspace 输出品牌能力配置与配置字段声明;发布快照保持发布时状态。
|
||||
- [ ] Phase 5:林境门作与第二行业双模板验证。
|
||||
- [x] 注册 `doors@1.0.0` 门窗行业模板,复用个人品牌、信任、Offering 与 Inquiry 能力。
|
||||
- [x] 增加门窗行业 fixture,并验证 Admin 安装后 Runtime Workspace 契约完整。
|
||||
|
||||
@@ -17,6 +17,7 @@ export type {
|
||||
BrandUpdate,
|
||||
} from "./types/brand.js";
|
||||
export type { CapabilityInstallation } from "./types/capability.js";
|
||||
export type { CapabilityMetadata } from "./types/capability.js";
|
||||
export type { ApiErrorBody } from "./types/common.js";
|
||||
export type { BrandFieldDefinition } from "./types/field.js";
|
||||
export type { InquiryForm, InquirySubmission } from "./types/inquiry.js";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { BrandTemplateKey, RuntimeWorkspace } from "@personal-brand/types";
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type { BrandProfile } from "../types/brand.js";
|
||||
import type { CapabilityInstallation } from "../types/capability.js";
|
||||
import type { CapabilityWithMetadata } from "../types/capability.js";
|
||||
import type { BrandFieldDefinition } from "../types/field.js";
|
||||
import type { Offering } from "../types/offering.js";
|
||||
import type { AdminTemplateContent } from "../types/template.js";
|
||||
@@ -55,18 +55,18 @@ export interface TemplateMethods {
|
||||
offerings: Offering[];
|
||||
forms: unknown[];
|
||||
templateContent: AdminTemplateContent | null;
|
||||
capabilities?: CapabilityWithMetadata[];
|
||||
}>;
|
||||
getAdminPreviewWorkspace(): Promise<RuntimeWorkspace>;
|
||||
installAdminTemplate(templateKey: BrandTemplateKey): Promise<unknown>;
|
||||
listAdminCapabilities(): Promise<CapabilityInstallation[]>;
|
||||
listAdminCapabilities(): Promise<CapabilityWithMetadata[]>;
|
||||
updateAdminCapability(
|
||||
key: string,
|
||||
body: {
|
||||
capabilityVersion: string;
|
||||
status: CapabilityInstallation["status"];
|
||||
status: CapabilityWithMetadata["status"];
|
||||
config?: Record<string, unknown>;
|
||||
},
|
||||
): Promise<CapabilityInstallation>;
|
||||
): Promise<CapabilityWithMetadata>;
|
||||
previewAdminSampleContent(): Promise<{
|
||||
templateKey: string;
|
||||
alreadyImported: boolean;
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
export interface CapabilityInstallation {
|
||||
export interface CapabilityMetadata {
|
||||
displayName?: string;
|
||||
description?: string;
|
||||
impact?: string;
|
||||
optional?: boolean;
|
||||
disablePolicy?: "allowed" | "disabled";
|
||||
allowedPages?: string[];
|
||||
requiredModules?: string[];
|
||||
purposeBindings?: string[];
|
||||
entryNavigationKey?: string;
|
||||
configFields?: Array<{ key: string; label: string; input: string; required: boolean }>;
|
||||
}
|
||||
|
||||
export interface CapabilityInstallation extends CapabilityMetadata {
|
||||
id: string | null;
|
||||
capabilityKey: string;
|
||||
capabilityVersion: string;
|
||||
@@ -7,3 +20,5 @@ export interface CapabilityInstallation {
|
||||
updatedAt: string | null;
|
||||
source?: "template" | "brand";
|
||||
}
|
||||
|
||||
export type CapabilityWithMetadata = CapabilityInstallation;
|
||||
@@ -13,6 +13,33 @@ export interface CapabilityDefinition {
|
||||
workflowKey?: string;
|
||||
}
|
||||
|
||||
export type CapabilityDisablePolicy = "allowed" | "disabled";
|
||||
|
||||
export interface CapabilityMetadata {
|
||||
displayName: string;
|
||||
description: string;
|
||||
impact: string;
|
||||
optional: boolean;
|
||||
disablePolicy: CapabilityDisablePolicy;
|
||||
allowedPages: readonly string[];
|
||||
requiredModules: readonly string[];
|
||||
purposeBindings: readonly string[];
|
||||
entryNavigationKey?: string;
|
||||
}
|
||||
|
||||
export type CapabilityConfigFieldKey = "entryLabel" | "submitHint" | "disabledHint";
|
||||
|
||||
export interface CapabilityConfigField {
|
||||
key: CapabilityConfigFieldKey;
|
||||
label: string;
|
||||
input: "text";
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
export interface CapabilityMetadataDefinition extends CapabilityMetadata {
|
||||
configFields: readonly CapabilityConfigField[];
|
||||
}
|
||||
|
||||
export const workflowRegistry = {
|
||||
"booking.basic": {
|
||||
key: "booking.basic",
|
||||
@@ -29,11 +56,84 @@ export const workflowRegistry = {
|
||||
} as const satisfies Record<string, WorkflowDefinition>;
|
||||
|
||||
export const capabilityRegistry = {
|
||||
offerings: { key: "offerings", version: "1.0.0" },
|
||||
inquiry: { key: "inquiry", version: "1.0.0" },
|
||||
offerings: {
|
||||
key: "offerings",
|
||||
version: "1.0.0",
|
||||
displayName: "业务提供项",
|
||||
description: "展示品牌的服务与产品。",
|
||||
impact: "停用会移除业务提供项展示入口。",
|
||||
optional: false,
|
||||
disablePolicy: "disabled",
|
||||
allowedPages: ["home", "offerings", "detail"],
|
||||
requiredModules: ["offering-list", "offering-detail"],
|
||||
purposeBindings: [],
|
||||
},
|
||||
inquiry: {
|
||||
key: "inquiry",
|
||||
version: "1.0.0",
|
||||
displayName: "通用咨询",
|
||||
description: "接收客户的一对一合作咨询。",
|
||||
impact: "停用后所有通用咨询表单都无法提交。",
|
||||
optional: false,
|
||||
disablePolicy: "allowed",
|
||||
allowedPages: ["inquiry", "success"],
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
purposeBindings: ["inquiry"],
|
||||
entryNavigationKey: "inquiry",
|
||||
},
|
||||
booking: { key: "booking", version: "1.0.0", workflowKey: "booking.basic" },
|
||||
"quote-request": { key: "quote-request", version: "1.0.0" },
|
||||
} as const satisfies Record<CapabilityKey, CapabilityDefinition>;
|
||||
"quote-request": {
|
||||
key: "quote-request",
|
||||
version: "1.0.0",
|
||||
displayName: "报价咨询",
|
||||
description: "可选安装的报价请求链路。",
|
||||
impact: "安装后可提交报价咨询;移除后报价表单不再接收提交。",
|
||||
optional: true,
|
||||
disablePolicy: "allowed",
|
||||
allowedPages: ["inquiry", "success"],
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
purposeBindings: ["quote-request"],
|
||||
},
|
||||
} as const satisfies Record<CapabilityKey, CapabilityDefinition & Partial<CapabilityMetadata>>;
|
||||
|
||||
export const capabilityConfigFields = {
|
||||
entryLabel: { key: "entryLabel", label: "入口文案", input: "text", required: false },
|
||||
submitHint: { key: "submitHint", label: "提交提示", input: "text", required: false },
|
||||
disabledHint: { key: "disabledHint", label: "停用提示", input: "text", required: false },
|
||||
} as const satisfies Record<CapabilityConfigFieldKey, CapabilityConfigField>;
|
||||
|
||||
export function capabilityMetadata(key: CapabilityKey): CapabilityMetadataDefinition | null {
|
||||
const definition = capabilityRegistry[key];
|
||||
if (!("disablePolicy" in definition)) return null;
|
||||
return { ...definition, configFields: Object.values(capabilityConfigFields) };
|
||||
}
|
||||
|
||||
export function validateCapabilityConfig(
|
||||
capabilityKey: CapabilityKey,
|
||||
config: unknown,
|
||||
): Record<string, string> | null {
|
||||
if (config === undefined || config === null) return {};
|
||||
if (typeof config !== "object" || Array.isArray(config)) return null;
|
||||
const metadata = capabilityMetadata(capabilityKey);
|
||||
if (!metadata) return {};
|
||||
const source = config as Record<string, unknown>;
|
||||
if (Object.keys(source).some((key) => !metadata.configFields.some((field) => field.key === key)))
|
||||
return null;
|
||||
const errors: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(source)) {
|
||||
const field = capabilityConfigFields[key as CapabilityConfigFieldKey];
|
||||
const message =
|
||||
value === undefined || value === null || (typeof value === "string" && !value.trim())
|
||||
? "不能为空"
|
||||
: typeof value !== "string"
|
||||
? "必须是字符串"
|
||||
: value.length > 80
|
||||
? "不能超过 80 个字符"
|
||||
: "";
|
||||
if (message) errors[key] = `${field?.label ?? key}${message}`;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const capabilityPlugins = {
|
||||
inquiry: {
|
||||
@@ -44,6 +144,8 @@ export const capabilityPlugins = {
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
apiContract: "/customer/inquiry-submissions",
|
||||
configSchema: "capability.inquiry.v1",
|
||||
purposeBindings: ["inquiry"],
|
||||
entryNavigationKey: "inquiry",
|
||||
},
|
||||
"quote-request": {
|
||||
key: "quote-request",
|
||||
@@ -53,5 +155,6 @@ export const capabilityPlugins = {
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
apiContract: "/customer/inquiry-submissions",
|
||||
configSchema: "capability.quote-request.v1",
|
||||
purposeBindings: ["quote-request"],
|
||||
},
|
||||
} as const;
|
||||
@@ -4,6 +4,7 @@ import Taro from "@tarojs/taro";
|
||||
import type { TemplateProps } from "../../../apps/taro/src/runtime/template";
|
||||
import { navigate } from "../../../apps/taro/src/runtime/navigation";
|
||||
import { presentation, offering, slot, text, rows } from "../../../apps/taro/src/runtime/content";
|
||||
import { inquiryPluginState, pluginStateText } from "../../../apps/taro/src/runtime/plugins";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/types";
|
||||
import "./style.css";
|
||||
const asset = (name: string) =>
|
||||
@@ -30,9 +31,17 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
{p.stallTime && <Text className="notice-time">{p.stallTime}</Text>}
|
||||
</View>
|
||||
<View className="actions" data-editor-target="food.home.actions">
|
||||
<Button className="home-action" onClick={() => navigate("inquiry")}>
|
||||
{p.primaryAction || "咨询 / 预订"}
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button className="home-action" onClick={() => navigate("inquiry")}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") ||
|
||||
p.primaryAction ||
|
||||
"咨询 / 预订"}
|
||||
</Button>
|
||||
) : (
|
||||
<Text className="home-action disabled">
|
||||
{inquiryPluginState(workspace).disabledHint || "咨询 / 预订暂不可用"}
|
||||
</Text>
|
||||
)}
|
||||
<Button className="home-action muted" onClick={() => navigate("offerings")}>
|
||||
{p.secondaryAction || "查看餐品"}
|
||||
</Button>
|
||||
@@ -222,13 +231,25 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
)}
|
||||
<Text>{text(process.config.refundNote)}</Text>
|
||||
</View>
|
||||
<Button
|
||||
data-editor-target="food.service.process-action"
|
||||
className="process-action"
|
||||
onClick={() => navigate("inquiry")}
|
||||
>
|
||||
{p.processAction || "立即咨询"} →
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button
|
||||
data-editor-target="food.service.process-action"
|
||||
className="process-action"
|
||||
onClick={() => navigate("inquiry")}
|
||||
>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") ||
|
||||
p.processAction ||
|
||||
"立即咨询"}{" "}
|
||||
→
|
||||
</Button>
|
||||
) : (
|
||||
<Text
|
||||
data-editor-target="food.service.process-action"
|
||||
className="process-action disabled"
|
||||
>
|
||||
{inquiryPluginState(workspace).disabledHint || "咨询暂不可用"}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
@@ -476,9 +497,15 @@ function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<View className="empty-state">没有找到相关餐品,换个词试试</View>
|
||||
)}
|
||||
</View>
|
||||
<Button className="menu-cta" onClick={() => navigate("inquiry")}>
|
||||
咨询 / 预订
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button className="menu-cta" onClick={() => navigate("inquiry")}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") || "咨询 / 预订"}
|
||||
</Button>
|
||||
) : (
|
||||
<Text className="menu-cta disabled">
|
||||
{inquiryPluginState(workspace).disabledHint || "咨询 / 预订暂不可用"}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
@@ -567,9 +594,15 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
</View>
|
||||
</View>
|
||||
<View className="bar" data-editor-target="acheng-campus-food.detail.action">
|
||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||
{p.inquiryAction || "咨询 / 提前预订"}
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") ||
|
||||
p.inquiryAction ||
|
||||
"咨询 / 提前预订"}
|
||||
</Button>
|
||||
) : (
|
||||
<Text>{inquiryPluginState(workspace).disabledHint || "咨询 / 提前预订暂不可用"}</Text>
|
||||
)}
|
||||
<Text>{p.inquiryHint}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
text,
|
||||
rows,
|
||||
} from "../../../apps/taro/src/runtime/content";
|
||||
import { inquiryPluginState, pluginStateText } from "../../../apps/taro/src/runtime/plugins";
|
||||
import "./style.css";
|
||||
function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
const b = workspace.brand;
|
||||
@@ -277,7 +278,16 @@ function List({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</View>
|
||||
))}
|
||||
<Text className="subtitle">{p.closingText}</Text>
|
||||
{p.closingAction && <Button onClick={() => navigate("inquiry")}>{p.closingAction}</Button>}
|
||||
{p.closingAction &&
|
||||
(inquiryPluginState(workspace).enabled ? (
|
||||
<Button onClick={() => navigate("inquiry")}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") || p.closingAction}
|
||||
</Button>
|
||||
) : (
|
||||
<Text>
|
||||
{inquiryPluginState(workspace).disabledHint || `${p.closingAction}暂不可用`}
|
||||
</Text>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
@@ -366,9 +376,13 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
</View>
|
||||
</View>
|
||||
<View className="bar" data-editor-target="linjing-editorial.detail.action">
|
||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||
{p.inquiryAction}
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") || p.inquiryAction || "咨询"}
|
||||
</Button>
|
||||
) : (
|
||||
<Text>{inquiryPluginState(workspace).disabledHint || "咨询暂不可用"}</Text>
|
||||
)}
|
||||
<Text>{p.inquiryHint}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -68,6 +68,18 @@ export interface RuntimeCapability {
|
||||
version: string;
|
||||
config: Record<string, unknown>;
|
||||
status: "enabled" | "disabled" | "degraded";
|
||||
metadata?: {
|
||||
displayName?: string;
|
||||
description?: string;
|
||||
impact?: string;
|
||||
optional?: boolean;
|
||||
disablePolicy?: "allowed" | "disabled";
|
||||
allowedPages?: readonly string[];
|
||||
requiredModules?: readonly string[];
|
||||
purposeBindings?: readonly string[];
|
||||
entryNavigationKey?: string;
|
||||
configFields?: readonly { key: string; label: string; input: string; required: boolean }[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface TrustPresentation {
|
||||
@@ -94,6 +106,8 @@ export interface CapabilityPluginManifest {
|
||||
requiredModules: readonly string[];
|
||||
apiContract: string;
|
||||
configSchema: string;
|
||||
purposeBindings?: readonly string[];
|
||||
entryNavigationKey?: string;
|
||||
}
|
||||
|
||||
export interface RuntimeWorkspace {
|
||||
|
||||
Reference in new issue
Block a user