索引(a,b,c)已创建的情况下不能再创建索引(a)和(a,b)

checkDuplicate(rule, value, callback) {
if (!value) {
callback(new Error('必填项'))
} else {
const allValues = this.form.tableData.map((item) => item.inputValue)
const count = allValues?.filter((v) => v === value).length
if (count > 1) {
callback(new Error('该内容已存在'))
} else {
callback()
}
}
},
checkFieldEnName(rule, value, callback) {
if (!value || value.length < 1) {
callback(new Error('必填项'))
} else {
const listTableIndexInfo = this.form.tableData
if (listTableIndexInfo.length < 2) {
return callback()
}
const key = rule.field.split('.')
const current_index = Number(key[1])
const newIndex = value.map((v) => v + '|')
for (let j = 0; j < listTableIndexInfo.length; j++) {
if (j === current_index) {
continue
}
const existingIndices = listTableIndexInfo[j].selectedList.map((v) => v + '|')
if (existingIndices?.length > 0 && newIndex?.length) {
const is_equal = this.shouldCreateIndex([existingIndices], newIndex)
console.log(j, current_index, is_equal ? '重复' : '不重复', existingIndices, newIndex)
if (is_equal) {
return callback(new Error('索引字段重复'))
}
}
}
}
callback()
},
checkIndexColumn(rule, value, callback) {
if (!value || value.length < 1) {
callback(new Error('必填项'))
} else {
const formList = this.form.tableData
if (formList?.length < 2) {
return callback()
}
const key = rule.field.split('.')
const current_index = Number(key[1])
for (let i = 0; i < formList.length; i++) {
const elementList = formList[i]
if (i === current_index || elementList?.securityOperateList?.length === 0) {
continue
}
const sortDataValue = value
.map((ele) => ele)
.slice()
.sort()
const sortData = elementList.securityOperateList
.map((ele) => ele)
.slice()
.sort()
const is_equal = JSON.stringify(sortDataValue) === JSON.stringify(sortData)
if (is_equal) {
return callback(new Error('字段重复'))
}
}
}
callback()
},
shouldCreateIndex(existingIndices, newIndex) {
for (const existingIndex of existingIndices) {
const existingIndexArr = existingIndex.join('|')
const newIndexArr = newIndex.join('|')
const hasSubIndex = existingIndexArr.startsWith(newIndexArr) || newIndexArr.startsWith(existingIndexArr)
if (hasSubIndex) return true
}
return false
},
当主键为一个字段时,索引不允许出现该字段;当主键为多个字段时如abc,则不允许出现的情况a,ab,abc,abc*,*abc,abc
checkFieldEnName(rule, value, callback) {
if (!value || value.length < 1) {
callback(new Error('必填项'))
} else {
const valueFieldArr = value.map(v=>v.fieldEnName + '|')
if(this.primaryList.length === 1){
const primaryFieldEnName = this.primaryList[0].fieldEnName + '|'
if(valueFieldArr.includes(primaryFieldEnName)){
return callback(new Error('索引字段与主键冲突'))
}
}else{
const primaryFieldEnName = this.primaryList.map(v=>v.fieldEnName + '|')
const primaryFieldStr = primaryFieldEnName.join('|')
const valueFieldStr = valueFieldArr.join('|')
if(valueFieldStr.includes(primaryFieldStr) || primaryFieldStr.startsWith(valueFieldStr)){
return callback(new Error('索引字段与主键冲突'))
}
}
}
callback()
}