CN-1273 自定义library增加tag颜色选择功能

This commit is contained in:
hyx
2023-10-09 11:55:19 +08:00
parent 6f72b2258f
commit 16e63ab905
6 changed files with 121 additions and 16 deletions

View File

@@ -1156,7 +1156,6 @@ height: 100%;
.el-form { .el-form {
margin-top: 20px; margin-top: 20px;
width: 620px; width: 620px;
label { label {
padding-bottom: 6px; padding-bottom: 6px;
font-size: 14px; font-size: 14px;
@@ -1191,6 +1190,7 @@ height: 100%;
.el-input__inner { .el-input__inner {
background-color: white !important; background-color: white !important;
padding-left: 22px !important;
} }
} }
} }
@@ -1872,3 +1872,24 @@ height:300px !important;
} }
} }
} }
.knowledge-color {
display:flex;
flex-direction: row;
align-items: center;
.knowledge-color__icon {
width: 10px;
height: 10px;
border-radius: 2px;
margin-right:6px;
margin-left:2px;
}
}
.info {
background-color:rgb(119,131,145)
}
.benign {
background-color:rgb(116,159,77)
}
.malicious {
background-color:rgb(226,97,84)
}

View File

@@ -392,7 +392,7 @@ export default {
this.dnsRcodeMapData = await getDnsMapData('dnsRcode') this.dnsRcodeMapData = await getDnsMapData('dnsRcode')
} }
} }
let path = this.$route.path; const path = this.$route.path
if (path.indexOf('panel') > -1 && path.indexOf('linkMonitor') === -1) { if (path.indexOf('panel') > -1 && path.indexOf('linkMonitor') === -1) {
await this.initDropdownList() await this.initDropdownList()
} }

View File

@@ -104,6 +104,11 @@
> >
</el-switch> </el-switch>
</template> </template>
<template v-else-if="item.prop === 'color'">
<div class="knowledge-color">
<span class="knowledge-color__icon" :class="colorName(scope.row[item.prop])"></span> <span>{{colorText(scope.row[item.prop])}}</span>
</div>
</template>
<span v-else>{{scope.row[item.prop] || '-'}}</span> <span v-else>{{scope.row[item.prop] || '-'}}</span>
</template> </template>
</el-table-column> </el-table-column>
@@ -117,7 +122,7 @@
<script> <script>
import table from '@/mixins/table' import table from '@/mixins/table'
import { knowledgeBaseCategory, knowledgeBaseSource } from '@/utils/constants' import { knowledgeBaseCategory, knowledgeBaseSource, knowledgeBaseColor } from '@/utils/constants'
export default { export default {
name: 'KnowledgeBaseTableForRow', name: 'KnowledgeBaseTableForRow',
props: { props: {
@@ -153,6 +158,11 @@ export default {
prop: 'reference', prop: 'reference',
width: 180, width: 180,
show: true show: true
}, {
label: this.$t('overall.color'),
prop: 'color',
width: 180,
show: true
}, { }, {
label: this.$t('overall.remark'), label: this.$t('overall.remark'),
prop: 'description', prop: 'description',
@@ -189,7 +199,8 @@ export default {
show: true, show: true,
width: 80 width: 80
} }
] ],
knowledgeBaseColor
} }
}, },
watch: { watch: {
@@ -221,6 +232,18 @@ export default {
const t = knowledgeBaseSource.find(t => t.value === type) const t = knowledgeBaseSource.find(t => t.value === type)
return t ? t.name : '' return t ? t.name : ''
} }
},
colorText () {
return function (color) {
const t = knowledgeBaseColor.find(t => t.value === color)
return t ? t.label : knowledgeBaseColor[0].label
}
},
colorName () {
return function (color) {
const t = knowledgeBaseColor.find(t => t.value === color)
return t ? t.name : knowledgeBaseColor[0].name
}
} }
} }
} }

View File

@@ -338,6 +338,25 @@ export const knowledgeBaseType = [
} }
] ]
export const knowledgeBaseColor = [
{
label: 'Info',
value: 'rgb(119,131,145)',
name: 'info'
},
{
label: 'Benign',
value: 'rgb(116,159,77)',
name: 'benign'
},
{
label: 'Malicious',
value: 'rgb(226,97,84)',
name: 'malicious'
}
]
export const knowledgeBaseCategory = [ export const knowledgeBaseCategory = [
{ {
name: 'WebSketch', name: 'WebSketch',

View File

@@ -31,6 +31,28 @@
</template> </template>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item :label="$t('overall.color')" prop="color">
<el-select v-model="editObject.colorLabel"
class="form-select__enable"
placeholder=" "
popper-class="form-select-popper"
size="mini"
@change="changeColor"
>
<template #prefix>
<div class="knowledge-color">
<span class="knowledge-color__icon info" :class="editObject.colorName"></span>
</div>
</template>
<template v-for="color in knowledgeBaseColor" :key="color.name">
<el-option :value="color.label" >
<div class="knowledge-color">
<span class="knowledge-color__icon" :class="color.name"></span> <span>{{color.label}}</span>
</div>
</el-option>
</template>
</el-select>
</el-form-item>
<el-form-item :label="$t('overall.remark')" prop="description"> <el-form-item :label="$t('overall.remark')" prop="description">
<el-input maxlength="255" show-word-limit :rows="4" size='mini' type="textarea" resize='none' <el-input maxlength="255" show-word-limit :rows="4" size='mini' type="textarea" resize='none'
v-model="editObject.description" id="role-box-input-remark"/> v-model="editObject.description" id="role-box-input-remark"/>
@@ -214,7 +236,7 @@
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { nextTick, reactive, ref } from 'vue' import { nextTick, reactive, ref } from 'vue'
import _ from 'lodash' import _ from 'lodash'
import { knowledgeBaseType, storageKey, unitTypes, knowledgeSourceValue, itemListHeight, knowledgeCategoryValue } from '@/utils/constants' import { knowledgeBaseType, storageKey, unitTypes, knowledgeSourceValue, itemListHeight, knowledgeCategoryValue, knowledgeBaseColor } from '@/utils/constants'
import Pagination from '@/components/common/Pagination' import Pagination from '@/components/common/Pagination'
import ChartNoData from '@/views/charts/charts/ChartNoData' import ChartNoData from '@/views/charts/charts/ChartNoData'
import axios from 'axios' import axios from 'axios'
@@ -497,6 +519,11 @@ export default {
} }
}, },
methods: { methods: {
changeColor (label) {
const curColorObj = knowledgeBaseColor.find(item => item.label === this.editObject.colorLabel)
this.editObject.color = curColorObj.value
this.editObject.colorName = curColorObj.name
},
tagNameBlur () { tagNameBlur () {
if (!this.tagNameFirstBlur) { if (!this.tagNameFirstBlur) {
this.$refs.form.validate(valid => { this.$refs.form.validate(valid => {
@@ -832,6 +859,7 @@ export default {
const postData = { const postData = {
name: this.editObject.name, name: this.editObject.name,
category: knowledgeCategoryValue.userDefined, category: knowledgeCategoryValue.userDefined,
color: this.editObject.color,
source: this.editObject.source, source: this.editObject.source,
description: this.editObject.description, description: this.editObject.description,
status: this.editObject.status, status: this.editObject.status,
@@ -1187,6 +1215,16 @@ export default {
throw new Error('No data found, id: ' + this.knowledgeBaseId) throw new Error('No data found, id: ' + this.knowledgeBaseId)
} }
this.editObject = response.data.data this.editObject = response.data.data
if (response.data.data.color) {
const curColorObj = knowledgeBaseColor.find(item => item.value === response.data.data.color)
this.editObject.color = curColorObj.value
this.editObject.colorName = curColorObj.name
this.editObject.colorLabel = curColorObj.label
} else {
this.editObject.color = knowledgeBaseColor[0].value
this.editObject.colorName = knowledgeBaseColor[0].name
this.editObject.colorLabel = knowledgeBaseColor[0].label
}
this.importedData = this.handleSpeticalTypeData(this.editObject.itemList) this.importedData = this.handleSpeticalTypeData(this.editObject.itemList)
this.importedData.forEach(item => { this.importedData.forEach(item => {
this.oldItemIds.push(item.id) this.oldItemIds.push(item.id)
@@ -1283,7 +1321,10 @@ export default {
source: 'cn_ip_tag_user_defined', source: 'cn_ip_tag_user_defined',
description: '', description: '',
updateTime: '', updateTime: '',
status: 1 status: 1,
color: knowledgeBaseColor[0].value,
colorLabel: knowledgeBaseColor[0].label,
colorName: knowledgeBaseColor[0].name
} }
/* 将组织后的数据还原拉平 */ /* 将组织后的数据还原拉平 */
const revertImportedData = (data) => { const revertImportedData = (data) => {
@@ -1366,6 +1407,7 @@ export default {
stepHeightConstant, stepHeightConstant,
stepHeights, stepHeights,
knowledgeBaseType, knowledgeBaseType,
knowledgeBaseColor,
importedData, importedData,
showImportedData, showImportedData,
addItemList, addItemList,