From 77f502579a34b61b0c2e4cf570cdb360b94dc11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liu=20=E5=AE=87=E9=98=B3?= Date: Wed, 6 Nov 2024 20:50:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=87=E7=AB=A0=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=87=8D=E5=A4=8D=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 | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/pages/Create/components/PublishForm/index.tsx b/src/pages/Create/components/PublishForm/index.tsx index 47f7099..34fca4a 100644 --- a/src/pages/Create/components/PublishForm/index.tsx +++ b/src/pages/Create/components/PublishForm/index.tsx @@ -85,25 +85,24 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo const onSubmit: FormProps['onFinish'] = async (values) => { // 如果是文章标签,则先判断是否存在,如果不存在则添加 let tagIds: number[] = [] - if (values.tagIds) { - for (const item of values.tagIds) { - if (typeof item === "string") { - // 如果已经有这个标签了,就没必要再创建一个了 - const tag1 = tagList.find(t => t.name === item)?.id; + for (const item of (values.tagIds ? values.tagIds : [])) { + if (typeof item === "string") { + // 如果已经有这个标签了,就没必要再创建一个了 + // 先转换为大写进行查找,否则会出现大小写不匹配问题 + const tag1 = tagList.find(t => t.name.toUpperCase() === item.toUpperCase())?.id; - if (tag1) { - tagIds.push(tag1) - continue - } - - await addTagDataAPI({ name: item }); - const { data: list } = await getTagListAPI(); - // 添加成功后查找对应的标签id - const tag2 = list.find(t => t.name === item)?.id; - if (tag2) tagIds.push(tag2); - } else { - tagIds.push(item); + if (tag1) { + tagIds.push(tag1) + continue } + + await addTagDataAPI({ name: item }); + const { data: list } = await getTagListAPI(); + // 添加成功后查找对应的标签id + const tag2 = list.find(t => t.name === item)?.id; + if (tag2) tagIds.push(tag2); + } else { + tagIds.push(item); } }