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-05-29 13:00:28 +08:00
|
|
|
|
<div class="edit-knowledge-base__header">{{ editObject.knowledgeId ? $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-->
|
2023-05-29 13:00:28 +08:00
|
|
|
|
<el-form-item :label="$t('config.roles.name')" prop="name">
|
|
|
|
|
|
<el-input class="form-input" maxlength="64" placeholder="" :disabled="!!editObject.knowledgeId" show-word-limit
|
|
|
|
|
|
size="mini" type="text" v-model="editObject.name" @blur="tagNameBlur"></el-input>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</el-form-item>
|
2023-05-29 13:00:28 +08:00
|
|
|
|
<el-form-item :label="$t('overall.type')" prop="source">
|
|
|
|
|
|
<el-select v-model="editObject.source"
|
2023-07-14 15:05:42 +08:00
|
|
|
|
:class="(!!editObject.knowledgeId || (uploaded && !importedDataNoData)) ? 'form-select__disable' : 'form-select__enable'"
|
2023-03-02 20:37:21 +08:00
|
|
|
|
placeholder=" "
|
|
|
|
|
|
popper-class="form-select-popper"
|
2023-06-09 16:59:11 +08:00
|
|
|
|
:disabled="!!editObject.knowledgeId || (uploaded && !importedDataNoData)"
|
2023-03-02 20:37:21 +08:00
|
|
|
|
size="mini"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template v-for="type in knowledgeBaseType" :key="type.name">
|
2023-05-29 13:00:28 +08:00
|
|
|
|
<el-option :label="type.label" :value="type.value"></el-option>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
2023-05-29 13:00:28 +08:00
|
|
|
|
<el-form-item :label="$t('overall.remark')" prop="description">
|
2023-05-16 17:03:42 +08:00
|
|
|
|
<el-input maxlength="255" show-word-limit :rows="4" size='mini' type="textarea" resize='none'
|
2023-05-29 13:00:28 +08:00
|
|
|
|
v-model="editObject.description" 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-05-29 13:00:28 +08:00
|
|
|
|
<el-upload :action="`${baseUrl}${apiVersion}/knowledgeBase/parser`"
|
2023-03-02 20:37:21 +08:00
|
|
|
|
:headers="uploadHeaders"
|
|
|
|
|
|
:data="uploadParams"
|
|
|
|
|
|
:multiple="false"
|
|
|
|
|
|
:file-list="fileList"
|
|
|
|
|
|
:on-change="fileChange"
|
|
|
|
|
|
:on-success="uploadSuccess"
|
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"
|
|
|
|
|
|
>
|
2023-06-06 15:12:58 +08:00
|
|
|
|
<i class="cn-icon cn-icon-upload2"></i>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
<div class="el-upload__text">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<div>{{ $t('knowledgeBase.dropFileHereOr') }}<em>{{ $t('knowledgeBase.clickToUpload') }}</em></div>
|
2023-06-06 15:12:58 +08:00
|
|
|
|
<div class="upload-tip">{{ $t('knowledgeBase.supportCsv') }}<span @click.stop="downloadTemplate">{{$t('knowledgeBase.downloadTemplate')}}</span></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-05-29 13:00:28 +08:00
|
|
|
|
<div class="skeleton-border" v-if="!uploaded && !editObject.knowledgeId">
|
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-05-29 13:00:28 +08:00
|
|
|
|
{{ editObject.knowledgeId && isLoad? $t('knowledgeBase.loadTip', {
|
2023-04-11 15:38:47 +08:00
|
|
|
|
load: originalImportInfo.total
|
|
|
|
|
|
}) : $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-07-14 20:32:18 +08:00
|
|
|
|
<div class="entity-format-tip">
|
|
|
|
|
|
<template v-if="editObject.source === knowledgeBaseType.find(t => t.name === 'ip').value">
|
|
|
|
|
|
<div><span>{{$t('overall.format')}}:</span></div>
|
|
|
|
|
|
<div><span>IPv4</span> x.x.x.x</div>
|
|
|
|
|
|
<div><span>IPv4 CIDR</span> x.x.x.x/n</div>
|
|
|
|
|
|
<div><span>IPv4 Range</span> x.x.x.x-y.y.y.y</div>
|
|
|
|
|
|
<div><span>IPv6</span> x:x:x::x</div>
|
|
|
|
|
|
<div><span>IPv6 CIDR</span> x:x:x::x/n</div>
|
|
|
|
|
|
<div><span>IPv6 Range</span> x:x:x::x-y:y:y::y</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else-if="editObject.source === knowledgeBaseType.find(t => t.name === 'domain').value">
|
|
|
|
|
|
<div><span>{{$t('overall.format')}}:</span></div>
|
|
|
|
|
|
<div><span>{{$t('entities.format.suffix')}}</span> *example.com</div>
|
|
|
|
|
|
<div><span>{{$t('entities.format.exactly')}}</span> $www.example.com</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</div>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<el-form ref="editForm" :model="editTagForm" :rules="editTagFormRules">
|
|
|
|
|
|
<table class="imported-table" v-if="!importedDataNoData">
|
|
|
|
|
|
<tr>
|
2023-04-21 16:22:29 +08:00
|
|
|
|
<th style="width: 230px">{{ importedTableFirstColumn }}</th>
|
2023-06-09 09:45:08 +08:00
|
|
|
|
<th >Label</th>
|
|
|
|
|
|
<th style="width: 200px">{{ $t('overall.tip') }}</th>
|
|
|
|
|
|
<th style="width: 50px"></th>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
</tr>
|
2023-05-29 13:00:28 +08:00
|
|
|
|
<tr v-for="(d, i) in showImportedData" :key="importedType + d.tagName + d.tagValue + i">
|
|
|
|
|
|
<td class="imported-data-item" :title="d.tagName">
|
2023-06-08 11:22:12 +08:00
|
|
|
|
<el-form-item v-if="(editIndex === i) || (addEditFlag && d.tagName === '' && d.tagValue === '')" prop="tagName">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<span class="imported-data-item-edit__input">
|
2023-06-09 09:45:08 +08:00
|
|
|
|
<el-input v-model="editTagForm.tagName" @blur="onBlurTagItem(i)"></el-input>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</el-form-item>
|
2023-05-29 13:00:28 +08:00
|
|
|
|
<span v-else>{{ d.tagName }}</span>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
</td>
|
|
|
|
|
|
<td class="imported-data-value" :title="d.tagValue">
|
2023-06-08 11:22:12 +08:00
|
|
|
|
<el-form-item v-if="editIndex === i || (addEditFlag && d.tagName === '' && d.tagValue === '')" prop="tagValue">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<span class="imported-data-item-edit__input">
|
2023-06-09 09:45:08 +08:00
|
|
|
|
<el-input v-model="editTagForm.tagValue" @blur="onBlurTagItem(i)"></el-input>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<span v-else>{{ d.tagValue }}</span>
|
|
|
|
|
|
</td>
|
2023-06-08 11:22:12 +08:00
|
|
|
|
<td class="imported-data-msg" :title="d.msg">
|
2023-08-03 15:54:30 +08:00
|
|
|
|
<i :class="d.isValid === 1 ? 'el-icon-success' : (d.isValid === 0 ? 'el-icon-error' : '')"></i> {{(d.isValid === 1 && (d.msg==='' || !d.msg) )? $t('overall.success'): d.msg }}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
</td>
|
2023-06-08 11:22:12 +08:00
|
|
|
|
<!--返回和保存按钮:修改记录-->
|
|
|
|
|
|
<td v-if="backEditFlag && !addEditFlag && editIndex === i" class="imported-data-btn">
|
|
|
|
|
|
<i class="cn-icon cn-icon-revoke imported-data-left-btn imported-data-back"
|
|
|
|
|
|
@click="backImportedData(i)"></i>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<i class="cn-icon cn-icon-save imported-data-save" @click="saveImportedData(i)"></i>
|
|
|
|
|
|
</td>
|
2023-06-08 11:22:12 +08:00
|
|
|
|
<!--保存和删除按钮:新增记录-->
|
|
|
|
|
|
<td v-else-if="(addEditFlag && editIndex === i) || (addEditFlag && d.tagName === '' && d.tagValue === '')" class="imported-data-btn">
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<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>
|
2023-06-08 11:22:12 +08:00
|
|
|
|
<!--编辑和删除按钮:进入修改记录状态-->
|
2023-03-31 17:50:38 +08:00
|
|
|
|
<td v-else class="imported-data-btn">
|
2023-06-08 11:22:12 +08:00
|
|
|
|
<i class="cn-icon cn-icon-edit1 imported-data-left-btn"
|
2023-03-31 17:50:38 +08:00
|
|
|
|
@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-05-29 13:00:28 +08:00
|
|
|
|
:style="{'bottom': editObject.knowledgeId ? '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
|
|
|
|
<!--新增按钮-->
|
2023-04-19 14:01:37 +08:00
|
|
|
|
<el-button class="addTagBtn" :disabled="addEditFlag" @click="addTagAtLast">
|
|
|
|
|
|
<i class="cn-icon cn-icon-add add-tag-btn" :style="{'color': addEditFlag ? '#C0C4CC !important' : '#575757'}"></i>
|
2023-03-31 17:50:38 +08:00
|
|
|
|
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>
|
2023-05-29 13:00:28 +08:00
|
|
|
|
<el-collapse-item name="3" class="enable-form__mt">
|
|
|
|
|
|
<template #title>
|
|
|
|
|
|
<div class="form-sub-title">{{ $t('knowledge.enable') }}</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<el-switch class="card-enable"
|
2023-06-02 14:15:00 +08:00
|
|
|
|
v-model="editObject.status"
|
2023-05-29 13:00:28 +08:00
|
|
|
|
active-color="#38ACD2"
|
|
|
|
|
|
inactive-color="#C0CEDB"
|
2023-06-02 14:15:00 +08:00
|
|
|
|
:active-value="1"
|
|
|
|
|
|
:inactive-value="0"
|
2023-05-29 13:00:28 +08:00
|
|
|
|
>
|
|
|
|
|
|
</el-switch>
|
|
|
|
|
|
</el-collapse-item>
|
2023-03-02 20:37:21 +08:00
|
|
|
|
</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-04-21 16:22:29 +08:00
|
|
|
|
import { nextTick, reactive, ref } from 'vue'
|
2023-02-24 18:51:17 +08:00
|
|
|
|
import _ from 'lodash'
|
2023-08-03 15:54:30 +08:00
|
|
|
|
import { knowledgeBaseType, storageKey, unitTypes, knowledgeSourceValue, itemListHeight, knowledgeCategoryValue } 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-04-11 15:38:47 +08:00
|
|
|
|
import { regular } from '@/utils/regular'
|
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 () {
|
2023-04-21 16:22:29 +08:00
|
|
|
|
const nameValidator = (rule, value) => {
|
2023-03-08 17:35:22 +08:00
|
|
|
|
// /^[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEFA-Za-z0-9\-\_]*$/
|
|
|
|
|
|
const reg = /^[\u4e00-\u9fa5A-Za-z0-9\-\_]*$/
|
2023-04-21 16:22:29 +08:00
|
|
|
|
return reg.test(value)
|
2023-03-08 17:35:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
const nameAndTypeValidator = async (rule, value, callback) => {
|
|
|
|
|
|
let validate = true
|
2023-05-29 13:00:28 +08:00
|
|
|
|
if (!this.editObject.knowledgeId) {
|
|
|
|
|
|
this.$refs.form.clearValidate('type')
|
2023-03-23 16:13:55 +08:00
|
|
|
|
const response = await this.getKnowledgeBaseList()
|
|
|
|
|
|
if (response.data.code === 200) {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
const find = response.data.data.list.find(d => d.name === value && d.source === this.editObject.source)
|
2023-03-23 16:13:55 +08:00
|
|
|
|
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-05-29 13:00:28 +08:00
|
|
|
|
if (!this.editObject.knowledgeId) {
|
|
|
|
|
|
this.$refs.form.clearValidate('name')
|
2023-03-23 16:13:55 +08:00
|
|
|
|
const response = await this.getKnowledgeBaseList()
|
|
|
|
|
|
if (response.data.code === 200) {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
const find = response.data.data.list.find(d => d.name === this.editObject.name && d.source === value)
|
2023-03-23 16:13:55 +08:00
|
|
|
|
if (find) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
2023-03-08 17:35:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
2023-04-11 15:38:47 +08:00
|
|
|
|
const nameAndLabelDuplicateValidator = (rule, value, callback) => {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
let validate = true
|
|
|
|
|
|
let index = -1 // 当前编辑的键值index
|
2023-05-29 14:32:42 +08:00
|
|
|
|
// 查看是否重名前,需要对名称进行校验,分别是IP、domain、APP的校验
|
2023-03-31 17:50:38 +08:00
|
|
|
|
const findData = this.importedData.find((item, i) => {
|
|
|
|
|
|
index = i
|
2023-05-29 13:00:28 +08:00
|
|
|
|
return (item.tagName === this.editTagForm.tagName && item.tagValue === this.editTagForm.tagValue)
|
2023-03-31 17:50:38 +08:00
|
|
|
|
})
|
2023-04-11 15:38:47 +08:00
|
|
|
|
if (findData) { // 找到1条记录
|
2023-03-31 17:50:38 +08:00
|
|
|
|
// 如果name重复的第一个键值不是当前编辑item的index,即代表后续有重名的项了,提示重名
|
2023-04-11 15:38:47 +08:00
|
|
|
|
const realIndex = (this.importedPageObj.pageSize * (this.importedPageObj.pageNo - 1)) + this.editIndex
|
|
|
|
|
|
if (index !== realIndex) { // 记录为非当前记录,则数据重复
|
2023-03-31 17:50:38 +08:00
|
|
|
|
validate = false
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.editTagErrorTip = rule.message
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.showImportedData[this.editIndex].msg = rule.message
|
|
|
|
|
|
this.showImportedData[this.editIndex].isValid = 0
|
2023-03-31 17:50:38 +08:00
|
|
|
|
callback(new Error())
|
2023-04-11 15:38:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
|
|
|
|
|
const requiredItemValidator = (rule, value, callback) => {
|
2023-06-09 11:51:24 +08:00
|
|
|
|
value = this.editTagForm.tagName
|
2023-04-11 15:38:47 +08:00
|
|
|
|
let validate = true
|
2023-06-09 11:51:24 +08:00
|
|
|
|
const index = this.editIndex
|
2023-04-11 15:38:47 +08:00
|
|
|
|
const realValue = value.replace(/\s+/g, '')// 去掉空格
|
|
|
|
|
|
if (realValue === '') {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
this.editTagErrorTip = rule.message
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
2023-04-11 15:38:47 +08:00
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
|
|
|
|
|
const requiredValueValidator = (rule, value, callback) => {
|
2023-06-08 11:22:12 +08:00
|
|
|
|
value = this.editTagForm.tagValue
|
|
|
|
|
|
const index = this.editIndex
|
2023-04-11 15:38:47 +08:00
|
|
|
|
let validate = true
|
|
|
|
|
|
const realValue = value.replace(/\s+/g, '')// 去掉空格
|
|
|
|
|
|
if (realValue === '') {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
this.editTagErrorTip = rule.message
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
2023-04-11 15:38:47 +08:00
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
|
|
|
|
|
const nameFormatValidator = (rule, value, callback) => {
|
2023-06-08 11:22:12 +08:00
|
|
|
|
value = this.editTagForm.tagName
|
|
|
|
|
|
const index = this.editIndex
|
2023-04-11 15:38:47 +08:00
|
|
|
|
let validate = true
|
2023-05-29 13:00:28 +08:00
|
|
|
|
const type = this.editObject.source// 当前选中的类型
|
|
|
|
|
|
if (type === knowledgeSourceValue.ipTag) {
|
2023-04-11 15:38:47 +08:00
|
|
|
|
const formal = value.replace(/\s+/g, '')// 去掉空格
|
2023-04-21 16:22:29 +08:00
|
|
|
|
if (formal.indexOf('/') !== -1) {
|
2023-04-11 15:38:47 +08:00
|
|
|
|
if (!(regular.ipv4CIDR.test(formal)) && !(regular.ipv6CIDR.test(formal))) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
this.editTagErrorTip = rule.message
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
2023-04-11 15:38:47 +08:00
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
2023-07-03 15:54:32 +08:00
|
|
|
|
} else if (formal.indexOf('-') !== -1) {
|
2023-07-14 15:05:42 +08:00
|
|
|
|
const split2 = formal.split('-')
|
|
|
|
|
|
const startIp = split2[0].replace(/\s+/g, '')
|
|
|
|
|
|
const endIp = split2[1].replace(/\s+/g, '')
|
2023-07-03 08:42:33 +08:00
|
|
|
|
if (regular.ipv4Range.test(startIp) && regular.ipv4Range.test(endIp)) {
|
2023-07-03 15:54:32 +08:00
|
|
|
|
// ipv4对比大小
|
2023-07-03 08:42:33 +08:00
|
|
|
|
if (!(regular.compareIP4(startIp) <= regular.compareIP4(endIp))) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
this.editTagErrorTip = rule.message
|
|
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
|
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (regular.ipv6Range.test(startIp) && regular.ipv6Range.test(endIp)) {
|
2023-07-03 15:54:32 +08:00
|
|
|
|
// ipv6对比大小
|
2023-07-03 08:42:33 +08:00
|
|
|
|
if (!regular.ipv6Reg(startIp, endIp)) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
this.editTagErrorTip = rule.message
|
|
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
|
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
this.editTagErrorTip = rule.message
|
|
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
|
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
} else {
|
2023-04-11 15:38:47 +08:00
|
|
|
|
if (!regular.ip.test(formal)) {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
validate = false
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.editTagErrorTip = rule.message
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
2023-03-31 17:50:38 +08:00
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-05-29 13:00:28 +08:00
|
|
|
|
} else if (type === knowledgeSourceValue.appTag) {
|
2023-04-11 15:38:47 +08:00
|
|
|
|
const pattern = /.*[*?!&$%#^,.;:<>/@\"{}\-\]\[=+_\\|].*$/
|
|
|
|
|
|
if (pattern.test(value)) {
|
|
|
|
|
|
validate = false
|
|
|
|
|
|
this.editTagErrorTip = rule.message
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
2023-04-11 15:38:47 +08:00
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
2023-05-29 13:00:28 +08:00
|
|
|
|
} else if (type === knowledgeSourceValue.domainTag) { // 域名只支持 字母数字.-_
|
2023-04-11 15:38:47 +08:00
|
|
|
|
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
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.showImportedData[index].msg = rule.message
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
2023-04-11 15:38:47 +08:00
|
|
|
|
callback(new Error())
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
return validate
|
|
|
|
|
|
}
|
2023-03-08 17:35:22 +08:00
|
|
|
|
return {
|
|
|
|
|
|
rules: {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
name: [
|
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
|
|
|
|
],
|
2023-05-29 13:00:28 +08:00
|
|
|
|
source: [
|
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: {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
tagName: [
|
2023-03-31 17:50:38 +08:00
|
|
|
|
{
|
2023-04-11 15:38:47 +08:00
|
|
|
|
// required: true,
|
|
|
|
|
|
validator: requiredItemValidator,
|
2023-03-31 17:50:38 +08:00
|
|
|
|
message: this.$t('validate.required'),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2023-04-11 15:38:47 +08:00
|
|
|
|
validator: nameFormatValidator,
|
|
|
|
|
|
message: this.$t('validate.wrongFormat'),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: nameAndLabelDuplicateValidator,
|
|
|
|
|
|
message: this.$t('validate.duplicateName'),
|
2023-03-31 17:50:38 +08:00
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
tagValue: [{
|
2023-04-19 14:01:37 +08:00
|
|
|
|
// required: true,
|
2023-04-11 15:38:47 +08:00
|
|
|
|
validator: requiredValueValidator,
|
2023-03-31 17:50:38 +08:00
|
|
|
|
message: this.$t('validate.required'),
|
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
|
}]
|
|
|
|
|
|
},
|
|
|
|
|
|
editIndex: -1,
|
|
|
|
|
|
backEditFlag: false,
|
|
|
|
|
|
addEditFlag: false,
|
|
|
|
|
|
editTagErrorTip: '', // 编辑错误提示
|
2023-04-19 14:01:37 +08:00
|
|
|
|
timer: null,
|
|
|
|
|
|
isShowUploadTips: false,
|
|
|
|
|
|
isPreviewChange: false,
|
2023-05-15 11:42:21 +08:00
|
|
|
|
isClick: false,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
pageNoForTable: 1,
|
2023-08-03 15:54:30 +08:00
|
|
|
|
dataType: 'builtInList',
|
2023-06-02 14:15:00 +08:00
|
|
|
|
status: 1,
|
2023-06-08 11:22:12 +08:00
|
|
|
|
oldItemIds: [],
|
|
|
|
|
|
oldTagItem: {}
|
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) {
|
2023-04-19 14:01:37 +08:00
|
|
|
|
if (this.fileList.length > 0 && this.fileList[0].status === 'success') {
|
|
|
|
|
|
this.fileListBack = this.fileList[0]
|
|
|
|
|
|
}
|
2023-04-19 16:03:37 +08:00
|
|
|
|
this.fileList = fileList.slice(-1)
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
2023-03-08 17:35:22 +08:00
|
|
|
|
uploadError () {
|
|
|
|
|
|
this.uploadLoading = false
|
|
|
|
|
|
this.$message.error(this.$t('tip.uploadFailed', { msg: 'error' }))
|
|
|
|
|
|
},
|
2023-05-29 13:00:28 +08:00
|
|
|
|
handleSpeticalTypeData (originalImportedData) {
|
|
|
|
|
|
originalImportedData.forEach(item => {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
// const names = item.tagNames
|
|
|
|
|
|
if (this.editObject.source === knowledgeSourceValue.ipTag) {
|
|
|
|
|
|
const format = item.addrFormat
|
2023-05-29 13:00:28 +08:00
|
|
|
|
if (format === 'Single') {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
item.tagName = item.ip1
|
2023-05-29 13:00:28 +08:00
|
|
|
|
} else if (format === 'CIDR') {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
item.tagName = item.ip1 + '/' + item.ip2
|
2023-05-29 13:00:28 +08:00
|
|
|
|
} else if (format === 'Range') {
|
2023-07-03 08:42:33 +08:00
|
|
|
|
item.tagName = item.ip1 + '-' + item.ip2
|
2023-05-29 13:00:28 +08:00
|
|
|
|
}
|
2023-06-02 14:15:00 +08:00
|
|
|
|
} else if (this.editObject.source === knowledgeSourceValue.domainTag) {
|
|
|
|
|
|
item.tagName = item.domain
|
|
|
|
|
|
} else if (this.editObject.source === knowledgeSourceValue.appTag) {
|
|
|
|
|
|
item.tagName = item.appName
|
2023-05-29 13:00:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
return originalImportedData
|
|
|
|
|
|
},
|
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 = ''
|
2023-05-29 13:00:28 +08:00
|
|
|
|
this.importedType = this.editObject.source
|
2023-03-07 18:48:15 +08:00
|
|
|
|
const originalImportedData = _.cloneDeep(response.data.data)
|
|
|
|
|
|
this.importedDataNoData = originalImportedData.length === 0
|
2023-08-03 15:54:30 +08:00
|
|
|
|
if (originalImportedData.length > 0) {
|
|
|
|
|
|
originalImportedData.forEach(data => {
|
|
|
|
|
|
if (data.isValid === 1) {
|
|
|
|
|
|
data.msg = this.$t('overall.success')
|
|
|
|
|
|
} else if (data.isValid === 0) {
|
|
|
|
|
|
data.msg = this.$t('validate.wrongFormat')
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.originalImportInfo = {
|
|
|
|
|
|
total: originalImportedData.length,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
succeeded: originalImportedData.filter(d => d.isValid === 1).length,
|
|
|
|
|
|
failed: originalImportedData.filter(d => d.isValid !== 1).length
|
2023-03-02 20:37:21 +08:00
|
|
|
|
}
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.isLoad = false
|
2023-05-29 13:00:28 +08:00
|
|
|
|
originalImportedData.sort((a, b) => b.isValid - a.isValid)
|
|
|
|
|
|
this.importedData = this.handleSpeticalTypeData(originalImportedData)
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.addItemList = _.cloneDeep(this.importedData).filter(item => { return item.isValid === 1 })
|
2023-06-02 14:15:00 +08:00
|
|
|
|
this.updateItemList = []
|
|
|
|
|
|
this.deleteItemIds = this.oldItemIds
|
2023-03-23 16:13:55 +08:00
|
|
|
|
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.handleShowImportedData()
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.addEditFlag = false
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
this.editIndex = -1
|
2023-04-19 14:01:37 +08:00
|
|
|
|
this.isPreviewChange = true
|
2023-05-29 13:00:28 +08:00
|
|
|
|
this.stepHeights[2] = itemListHeight.hasData
|
|
|
|
|
|
this.stepHeightConstant.third = itemListHeight.hasData
|
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-04-21 16:22:29 +08:00
|
|
|
|
onRemove (files) {
|
2023-04-19 14:01:37 +08:00
|
|
|
|
if (files && files.status === 'success') {
|
|
|
|
|
|
this.uploaded = false
|
|
|
|
|
|
this.typeSelectDisable = false
|
2023-06-02 14:15:00 +08:00
|
|
|
|
this.importedData.forEach(item => {
|
|
|
|
|
|
if (item.id) {
|
|
|
|
|
|
const delIndex = this.deleteItemIds.indexOf(item.id)
|
|
|
|
|
|
if (delIndex === -1) {
|
|
|
|
|
|
this.deleteItemIds.push(item.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
this.addItemList = []
|
|
|
|
|
|
this.updateItemList = []
|
2023-04-19 14:01:37 +08:00
|
|
|
|
this.importedData = []
|
|
|
|
|
|
this.showImportedData = []
|
|
|
|
|
|
this.originalImportInfo = {
|
|
|
|
|
|
total: null,
|
|
|
|
|
|
succeeded: null,
|
|
|
|
|
|
failed: null
|
|
|
|
|
|
}
|
|
|
|
|
|
this.addEditFlag = false
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
this.editIndex = -1
|
|
|
|
|
|
this.isPreviewChange = true
|
2023-04-19 16:03:37 +08:00
|
|
|
|
this.importedDataNoData = true
|
2023-05-29 13:00:28 +08:00
|
|
|
|
|
|
|
|
|
|
if (!this.editObject.knowledgeId) { // 新增且删除文件时,高度变为250
|
|
|
|
|
|
this.stepHeights[2] = itemListHeight.noData
|
|
|
|
|
|
this.stepHeightConstant.third = itemListHeight.noData
|
|
|
|
|
|
}
|
2023-04-19 14:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (this.fileListBack !== undefined && this.fileListBack.status === 'success' &&
|
|
|
|
|
|
this.importedData.length > 0) {
|
|
|
|
|
|
this.fileList[0] = this.fileListBack
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-04-21 16:22:29 +08:00
|
|
|
|
uploadTip () {
|
2023-04-19 14:01:37 +08:00
|
|
|
|
if (!this.isShowUploadTips) {
|
|
|
|
|
|
this.isShowUploadTips = true
|
|
|
|
|
|
const self = this
|
2023-04-19 16:03:37 +08:00
|
|
|
|
if (this.importedData.length > 0) {
|
|
|
|
|
|
this.$confirm(this.$t('tip.uploadFile'), {
|
|
|
|
|
|
confirmButtonText: this.$t('tip.confirm'),
|
|
|
|
|
|
cancelButtonText: this.$t('overall.cancel'),
|
|
|
|
|
|
message: this.$t('tip.uploadFileTips'),
|
|
|
|
|
|
title: this.$t('tip.uploadFile'),
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
iconClass: 'width:0px;height:0px;',
|
|
|
|
|
|
customClass: 'del-model'
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
this.isClick = true
|
|
|
|
|
|
self.$refs.upload.$refs.uploadRef.handleClick()
|
2023-04-21 16:22:29 +08:00
|
|
|
|
}).catch(() => {}).finally(() => {
|
2023-04-19 16:03:37 +08:00
|
|
|
|
this.isShowUploadTips = false
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2023-04-19 14:01:37 +08:00
|
|
|
|
this.isClick = true
|
|
|
|
|
|
this.isShowUploadTips = false
|
2023-04-19 16:03:37 +08:00
|
|
|
|
self.$refs.upload.$refs.uploadRef.handleClick()
|
|
|
|
|
|
}
|
2023-04-19 14:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
promiseState (p) {
|
|
|
|
|
|
const t = {}
|
|
|
|
|
|
return Promise.race([p, t])
|
|
|
|
|
|
.then(v => (v === t) ? 'pending' : 'fulfilled', () => 'rejected')
|
2023-03-05 13:50:22 +08:00
|
|
|
|
},
|
2023-03-06 20:16:31 +08:00
|
|
|
|
beforeUpload (file) {
|
2023-04-21 16:22:29 +08:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-04-19 14:01:37 +08:00
|
|
|
|
// 判断后缀,仅支持.csv
|
|
|
|
|
|
if (!_.endsWith(file.name, '.csv')) {
|
|
|
|
|
|
this.$message.error(this.$t('validate.fileTypeLimit', { types: this.fileTypeLimit }))
|
|
|
|
|
|
this.fileList = []
|
|
|
|
|
|
reject(new Error(this.$t('validate.fileTypeLimit', { types: this.fileTypeLimit })))
|
|
|
|
|
|
} else if (file.size > this.uploadFileSizeLimit) { // 判断文件大小
|
|
|
|
|
|
this.$message.error(this.$t('validate.fileSizeLimit', { size: unitConvert(this.uploadFileSizeLimit, unitTypes.byte).join('') }))
|
|
|
|
|
|
this.fileList = []
|
|
|
|
|
|
reject(new Error(this.$t('validate.fileSizeLimit', { size: unitConvert(this.uploadFileSizeLimit, unitTypes.byte).join('') })))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (!this.isClick) {
|
2023-04-19 16:03:37 +08:00
|
|
|
|
if (this.importedData.length > 0) {
|
|
|
|
|
|
this.$confirm(this.$t('tip.uploadFile'), {
|
|
|
|
|
|
confirmButtonText: this.$t('tip.confirm'),
|
|
|
|
|
|
cancelButtonText: this.$t('overall.cancel'),
|
|
|
|
|
|
message: this.$t('tip.uploadFileTips'),
|
|
|
|
|
|
title: this.$t('tip.uploadFile'),
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
iconClass: 'width:0px;height:0px;',
|
|
|
|
|
|
customClass: 'del-model'
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
resolve()
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
|
reject(e)
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2023-04-19 14:01:37 +08:00
|
|
|
|
resolve()
|
2023-04-19 16:03:37 +08:00
|
|
|
|
}
|
2023-04-19 14:01:37 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
resolve()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-03-06 20:16:31 +08:00
|
|
|
|
},
|
2023-04-21 16:22:29 +08:00
|
|
|
|
onUpload () {
|
2023-03-06 20:16:31 +08:00
|
|
|
|
this.uploadLoading = true
|
2023-03-07 18:48:15 +08:00
|
|
|
|
this.typeSelectDisable = true
|
2023-04-19 14:01:37 +08:00
|
|
|
|
this.isClick = false
|
2023-03-06 20:16:31 +08:00
|
|
|
|
},
|
2023-06-16 17:51:08 +08:00
|
|
|
|
backEditData () {
|
|
|
|
|
|
if (this.oldTagItem.isValid) {
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.showImportedData[this.oldTagItem.index].isValid = this.oldTagItem.isValid
|
|
|
|
|
|
this.showImportedData[this.oldTagItem.index].msg = this.oldTagItem.msg
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-02 20:37:21 +08:00
|
|
|
|
pageNo (val) {
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.backEditData()
|
2023-04-11 15:38:47 +08:00
|
|
|
|
if (val !== this.importedPageObj.pageNo) {
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.importedPageObj.pageNo = val
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = -1
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.oldTagItem = {}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
|
|
|
|
|
prev () {
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.backEditData()
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.importedPageObj.pageNo--
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = -1
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.oldTagItem = {}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
|
|
|
|
|
next () {
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.backEditData()
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.importedPageObj.pageNo++
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = -1
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.oldTagItem = {}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
2023-04-11 15:38:47 +08:00
|
|
|
|
removeImportedData (index) { // index 为记录在当前页的索引
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.backEditData()
|
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-06-02 14:15:00 +08:00
|
|
|
|
const delItem = this.importedData[toRemoveIndex]
|
|
|
|
|
|
if (delItem.id) {
|
|
|
|
|
|
if (this.deleteItemIds.indexOf(delItem.id) === -1) {
|
|
|
|
|
|
this.deleteItemIds.push(delItem.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
const delIndex = this.updateItemList.findIndex(item => item.id === delItem.id)
|
|
|
|
|
|
if (delIndex > -1) {
|
|
|
|
|
|
this.updateItemList.splice(delIndex, 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const delIndex = this.addItemList.findIndex(item => item.tagName === delItem.tagName && item.tagValue === delItem.tagValue)
|
|
|
|
|
|
if (delIndex > -1) {
|
|
|
|
|
|
this.addItemList.splice(delIndex, 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
this.importedData.splice(toRemoveIndex, 1)
|
2023-04-11 15:38:47 +08:00
|
|
|
|
// 删除内容为空的新增记录
|
|
|
|
|
|
const lastIndex = this.importedData.length - 1
|
|
|
|
|
|
const lastData = this.importedData[lastIndex]
|
2023-05-29 13:00:28 +08:00
|
|
|
|
if (lastData !== undefined && lastData.tagName === '' && lastData.tagValue === '') {
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.importedData.pop()
|
|
|
|
|
|
}
|
|
|
|
|
|
this.importedPageObj.total = this.importedData.length
|
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-04-19 14:01:37 +08:00
|
|
|
|
this.isPreviewChange = true
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.oldTagItem = {}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
2023-03-06 20:16:31 +08:00
|
|
|
|
cancel () {
|
2023-05-15 11:42:21 +08:00
|
|
|
|
const self = this
|
2023-04-19 14:01:37 +08:00
|
|
|
|
if (this.isPreviewChange) {
|
|
|
|
|
|
this.$confirm(this.$t('tip.leavePage'), {
|
|
|
|
|
|
confirmButtonText: this.$t('tip.confirm'),
|
|
|
|
|
|
cancelButtonText: this.$t('overall.cancel'),
|
|
|
|
|
|
message: this.$t('tip.leavePageTips'),
|
|
|
|
|
|
title: this.$t('tip.leavePage'),
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
iconClass: 'width:0px;height:0px;',
|
|
|
|
|
|
customClass: 'del-model'
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
this.$router.push({
|
2023-08-03 15:54:30 +08:00
|
|
|
|
path: '/knowledgeBase/userDefinedLibrary',
|
2023-05-15 11:42:21 +08:00
|
|
|
|
query: {
|
|
|
|
|
|
pageNo: self.pageNoForTable ? Number(self.pageNoForTable) : 1,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
t: +new Date(),
|
2023-08-03 15:54:30 +08:00
|
|
|
|
dataType: this.dataType
|
2023-05-15 11:42:21 +08:00
|
|
|
|
}
|
2023-04-19 14:01:37 +08:00
|
|
|
|
})
|
2023-04-21 16:22:29 +08:00
|
|
|
|
}).catch(() => {})
|
2023-04-19 14:01:37 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.$router.push({
|
2023-08-03 15:54:30 +08:00
|
|
|
|
path: '/knowledgeBase/userDefinedLibrary',
|
2023-05-15 11:42:21 +08:00
|
|
|
|
query: {
|
|
|
|
|
|
pageNo: self.pageNoForTable ? Number(self.pageNoForTable) : 1,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
t: +new Date(),
|
2023-08-03 15:54:30 +08:00
|
|
|
|
dataType: this.dataType
|
2023-05-15 11:42:21 +08:00
|
|
|
|
}
|
2023-04-19 14:01:37 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
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-05-29 13:00:28 +08:00
|
|
|
|
this.$refs.form.validateField('name')
|
|
|
|
|
|
if (!this.uploaded && !this.editObject.knowledgeId) {
|
2023-03-10 13:32:46 +08:00
|
|
|
|
this.uploadErrorTip = this.$t('validate.required')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.uploadErrorTip = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
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-04-19 16:03:37 +08:00
|
|
|
|
if (this.$refs.editForm) {
|
|
|
|
|
|
this.$refs.editForm.validate((validImportData) => {
|
|
|
|
|
|
if (validImportData) {
|
|
|
|
|
|
// 校验通过后组织数据、请求接口
|
|
|
|
|
|
if (valid && !this.uploadErrorTip && !this.previewErrorTip) {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
if (this.importedData.length === 1 && this.importedData[0].tagName === '') {
|
2023-04-19 16:03:37 +08:00
|
|
|
|
// this.blockOperation.save = false
|
2023-04-11 15:38:47 +08:00
|
|
|
|
} else {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
const userId = localStorage.getItem(storageKey.userId)
|
2023-04-19 16:03:37 +08:00
|
|
|
|
const postData = {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
name: this.editObject.name,
|
2023-08-03 15:54:30 +08:00
|
|
|
|
category: knowledgeCategoryValue.userDefined,
|
2023-06-02 14:15:00 +08:00
|
|
|
|
source: this.editObject.source,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
description: this.editObject.description,
|
2023-06-02 14:15:00 +08:00
|
|
|
|
status: this.editObject.status,
|
|
|
|
|
|
user: {
|
|
|
|
|
|
id: userId ? Number(userId) : 1
|
|
|
|
|
|
}
|
2023-04-19 16:03:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 避免点击新增后,并没有保存新增项就点击了save,此时删除新增的空白项
|
2023-05-29 13:00:28 +08:00
|
|
|
|
if (this.importedData[this.importedData.length - 1].tagName === '') {
|
2023-04-19 16:03:37 +08:00
|
|
|
|
this.importedData.pop()
|
|
|
|
|
|
}
|
2023-05-29 13:00:28 +08:00
|
|
|
|
|
2023-05-15 11:42:21 +08:00
|
|
|
|
const self = this
|
2023-05-29 13:00:28 +08:00
|
|
|
|
if (!this.editObject.knowledgeId) {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
postData.addItemList = this.addItemList
|
2023-04-19 16:03:37 +08:00
|
|
|
|
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({
|
2023-08-03 15:54:30 +08:00
|
|
|
|
path: '/knowledgeBase/userDefinedLibrary',
|
2023-05-15 11:42:21 +08:00
|
|
|
|
query: {
|
|
|
|
|
|
pageNo: self.pageNoForTable ? Number(self.pageNoForTable) : 1,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
t: +new Date(),
|
2023-08-03 15:54:30 +08:00
|
|
|
|
dataType: this.dataType
|
2023-05-15 11:42:21 +08:00
|
|
|
|
}
|
2023-04-19 16:03:37 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2023-06-30 17:24:28 +08:00
|
|
|
|
this.$message.error(this.errorMsgHandler(response))
|
2023-04-19 16:03:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
|
console.error(e)
|
2023-06-30 17:24:28 +08:00
|
|
|
|
this.$message.error(this.errorMsgHandler(e))
|
2023-04-19 16:03:37 +08:00
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
this.blockOperation.save = false
|
2023-04-11 15:38:47 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
postData.updateItemList = this.updateItemList
|
|
|
|
|
|
postData.addItemList = this.addItemList
|
|
|
|
|
|
postData.deleteItemIds = this.deleteItemIds
|
2023-05-29 13:00:28 +08:00
|
|
|
|
postData.knowledgeId = this.editObject.knowledgeId
|
2023-04-19 16:03:37 +08:00
|
|
|
|
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({
|
2023-08-03 15:54:30 +08:00
|
|
|
|
path: '/knowledgeBase/userDefinedLibrary',
|
2023-05-15 11:42:21 +08:00
|
|
|
|
query: {
|
|
|
|
|
|
pageNo: self.pageNoForTable ? Number(self.pageNoForTable) : 1,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
t: +new Date(),
|
2023-08-03 15:54:30 +08:00
|
|
|
|
dataType: this.dataType
|
2023-05-15 11:42:21 +08:00
|
|
|
|
}
|
2023-04-19 16:03:37 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2023-06-30 17:24:28 +08:00
|
|
|
|
this.$message.error(this.errorMsgHandler(response))
|
2023-04-19 16:03:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
|
console.error(e)
|
2023-06-30 17:24:28 +08:00
|
|
|
|
this.$message.error(this.errorMsgHandler(e))
|
2023-04-19 16:03:37 +08:00
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
this.blockOperation.save = false
|
2023-04-11 15:38:47 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2023-04-19 16:03:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.blockOperation.save = false
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}
|
2023-04-11 15:38:47 +08:00
|
|
|
|
} else {
|
2023-03-23 16:13:55 +08:00
|
|
|
|
this.blockOperation.save = false
|
2023-04-11 15:38:47 +08:00
|
|
|
|
}
|
2023-04-19 16:03:37 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.blockOperation.save = false
|
|
|
|
|
|
}
|
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 () {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
return this.importedData.filter(d => d.isValid !== 1).length > 0
|
2023-03-08 17:35:22 +08:00
|
|
|
|
},
|
|
|
|
|
|
async getKnowledgeBaseList () {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
return await axios.get(this.listUrl, { params: { pageSize: 999 } }).catch(e => {
|
2023-03-28 15:37:30 +08:00
|
|
|
|
console.error(e)
|
2023-06-30 17:24:28 +08:00
|
|
|
|
this.$message.error(this.errorMsgHandler(e))
|
2023-03-28 15:37:30 +08:00
|
|
|
|
})
|
2023-03-31 17:50:38 +08:00
|
|
|
|
},
|
|
|
|
|
|
editImportedData (index) {
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.backEditData()
|
2023-05-29 13:00:28 +08:00
|
|
|
|
this.editTagForm.tagName = this.showImportedData[index].tagName
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editTagForm.tagValue = this.showImportedData[index].tagValue
|
|
|
|
|
|
|
2023-06-08 11:22:12 +08:00
|
|
|
|
// 点击编辑时,如正处于新增状态,则去除新增项(此时新增并未保存,不必保留)
|
2023-03-31 17:50:38 +08:00
|
|
|
|
if (this.addEditFlag) {
|
|
|
|
|
|
this.addEditFlag = false
|
2023-04-11 15:38:47 +08:00
|
|
|
|
const dataLen = this.importedData.length % this.importedPageObj.pageSize
|
|
|
|
|
|
if (dataLen === 1) {
|
|
|
|
|
|
this.importedPageObj.total--
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.importedData.pop()
|
|
|
|
|
|
this.handleShowImportedData()
|
|
|
|
|
|
}
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.oldTagItem = {
|
|
|
|
|
|
isValid: this.showImportedData[index].isValid,
|
2023-06-09 11:51:24 +08:00
|
|
|
|
msg: this.showImportedData[index].msg,
|
|
|
|
|
|
tagName: this.showImportedData[index].tagName,
|
|
|
|
|
|
tagValue: this.showImportedData[index].tagValue,
|
2023-06-16 17:51:08 +08:00
|
|
|
|
index: index
|
2023-06-08 11:22:12 +08:00
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = index
|
|
|
|
|
|
this.backEditFlag = true
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
},
|
2023-06-08 11:22:12 +08:00
|
|
|
|
backImportedData (index) {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editTagForm = reactive({
|
2023-05-29 13:00:28 +08:00
|
|
|
|
tagName: '',
|
2023-03-31 17:50:38 +08:00
|
|
|
|
tagValue: ''
|
|
|
|
|
|
})
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.showImportedData[index].isValid = this.oldTagItem.isValid
|
|
|
|
|
|
this.showImportedData[index].msg = this.oldTagItem.msg
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.editIndex = -1
|
|
|
|
|
|
this.backEditFlag = false
|
|
|
|
|
|
this.editTagErrorTip = ''
|
|
|
|
|
|
},
|
2023-06-02 14:15:00 +08:00
|
|
|
|
updateData (data) {
|
|
|
|
|
|
if (data) {
|
|
|
|
|
|
const updateItemIndex = this.updateItemList.findIndex(item => item.id === data.id)
|
|
|
|
|
|
if (updateItemIndex > -1) {
|
|
|
|
|
|
this.updateItemList.splice(updateItemIndex, 1, data)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let updateItemData = {
|
|
|
|
|
|
id: data.id,
|
|
|
|
|
|
tagValue: data.tagValue,
|
|
|
|
|
|
isValid: 1
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.editObject.source === knowledgeSourceValue.ipTag) {
|
2023-07-03 08:42:33 +08:00
|
|
|
|
const sepCidrIndex = data.tagName.indexOf('/')
|
|
|
|
|
|
const sepRangeIndex = data.tagName.indexOf('-')
|
|
|
|
|
|
if (sepCidrIndex > -1) { // CIDR
|
2023-06-02 14:15:00 +08:00
|
|
|
|
updateItemData = {
|
|
|
|
|
|
...updateItemData,
|
|
|
|
|
|
addrFormat: 'CIDR',
|
2023-07-03 08:42:33 +08:00
|
|
|
|
ip1: data.tagName.substring(0, sepCidrIndex),
|
|
|
|
|
|
ip2: data.tagName.substring(sepCidrIndex + 1)
|
|
|
|
|
|
}
|
2023-07-03 15:54:32 +08:00
|
|
|
|
} else if (sepRangeIndex > -1) {
|
2023-07-03 08:42:33 +08:00
|
|
|
|
updateItemData = {
|
|
|
|
|
|
...updateItemData,
|
|
|
|
|
|
addrFormat: 'Range',
|
|
|
|
|
|
ip1: data.tagName.substring(0, sepRangeIndex),
|
|
|
|
|
|
ip2: data.tagName.substring(sepRangeIndex + 1)
|
2023-06-02 14:15:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else { // Single
|
|
|
|
|
|
updateItemData = {
|
|
|
|
|
|
...updateItemData,
|
|
|
|
|
|
addrFormat: 'Single',
|
|
|
|
|
|
ip1: data.tagName,
|
|
|
|
|
|
ip2: ''
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (this.editObject.source === knowledgeSourceValue.domainTag) {
|
|
|
|
|
|
updateItemData = {
|
|
|
|
|
|
...updateItemData,
|
|
|
|
|
|
domain: data.tagName
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (this.editObject.source === knowledgeSourceValue.appTag) {
|
|
|
|
|
|
updateItemData = {
|
|
|
|
|
|
...updateItemData,
|
|
|
|
|
|
appName: data.tagName
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.updateItemList.push(updateItemData)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-06-08 11:22:12 +08:00
|
|
|
|
addData (data, oldTag) {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
if (data) {
|
2023-06-08 11:22:12 +08:00
|
|
|
|
let addItemIndex = -1
|
|
|
|
|
|
if (oldTag) {
|
|
|
|
|
|
addItemIndex = this.addItemList.findIndex(item => item.tagName === oldTag.tagName && item.tagValue === oldTag.tagValue)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
addItemIndex = this.addItemList.findIndex(item => item.tagName === data.tagName && item.tagValue === data.tagValue)
|
|
|
|
|
|
}
|
|
|
|
|
|
let addItem = data
|
|
|
|
|
|
if (this.editObject.source === knowledgeSourceValue.ipTag) {
|
2023-07-03 08:42:33 +08:00
|
|
|
|
const sepCidrIndex = data.tagName.indexOf('/')
|
|
|
|
|
|
const sepRangeIndex = data.tagName.indexOf('-')
|
|
|
|
|
|
if (sepCidrIndex > -1) { // CIDR
|
2023-06-02 14:15:00 +08:00
|
|
|
|
addItem = {
|
|
|
|
|
|
...addItem,
|
2023-06-08 11:22:12 +08:00
|
|
|
|
addrFormat: 'CIDR',
|
2023-07-03 08:42:33 +08:00
|
|
|
|
ip1: data.tagName.substring(0, sepCidrIndex),
|
|
|
|
|
|
ip2: data.tagName.substring(sepCidrIndex + 1)
|
|
|
|
|
|
}
|
2023-07-03 15:54:32 +08:00
|
|
|
|
} else if (sepRangeIndex > -1) {
|
2023-07-03 08:42:33 +08:00
|
|
|
|
addItem = {
|
|
|
|
|
|
...addItem,
|
|
|
|
|
|
addrFormat: 'Range',
|
|
|
|
|
|
ip1: data.tagName.substring(0, sepRangeIndex),
|
|
|
|
|
|
ip2: data.tagName.substring(sepRangeIndex + 1)
|
2023-06-02 14:15:00 +08:00
|
|
|
|
}
|
2023-06-08 11:22:12 +08:00
|
|
|
|
} else { // Single
|
2023-06-02 14:15:00 +08:00
|
|
|
|
addItem = {
|
|
|
|
|
|
...addItem,
|
2023-06-08 11:22:12 +08:00
|
|
|
|
addrFormat: 'Single',
|
|
|
|
|
|
ip1: data.tagName,
|
|
|
|
|
|
ip2: ''
|
2023-06-02 14:15:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-08 11:22:12 +08:00
|
|
|
|
} else if (this.editObject.source === knowledgeSourceValue.domainTag) {
|
|
|
|
|
|
addItem = {
|
|
|
|
|
|
...addItem,
|
|
|
|
|
|
domain: data.tagName
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (this.editObject.source === knowledgeSourceValue.appTag) {
|
|
|
|
|
|
addItem = {
|
|
|
|
|
|
...addItem,
|
|
|
|
|
|
appName: data.tagName
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-02 14:15:00 +08:00
|
|
|
|
|
2023-06-08 11:22:12 +08:00
|
|
|
|
if (addItemIndex === -1) {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
this.addItemList.push(addItem)
|
2023-06-08 11:22:12 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.addItemList.splice(addItemIndex, 1, addItem)
|
2023-06-02 14:15:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-06-08 11:22:12 +08:00
|
|
|
|
saveImportedData (index) { // 分为新增的保存,修改的保存
|
|
|
|
|
|
const self = this
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.$refs.editForm.validate(valid => {
|
|
|
|
|
|
if (valid) {
|
2023-06-08 11:22:12 +08:00
|
|
|
|
const oldTag = {
|
|
|
|
|
|
tagName: self.showImportedData[index].tagName,
|
|
|
|
|
|
tagValue: self.showImportedData[index].tagValue
|
|
|
|
|
|
}
|
|
|
|
|
|
self.showImportedData[index].tagName = self.editTagForm.tagName
|
|
|
|
|
|
self.showImportedData[index].tagValue = self.editTagForm.tagValue
|
2023-03-31 17:50:38 +08:00
|
|
|
|
let num = -1
|
2023-06-08 11:22:12 +08:00
|
|
|
|
const findData = self.importedData.find((item, i) => {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
num = i
|
2023-06-08 11:22:12 +08:00
|
|
|
|
return (item.tagName === self.editTagForm.tagName && item.tagValue === self.editTagForm.tagValue)
|
2023-03-31 17:50:38 +08:00
|
|
|
|
})
|
2023-06-08 11:22:12 +08:00
|
|
|
|
if (!findData) { // 新增记录(包括新增和修改界面)
|
|
|
|
|
|
self.importedData[num].tagName = self.editTagForm.tagName
|
|
|
|
|
|
self.importedData[num].tagValue = self.editTagForm.tagValue
|
|
|
|
|
|
self.importedData[num].isValid = 1
|
|
|
|
|
|
self.addData(self.importedData[num])
|
|
|
|
|
|
} else { // 修改记录
|
|
|
|
|
|
if (findData.id) { // 修改界面的修改记录
|
|
|
|
|
|
self.updateData(findData, oldTag)
|
|
|
|
|
|
} else { // 新增界面的修改记录
|
|
|
|
|
|
self.addData(findData, oldTag)
|
2023-06-02 14:15:00 +08:00
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 11:22:12 +08:00
|
|
|
|
self.addEditFlag = false
|
|
|
|
|
|
self.editIndex = -1
|
|
|
|
|
|
self.backEditFlag = false
|
|
|
|
|
|
self.isPreviewChange = true
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.oldTagItem = {}
|
2023-06-08 11:22:12 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
self.showImportedData[index].isValid = 0
|
2023-03-31 17:50:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2023-06-09 09:45:08 +08:00
|
|
|
|
onBlurTagItem (index) {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.$refs.editForm.validate(valid => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
this.editTagErrorTip = ''
|
2023-06-09 09:45:08 +08:00
|
|
|
|
this.showImportedData[index].isValid = 1
|
2023-08-03 15:54:30 +08:00
|
|
|
|
this.showImportedData[index].msg = this.$t('overall.success')
|
2023-06-09 09:45:08 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.showImportedData[index].isValid = 0
|
2023-03-31 17:50:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
addTagAtLast () {
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.backEditData()
|
2023-05-29 13:00:28 +08:00
|
|
|
|
this.editTagForm.tagName = ''
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.editTagForm.tagValue = ''
|
|
|
|
|
|
const total = this.importedData.length
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.addEditFlag = true
|
|
|
|
|
|
// 如果已经有新增空白项,则不再进行新增操作
|
2023-06-08 11:22:12 +08:00
|
|
|
|
if (this.importedData.length === 0 || !(this.importedData[this.importedData.length - 1].tagName === '' && this.importedData[this.importedData.length - 1].tagValue === '')) {
|
2023-04-27 14:47:55 +08:00
|
|
|
|
if (total >= 10) {
|
2023-03-31 17:50:38 +08:00
|
|
|
|
const lastPageSize = Math.ceil((total + 1) / 10)
|
|
|
|
|
|
this.pageNo(lastPageSize)
|
|
|
|
|
|
}
|
2023-06-08 11:22:12 +08:00
|
|
|
|
this.importedData.push({ tagName: '', tagValue: '' })
|
|
|
|
|
|
this.showImportedData.push({ tagName: '', tagValue: '' })
|
2023-04-27 14:47:55 +08:00
|
|
|
|
this.importedDataNoData = false
|
|
|
|
|
|
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.importedPageObj.total = this.importedData.length
|
2023-03-31 17:50:38 +08:00
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
|
this.editIndex = this.showImportedData.length - 1
|
|
|
|
|
|
}, 100)
|
|
|
|
|
|
}
|
2023-06-09 11:51:24 +08:00
|
|
|
|
this.oldTagItem = {}
|
2023-06-06 15:12:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
downloadTemplate () {
|
|
|
|
|
|
window.open('/assets/knowledgeBaseTemplate.zip', '_blank')
|
2023-03-02 20:37:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
uploadParams () {
|
|
|
|
|
|
return {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
source: this.editObject.source
|
2023-03-02 20:37:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
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-05-29 13:00:28 +08:00
|
|
|
|
if (this.editObject.knowledgeId) {
|
|
|
|
|
|
return 3
|
2023-03-23 16:13:55 +08:00
|
|
|
|
} else if (this.tagNameFirstBlur) {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
// return this.uploaded ? 2 : 1
|
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 () {
|
2023-05-15 11:42:21 +08:00
|
|
|
|
const pageNo = this.$router.currentRoute.value.query.pageNoForTable
|
2023-08-03 15:54:30 +08:00
|
|
|
|
const dataType = this.$router.currentRoute.value.query.dataType
|
2023-05-15 11:42:21 +08:00
|
|
|
|
this.pageNoForTable = pageNo || 1
|
2023-08-03 15:54:30 +08:00
|
|
|
|
this.dataType = dataType || 'builtInList'
|
2023-04-19 14:01:37 +08:00
|
|
|
|
const div = document.getElementsByClassName('el-upload-dragger')[0]
|
|
|
|
|
|
const self = this
|
|
|
|
|
|
div.addEventListener('click', function (event) {
|
|
|
|
|
|
this.isClick = true
|
|
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
self.uploadTip(event)
|
|
|
|
|
|
})
|
2023-03-23 16:13:55 +08:00
|
|
|
|
if (this.knowledgeBaseId) {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
this.stepHeights[2] = itemListHeight.hasData// 修改的时候一直是478
|
|
|
|
|
|
this.stepHeightConstant.third = itemListHeight.hasData// 修改的时候一直是478
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.isLoad = true
|
2023-06-02 14:15:00 +08:00
|
|
|
|
axios.get(`${api.knowledgeBase}/${this.knowledgeBaseId}`, { params: { pageSize: -1 } }).then(response => {
|
2023-03-23 16:13:55 +08:00
|
|
|
|
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
|
2023-06-02 14:15:00 +08:00
|
|
|
|
this.importedData = this.handleSpeticalTypeData(this.editObject.itemList)
|
|
|
|
|
|
this.importedData.forEach(item => {
|
|
|
|
|
|
this.oldItemIds.push(item.id)
|
|
|
|
|
|
})
|
2023-03-23 16:13:55 +08:00
|
|
|
|
this.handleShowImportedData()
|
|
|
|
|
|
this.originalImportInfo = {
|
|
|
|
|
|
total: this.importedData.length,
|
|
|
|
|
|
succeeded: this.importedData.length,
|
|
|
|
|
|
failed: 0
|
|
|
|
|
|
}
|
|
|
|
|
|
this.importedPageObj.total = this.importedData.length
|
2023-05-29 13:00:28 +08:00
|
|
|
|
this.importedType = this.editObject.source
|
2023-03-23 16:13:55 +08:00
|
|
|
|
this.initLoading = false
|
2023-03-28 15:37:30 +08:00
|
|
|
|
} else {
|
2023-05-09 17:46:31 +08:00
|
|
|
|
this.$message.error(this.errorMsgHandler(response))
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
|
console.error(e)
|
2023-05-09 17:46:31 +08:00
|
|
|
|
this.$message.error(this.errorMsgHandler(e))
|
2023-03-23 16:13:55 +08:00
|
|
|
|
this.$router.push({
|
2023-08-03 15:54:30 +08:00
|
|
|
|
path: '/knowledgeBase/userDefinedLibrary',
|
2023-05-15 11:42:21 +08:00
|
|
|
|
query: {
|
|
|
|
|
|
pageNo: self.pageNoForTable ? Number(self.pageNoForTable) : 1,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
t: +new Date(),
|
2023-08-03 15:54:30 +08:00
|
|
|
|
dataType: this.dataType
|
2023-05-15 11:42:21 +08:00
|
|
|
|
}
|
2023-03-23 16:13:55 +08:00
|
|
|
|
})
|
|
|
|
|
|
})
|
2023-05-29 13:00:28 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.stepHeightConstant.third = itemListHeight.noData// 进入新增时为250
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-02 20:37:21 +08:00
|
|
|
|
watch: {
|
|
|
|
|
|
activeCollapses (n) {
|
|
|
|
|
|
const index0 = n.indexOf('0')
|
|
|
|
|
|
const index1 = n.indexOf('1')
|
2023-05-29 13:00:28 +08:00
|
|
|
|
const index2 = n.indexOf('2')
|
|
|
|
|
|
if (index0 > -1) { // 第一个折叠为发开状态
|
2023-03-02 20:37:21 +08:00
|
|
|
|
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)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-05-29 13:00:28 +08:00
|
|
|
|
if (index2 > -1) {
|
|
|
|
|
|
if (this.stepHeights[2] === this.stepHeightConstant.collapse) {
|
|
|
|
|
|
this.stepHeights.splice(2, 1, this.stepHeightConstant.third)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (this.stepHeights[2] === this.stepHeightConstant.third) {
|
|
|
|
|
|
this.stepHeights.splice(2, 1, this.stepHeightConstant.collapse)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-02 20:37:21 +08:00
|
|
|
|
},
|
|
|
|
|
|
importedData (n) {
|
|
|
|
|
|
this.importedPageObj.total = n.length
|
|
|
|
|
|
},
|
2023-04-11 15:38:47 +08:00
|
|
|
|
addEditFlag (n) {
|
|
|
|
|
|
if (!n) {
|
|
|
|
|
|
const lastIndex = this.importedData.length - 1
|
|
|
|
|
|
const lastData = this.importedData[lastIndex]
|
2023-05-29 13:00:28 +08:00
|
|
|
|
if (lastData && lastData.tagName === '' && lastData.tagValue === '') {
|
2023-04-11 15:38:47 +08:00
|
|
|
|
this.importedData.pop()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-03-02 20:37:21 +08:00
|
|
|
|
'importedPageObj.pageNo': {
|
2023-04-21 16:22:29 +08:00
|
|
|
|
handler () {
|
2023-03-02 20:37:21 +08:00
|
|
|
|
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-05-29 13:00:28 +08:00
|
|
|
|
const listUrl = api.knowledgeBaseList
|
2023-02-24 18:51:17 +08:00
|
|
|
|
// 空白对象
|
|
|
|
|
|
const blankObject = {
|
2023-05-29 13:00:28 +08:00
|
|
|
|
name: '',
|
2023-02-24 18:51:17 +08:00
|
|
|
|
buildIn: '',
|
2023-05-29 13:00:28 +08:00
|
|
|
|
knowledgeId: '',
|
|
|
|
|
|
source: 'cn_ip_tag_user_defined',
|
|
|
|
|
|
description: '',
|
|
|
|
|
|
updateTime: '',
|
2023-06-02 14:15:00 +08:00
|
|
|
|
status: 1
|
2023-02-24 18:51:17 +08:00
|
|
|
|
}
|
2023-03-23 16:13:55 +08:00
|
|
|
|
/* 将组织后的数据还原拉平 */
|
|
|
|
|
|
const revertImportedData = (data) => {
|
|
|
|
|
|
const importedData = []
|
|
|
|
|
|
data.forEach(d => {
|
|
|
|
|
|
d.itemList.forEach(item => {
|
|
|
|
|
|
importedData.push({
|
2023-05-29 13:00:28 +08:00
|
|
|
|
tagName: item,
|
2023-03-23 16:13:55 +08:00
|
|
|
|
tagValue: d.tagValue,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
isValid: 1
|
2023-03-23 16:13:55 +08:00
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
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-06-02 14:15:00 +08:00
|
|
|
|
// 新增数据
|
|
|
|
|
|
const addItemList = ref([])
|
|
|
|
|
|
// 修改的数据
|
|
|
|
|
|
const updateItemList = ref([])
|
|
|
|
|
|
// 删除的数据
|
|
|
|
|
|
const deleteItemIds = 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
|
|
|
|
|
|
}
|
|
|
|
|
|
// 折叠组件控制
|
2023-05-29 13:00:28 +08:00
|
|
|
|
const activeCollapses = ref(['0', '1', '2', '3'])
|
2023-03-23 16:13:55 +08:00
|
|
|
|
// 步骤条控制
|
|
|
|
|
|
const stepHeightConstant = {
|
|
|
|
|
|
collapse: 58,
|
|
|
|
|
|
first: 333,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
second: 284,
|
|
|
|
|
|
third: itemListHeight.noData
|
2023-03-23 16:13:55 +08:00
|
|
|
|
}
|
2023-05-29 13:00:28 +08:00
|
|
|
|
|
|
|
|
|
|
const stepHeights = ref([stepHeightConstant.first, stepHeightConstant.second, stepHeightConstant.third, stepHeightConstant.collapse])
|
2023-03-23 16:13:55 +08:00
|
|
|
|
|
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({
|
2023-05-29 13:00:28 +08:00
|
|
|
|
tagName: '', // 待编辑的item项,如ip、domain、app等
|
2023-03-31 17:50:38 +08:00
|
|
|
|
tagValue: '' // 待编辑的label
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2023-04-11 15:38:47 +08:00
|
|
|
|
const isLoad = ref(false)
|
2023-02-24 18:51:17 +08:00
|
|
|
|
return {
|
|
|
|
|
|
knowledgeBaseId,
|
|
|
|
|
|
editObject,
|
2023-04-11 15:38:47 +08:00
|
|
|
|
isLoad,
|
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,
|
2023-06-02 14:15:00 +08:00
|
|
|
|
addItemList,
|
|
|
|
|
|
updateItemList,
|
|
|
|
|
|
deleteItemIds,
|
2023-03-02 20:37:21 +08:00
|
|
|
|
importedPageObj,
|
|
|
|
|
|
importedType,
|
2023-03-23 16:13:55 +08:00
|
|
|
|
revertImportedData,
|
|
|
|
|
|
handleShowImportedData,
|
2023-06-01 11:30:21 +08:00
|
|
|
|
baseUrl: BASE_CONFIG.baseUrl,
|
|
|
|
|
|
apiVersion: BASE_CONFIG.apiVersion,
|
2023-03-02 20:37:21 +08:00
|
|
|
|
fileList: ref([]),
|
2023-04-19 14:01:37 +08:00
|
|
|
|
fileListBack: ref(),
|
2023-03-02 20:37:21 +08:00
|
|
|
|
uploadHeaders: {
|
|
|
|
|
|
'Cn-Authorization': localStorage.getItem(storageKey.token)
|
|
|
|
|
|
},
|
|
|
|
|
|
uploaded: ref(false),
|
|
|
|
|
|
importedDataNoData: ref(false),
|
2023-03-08 17:35:22 +08:00
|
|
|
|
url,
|
2023-05-29 13:00:28 +08:00
|
|
|
|
listUrl,
|
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
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
.del-model {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
padding-bottom: 0 !important;
|
|
|
|
|
|
width: 480px !important;
|
|
|
|
|
|
height: 190px;
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
.el-message-box__header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
|
border-bottom: 1px solid #eee;
|
|
|
|
|
|
height: 42px;
|
|
|
|
|
|
background: #F7F7F7;
|
|
|
|
|
|
box-shadow: 0 1px 0 0 rgba(53, 54, 54, 0.08);
|
|
|
|
|
|
padding-left: 20px;
|
|
|
|
|
|
padding-top: 14px;
|
|
|
|
|
|
padding-bottom: 14px;
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
.el-message-box__headerbtn {
|
|
|
|
|
|
display: flex !important;
|
|
|
|
|
|
flex-direction: row-reverse;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
font-size: 10px;
|
|
|
|
|
|
line-height: 10px;
|
|
|
|
|
|
padding-right: 5px !important;
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
i {
|
|
|
|
|
|
width: 10px;
|
|
|
|
|
|
height: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
.el-message-box__title {
|
|
|
|
|
|
font-size: 14px !important;
|
|
|
|
|
|
color: #353636;
|
|
|
|
|
|
letter-spacing: 0;
|
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
.el-message-box__content {
|
|
|
|
|
|
height: 96px;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: #353636;
|
|
|
|
|
|
letter-spacing: 0;
|
|
|
|
|
|
line-height: 22px;
|
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
padding-top: 8px;
|
|
|
|
|
|
padding-right: 20px;
|
|
|
|
|
|
padding-left: 20px;
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
.el-message-box__message {
|
|
|
|
|
|
padding-left: 0 !important;
|
|
|
|
|
|
padding-right: 0 !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
.el-message-box__btns {
|
|
|
|
|
|
height: 52px;
|
|
|
|
|
|
border-top: 1px solid #eee;
|
|
|
|
|
|
box-shadow: inset 0 -1px 0 0 rgba(0, 0, 0, 0.07);
|
|
|
|
|
|
padding: 11px 0 12px !important;
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
.el-button--small {
|
|
|
|
|
|
padding: 8px 21px !important;
|
|
|
|
|
|
line-height: 12px;
|
|
|
|
|
|
font-family: NotoSansHans-Medium !important;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
min-height: 28px;
|
|
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
|
2023-04-21 14:57:18 +08:00
|
|
|
|
.el-button:nth-child(1) {
|
|
|
|
|
|
margin-right: 20px;
|
|
|
|
|
|
width: 80px;
|
|
|
|
|
|
height: 28px;
|
2023-04-19 14:01:37 +08:00
|
|
|
|
color: #353636;
|
|
|
|
|
|
}
|
2023-04-21 14:57:18 +08:00
|
|
|
|
|
|
|
|
|
|
.el-button:nth-child(2) {
|
|
|
|
|
|
width: 80px;
|
|
|
|
|
|
height: 28px;
|
|
|
|
|
|
margin-right: 20px;
|
|
|
|
|
|
margin-left: 0 !important;
|
|
|
|
|
|
background-color: #2d8cf0;
|
|
|
|
|
|
border-color: #2d8cf0;
|
2023-04-19 14:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-04-21 14:57:18 +08:00
|
|
|
|
}
|
2023-03-31 17:50:38 +08:00
|
|
|
|
</style>
|