diff --git a/model/ability.go b/model/ability.go index 4300b5eb..dd1a11be 100644 --- a/model/ability.go +++ b/model/ability.go @@ -8,6 +8,7 @@ import ( "github.com/samber/lo" "gorm.io/gorm" + "gorm.io/gorm/clause" ) type Ability struct { @@ -158,7 +159,7 @@ func (channel *Channel) AddAbilities() error { return nil } for _, chunk := range lo.Chunk(abilities, 50) { - err := DB.Create(&chunk).Error + err := DB.Clauses(clause.OnConflict{DoNothing: true}).Create(&chunk).Error if err != nil { return err } @@ -224,7 +225,7 @@ func (channel *Channel) UpdateAbilities(tx *gorm.DB) error { if len(abilities) > 0 { for _, chunk := range lo.Chunk(abilities, 50) { - err = tx.Create(&chunk).Error + err = tx.Clauses(clause.OnConflict{DoNothing: true}).Create(&chunk).Error if err != nil { if isNewTx { tx.Rollback() diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index 4fcf19e4..db0d2980 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -1652,5 +1652,7 @@ "开启后,仅“消费”和“错误”日志将记录您的客户端 IP 地址": "After enabling, only \"consumption\" and \"error\" logs will record your client IP address", "只有当用户设置开启IP记录时,才会进行请求和错误类型日志的IP记录": "Only when the user sets IP recording, the IP recording of request and error type logs will be performed", "设置保存成功": "Settings saved successfully", - "设置保存失败": "Settings save failed" + "设置保存失败": "Settings save failed", + "已新增 {{count}} 个模型:{{list}}": "Added {{count}} models: {{list}}", + "未发现新增模型": "No new models were added" } \ No newline at end of file diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 04dc284b..8bfe5812 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -385,7 +385,7 @@ const EditChannel = (props) => { let localModels = [...inputs.models]; let localModelOptions = [...modelOptions]; - let hasError = false; + const addedModels = []; modelArray.forEach((model) => { if (model && !localModels.includes(model)) { @@ -395,17 +395,24 @@ const EditChannel = (props) => { text: model, value: model, }); - } else if (model) { - showError(t('某些模型已存在!')); - hasError = true; + addedModels.push(model); } }); - if (hasError) return; - setModelOptions(localModelOptions); setCustomModel(''); handleInputChange('models', localModels); + + if (addedModels.length > 0) { + showSuccess( + t('已新增 {{count}} 个模型:{{list}}', { + count: addedModels.length, + list: addedModels.join(', '), + }) + ); + } else { + showInfo(t('未发现新增模型')); + } }; return ( diff --git a/web/src/pages/Channel/EditTagModal.js b/web/src/pages/Channel/EditTagModal.js index 04089615..2195724c 100644 --- a/web/src/pages/Channel/EditTagModal.js +++ b/web/src/pages/Channel/EditTagModal.js @@ -229,7 +229,7 @@ const EditTagModal = (props) => { let localModels = [...inputs.models]; let localModelOptions = [...modelOptions]; - let hasError = false; + const addedModels = []; modelArray.forEach((model) => { // 检查模型是否已存在,且模型名称非空 @@ -241,18 +241,25 @@ const EditTagModal = (props) => { text: model, value: model, }); - } else if (model) { - showError('某些模型已存在!'); - hasError = true; + addedModels.push(model); } }); - if (hasError) return; // 如果有错误则终止操作 - // 更新状态值 setModelOptions(localModelOptions); setCustomModel(''); handleInputChange('models', localModels); + + if (addedModels.length > 0) { + showSuccess( + t('已新增 {{count}} 个模型:{{list}}', { + count: addedModels.length, + list: addedModels.join(', '), + }) + ); + } else { + showInfo(t('未发现新增模型')); + } }; return (