feat: 增加能力插件管理页面
This commit is contained in:
1 parent
8a02d09e2d
commit
b3e2ece41b
3 files changed
+160
No files matched your search
@@ -0,0 +1,129 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { Alert, Button, Card, Form, Input, Select, Space, Table, Tag, message } from "antd";
|
||||
import type { CapabilityInstallation } from "@personal-brand/api-client";
|
||||
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;
|
||||
|
||||
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) : {},
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("能力配置已更新");
|
||||
queryClient.invalidateQueries({ queryKey: ["admin", "capabilities"] });
|
||||
},
|
||||
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 }}
|
||||
/>
|
||||
<Table
|
||||
rowKey="capabilityKey"
|
||||
dataSource={items}
|
||||
locale={{ emptyText: "当前还没有品牌级能力覆盖,系统将使用模板默认能力。" }}
|
||||
columns={[
|
||||
{ title: "能力", dataIndex: "capabilityKey" },
|
||||
{ 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>
|
||||
);
|
||||
}
|
||||
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -31,6 +31,11 @@ const FeatureOverviewPage = React.lazy(() =>
|
||||
default: module.OverviewPage,
|
||||
})),
|
||||
);
|
||||
const FeatureCapabilitiesPage = React.lazy(() =>
|
||||
import("./features/capabilities/CapabilitiesPage.js").then((module) => ({
|
||||
default: module.CapabilitiesPage,
|
||||
})),
|
||||
);
|
||||
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
||||
import "antd/dist/reset.css";
|
||||
|
||||
@@ -79,6 +84,7 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
{ key: "trust", label: "信任内容" },
|
||||
{ key: "services", label: "业务提供项" },
|
||||
{ key: "workspace", label: "模板与设置" },
|
||||
{ key: "capabilities", label: "能力插件" },
|
||||
{ key: "inquiries", label: "咨询记录" },
|
||||
];
|
||||
return (
|
||||
@@ -114,6 +120,7 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
||||
<Route path="/admin/overview" element={<FeatureOverviewPage />} />
|
||||
<Route path="/admin/brand" element={<FeatureBrandPage />} />
|
||||
<Route path="/admin/workspace" element={<FeatureWorkspacePage />} />
|
||||
<Route path="/admin/capabilities" element={<FeatureCapabilitiesPage />} />
|
||||
<Route path="/admin/trust" element={<FeatureTrustContentPage />} />
|
||||
<Route path="/admin/services" element={<FeatureServicesPage />} />
|
||||
<Route path="/admin/inquiries" element={<FeatureInquiriesPage />} />
|
||||
|
||||
Reference in new issue
Block a user