解决文章标签重复问题

This commit is contained in:
Liu 宇阳
2024-11-06 20:50:13 +08:00
parent c273933ede
commit 77f502579a

View File

@@ -85,11 +85,11 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo
const onSubmit: FormProps<FieldType>['onFinish'] = async (values) => {
// 如果是文章标签,则先判断是否存在,如果不存在则添加
let tagIds: number[] = []
if (values.tagIds) {
for (const item of values.tagIds) {
for (const item of (values.tagIds ? values.tagIds : [])) {
if (typeof item === "string") {
// 如果已经有这个标签了,就没必要再创建一个了
const tag1 = tagList.find(t => t.name === item)?.id;
// 先转换为大写进行查找,否则会出现大小写不匹配问题
const tag1 = tagList.find(t => t.name.toUpperCase() === item.toUpperCase())?.id;
if (tag1) {
tagIds.push(tag1)
@@ -105,7 +105,6 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo
tagIds.push(item);
}
}
}
values.createTime = values.createTime.valueOf()
values.cateIds = [...new Set(values.cateIds?.flat())]