CN-952 知识库对导入数据的增删改:导入数据的校验,问题的修改等

This commit is contained in:
hyx
2023-04-11 15:38:47 +08:00
parent 4dea59edfc
commit f01af02dd1
3 changed files with 309 additions and 110 deletions

View File

@@ -342,7 +342,7 @@
min-width: 74px; min-width: 74px;
padding: 0 15px; padding: 0 15px;
color: white; color: white;
background-color: #38ACD2; background-color: #699DC9;
border: none; border: none;
border-radius: 4px; border-radius: 4px;
outline: none; outline: none;
@@ -351,7 +351,7 @@
transition: background-color linear .2s, color linear .1s; transition: background-color linear .2s, color linear .1s;
} }
.footer__btn:hover:not(.footer__btn--disabled) { .footer__btn:hover:not(.footer__btn--disabled) {
background-color: lighten(#38ACD2, 10%); background-color: lighten(#699DC9, 10%);
} }
.footer__btn--light { .footer__btn--light {
background-color: #F5F6F7; background-color: #F5F6F7;

65
src/utils/regular.js Normal file
View File

@@ -0,0 +1,65 @@
// 正则表达式
const regular = {
ipv4CIDR: /^(?:(?:[0-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\/([1-9]|[1-2]\d|3[0-2])$/,
ipv4CIDRMask: /^(?:(?:[0-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2]\d|3[0-2])$/, // 掩码可以为0
// ipv6CIDR并可以配置任意范围 如ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0和::/0
ipv6CIDRA: /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\/([0-9]|[1-9]\d|1[01]\d|12[0-8])$/,
ipv6CIDRB: /^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)\/([0-9]|[1-9]\d|1[01]\d|12[0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\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])$/,
ipv4: /^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,
ipv6: /^([\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^::([\da-fA-F]{1,4}:){0,4}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:):([\da-fA-F]{1,4}:){0,3}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){2}:([\da-fA-F]{1,4}:){0,2}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){3}:([\da-fA-F]{1,4}:){0,1}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){4}:((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$|^:((:[\da-fA-F]{1,4}){1,6}|:)$|^[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,5}|:)$|^([\da-fA-F]{1,4}:){2}((:[\da-fA-F]{1,4}){1,4}|:)$|^([\da-fA-F]{1,4}:){3}((:[\da-fA-F]{1,4}){1,3}|:)$|^([\da-fA-F]{1,4}:){4}((:[\da-fA-F]{1,4}){1,2}|:)$|^([\da-fA-F]{1,4}:){5}:([\da-fA-F]{1,4})?$|^([\da-fA-F]{1,4}:){6}:$/,
// ipv4/ipv6
ip: /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^::([\da-fA-F]{1,4}:){0,4}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:):([\da-fA-F]{1,4}:){0,3}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){2}:([\da-fA-F]{1,4}:){0,2}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){3}:([\da-fA-F]{1,4}:){0,1}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){4}:((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$|^:((:[\da-fA-F]{1,4}){1,6}|:)$|^[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,5}|:)$|^([\da-fA-F]{1,4}:){2}((:[\da-fA-F]{1,4}){1,4}|:)$|^([\da-fA-F]{1,4}:){3}((:[\da-fA-F]{1,4}){1,3}|:)$|^([\da-fA-F]{1,4}:){4}((:[\da-fA-F]{1,4}){1,2}|:)$|^([\da-fA-F]{1,4}:){5}:([\da-fA-F]{1,4})?$|^([\da-fA-F]{1,4}:){6}:$/,
port: /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/,
ipv6Serialize: function (ipv6) {
let splited = ipv6.split(':')
if (splited.length < 8) {
// 将""替换成对应数量的"0000"
const index = splited.indexOf('')
const temp = splited.slice(index + 1, splited.length)
const zero = []
for (let i = 0; i < (8 - splited.length + 1); i++) {
// 8-去掉""之后的长度,得到需要补齐的元素数量
zero.push('0000')
}
return splited = splited.slice(0, index).concat(zero).concat(temp)// 空间复杂度比较大了,
} else {
return ipv6
}
},
trans: function (ip) {
if (this.ipv6Serialize(ip) instanceof Array) {
const arr1 = this.ipv6Serialize(ip)
// 找到数组最后一项然后转化为16进制的
const num = arr1[arr1.length - 1]
return parseInt((num), 16)
} else {
const arr1 = this.ipv6Serialize(ip).toUpperCase().split(':')
// 找到数组最后一项然后转化为16进制的
const num = arr1[arr1.length - 1]
return parseInt((num), 16)
}
},
ipv6Reg: function (start, end) {
return this.trans(start) <= this.trans(end)
},
// ipv4对比大小 结束ip不能小于开始ip
// 比较两个ip的大小,如果大于返回1等于返回0小于返回-1
compareIP4: function (ip) {
let e = ip; const t = /^[0-9]([0-9\.]+\d)?$/
let c
let num
e ? true ? (e = e.split('.'), e.length !== 4 ? (msgError('IP格式错误'), void 0) : (num = 256 * 256 * 256 * Number(e[0]) + 256 * 256 * Number(e[1]) + 256 * Number(e[2]) + Number(e[3]), num >>>= 0, c = num, void 0)) : (msgError('IP格式错误'), void 0) : (msgError('请输入IP'), void 0)  
return c
}
}
export {
regular
}

View File

@@ -86,13 +86,13 @@
</div> </div>
<template v-else> <template v-else>
<div class="imported-tip"><i class="cn-icon cn-icon-baocuo"/> <div class="imported-tip"><i class="cn-icon cn-icon-baocuo"/>
&nbsp;&nbsp;{{ &nbsp;&nbsp;{{ editObject.id && isLoad? $t('knowledgeBase.loadTip', {
$t('knowledgeBase.importTip', { load: originalImportInfo.total
total: originalImportInfo.total, }) : $t('knowledgeBase.importTip', {
succeeded: originalImportInfo.succeeded, total: originalImportInfo.total,
failed: originalImportInfo.failed succeeded: originalImportInfo.succeeded,
}) failed: originalImportInfo.failed
}} }) }}
</div> </div>
<div class="imported-table-box" :class="previewErrorTip ? 'imported-table-box--error' : ''"> <div class="imported-table-box" :class="previewErrorTip ? 'imported-table-box--error' : ''">
<el-form ref="editForm" :model="editTagForm" :rules="editTagFormRules"> <el-form ref="editForm" :model="editTagForm" :rules="editTagFormRules">
@@ -105,7 +105,7 @@
</tr> </tr>
<tr v-for="(d, i) in showImportedData" :key="importedType + d.tagItem + d.tagValue + i"> <tr v-for="(d, i) in showImportedData" :key="importedType + d.tagItem + d.tagValue + i">
<td class="imported-data-item" :title="d.tagItem"> <td class="imported-data-item" :title="d.tagItem">
<el-form-item v-if="editObject.id && editIndex === i" prop="tagItem"> <el-form-item v-if="(editObject.id && editIndex === i) || (addEditFlag && d.tagItem === '' && d.tagValue === '')" prop="tagItem">
<span class="imported-data-item-edit__input"> <span class="imported-data-item-edit__input">
<el-input v-model="editTagForm.tagItem" @blur="onBlurTagItem"></el-input> <el-input v-model="editTagForm.tagItem" @blur="onBlurTagItem"></el-input>
</span> </span>
@@ -113,7 +113,7 @@
<span v-else>{{ d.tagItem }}</span> <span v-else>{{ d.tagItem }}</span>
</td> </td>
<td class="imported-data-value" :title="d.tagValue"> <td class="imported-data-value" :title="d.tagValue">
<el-form-item v-if="editObject.id && editIndex === i" prop="tagValue"> <el-form-item v-if="(editObject.id && editIndex === i) || (addEditFlag && d.tagItem === '' && d.tagValue === '')" prop="tagValue">
<span class="imported-data-item-edit__input"> <span class="imported-data-item-edit__input">
<el-input v-model="editTagForm.tagValue" @blur="onBlurTagItem"></el-input> <el-input v-model="editTagForm.tagValue" @blur="onBlurTagItem"></el-input>
</span> </span>
@@ -125,13 +125,13 @@
</td> </td>
<td v-else></td> <td v-else></td>
<!--返回和保存按钮--> <!--返回和保存按钮-->
<td v-if="editObject.id && backEditFlag && editIndex === i" class="imported-data-btn"> <td v-if="editObject.id && backEditFlag && !addEditFlag && editIndex === i" class="imported-data-btn">
<i v-if="editObject.id" class="cn-icon cn-icon-revoke imported-data-left-btn imported-data-back" <i v-if="editObject.id" class="cn-icon cn-icon-revoke imported-data-left-btn imported-data-back"
@click="backImportedData"></i> @click="backImportedData"></i>
<i class="cn-icon cn-icon-save imported-data-save" @click="saveImportedData(i)"></i> <i class="cn-icon cn-icon-save imported-data-save" @click="saveImportedData(i)"></i>
</td> </td>
<!--保存和删除按钮--> <!--保存和删除按钮-->
<td v-else-if="editObject.id && addEditFlag && editIndex === i" class="imported-data-btn"> <td v-else-if="(editObject.id && addEditFlag && editIndex === i) || (addEditFlag && d.tagItem === '' && d.tagValue === '')" class="imported-data-btn">
<i class="cn-icon cn-icon-save imported-data-save" style="margin: 0 7px" <i class="cn-icon cn-icon-save imported-data-save" style="margin: 0 7px"
@click="saveImportedData(i)"></i> @click="saveImportedData(i)"></i>
<i class="el-icon-close" @click="removeImportedData(i)"></i> <i class="el-icon-close" @click="removeImportedData(i)"></i>
@@ -191,6 +191,7 @@ import Pagination from '@/components/common/Pagination'
import ChartNoData from '@/views/charts/charts/ChartNoData' import ChartNoData from '@/views/charts/charts/ChartNoData'
import axios from 'axios' import axios from 'axios'
import { api } from '@/utils/api' import { api } from '@/utils/api'
import { regular } from '@/utils/regular'
import unitConvert from '@/utils/unit-convert' import unitConvert from '@/utils/unit-convert'
import Loading from '@/components/common/Loading' import Loading from '@/components/common/Loading'
@@ -239,26 +240,110 @@ export default {
} }
return validate return validate
} }
const nameAndLabelDuplicateValidator = (rule, value, callback) => {
const nameAndLabelValidator = (rule, value, callback) => {
let validate = true let validate = true
let index = -1 // 当前编辑的键值index let index = -1 // 当前编辑的键值index
// todo 查看是否重名前需要对名称进行校验分别是IP、domain、APP的校验 // todo 查看是否重名前需要对名称进行校验分别是IP、domain、APP的校验
const findData = this.importedData.find((item, i) => { const findData = this.importedData.find((item, i) => {
index = i index = i
return item.tagItem === this.editTagForm.tagItem return (item.tagItem === this.editTagForm.tagItem && item.tagValue === this.editTagForm.tagValue)
}) })
if (findData) { if (findData) { // 找到1条记录
// 如果name重复的第一个键值不是当前编辑item的index即代表后续有重名的项了提示重名 // 如果name重复的第一个键值不是当前编辑item的index即代表后续有重名的项了提示重名
if (index !== this.editIndex) { const realIndex = (this.importedPageObj.pageSize * (this.importedPageObj.pageNo - 1)) + this.editIndex
if (index !== realIndex) { // 记录为非当前记录,则数据重复
validate = false validate = false
this.editTagErrorTip = rule.message
callback(new Error()) callback(new Error())
} else { }
// 此情况为仅修改label不修改name }
if (findData.tagValue === this.editTagForm.tagValue) { return validate
}
const requiredItemValidator = (rule, value, callback) => {
let validate = true
const realValue = value.replace(/\s+/g, '')// 去掉空格
if (realValue === '') {
validate = false
this.editTagErrorTip = rule.message
callback(new Error())
}
return validate
}
const requiredValueValidator = (rule, value, callback) => {
let validate = true
const realValue = value.replace(/\s+/g, '')// 去掉空格
if (realValue === '') {
validate = false
this.editTagErrorTip = rule.message
callback(new Error())
}
return validate
}
const nameFormatValidator = (rule, value, callback) => {
let validate = true
const tagType = this.editObject.tagType// 当前选中的类型
if (tagType === 'ip') {
const formal = value.replace(/\s+/g, '')// 去掉空格
if (formal.indexOf('/') != -1) {
if (!(regular.ipv4CIDR.test(formal)) && !(regular.ipv6CIDR.test(formal))) {
validate = false validate = false
this.editTagErrorTip = rule.message
callback(new Error()) callback(new Error())
} }
} else {
if (!regular.ip.test(formal)) {
validate = false
this.editTagErrorTip = rule.message
callback(new Error())
}
}
} else if (tagType === 'app') {
const pattern = /.*[*?!&$%#^,.;:<>/@\"{}\-\]\[=+_\\|].*$/
if (pattern.test(value)) {
validate = false
this.editTagErrorTip = rule.message
callback(new Error())
}
} else if (tagType === 'domain') { // 域名只支持 字母数字.-_
if ((value.substr(0, 1) === '*' || value.substr(0, 1) === '$') &&
!(value.substr(-1) === '*' || value.substr(-1) === '$')) {
if (value.substr(0, 1) === '$') { // 处理$开头的情况
// 域名中的标号都由英文字母和数字组成每一个标号不超过63个字符也不区分大小写字母。标号中除连字符-)外不能使用其他的标点符号。
// 级别最低的域名写在最左边而级别最高的域名写在最右边。由多个标号组成的完整域名总共不超过255个字符
const strFqdn = value.replace('$', '').trim()
// let fqdnPattern = /^(?=^.{3,255}$)[a-zA-Z0-9_][-a-zA-Z0-9_]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/
const fqdnPattern = /^(?=^.{3,255}$)[a-zA-Z0-9*]?[-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9*][-a-zA-Z0-9]{0,62})+[(com)|(cn)|(xin)|(net)|(top)|(xyz)|(wang)|(shop)|(site)|(club)|(cc)|(fun)|(online)|(biz)|(red)|(link)|(ltd)|(mobi)|(info)|(org)|(name)|(vip)|(pro)|(work)|(tv)|(co)|(kim)|(group)|(tech)|(store)|(ren)|(pub)|(ink)|(live)|(wiki)|(design)]$/
if (!fqdnPattern.test(strFqdn)) {
validate = false
}
}
const pattern = /^[*$]{1}[0-9a-zA-Z-._]{1,}$/
if (!pattern.test(value.trim())) {
validate = false
}
// 验证域名的合法 长度小于255
const domain = value.replace('*', '').replace('$', '').trim()
// 域名 长度小于255最多三级
if (domain.length > 255 || domain.length < 3) {
validate = false
}
// 域名不能以.或-或_结尾且.与.不能连续
if (domain.indexOf('..') > -1 || domain.substr(-1) === '.' || domain.substr(-1) === '-' || domain.substr(-1) === '_') {
validate = false
}
// 每个.之间字符不大于63
const split = domain.split('\\.')
split.forEach(item => {
if (item.length > 63) {
validate = false
}
})
} else {
validate = false
}
if (!validate) {
this.editTagErrorTip = rule.message
callback(new Error())
} }
} }
return validate return validate
@@ -298,18 +383,25 @@ export default {
editTagFormRules: { editTagFormRules: {
tagItem: [ tagItem: [
{ {
required: true, // required: true,
validator: requiredItemValidator,
message: this.$t('validate.required'), message: this.$t('validate.required'),
trigger: 'blur' trigger: 'blur'
}, },
{ {
validator: nameAndLabelValidator, validator: nameFormatValidator,
message: this.$t('validate.duplicateRecord'), message: this.$t('validate.wrongFormat'),
trigger: 'blur'
},
{
validator: nameAndLabelDuplicateValidator,
message: this.$t('validate.duplicateName'),
trigger: 'blur' trigger: 'blur'
} }
], ],
tagValue: [{ tagValue: [{
required: true, //required: true,
validator: requiredValueValidator,
message: this.$t('validate.required'), message: this.$t('validate.required'),
trigger: 'blur' trigger: 'blur'
}] }]
@@ -354,10 +446,14 @@ export default {
succeeded: originalImportedData.filter(d => d.status === 1).length, succeeded: originalImportedData.filter(d => d.status === 1).length,
failed: originalImportedData.filter(d => d.status !== 1).length failed: originalImportedData.filter(d => d.status !== 1).length
} }
this.isLoad = false
originalImportedData.sort((a, b) => b.status - a.status) originalImportedData.sort((a, b) => b.status - a.status)
this.importedData = originalImportedData this.importedData = originalImportedData
this.handleShowImportedData() this.handleShowImportedData()
this.addEditFlag = false
this.editTagErrorTip = ''
this.editIndex = -1
} else { } else {
this.uploadLoading = false this.uploadLoading = false
this.$message.error(this.$t('tip.uploadFailed', { msg: response.message })) this.$message.error(this.$t('tip.uploadFailed', { msg: response.message }))
@@ -373,6 +469,9 @@ export default {
succeeded: null, succeeded: null,
failed: null failed: null
} }
this.addEditFlag = false
this.editTagErrorTip = ''
this.editIndex = -1
}, },
beforeUpload (file) { beforeUpload (file) {
// 判断后缀,仅支持.csv // 判断后缀,仅支持.csv
@@ -394,6 +493,9 @@ export default {
this.typeSelectDisable = true this.typeSelectDisable = true
}, },
pageNo (val) { pageNo (val) {
if (val !== this.importedPageObj.pageNo) {
this.editTagErrorTip = ''
}
this.importedPageObj.pageNo = val this.importedPageObj.pageNo = val
this.editIndex = -1 this.editIndex = -1
}, },
@@ -405,14 +507,21 @@ export default {
this.importedPageObj.pageNo++ this.importedPageObj.pageNo++
this.editIndex = -1 this.editIndex = -1
}, },
removeImportedData (index) { removeImportedData (index) { // index 为记录在当前页的索引
this.editIndex = -1 // 取消编辑标识 this.editIndex = -1 // 取消编辑标识
this.addEditFlag = false // 取消新增标识 this.addEditFlag = false // 取消新增标识
this.editTagErrorTip = '' this.editTagErrorTip = ''
const toRemoveIndex = (this.importedPageObj.pageNo - 1) * this.importedPageObj.pageSize + index const toRemoveIndex = (this.importedPageObj.pageNo - 1) * this.importedPageObj.pageSize + index
this.importedData.splice(toRemoveIndex, 1) this.importedData.splice(toRemoveIndex, 1)
this.importedPageObj.total-- // 删除内容为空的新增记录
const lastIndex = this.importedData.length - 1
const lastData = this.importedData[lastIndex]
if (lastData.tagItem === '' && lastData.tagValue === '') {
this.importedData.pop()
}
// this.importedPageObj.total--
this.importedPageObj.total = this.importedData.length
this.handleShowImportedData() this.handleShowImportedData()
// 若删除后本页无数据则页码减1或者提示无数据 // 若删除后本页无数据则页码减1或者提示无数据
if (this.showImportedData.length === 0) { if (this.showImportedData.length === 0) {
@@ -447,7 +556,6 @@ export default {
} else { } else {
this.uploadErrorTip = '' this.uploadErrorTip = ''
} }
if (this.importedData.length === 0) { if (this.importedData.length === 0) {
this.previewErrorTip = this.$t('validate.required') this.previewErrorTip = this.$t('validate.required')
} else if (this.hasErrorImportedData()) { } else if (this.hasErrorImportedData()) {
@@ -456,81 +564,88 @@ export default {
this.previewErrorTip = '' this.previewErrorTip = ''
} }
if (valid) { if (valid) {
// 校验通过后组织数据、请求接口 this.$refs.editForm.validate((validImportData) => {
if (valid && !this.uploadErrorTip && !this.previewErrorTip) { if (validImportData) {
const postData = { // 校验通过后组织数据、请求接口
tagName: this.editObject.tagName, if (valid && !this.uploadErrorTip && !this.previewErrorTip) {
tagType: this.editObject.tagType, const postData = {
data: [] tagName: this.editObject.tagName,
} tagType: this.editObject.tagType,
// 避免点击新增后并没有保存新增项就点击了save此时删除新增的空白项 data: []
if (this.importedData[this.importedData.length - 1].tagItem === '') { }
this.importedData.pop() // 避免点击新增后并没有保存新增项就点击了save此时删除新增的空白项
} if (this.importedData[this.importedData.length - 1].tagItem === '') {
this.importedData.forEach(d => { this.importedData.pop()
const findData = postData.data.find(d2 => d2.tagValue === d.tagValue) }
if (findData) { this.importedData.forEach(d => {
findData.itemList.add(d.tagItem) const findData = postData.data.find(d2 => d2.tagValue === d.tagValue)
} else { if (findData) {
const set = new Set() findData.itemList.add(d.tagItem)
set.add(d.tagItem) } else {
postData.data.push({ const set = new Set()
tagValue: d.tagValue, set.add(d.tagItem)
itemList: set postData.data.push({
tagValue: d.tagValue,
itemList: set
})
}
}) })
postData.data.forEach(d => {
// d.itemList = [...d.itemList]
d.itemList = Array.from(d.itemList)
})
postData.remark = this.editObject.remark
if (!this.editObject.id) {
axios.post(this.url, postData).then(response => {
if (response.data.code === 200) {
this.$message({
duration: 2000,
type: 'success',
message: this.$t('tip.saveSuccess')
})
this.$router.push({
path: '/knowledgeBase',
t: +new Date()
})
} else {
this.errorMsgHandler(response)
}
}).catch(e => {
console.error(e)
this.errorMsgHandler(e)
}).finally(() => {
this.blockOperation.save = false
})
} else {
postData.id = this.editObject.id
axios.put(this.url, postData).then(response => {
if (response.data.code === 200) {
this.$message({
duration: 2000,
type: 'success',
message: this.$t('tip.saveSuccess')
})
this.$router.push({
path: '/knowledgeBase',
t: +new Date()
})
} else {
this.errorMsgHandler(response)
}
}).catch(e => {
console.error(e)
this.errorMsgHandler(e)
}).finally(() => {
this.blockOperation.save = false
})
}
} else {
this.blockOperation.save = false
} }
})
postData.data.forEach(d => {
d.itemList = [...d.itemList]
})
postData.remark = this.editObject.remark
if (!this.editObject.id) {
axios.post(this.url, postData).then(response => {
if (response.data.code === 200) {
this.$message({
duration: 2000,
type: 'success',
message: this.$t('tip.saveSuccess')
})
this.$router.push({
path: '/knowledgeBase',
t: +new Date()
})
} else {
this.errorMsgHandler(response)
}
}).catch(e => {
console.error(e)
this.errorMsgHandler(e)
}).finally(() => {
this.blockOperation.save = false
})
} else { } else {
postData.id = this.editObject.id this.blockOperation.save = false
axios.put(this.url, postData).then(response => {
if (response.data.code === 200) {
this.$message({
duration: 2000,
type: 'success',
message: this.$t('tip.saveSuccess')
})
this.$router.push({
path: '/knowledgeBase',
t: +new Date()
})
} else {
this.errorMsgHandler(response)
}
}).catch(e => {
console.error(e)
this.errorMsgHandler(e)
}).finally(() => {
this.blockOperation.save = false
})
} }
} else { })
this.blockOperation.save = false
}
} else { } else {
this.blockOperation.save = false this.blockOperation.save = false
} }
@@ -552,6 +667,10 @@ export default {
// 点击编辑时,如正处于新增状态,则去除新增项(此时新增并为保存,不必保留) // 点击编辑时,如正处于新增状态,则去除新增项(此时新增并为保存,不必保留)
if (this.addEditFlag) { if (this.addEditFlag) {
this.addEditFlag = false this.addEditFlag = false
const dataLen = this.importedData.length % this.importedPageObj.pageSize
if (dataLen === 1) {
this.importedPageObj.total--
}
this.importedData.pop() this.importedData.pop()
this.handleShowImportedData() this.handleShowImportedData()
} }
@@ -575,21 +694,21 @@ export default {
if (valid) { if (valid) {
this.showImportedData[index].tagItem = this.editTagForm.tagItem this.showImportedData[index].tagItem = this.editTagForm.tagItem
this.showImportedData[index].tagValue = this.editTagForm.tagValue this.showImportedData[index].tagValue = this.editTagForm.tagValue
this.showImportedData[index].status = 1
let num = -1 let num = -1
const findData = this.importedData.find((item, i) => { const findData = this.importedData.find((item, i) => {
num = i num = i
return item.tagItem === this.editTagForm.tagItem return (item.tagItem === this.editTagForm.tagItem && item.tagValue === this.editTagForm.tagValue)
}) })
if (!findData) { if (!findData) {
this.importedData[num].tagItem = this.editTagForm.tagItem this.importedData[num].tagItem = this.editTagForm.tagItem
this.importedData[num].tagValue = this.editTagForm.tagValue this.importedData[num].tagValue = this.editTagForm.tagValue
this.importedData[num].status = 1
} }
this.addEditFlag = false this.addEditFlag = false
this.editIndex = -1 this.editIndex = -1
this.backEditFlag = false this.backEditFlag = false
} else {
this.editTagErrorTip = this.$t('validate.duplicateNameOrWrongFormat')
} }
}) })
}, },
@@ -597,17 +716,18 @@ export default {
this.$refs.editForm.validate(valid => { this.$refs.editForm.validate(valid => {
if (valid) { if (valid) {
this.editTagErrorTip = '' this.editTagErrorTip = ''
} else {
this.editTagErrorTip = this.$t('validate.duplicateNameOrWrongFormat')
} }
}) })
}, },
addTagAtLast () { addTagAtLast () {
const total = this.importedPageObj.total this.editTagForm.tagItem = ''
this.editTagForm.tagValue = ''
// const total = this.importedPageObj.total
const total = this.importedData.length
this.addEditFlag = true this.addEditFlag = true
// 如果已经有新增空白项,则不再进行新增操作 // 如果已经有新增空白项,则不再进行新增操作
if (this.importedData[this.importedData.length - 1].tagItem !== '' && this.importedData[this.importedData.length - 1].tagValue !== '') { if (this.importedData.length === 0 ||
this.importedPageObj.total = this.importedPageObj.total + 1 this.importedData[this.importedData.length - 1].tagItem !== '' && this.importedData[this.importedData.length - 1].tagValue !== '') {
if (total > 0 && total < 10) { if (total > 0 && total < 10) {
this.importedData.push({ tagItem: '', tagValue: '', status: 1 }) this.importedData.push({ tagItem: '', tagValue: '', status: 1 })
this.showImportedData.push({ tagItem: '', tagValue: '', status: 1 }) this.showImportedData.push({ tagItem: '', tagValue: '', status: 1 })
@@ -617,10 +737,9 @@ export default {
this.importedData.push({ tagItem: '', tagValue: '', status: 1 }) this.importedData.push({ tagItem: '', tagValue: '', status: 1 })
this.showImportedData.push({ tagItem: '', tagValue: '', status: 1 }) this.showImportedData.push({ tagItem: '', tagValue: '', status: 1 })
} }
this.importedPageObj.total = this.importedData.length
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
this.editIndex = this.showImportedData.length - 1 this.editIndex = this.showImportedData.length - 1
this.editTagForm.tagItem = ''
this.editTagForm.tagValue = ''
}, 100) }, 100)
} }
} }
@@ -647,6 +766,7 @@ export default {
}, },
mounted () { mounted () {
if (this.knowledgeBaseId) { if (this.knowledgeBaseId) {
this.isLoad = true
axios.get(`${api.knowledgeBase}/${this.knowledgeBaseId}`).then(response => { axios.get(`${api.knowledgeBase}/${this.knowledgeBaseId}`).then(response => {
if (response.data.code === 200) { if (response.data.code === 200) {
if (!response.data.data) { if (!response.data.data) {
@@ -702,6 +822,15 @@ export default {
importedData (n) { importedData (n) {
this.importedPageObj.total = n.length this.importedPageObj.total = n.length
}, },
addEditFlag (n) {
if (!n) {
const lastIndex = this.importedData.length - 1
const lastData = this.importedData[lastIndex]
if (lastData && lastData.tagItem === '' && lastData.tagValue === '') {
this.importedData.pop()
}
}
},
'importedPageObj.pageNo': { 'importedPageObj.pageNo': {
handler (n) { handler (n) {
this.handleShowImportedData() this.handleShowImportedData()
@@ -783,9 +912,11 @@ export default {
tagValue: '' // 待编辑的label tagValue: '' // 待编辑的label
}) })
const isLoad = ref(false)
return { return {
knowledgeBaseId, knowledgeBaseId,
editObject, editObject,
isLoad,
tagNameFirstBlur: ref(false), tagNameFirstBlur: ref(false),
blankObject, blankObject,
activeCollapses, activeCollapses,
@@ -859,14 +990,17 @@ export default {
font-size: 14px; font-size: 14px;
margin: 0 7px; margin: 0 7px;
color: #666; color: #666;
cursor: pointer;
} }
.imported-data-back { .imported-data-back {
color: #cbcbcb; color: #666;
cursor: pointer;
} }
.imported-data-save { .imported-data-save {
color: #38ACD2; color: #38ACD2;
cursor: pointer;
} }
.addTagBtn { .addTagBtn {