perf: 支持点击 label 搜索

This commit is contained in:
ibuler
2023-12-19 16:59:25 +08:00
committed by huailei
parent 3739d710f8
commit 7eac62635b
3 changed files with 51 additions and 12 deletions

View File

@@ -375,6 +375,7 @@ export default {
this.refresh()
this.$log.debug('Visible change, refresh select2')
}
this.$emit('visible-change', visible)
}
}
}

View File

@@ -1,7 +1,7 @@
<template>
<div class="label-search">
<el-button
v-if="showLabelButton"
v-if="!showLabelSearch"
class="label-button"
plain
size="small"
@@ -64,6 +64,27 @@ export default {
this.$emit('labelSearch', labelSearch)
}
},
mounted() {
this.$eventBus.$on('labelSearch', label => {
if (!label) {
this.labelValue = []
this.showLabelSearch = true
return
}
const labels = label.split(',').map(item => item.split(':'))
const notExistLabels = labels.filter(item => {
return !this.labelValue.find(label => label[0] === item[0] && label[1] === item[1])
})
this.labelValue = [...this.labelValue, ...notExistLabels]
this.getLabelOptions()
setTimeout(() => {
this.showLabelSearch = true
}, 500)
})
},
destroyed() {
this.$eventBus.$off('labelSearch')
},
methods: {
getLabelOptions() {
if (this.labelOptions.length > 0) {

View File

@@ -1,25 +1,30 @@
<template>
<div>
<a class="tag" @click="showDialog=true">
<a class="label-formatter-col">
<span v-if="!iLabels || iLabels.length === 0">
<el-tag effect="plain" size="mini">
<i class="fa fa-tag" /> -
</el-tag>
</span>
<div v-else>
<el-tag
<div
v-for="label of iLabels"
:key="label"
:type="getLabelType(label)"
class="tag-formatter"
disable-transitions
effect="plain"
size="mini"
v-bind="formatterArgs.config"
>
<i class="fa fa-tag" /> <b> {{ getKey(label) }}</b>: {{ getValue(label) }}
</el-tag>
<el-tag
:type="getLabelType(label)"
class="tag-formatter"
disable-transitions
effect="plain"
size="mini"
v-bind="formatterArgs.config"
@click="handleLabelSearch(label)"
>
<i class="fa fa-tag" /> <b> {{ getKey(label) }}</b>: {{ getValue(label) }}
</el-tag>
</div>
</div>
<a class="edit-btn" style="padding-left: 5px" @click="showDialog = true"> <i class="fa fa-edit" /></a>
</a>
<Dialog
v-if="showDialog"
@@ -97,6 +102,7 @@ export default {
},
data() {
return {
focusOn: '',
formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs),
initial: [],
iLabels: [],
@@ -131,6 +137,9 @@ export default {
this.iLabels = [...this.initial]
},
methods: {
handleLabelSearch(label) {
this.$eventBus.$emit('labelSearch', label)
},
getLabelType(tag) {
return this.formatterArgs.getLabelType(tag)
},
@@ -198,6 +207,14 @@ export default {
}
}
.edit-btn {
display: none;
float: right;
}
.label-formatter-col:hover .edit-btn {
display: inline;
}
.tag-zone {
margin: 20px 0 0 0;
border: solid 1px #ebeef5;
@@ -223,7 +240,7 @@ export default {
.tag-formatter {
margin: 2px 0;
display: table;
//display: table;
}
.tag-tip {