fix: 1、添加创建source时名称重复的校验;2、source文件上传的id参数修改,去掉多余代码。

This commit is contained in:
刘洪洪
2024-11-19 10:36:47 +08:00
parent d2b6eab486
commit 27650f2c37
2 changed files with 28 additions and 48 deletions

View File

@@ -101,7 +101,7 @@
<script>
import table from '@/mixins/table'
import { dateFormatByAppearance } from '@/utils/date-util'
import { itemListHeight, storageKey, unitTypes, EN } from '@/utils/constants'
import { storageKey, unitTypes, EN } from '@/utils/constants'
import _ from 'lodash'
import unitConvert from '@/utils/unit-convert'
import { ElMessageBox } from 'element-plus'
@@ -187,7 +187,7 @@ export default {
computed: {
uploadParams () {
return {
id: this.sourceId
sourceId: this.sourceId
}
}
},
@@ -208,51 +208,10 @@ export default {
}
this.fileList = fileList.slice(-1)
},
uploadSuccess (response) {
if (response.code === 200) {
this.uploaded = true
// 上传成功后去掉upload和preview的错误提示
this.uploadErrorTip = ''
this.previewErrorTip = ''
this.importedType = this.editObject.indicatorType
const originalImportedData = _.cloneDeep(response.data.list)
this.importedDataNoData = originalImportedData.length === 0
if (originalImportedData.length > 0) {
originalImportedData.forEach(data => {
if (data.isValid === 1) {
data.msg = this.$t('overall.success')
} else if (data.isValid === 0) {
if (data.errorAttribute === 'entityType') {
data.msg = this.$t('validate.wrongType')
} else if (data.errorAttribute === 'entityValue') {
data.msg = this.$t('validate.wrongFormat')
}
}
})
}
this.originalImportInfo = {
total: originalImportedData.length,
succeeded: originalImportedData.filter(d => d.isValid === 1).length,
failed: originalImportedData.filter(d => d.isValid !== 1).length
}
this.isLoad = false
originalImportedData.sort((a, b) => b.isValid - a.isValid)
this.importedData = this.handleSpeticalTypeData(originalImportedData)
this.addItemList = _.cloneDeep(this.importedData).filter(item => { return item.isValid === 1 })
this.updateItemList = []
this.deleteItemIds = this.oldItemIds
this.handleShowImportedData()
this.addEditFlag = false
this.editTagErrorTip = ''
this.editIndex = -1
this.isPreviewChange = true
this.stepHeights[2] = itemListHeight.hasData
this.stepHeightConstant.third = itemListHeight.hasData
} else {
this.uploadLoading = false
this.$message.error(this.$t('tip.uploadFailed', { msg: response.message }))
}
uploadSuccess () {
this.uploaded = false
this.dialogVisible = false
this.$message.success(this.$t('tip.success'))
},
beforeUpload (file) {
return new Promise((resolve, reject) => {

View File

@@ -178,6 +178,20 @@ export default {
Loading
},
data () {
const nameDuplicateValidator = async (rule, value, callback) => {
let validate = true
if (!this.sourceObj.knowledgeId) {
const response = await this.getSourceList()
if (response.status === 200) {
const find = response.data.data.list.find(d => d.name === value)
if (find) {
validate = false
callback(new Error())
}
}
}
return validate
}
const nameValidator = (rule, value, callback) => {
// 校验value包含字母、数字和下划线并且不是全数字、全下划线和连续下划线
const regex = /^(?=.*[a-zA-Z])(?=.*\d|^(?!\d+$))[a-zA-Z\d]+(?:_[a-zA-Z\d]+)*$/
@@ -204,7 +218,8 @@ export default {
return {
rules: {
name: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
{ validator: nameDuplicateValidator, message: this.$t('validate.duplicateRecord', { columns: `(${this.$t('config.roles.name')})` }), trigger: 'blur' }
],
dataFormat: [
{ required: true, message: this.$t('validate.required'), trigger: 'change' }
@@ -460,6 +475,12 @@ export default {
onChangeFunction (index) {
this.sourceObj.lookupsData.data[index].output_type = ''
// this.$refs.lookupsForm.clearValidate('output_type')
},
async getSourceList () {
return await axios.get(api.setting.source.source, { params: { pageSize: 999 } }).catch(e => {
console.error(e)
this.$message.error(this.errorMsgHandler(e))
})
}
},
setup () {