feat: 能力插件元数据与运行时消费闭环
This commit is contained in:
1 parent
076c6124c8
commit
bb0709b8cc
26 files changed
+2188
-267
No files matched your search
@@ -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) => (
|
||||
|
||||
Reference in new issue
Block a user