From f6f255b32140a6d7929f232af3f26a6023a82aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liu=20=E5=AE=87=E9=98=B3?= Date: Thu, 24 Oct 2024 18:48:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=8F=91=E5=B8=83=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E6=97=B6=E6=A0=87=E7=AD=BE=E9=87=8D=E5=A4=8D=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Create/components/PublishForm/index.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/pages/Create/components/PublishForm/index.tsx b/src/pages/Create/components/PublishForm/index.tsx index 64b4e32..effeba2 100644 --- a/src/pages/Create/components/PublishForm/index.tsx +++ b/src/pages/Create/components/PublishForm/index.tsx @@ -15,8 +15,6 @@ import { Article } from "@/types/app/article"; import dayjs from 'dayjs'; -import "./index.scss" - interface FieldType { title: string, createTime: number; @@ -83,16 +81,27 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo let tagIds: number[] = [] for (const item of values.tagIds) { if (typeof item === "string") { + // 如果已经有这个标签了,就没必要再创建一个了 + const tag1 = tagList.find(t => t.name === item)?.id; + + if (tag1) { + tagIds.push(tag1) + continue + } + await addTagDataAPI({ name: item }); - const { data: tagList } = await getTagListAPI(); + const { data: list } = await getTagListAPI(); // 添加成功后查找对应的标签id - const tag = tagList.find(t => t.name === item)?.id; - if (tag !== undefined) tagIds.push(tag); + const tag2 = list.find(t => t.name === item)?.id; + if (tag2) tagIds.push(tag2); } else { tagIds.push(item); } } + console.log(222); + + values.createTime = values.createTime.valueOf() values.cateIds = [...new Set(values.cateIds?.flat())]