2023-02-24 18:51:17 +08:00
|
|
|
|
<template>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
<div class="edit-knowledge-base">
|
2023-03-23 16:13:55 +08:00
|
|
|
|
<loading :loading="initLoading"></loading>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<div class="edit-knowledge-base__header">{{ editObject.id ? $t('overall.edit') : $t('overall.create') }}</div>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
<div class="edit-knowledge-base__body">
|
|
|
|
|
|
<el-steps direction="vertical" :active="activeStep">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<el-step v-for="(height, index) in stepHeights" :style="`flex-basis: ${height}px; flex-shrink: 0;`"
|
|
|
|
|
|
:key="index"></el-step>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</el-steps>
|
|
|
|
|
|
<el-collapse v-model="activeCollapses">
|
|
|
|
|
|
<el-collapse-item name="0">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<template #title>
|
|
|
|
|
|
<div class="form-sub-title">{{ $t('knowledgeBase.editInformation') }}</div>
|
|
|
|
|
|
</template>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
<el-form :model="editObject" label-position="top" ref="form" :rules="rules">
|
|
|
|
|
|
<!--name-->
|
|
|
|
|
|
<el-form-item :label="$t('config.roles.name')" prop="tagName">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<el-input class="form-input" maxlength="64" placeholder="" :disabled="!!editObject.id" show-word-limit
|
|
|
|
|
|
size="mini" type="text" v-model="editObject.tagName" @blur="tagNameBlur"></el-input>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item :label="$t('overall.type')" prop="tagType">
|
|
|
|
|
|
<el-select v-model="editObject.tagType"
|
|
|
|
|
|
class="form-select"
|
|
|
|
|
|
placeholder=" "
|
|
|
|
|
|
popper-class="form-select-popper"
|
2023-03-05 13:50:22 +08:00
|
|
|
|
:disabled="!!editObject.id || typeSelectDisable"
|
2023-03-02 20:37:21 +08:00
|
|
|
|
size="mini"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template v-for="type in knowledgeBaseType" :key="type.name">
|
|
|
|
|
|
<el-option :label="type.name" :value="type.value"></el-option>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
2023-03-07 18:48:15 +08:00
|
|
|
|
<el-form-item :label="$t('overall.remark')" prop="remark">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<el-input maxlength="255" show-word-limit :rows="4" size='mini' type="textarea"
|
|
|
|
|
|
v-model="editObject.remark" id="role-box-input-remark"/>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
</el-collapse-item>
|
|
|
|
|
|
<el-collapse-item name="1" class="upload-collapse">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<template #title>
|
|
|
|
|
|
<div class="form-sub-title">{{ $t('overall.importFromFile') }}</div>
|
|
|
|
|
|
</template>
|
2023-03-06 20:16:31 +08:00
|
|
|
|
<loading :loading="uploadLoading"></loading>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
<el-upload :action="`${baseUrl}knowledge/import`"
|
|
|
|
|
|
:headers="uploadHeaders"
|
|
|
|
|
|
:data="uploadParams"
|
|
|
|
|
|
:multiple="false"
|
|
|
|
|
|
:file-list="fileList"
|
|
|
|
|
|
:on-change="fileChange"
|
|
|
|
|
|
:on-success="uploadSuccess"
|
2023-03-05 13:50:22 +08:00
|
|
|
|
:on-remove="onRemove"
|
2023-03-06 20:16:31 +08:00
|
|
|
|
:before-upload="beforeUpload"
|
|
|
|
|
|
:on-progress="onUpload"
|
2023-03-08 17:35:22 +08:00
|
|
|
|
:on-error="uploadError"
|
2023-03-02 20:37:21 +08:00
|
|
|
|
:class="uploadErrorTip ? 'el-upload--error' : ''"
|
|
|
|
|
|
drag
|
2023-03-08 17:35:22 +08:00
|
|
|
|
:accept="fileTypeLimit"
|
2023-03-02 20:37:21 +08:00
|
|
|
|
ref="upload"
|
|
|
|
|
|
>
|
|
|
|
|
|
<i class="el-icon-upload"></i>
|
|
|
|
|
|
<div class="el-upload__text">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<div>{{ $t('knowledgeBase.dropFileHereOr') }}<em>{{ $t('knowledgeBase.clickToUpload') }}</em></div>
|
|
|
|
|
|
<div class="upload-tip">{{ $t('knowledgeBase.supportCsv') }}</div>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
<transition name="el-zoom-in-top">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<div class="upload-error-tip" v-if="uploadErrorTip">{{ uploadErrorTip }}</div>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</transition>
|
|
|
|
|
|
</el-collapse-item>
|
|
|
|
|
|
<el-collapse-item name="2">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<template #title>
|
|
|
|
|
|
<div class="form-sub-title">{{ $t('overall.preview') }}</div>
|
|
|
|
|
|
</template>
|
2023-03-23 16:13:55 +08:00
|
|
|
|
<div class="skeleton-border" v-if="!uploaded && !editObject.id">
|
2023-03-02 20:37:21 +08:00
|
|
|
|
<el-skeleton>
|
|
|
|
|
|
<template #template>
|
|
|
|
|
|
<div v-for="item of 6" :key="item" class="skeleton-item-row">
|
|
|
|
|
|
<el-skeleton-item variant="text" style="width: calc(33% - 25px); margin-right: 38px;"/>
|
|
|
|
|
|
<el-skeleton-item variant="text" style="width: calc(33% - 25px); margin-right: 38px;"/>
|
|
|
|
|
|
<el-skeleton-item variant="text" style="width: calc(33% - 26px);"/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-skeleton>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<div class="skeleton-tip">{{ $t('knowledgeBase.skeletonTip') }}</div>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</div>
|
2023-03-23 16:13:55 +08:00
|
|
|
|
<template v-else>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
<div class="imported-tip"><i class="cn-icon cn-icon-baocuo"/>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
{{
|
|
|
|
|
|
$t('knowledgeBase.importTip', {
|
|
|
|
|
|
total: originalImportInfo.total,
|
|
|
|
|
|
succeeded: originalImportInfo.succeeded,
|
|
|
|
|
|
failed: originalImportInfo.failed
|
|
|
|
|
|
})
|
|
|
|
|
|
}}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="imported-table-box" :class="previewErrorTip ? 'imported-table-box--error' : ''">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<el-form ref="editForm" :model="editTagForm" :rules="editTagFormRules">
|
|
|
|
|
|
<table class="imported-table" v-if="!importedDataNoData">
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<th width="230">{{ importedTableFirstColumn }}</th>
|
|
|
|
|
|
<th width="180">Label</th>
|
|
|
|
|
|
<th v-if="!editObject.id">{{ $t('overall.import') }}</th>
|
|
|
|
|
|
<th width="16"></th>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<tr v-for="(d, i) in showImportedData" :key="importedType + d.tagItem + d.tagValue + i">
|
|
|
|
|
|
<td class="imported-data-item" :title="d.tagItem">
|
|
|
|
|
|
<el-form-item v-if="editObject.id && editIndex === i" prop="tagItem">
|
|
|
|
|
|
<span class="imported-data-item-edit__input">
|
|
|
|
|
|
<el-input v-model="editTagForm.tagItem" @blur="onBlurTagItem"></el-input>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<span v-else>{{ d.tagItem }}</span>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="imported-data-value" :title="d.tagValue">
|
|
|
|
|
|
<el-form-item v-if="editObject.id && editIndex === i" prop="tagValue">
|
|
|
|
|
|
<span class="imported-data-item-edit__input">
|
|
|
|
|
|
<el-input v-model="editTagForm.tagValue" @blur="onBlurTagItem"></el-input>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<span v-else>{{ d.tagValue }}</span>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td v-if="!editObject.id" class="imported-data-msg" :title="d.msg">
|
|
|
|
|
|
<i :class="d.status === 1 ? 'el-icon-success' : 'el-icon-error'"></i> {{ d.msg }}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td v-else></td>
|
|
|
|
|
|
<!--返回和保存按钮-->
|
|
|
|
|
|
<td v-if="editObject.id && backEditFlag && editIndex === i" class="imported-data-btn">
|
|
|
|
|
|
<i v-if="editObject.id" class="cn-icon cn-icon-revoke imported-data-left-btn imported-data-back"
|
|
|
|
|
|
@click="backImportedData"></i>
|
|
|
|
|
|
<i class="cn-icon cn-icon-save imported-data-save" @click="saveImportedData(i)"></i>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<!--保存和删除按钮-->
|
|
|
|
|
|
<td v-else-if="editObject.id && addEditFlag && editIndex === i" class="imported-data-btn">
|
|
|
|
|
|
<i class="cn-icon cn-icon-save imported-data-save" style="margin: 0 7px"
|
|
|
|
|
|
@click="saveImportedData(i)"></i>
|
|
|
|
|
|
<i class="el-icon-close" @click="removeImportedData(i)"></i>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<!--编辑和删除按钮-->
|
|
|
|
|
|
<td v-else class="imported-data-btn">
|
|
|
|
|
|
<i v-if="editObject.id" class="cn-icon cn-icon-edit1 imported-data-left-btn"
|
|
|
|
|
|
@click="editImportedData(i)"></i>
|
|
|
|
|
|
<i class="el-icon-close" @click="removeImportedData(i)"></i>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
<chart-no-data v-else></chart-no-data>
|
|
|
|
|
|
</el-form>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
<Pagination
|
|
|
|
|
|
class="imported-pagination"
|
2023-03-31 17:50:38 +08:00
|
|
|
|
:style="{'bottom': editObject.id ? '48px' : '0'}"
|
2023-03-02 20:37:21 +08:00
|
|
|
|
:page-obj="importedPageObj"
|
|
|
|
|
|
:store-page-no-on-url="false"
|
|
|
|
|
|
layout="prev,pager,next"
|
|
|
|
|
|
@pageNo='pageNo'
|
|
|
|
|
|
@prev-click="prev"
|
|
|
|
|
|
@next-click="next"
|
|
|
|
|
|
></Pagination>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<!--新增按钮-->
|
|
|
|
|
|
<el-button v-if="editObject.id" class="addTagBtn" :disabled="addEditFlag" @click="addTagAtLast">
|
|
|
|
|
|
<i class="cn-icon cn-icon-add add-tag-btn" :style="{'color': addEditFlag ? '#C0C4CC' : '#575757'}"></i>
|
|
|
|
|
|
Add
|
|
|
|
|
|
</el-button>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<transition name="el-zoom-in-top">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<div class="preview-error-tip" v-if="previewErrorTip">{{ previewErrorTip }}</div>
|
|
|
|
|
|
<div class="preview-error-tip" v-else-if="editTagErrorTip">{{ editTagErrorTip }}</div>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</transition>
|
2023-03-23 16:13:55 +08:00
|
|
|
|
</template>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</el-collapse-item>
|
|
|
|
|
|
</el-collapse>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="edit-knowledge-base__footer">
|
2023-03-06 20:16:31 +08:00
|
|
|
|
<button class="footer__btn footer__btn--light" @click="cancel">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<span>{{ $t('overall.cancel') }}</span>
|
2023-03-06 20:16:31 +08:00
|
|
|
|
</button>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<button style="position: relative;" :class="{'footer__btn--disabled': blockOperation.save}"
|
|
|
|
|
|
:disabled="blockOperation.save" class="footer__btn" @click="save">
|
2023-03-06 20:16:31 +08:00
|
|
|
|
<loading size="small" :loading="blockOperation.save"></loading>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<span>{{ $t('overall.save') }}</span>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2023-02-24 18:51:17 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import { useRoute } from 'vue-router'
|
2023-03-31 17:50:38 +08:00
|
|
|
|
import { ref, nextTick, reactive } from 'vue'
|
2023-02-24 18:51:17 +08:00
|
|
|
|
import _ from 'lodash'
|
2023-03-06 20:16:31 +08:00
|
|
|
|
import { knowledgeBaseType, storageKey, unitTypes } from '@/utils/constants'
|
2023-03-02 20:37:21 +08:00
|
|
|
|
import Pagination from '@/components/common/Pagination'
|
|
|
|
|
|
import ChartNoData from '@/views/charts/charts/ChartNoData'
|
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
import { api } from '@/utils/api'
|
2023-03-06 20:16:31 +08:00
|
|
|
|
import unitConvert from '@/utils/unit-convert'
|
|
|
|
|
|
import Loading from '@/components/common/Loading'
|
2023-03-23 16:13:55 +08:00
|
|
|
|
|
2023-02-24 18:51:17 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'CreateKnowledgeBase',
|
2023-03-02 20:37:21 +08:00
|
|
|
|
components: {
|
|
|
|
|
|
Pagination,
|
2023-03-06 20:16:31 +08:00
|
|
|
|
ChartNoData,
|
|
|
|
|
|
Loading
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
2023-03-08 17:35:22 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
const nameValidator = (rule, value, callback) => {
|
|
|
|
|
|
let validate = true
|
|
|
|
|
|
// /^[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEFA-Za-z0-9\-\_]*$/
|
|
|
|
|
|
const reg = /^[\u4e00-\u9fa5A-Za-z0-9\-\_]*$/
|
|
|
|
|
|
validate = reg.test(value)
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
|
|
|
|
|
const nameAndTypeValidator = async (rule, value, callback) => {
|
|
|
|
|
|
let validate = true
|
2023-03-23 16:13:55 +08:00
|
|
|
|
if (!this.editObject.id) {
|
|
|
|
|
|
this.$refs.form.clearValidate('tagType')
|
|
|
|
|
|
const response = await this.getKnowledgeBaseList()
|
|
|
|
|
|
if (response.data.code === 200) {
|
|
|
|
|
|
const find = response.data.data.list.find(d => d.tagName === value && d.tagType === this.editObject.tagType)
|
|
|
|
|
|
if (find) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
2023-03-08 17:35:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
|
|
|
|
|
const typeAndNameValidator = async (rule, value, callback) => {
|
|
|
|
|
|
let validate = true
|
2023-03-23 16:13:55 +08:00
|
|
|
|
if (!this.editObject.id) {
|
|
|
|
|
|
this.$refs.form.clearValidate('tagName')
|
|
|
|
|
|
const response = await this.getKnowledgeBaseList()
|
|
|
|
|
|
if (response.data.code === 200) {
|
|
|
|
|
|
const find = response.data.data.list.find(d => d.tagName === this.editObject.tagName && d.tagType === value)
|
|
|
|
|
|
if (find) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
2023-03-08 17:35:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
|
|
|
|
|
const nameAndLabelValidator = (rule, value, callback) => {
|
|
|
|
|
|
let validate = true
|
|
|
|
|
|
let index = -1 // 当前编辑的键值index
|
|
|
|
|
|
// todo 查看是否重名前,需要对名称进行校验,分别是IP、domain、APP的校验
|
|
|
|
|
|
const findData = this.importedData.find((item, i) => {
|
|
|
|
|
|
index = i
|
|
|
|
|
|
return item.tagItem === this.editTagForm.tagItem
|
|
|
|
|
|
})
|
|
|
|
|
|
if (findData) {
|
|
|
|
|
|
// 如果name重复的第一个键值不是当前编辑item的index,即代表后续有重名的项了,提示重名
|
|
|
|
|
|
if (index !== this.editIndex) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
callback(new Error())
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 此情况为,仅修改label,不修改name
|
|
|
|
|
|
if (findData.tagValue === this.editTagForm.tagValue) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
2023-03-08 17:35:22 +08:00
|
|
|
|
return {
|
|
|
|
|
|
rules: {
|
|
|
|
|
|
tagName: [
|
2023-03-31 17:50:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: this.$t('validate.required'),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: nameValidator,
|
|
|
|
|
|
message: this.$t('validate.onlyAllowNumberLetterChinese-_'),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: nameAndTypeValidator,
|
|
|
|
|
|
message: this.$t('validate.duplicateRecord', { columns: '(' + this.$t('config.roles.name') + '+' + this.$t('overall.type') + ')' }),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
}
|
2023-03-08 17:35:22 +08:00
|
|
|
|
],
|
|
|
|
|
|
tagType: [
|
2023-03-31 17:50:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: this.$t('validate.required'),
|
|
|
|
|
|
trigger: 'change'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: typeAndNameValidator,
|
|
|
|
|
|
message: this.$t('validate.duplicateRecord', { columns: '(' + this.$t('config.roles.name') + '+' + this.$t('overall.type') + ')' }),
|
|
|
|
|
|
trigger: 'change'
|
|
|
|
|
|
}
|
2023-03-08 17:35:22 +08:00
|
|
|
|
]
|
2023-03-31 17:50:38 +08:00
|
|
|
|
},
|
|
|
|
|
|
editTagFormRules: {
|
|
|
|
|
|
tagItem: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: this.$t('validate.required'),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: nameAndLabelValidator,
|
|
|
|
|
|
message: this.$t('validate.duplicateRecord'),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
tagValue: [{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: this.$t('validate.required'),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
}]
|
|
|
|
|
|
},
|
|
|
|
|
|
editIndex: -1,
|
|
|
|
|
|
backEditFlag: false,
|
|
|
|
|
|
addEditFlag: false,
|
|
|
|
|
|
editTagErrorTip: '', // 编辑错误提示
|
|
|
|
|
|
timer: null
|
2023-03-08 17:35:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-02-24 18:51:17 +08:00
|
|
|
|
methods: {
|
2023-03-09 15:20:59 +08:00
|
|
|
|
tagNameBlur () {
|
|
|
|
|
|
if (!this.tagNameFirstBlur) {
|
|
|
|
|
|
this.$refs.form.validate(valid => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
this.tagNameFirstBlur = true
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-02 20:37:21 +08:00
|
|
|
|
fileChange (files, fileList) {
|
|
|
|
|
|
this.fileList = fileList.slice(-1)
|
|
|
|
|
|
},
|
2023-03-08 17:35:22 +08:00
|
|
|
|
uploadError () {
|
|
|
|
|
|
this.uploadLoading = false
|
|
|
|
|
|
this.$message.error(this.$t('tip.uploadFailed', { msg: 'error' }))
|
|
|
|
|
|
},
|
2023-03-02 20:37:21 +08:00
|
|
|
|
uploadSuccess (response) {
|
|
|
|
|
|
this.uploaded = response.code === 200
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
// 上传成功后去掉upload和preview的错误提示
|
|
|
|
|
|
this.uploadErrorTip = ''
|
|
|
|
|
|
this.previewErrorTip = ''
|
|
|
|
|
|
|
|
|
|
|
|
this.importedType = this.editObject.tagType
|
2023-03-23 16:13:55 +08:00
|
|
|
|
|
2023-03-07 18:48:15 +08:00
|
|
|
|
const originalImportedData = _.cloneDeep(response.data.data)
|
|
|
|
|
|
this.importedDataNoData = originalImportedData.length === 0
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.originalImportInfo = {
|
|
|
|
|
|
total: originalImportedData.length,
|
|
|
|
|
|
succeeded: originalImportedData.filter(d => d.status === 1).length,
|
|
|
|
|
|
failed: originalImportedData.filter(d => d.status !== 1).length
|
|
|
|
|
|
}
|
|
|
|
|
|
originalImportedData.sort((a, b) => b.status - a.status)
|
|
|
|
|
|
this.importedData = originalImportedData
|
2023-03-23 16:13:55 +08:00
|
|
|
|
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.handleShowImportedData()
|
2023-03-06 20:16:31 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.uploadLoading = false
|
|
|
|
|
|
this.$message.error(this.$t('tip.uploadFailed', { msg: response.message }))
|
2023-03-02 20:37:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-05 13:50:22 +08:00
|
|
|
|
onRemove (files, fileList) {
|
|
|
|
|
|
this.uploaded = false
|
|
|
|
|
|
this.typeSelectDisable = false
|
|
|
|
|
|
this.importedData = []
|
|
|
|
|
|
this.showImportedData = []
|
|
|
|
|
|
this.originalImportInfo = {
|
|
|
|
|
|
total: null,
|
|
|
|
|
|
succeeded: null,
|
|
|
|
|
|
failed: null
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-06 20:16:31 +08:00
|
|
|
|
beforeUpload (file) {
|
2023-03-08 17:35:22 +08:00
|
|
|
|
// 判断后缀,仅支持.csv
|
|
|
|
|
|
if (!_.endsWith(file.name, '.csv')) {
|
|
|
|
|
|
this.$message.error(this.$t('validate.fileTypeLimit', { types: this.fileTypeLimit }))
|
|
|
|
|
|
this.fileList = []
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
2023-03-06 20:16:31 +08:00
|
|
|
|
// 判断文件大小
|
|
|
|
|
|
if (file.size > this.uploadFileSizeLimit) {
|
|
|
|
|
|
this.$message.error(this.$t('validate.fileSizeLimit', { size: unitConvert(this.uploadFileSizeLimit, unitTypes.byte).join('') }))
|
|
|
|
|
|
this.fileList = []
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
return true
|
|
|
|
|
|
},
|
|
|
|
|
|
onUpload (event, file) {
|
|
|
|
|
|
this.uploadLoading = true
|
2023-03-07 18:48:15 +08:00
|
|
|
|
this.typeSelectDisable = true
|
2023-03-06 20:16:31 +08:00
|
|
|
|
},
|
2023-03-02 20:37:21 +08:00
|
|
|
|
pageNo (val) {
|
|
|
|
|
|
this.importedPageObj.pageNo = val
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = -1
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
|
|
|
|
|
prev () {
|
|
|
|
|
|
this.importedPageObj.pageNo--
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = -1
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
|
|
|
|
|
next () {
|
|
|
|
|
|
this.importedPageObj.pageNo++
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = -1
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
2023-03-07 18:48:15 +08:00
|
|
|
|
removeImportedData (index) {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = -1 // 取消编辑标识
|
|
|
|
|
|
this.addEditFlag = false // 取消新增标识
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
|
2023-03-07 18:48:15 +08:00
|
|
|
|
const toRemoveIndex = (this.importedPageObj.pageNo - 1) * this.importedPageObj.pageSize + index
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.importedData.splice(toRemoveIndex, 1)
|
2023-03-08 18:10:55 +08:00
|
|
|
|
this.importedPageObj.total--
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.handleShowImportedData()
|
|
|
|
|
|
// 若删除后本页无数据,则页码减1,或者提示无数据
|
|
|
|
|
|
if (this.showImportedData.length === 0) {
|
|
|
|
|
|
if (this.importedData.length > 0) {
|
|
|
|
|
|
this.importedPageObj.pageNo--
|
|
|
|
|
|
this.handleShowImportedData()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.importedDataNoData = true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 删除后若有错误提示且列表中不再有错误项,则清空错误提示
|
|
|
|
|
|
if (!this.hasErrorImportedData() && this.previewErrorTip) {
|
|
|
|
|
|
this.previewErrorTip = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-06 20:16:31 +08:00
|
|
|
|
cancel () {
|
2023-03-16 18:02:44 +08:00
|
|
|
|
this.$router.push({
|
|
|
|
|
|
path: '/knowledgeBase',
|
|
|
|
|
|
t: +new Date()
|
|
|
|
|
|
})
|
2023-03-06 20:16:31 +08:00
|
|
|
|
},
|
2023-03-02 20:37:21 +08:00
|
|
|
|
save () {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
if (this.blockOperation.save) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.blockOperation.save = true
|
|
|
|
|
|
// 校验form + upload + preview
|
|
|
|
|
|
this.$refs.form.validate(valid => {
|
2023-03-10 13:32:46 +08:00
|
|
|
|
this.$refs.form.validateField('tagName')
|
2023-03-23 16:13:55 +08:00
|
|
|
|
if (!this.uploaded && !this.editObject.id) {
|
2023-03-10 13:32:46 +08:00
|
|
|
|
this.uploadErrorTip = this.$t('validate.required')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.uploadErrorTip = ''
|
|
|
|
|
|
}
|
2023-03-10 13:13:27 +08:00
|
|
|
|
|
2023-03-10 13:32:46 +08:00
|
|
|
|
if (this.importedData.length === 0) {
|
|
|
|
|
|
this.previewErrorTip = this.$t('validate.required')
|
|
|
|
|
|
} else if (this.hasErrorImportedData()) {
|
|
|
|
|
|
this.previewErrorTip = this.$t('validate.pleaseCheckForErrorItem')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.previewErrorTip = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
if (valid) {
|
2023-03-10 13:13:27 +08:00
|
|
|
|
// 校验通过后组织数据、请求接口
|
|
|
|
|
|
if (valid && !this.uploadErrorTip && !this.previewErrorTip) {
|
|
|
|
|
|
const postData = {
|
|
|
|
|
|
tagName: this.editObject.tagName,
|
|
|
|
|
|
tagType: this.editObject.tagType,
|
|
|
|
|
|
data: []
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
// 避免点击新增后,并没有保存新增项就点击了save,此时删除新增的空白项
|
|
|
|
|
|
if (this.importedData[this.importedData.length - 1].tagItem === '') {
|
|
|
|
|
|
this.importedData.pop()
|
|
|
|
|
|
}
|
2023-03-10 13:13:27 +08:00
|
|
|
|
this.importedData.forEach(d => {
|
|
|
|
|
|
const findData = postData.data.find(d2 => d2.tagValue === d.tagValue)
|
|
|
|
|
|
if (findData) {
|
|
|
|
|
|
findData.itemList.add(d.tagItem)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const set = new Set()
|
|
|
|
|
|
set.add(d.tagItem)
|
|
|
|
|
|
postData.data.push({
|
|
|
|
|
|
tagValue: d.tagValue,
|
|
|
|
|
|
itemList: set
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
postData.data.forEach(d => {
|
|
|
|
|
|
d.itemList = [...d.itemList]
|
|
|
|
|
|
})
|
|
|
|
|
|
postData.remark = this.editObject.remark
|
2023-03-23 16:13:55 +08:00
|
|
|
|
if (!this.editObject.id) {
|
|
|
|
|
|
axios.post(this.url, postData).then(response => {
|
|
|
|
|
|
if (response.data.code === 200) {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
|
duration: 2000,
|
|
|
|
|
|
type: 'success',
|
|
|
|
|
|
message: this.$t('tip.saveSuccess')
|
|
|
|
|
|
})
|
2023-03-23 16:13:55 +08:00
|
|
|
|
this.$router.push({
|
|
|
|
|
|
path: '/knowledgeBase',
|
|
|
|
|
|
t: +new Date()
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2023-03-28 15:37:30 +08:00
|
|
|
|
this.errorMsgHandler(response)
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
|
console.error(e)
|
2023-03-28 15:37:30 +08:00
|
|
|
|
this.errorMsgHandler(e)
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
this.blockOperation.save = false
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
postData.id = this.editObject.id
|
|
|
|
|
|
axios.put(this.url, postData).then(response => {
|
|
|
|
|
|
if (response.data.code === 200) {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
|
duration: 2000,
|
|
|
|
|
|
type: 'success',
|
|
|
|
|
|
message: this.$t('tip.saveSuccess')
|
|
|
|
|
|
})
|
2023-03-23 16:13:55 +08:00
|
|
|
|
this.$router.push({
|
|
|
|
|
|
path: '/knowledgeBase',
|
|
|
|
|
|
t: +new Date()
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2023-03-28 15:37:30 +08:00
|
|
|
|
this.errorMsgHandler(response)
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
|
console.error(e)
|
2023-03-28 15:37:30 +08:00
|
|
|
|
this.errorMsgHandler(e)
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
this.blockOperation.save = false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2023-03-06 20:16:31 +08:00
|
|
|
|
} else {
|
2023-03-10 13:13:27 +08:00
|
|
|
|
this.blockOperation.save = false
|
2023-03-06 20:16:31 +08:00
|
|
|
|
}
|
2023-03-10 13:13:27 +08:00
|
|
|
|
} else {
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.blockOperation.save = false
|
2023-03-10 13:13:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
|
|
|
|
|
hasErrorImportedData () {
|
|
|
|
|
|
return this.importedData.filter(d => d.status !== 1).length > 0
|
2023-03-08 17:35:22 +08:00
|
|
|
|
},
|
|
|
|
|
|
async getKnowledgeBaseList () {
|
2023-03-28 15:37:30 +08:00
|
|
|
|
return await axios.get(this.url, { params: { pageSize: 999 } }).catch(e => {
|
|
|
|
|
|
console.error(e)
|
|
|
|
|
|
this.errorMsgHandler(e)
|
|
|
|
|
|
})
|
2023-03-31 17:50:38 +08:00
|
|
|
|
},
|
|
|
|
|
|
editImportedData (index) {
|
|
|
|
|
|
this.editTagForm.tagItem = this.showImportedData[index].tagItem
|
|
|
|
|
|
this.editTagForm.tagValue = this.showImportedData[index].tagValue
|
|
|
|
|
|
|
|
|
|
|
|
// 点击编辑时,如正处于新增状态,则去除新增项(此时新增并为保存,不必保留)
|
|
|
|
|
|
if (this.addEditFlag) {
|
|
|
|
|
|
this.addEditFlag = false
|
|
|
|
|
|
this.importedData.pop()
|
|
|
|
|
|
this.handleShowImportedData()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.editIndex = index
|
|
|
|
|
|
this.backEditFlag = true
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
},
|
|
|
|
|
|
backImportedData () {
|
|
|
|
|
|
this.editTagForm = reactive({
|
|
|
|
|
|
tagItem: '',
|
|
|
|
|
|
tagValue: ''
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
this.editIndex = -1
|
|
|
|
|
|
this.backEditFlag = false
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
},
|
|
|
|
|
|
saveImportedData (index) {
|
|
|
|
|
|
this.$refs.editForm.validate(valid => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
this.showImportedData[index].tagItem = this.editTagForm.tagItem
|
|
|
|
|
|
this.showImportedData[index].tagValue = this.editTagForm.tagValue
|
|
|
|
|
|
let num = -1
|
|
|
|
|
|
const findData = this.importedData.find((item, i) => {
|
|
|
|
|
|
num = i
|
|
|
|
|
|
return item.tagItem === this.editTagForm.tagItem
|
|
|
|
|
|
})
|
|
|
|
|
|
if (!findData) {
|
|
|
|
|
|
this.importedData[num].tagItem = this.editTagForm.tagItem
|
|
|
|
|
|
this.importedData[num].tagValue = this.editTagForm.tagValue
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.addEditFlag = false
|
|
|
|
|
|
this.editIndex = -1
|
|
|
|
|
|
this.backEditFlag = false
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.editTagErrorTip = this.$t('validate.duplicateNameOrWrongFormat')
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
onBlurTagItem () {
|
|
|
|
|
|
this.$refs.editForm.validate(valid => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.editTagErrorTip = this.$t('validate.duplicateNameOrWrongFormat')
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
addTagAtLast () {
|
|
|
|
|
|
const total = this.importedPageObj.total
|
|
|
|
|
|
this.addEditFlag = true
|
|
|
|
|
|
// 如果已经有新增空白项,则不再进行新增操作
|
|
|
|
|
|
if (this.importedData[this.importedData.length - 1].tagItem !== '' && this.importedData[this.importedData.length - 1].tagValue !== '') {
|
|
|
|
|
|
this.importedPageObj.total = this.importedPageObj.total + 1
|
|
|
|
|
|
if (total > 0 && total < 10) {
|
|
|
|
|
|
this.importedData.push({ tagItem: '', tagValue: '', status: 1 })
|
|
|
|
|
|
this.showImportedData.push({ tagItem: '', tagValue: '', status: 1 })
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const lastPageSize = Math.ceil((total + 1) / 10)
|
|
|
|
|
|
this.pageNo(lastPageSize)
|
|
|
|
|
|
this.importedData.push({ tagItem: '', tagValue: '', status: 1 })
|
|
|
|
|
|
this.showImportedData.push({ tagItem: '', tagValue: '', status: 1 })
|
|
|
|
|
|
}
|
|
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
|
this.editIndex = this.showImportedData.length - 1
|
|
|
|
|
|
this.editTagForm.tagItem = ''
|
|
|
|
|
|
this.editTagForm.tagValue = ''
|
|
|
|
|
|
}, 100)
|
|
|
|
|
|
}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
uploadParams () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
type: this.editObject.tagType
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
importedTableFirstColumn () {
|
|
|
|
|
|
const t = this.knowledgeBaseType.find(t => t.value === this.importedType)
|
|
|
|
|
|
return t ? t.name : ''
|
2023-03-09 15:20:59 +08:00
|
|
|
|
},
|
|
|
|
|
|
activeStep () {
|
2023-03-23 16:13:55 +08:00
|
|
|
|
if (this.editObject.id) {
|
|
|
|
|
|
return 2
|
|
|
|
|
|
} else if (this.tagNameFirstBlur) {
|
2023-03-09 15:20:59 +08:00
|
|
|
|
return this.uploaded ? 2 : 1
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-23 16:13:55 +08:00
|
|
|
|
mounted () {
|
|
|
|
|
|
if (this.knowledgeBaseId) {
|
|
|
|
|
|
axios.get(`${api.knowledgeBase}/${this.knowledgeBaseId}`).then(response => {
|
|
|
|
|
|
if (response.data.code === 200) {
|
2023-03-23 18:08:37 +08:00
|
|
|
|
if (!response.data.data) {
|
|
|
|
|
|
throw new Error('No data found, id: ' + this.knowledgeBaseId)
|
|
|
|
|
|
}
|
2023-03-23 16:13:55 +08:00
|
|
|
|
this.editObject = response.data.data
|
|
|
|
|
|
this.importedData = this.revertImportedData(this.editObject.data)
|
|
|
|
|
|
this.handleShowImportedData()
|
|
|
|
|
|
this.originalImportInfo = {
|
|
|
|
|
|
total: this.importedData.length,
|
|
|
|
|
|
succeeded: this.importedData.length,
|
|
|
|
|
|
failed: 0
|
|
|
|
|
|
}
|
|
|
|
|
|
this.importedPageObj.total = this.importedData.length
|
|
|
|
|
|
this.importedType = this.editObject.tagType
|
|
|
|
|
|
this.initLoading = false
|
2023-03-28 15:37:30 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.errorMsgHandler(response)
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
|
console.error(e)
|
2023-03-28 15:37:30 +08:00
|
|
|
|
this.errorMsgHandler(e)
|
2023-03-23 16:13:55 +08:00
|
|
|
|
this.$router.push({
|
|
|
|
|
|
path: '/knowledgeBase',
|
|
|
|
|
|
t: +new Date()
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-02 20:37:21 +08:00
|
|
|
|
watch: {
|
|
|
|
|
|
activeCollapses (n) {
|
|
|
|
|
|
const index0 = n.indexOf('0')
|
|
|
|
|
|
const index1 = n.indexOf('1')
|
|
|
|
|
|
if (index0 > -1) {
|
|
|
|
|
|
if (this.stepHeights[0] === this.stepHeightConstant.collapse) {
|
|
|
|
|
|
this.stepHeights.splice(0, 1, this.stepHeightConstant.first)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (this.stepHeights[0] === this.stepHeightConstant.first) {
|
|
|
|
|
|
this.stepHeights.splice(0, 1, this.stepHeightConstant.collapse)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (index1 > -1) {
|
|
|
|
|
|
if (this.stepHeights[1] === this.stepHeightConstant.collapse) {
|
|
|
|
|
|
this.stepHeights.splice(1, 1, this.stepHeightConstant.second)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (this.stepHeights[1] === this.stepHeightConstant.second) {
|
|
|
|
|
|
this.stepHeights.splice(1, 1, this.stepHeightConstant.collapse)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
importedData (n) {
|
|
|
|
|
|
this.importedPageObj.total = n.length
|
|
|
|
|
|
},
|
|
|
|
|
|
'importedPageObj.pageNo': {
|
|
|
|
|
|
handler (n) {
|
|
|
|
|
|
this.handleShowImportedData()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-24 18:51:17 +08:00
|
|
|
|
},
|
|
|
|
|
|
setup () {
|
|
|
|
|
|
const { query } = useRoute()
|
2023-03-23 16:13:55 +08:00
|
|
|
|
const knowledgeBaseId = query.id || ''
|
2023-03-08 17:35:22 +08:00
|
|
|
|
const url = api.knowledgeBase
|
2023-02-24 18:51:17 +08:00
|
|
|
|
// 空白对象
|
|
|
|
|
|
const blankObject = {
|
|
|
|
|
|
tagName: '',
|
|
|
|
|
|
buildIn: '',
|
|
|
|
|
|
id: '',
|
2023-03-02 20:37:21 +08:00
|
|
|
|
tagType: 'ip',
|
2023-02-24 18:51:17 +08:00
|
|
|
|
remark: '',
|
|
|
|
|
|
updateTime: ''
|
|
|
|
|
|
}
|
2023-03-23 16:13:55 +08:00
|
|
|
|
/* 将组织后的数据还原拉平 */
|
|
|
|
|
|
const revertImportedData = (data) => {
|
|
|
|
|
|
const importedData = []
|
|
|
|
|
|
data.forEach(d => {
|
|
|
|
|
|
d.itemList.forEach(item => {
|
|
|
|
|
|
importedData.push({
|
|
|
|
|
|
tagItem: item,
|
|
|
|
|
|
tagValue: d.tagValue,
|
|
|
|
|
|
status: 1
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
return importedData
|
|
|
|
|
|
}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
// form绑定的对象
|
2023-02-24 18:51:17 +08:00
|
|
|
|
const editObject = ref(_.cloneDeep(blankObject))
|
2023-03-02 20:37:21 +08:00
|
|
|
|
// 所有导入的数据
|
|
|
|
|
|
const importedData = ref([])
|
|
|
|
|
|
// 导入数据的原始数量信息
|
|
|
|
|
|
const originalImportInfo = ref({
|
|
|
|
|
|
total: null,
|
|
|
|
|
|
succeeded: null,
|
|
|
|
|
|
failed: null
|
|
|
|
|
|
})
|
|
|
|
|
|
// table中显示的导入的数据
|
|
|
|
|
|
const showImportedData = ref([])
|
2023-03-23 16:13:55 +08:00
|
|
|
|
// table分页对象
|
2023-03-02 20:37:21 +08:00
|
|
|
|
const importedPageObj = ref({
|
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
|
total: null
|
|
|
|
|
|
})
|
|
|
|
|
|
const importedType = ref('')
|
2023-03-23 16:13:55 +08:00
|
|
|
|
const uploadLoading = ref(false)
|
|
|
|
|
|
const initLoading = ref(!!knowledgeBaseId)
|
|
|
|
|
|
const handleShowImportedData = async () => {
|
|
|
|
|
|
const startIndex = (importedPageObj.value.pageNo - 1) * importedPageObj.value.pageSize
|
|
|
|
|
|
const endIndex = importedPageObj.value.pageNo * importedPageObj.value.pageSize
|
|
|
|
|
|
showImportedData.value = importedData.value.slice(startIndex, endIndex)
|
|
|
|
|
|
await nextTick()
|
|
|
|
|
|
uploadLoading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
// 折叠组件控制
|
|
|
|
|
|
const activeCollapses = ref(['0', '1', '2'])
|
|
|
|
|
|
// 步骤条控制
|
|
|
|
|
|
const stepHeightConstant = {
|
|
|
|
|
|
collapse: 58,
|
|
|
|
|
|
first: 333,
|
|
|
|
|
|
second: 284
|
|
|
|
|
|
}
|
|
|
|
|
|
const stepHeights = ref([stepHeightConstant.first, stepHeightConstant.second, stepHeightConstant.collapse])
|
|
|
|
|
|
|
2023-03-02 20:37:21 +08:00
|
|
|
|
// 没上传过文件的提示
|
|
|
|
|
|
const uploadErrorTip = ref('')
|
|
|
|
|
|
// 预览区无内容的提示
|
|
|
|
|
|
const previewErrorTip = ref('')
|
2023-03-31 17:50:38 +08:00
|
|
|
|
// 编辑项的form表单内容
|
|
|
|
|
|
const editTagForm = reactive({
|
|
|
|
|
|
tagItem: '', // 待编辑的item项,如ip、domain、app等
|
|
|
|
|
|
tagValue: '' // 待编辑的label
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2023-02-24 18:51:17 +08:00
|
|
|
|
return {
|
|
|
|
|
|
knowledgeBaseId,
|
|
|
|
|
|
editObject,
|
2023-03-09 15:20:59 +08:00
|
|
|
|
tagNameFirstBlur: ref(false),
|
2023-03-02 20:37:21 +08:00
|
|
|
|
blankObject,
|
|
|
|
|
|
activeCollapses,
|
|
|
|
|
|
stepHeightConstant,
|
|
|
|
|
|
stepHeights,
|
|
|
|
|
|
knowledgeBaseType,
|
|
|
|
|
|
importedData,
|
|
|
|
|
|
showImportedData,
|
|
|
|
|
|
importedPageObj,
|
|
|
|
|
|
importedType,
|
2023-03-23 16:13:55 +08:00
|
|
|
|
revertImportedData,
|
|
|
|
|
|
handleShowImportedData,
|
2023-03-02 20:37:21 +08:00
|
|
|
|
baseUrl: BASE_CONFIG.baseUrl,
|
|
|
|
|
|
fileList: ref([]),
|
|
|
|
|
|
uploadHeaders: {
|
|
|
|
|
|
'Cn-Authorization': localStorage.getItem(storageKey.token)
|
|
|
|
|
|
},
|
|
|
|
|
|
uploaded: ref(false),
|
|
|
|
|
|
importedDataNoData: ref(false),
|
2023-03-08 17:35:22 +08:00
|
|
|
|
url,
|
2023-03-02 20:37:21 +08:00
|
|
|
|
originalImportInfo,
|
|
|
|
|
|
uploadErrorTip,
|
2023-03-05 13:50:22 +08:00
|
|
|
|
previewErrorTip,
|
2023-03-06 20:16:31 +08:00
|
|
|
|
typeSelectDisable: ref(false),
|
|
|
|
|
|
uploadFileSizeLimit: 100 * 1024 * 1024,
|
2023-03-23 16:13:55 +08:00
|
|
|
|
uploadLoading,
|
|
|
|
|
|
initLoading,
|
2023-03-31 17:50:38 +08:00
|
|
|
|
fileTypeLimit: '.csv',
|
|
|
|
|
|
editTagForm
|
2023-02-24 18:51:17 +08:00
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
},
|
|
|
|
|
|
beforeUnmount () {
|
|
|
|
|
|
clearTimeout(this.timer)
|
2023-02-24 18:51:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
:deep .imported-table-box .el-form {
|
|
|
|
|
|
margin-top: 0 !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep .imported-table .el-input {
|
|
|
|
|
|
height: 24px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep .imported-table .el-form-item__content {
|
|
|
|
|
|
margin-top: -16px;
|
|
|
|
|
|
margin-bottom: -17px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep .imported-table .el-form-item__error {
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep .imported-data-item-edit__input .el-input__inner {
|
|
|
|
|
|
width: calc(100% - 50px);
|
|
|
|
|
|
height: 24px;
|
|
|
|
|
|
line-height: 0;
|
|
|
|
|
|
padding: 0 !important;
|
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.imported-data-btn {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.imported-data-left-btn {
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
margin: 0 7px;
|
|
|
|
|
|
color: #666;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.imported-data-back {
|
|
|
|
|
|
color: #cbcbcb;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.imported-data-save {
|
|
|
|
|
|
color: #38ACD2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.addTagBtn {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
bottom: 12px;
|
|
|
|
|
|
width: calc(100% - 24px);
|
|
|
|
|
|
margin-left: 12px;
|
|
|
|
|
|
background: rgb(245, 248, 250);
|
|
|
|
|
|
border: 1px #DEDEDE solid;
|
|
|
|
|
|
|
|
|
|
|
|
.add-tag-btn {
|
|
|
|
|
|
color: #575757;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
margin: 0 8px 2px 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|