From 539cdc4bc331337e59cb4c36336f1d143640d753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E9=98=B3?= Date: Sat, 4 Jan 2025 21:42:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=87=E7=AB=A0=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=E5=B7=B2=E7=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Create/components/Editor/index.tsx | 2 +- .../Create/components/PublishForm/index.tsx | 34 +++++++++++++++---- src/types/app/article.d.ts | 1 + 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/pages/Create/components/Editor/index.tsx b/src/pages/Create/components/Editor/index.tsx index 57bed86..e23db05 100644 --- a/src/pages/Create/components/Editor/index.tsx +++ b/src/pages/Create/components/Editor/index.tsx @@ -30,7 +30,7 @@ const EditorMD = ({ value, onChange }: Props) => { formData.append("dir", "article"); for (let i = 0; i < files.length; i++) formData.append('files', files[i]) - const { data: { code, data } } = await axios.post(`${baseURL}/file`, formData, { + const { data: { code, data } } = await axios.post(`${baseURL}/file/plus`, formData, { headers: { "Authorization": `Bearer ${store.token}`, "Content-Type": "multipart/form-data" diff --git a/src/pages/Create/components/PublishForm/index.tsx b/src/pages/Create/components/PublishForm/index.tsx index a21cdf1..f6ea628 100644 --- a/src/pages/Create/components/PublishForm/index.tsx +++ b/src/pages/Create/components/PublishForm/index.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from "react"; import { useNavigate, useSearchParams } from "react-router-dom"; -import { Form, Input, Button, Select, DatePicker, Cascader, FormProps, message, Switch, Radio } from "antd"; +import { Form, Input, Button, Select, DatePicker, Cascader, message, Switch, Radio } from "antd"; import TextArea from "antd/es/input/TextArea"; import { RuleObject } from "antd/es/form"; @@ -23,7 +23,8 @@ interface FieldType { cover: string; description: string; top: boolean; - status: Status, + isEncrypt: number; + status: Status; password: string } @@ -39,6 +40,7 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo const [cateList, setCateList] = useState([]) const [tagList, setTagList] = useState([]) + const [isEncryptEnabled, setIsEncryptEnabled] = useState(false); useEffect(() => { if (!id) return form.resetFields() @@ -54,14 +56,18 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo const tagIds = data.tagList!.map(item => item.id) - form.setFieldsValue({ + const formValues = { ...data, status: data.config.status, password: data.config.password, cateIds, tagIds, createTime: dayjs(+data.createTime!) - }) + } + + form.setFieldsValue(formValues) + // 设置初始的加密状态 + setIsEncryptEnabled(!!formValues.isEncrypt) }, [data, id]) const getCateList = async () => { @@ -87,6 +93,9 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo const onSubmit = async (values: FieldType, isDraft?: boolean) => { setBtnLoading(true) + console.log(values); + values.isEncrypt = values.isEncrypt ? 1 : 0 + // 如果是文章标签,则先判断是否存在,如果不存在则添加 let tagIds: number[] = [] for (const item of (values.tagIds ? values.tagIds : [])) { @@ -134,6 +143,7 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo tagIds: tagIds.join(','), isDraft: isDraft ? 1 : 0, isDel: 0, + isEncrypt: 0, config: { status: values.status, password: values.password @@ -228,7 +238,7 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo - + @@ -240,10 +250,20 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo - - + + setIsEncryptEnabled(checked)} /> + {isEncryptEnabled && ( + + + + )} + diff --git a/src/types/app/article.d.ts b/src/types/app/article.d.ts index 42cc984..bd1cc7f 100644 --- a/src/types/app/article.d.ts +++ b/src/types/app/article.d.ts @@ -24,6 +24,7 @@ export interface Article { comment?: number, config: Config, isDraft: number, + isEncrypt: number, isDel: number, createTime?: string, }