feat: 完善信任内容配置流程
This commit is contained in:
1 parent
ae2eb08fca
commit
37e898a4b9
4 files changed
+70
-2
No files matched your search
@@ -3,12 +3,14 @@ import {
|
||||
Card,
|
||||
Form,
|
||||
Input,
|
||||
List,
|
||||
Modal,
|
||||
Popconfirm,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
@@ -56,6 +58,7 @@ type TrustTypeOption = {
|
||||
label: string;
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
};
|
||||
const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({
|
||||
type: value,
|
||||
@@ -83,6 +86,11 @@ export function TrustContentPage() {
|
||||
? workspace.data.templateContent.trustContentTypes
|
||||
: fallbackTypes;
|
||||
const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType);
|
||||
const contentByType = new Map((query.data ?? []).map((item) => [item.type, item]));
|
||||
const firstMissingRequiredType =
|
||||
availableTypes.find((item) => item.required && !contentByType.has(item.type))?.type ??
|
||||
availableTypes[0]?.type ??
|
||||
"credential";
|
||||
const save = useMutation({
|
||||
mutationFn: (values: TrustContentInput) =>
|
||||
editing
|
||||
@@ -103,7 +111,7 @@ export function TrustContentPage() {
|
||||
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
|
||||
},
|
||||
});
|
||||
const begin = (item?: TrustContent) => {
|
||||
const begin = (item?: TrustContent, type?: string) => {
|
||||
setEditing(item ?? null);
|
||||
setOpen(true);
|
||||
form.setFieldsValue(
|
||||
@@ -116,7 +124,7 @@ export function TrustContentPage() {
|
||||
...(item.coverUrl ? { coverUrl: item.coverUrl } : {}),
|
||||
isPublished: item.isPublished,
|
||||
}
|
||||
: { type: "credential", isPublished: false },
|
||||
: { type: type ?? firstMissingRequiredType, isPublished: false },
|
||||
);
|
||||
};
|
||||
return (
|
||||
@@ -134,10 +142,47 @@ export function TrustContentPage() {
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<Card title="当前模板需要哪些信任内容?" style={{ marginBottom: 24 }}>
|
||||
<Typography.Paragraph type="secondary">
|
||||
这些内容会帮助访客判断你是否值得信任。带有“发布必需”的项目需要填写完整后,才能发布小程序。
|
||||
</Typography.Paragraph>
|
||||
<List
|
||||
size="small"
|
||||
dataSource={availableTypes}
|
||||
renderItem={(item) => {
|
||||
const content = contentByType.get(item.type);
|
||||
const complete = Boolean(content?.title?.trim() && content?.content?.trim());
|
||||
return (
|
||||
<List.Item
|
||||
actions={[
|
||||
<Button
|
||||
key={item.type}
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => (content ? begin(content) : begin(undefined, item.type))}
|
||||
>
|
||||
{content ? "编辑" : "新增"}
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<Space wrap>
|
||||
<Typography.Text strong>{item.label}</Typography.Text>
|
||||
{item.required && <Tag color="orange">发布必需</Tag>}
|
||||
<Tag color={complete ? "success" : "default"}>
|
||||
{complete ? "内容完整" : content ? "需要完善" : "尚未填写"}
|
||||
</Tag>
|
||||
{item.help && <Typography.Text type="secondary">{item.help}</Typography.Text>}
|
||||
</Space>
|
||||
</List.Item>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
<Card>
|
||||
<Table
|
||||
rowKey="id"
|
||||
dataSource={query.data ?? []}
|
||||
locale={{ emptyText: "还没有信任内容,请先按上方模板要求添加。" }}
|
||||
columns={[
|
||||
{
|
||||
title: "证据类型",
|
||||
|
||||
Reference in new issue
Block a user