This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nezha-fronted/nezha-fronted/src/components/common/table/alert/alertSilenceTable.vue

288 lines
8.4 KiB
Vue
Raw Normal View History

2021-04-13 20:33:12 +08:00
<template>
<el-table
id="alertSilenceTable"
ref="dataTable"
:data="tableData"
:height="height"
border
@header-dragend="dragend"
@sort-change="tableDataSort"
@selection-change="selectionChange"
>
<el-table-column
:resizable="false"
align="center"
type="selection"
width="55">
</el-table-column>
<el-table-column
v-for="(item, index) in customTableTitle"
v-if="item.show"
:key="`col-${index}`"
:fixed="item.fixed"
:label="item.label"
:min-width="`${item.minWidth}`"
:prop="item.prop"
:resizable="true"
:sort-orders="['ascending', 'descending']"
:sortable="item.sortable"
2021-04-13 20:33:12 +08:00
:width="`${item.width}`"
class="data-column"
>
<template slot="header">
<span>{{item.label}}</span>
<div class="col-resize-area"></div>
</template>
<template slot-scope="scope" :column="item">
<template v-if="item.prop === 'duration'">
<el-tooltip :disabled="!scope.row.endAt" effect="light" placement="right">
<div slot="content">
{{$t('config.terminallog.endTime')}}<br/>
2021-05-10 19:04:39 +08:00
{{utcTimeToTimezoneStr(scope.row.endAt)}}
2021-04-13 20:33:12 +08:00
</div>
<span>{{getDuration(scope.row)}}</span>
</el-tooltip>
</template>
<template v-else-if="item.prop === 'matchers'">
<!-- <div class="nz-silence-tag-box">-->
<!-- <span v-if="scope.row.linkId!==-1" class="nz-silence-tag blue">-->
<!-- <span class="nz-silence-tag-title">{{scope.row.type}}</span>-->
<!-- <span :title="scope.row.linkName" class="nz-silence-tag-content">{{scope.row.linkName}}</span>-->
<!-- </span>-->
<!-- <span v-if="scope.row.ruleId!==-1" class="nz-silence-tag rule-gray">-->
<!-- <span class="nz-silence-tag-title">Alert rule</span>-->
<!-- <span :title="scope.row.ruleName" class="nz-silence-tag-content">{{scope.row.ruleName}}</span>-->
<!-- </span>-->
<!-- </div>-->
<span v-for="(item1, i) in labelsSort(scope.row.matchers)" :key="i">
<span >
<nz-alert-tag
v-if="item1.name !== 'alertname' && item1.name !== 'severity'" :key="i" :cursor-point="tagType(item1.name) !== 'info'"
:label="item1.name"
:type="tagType(item1.name)"
:regex="item1.regex"
style="margin: 5px 0 5px 5px;"
>
{{item1.value}}
</nz-alert-tag>
</span>
</span>
2021-04-13 20:33:12 +08:00
</template>
<template v-else-if="item.prop === 'state'">
2021-05-10 17:41:54 +08:00
<span v-if="scope.row.state===1" class="silence-active">active</span>
<span v-if="scope.row.state===2" class="silence-pending">pending</span>
2021-04-13 20:33:12 +08:00
<span v-if="scope.row.state===3" class="silence-expired">expired</span>
</template>
<template v-else-if="item.prop === 'utime'">
{{utcTimeToTimezoneStr(scope.row[item.prop])}}
</template>
2021-05-10 19:04:39 +08:00
<template v-else-if="item.prop === 'startAt'">
{{utcTimeToTimezoneStr(scope.row[item.prop])}}
</template>
2021-04-13 20:33:12 +08:00
<span v-else-if="scope.row[item.prop]">{{scope.row[item.prop] || '-'}}</span>
<template v-else>-</template>
</template>
</el-table-column>
<el-table-column
:resizable="false"
:width="operationWidth"
fixed="right">
<div slot="header" class="table-operation-title">{{$t('overall.option')}}</div>
<div slot-scope="scope" class="table-operation-items">
<button class="table-operation-item" @click="$emit('edit', scope.row)"><i class="nz-icon nz-icon-edit"></i></button>
2021-04-13 20:33:12 +08:00
<el-dropdown size="medium" trigger="hover" @command="tableOperation">
<div class="table-operation-item table-operation-item--more">
<span></span><i class="nz-icon nz-icon-arrow-down"></i>
</div>
<el-dropdown-menu slot="dropdown">
<!-- <el-dropdown-item :command="['edit', scope.row]"><i class="nz-icon nz-icon-edit"></i><span class="operation-dropdown-text">{{$t('overall.edit')}}</span></el-dropdown-item>-->
2021-04-13 20:33:12 +08:00
<el-dropdown-item :command="['delete', scope.row]"><i class="nz-icon nz-icon-delete"></i><span class="operation-dropdown-text">{{$t('buttons.expire')}}</span></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-table-column>
</el-table>
</template>
<script>
import table from '@/components/common/mixin/table'
import { calcDurationByStringTimeB } from '@/components/common/js/tools'
import nzAlertTag from '../../../page/alert/nzAlertTag'
import { sameLabels } from '@/components/common/js/constants'
2021-04-13 20:33:12 +08:00
export default {
name: 'alertSilenceTable',
components: {
nzAlertTag
},
2021-04-13 20:33:12 +08:00
mixins: [table],
data () {
return {
/* 表格相关 */
tableTitle: [
{
label: 'ID',
prop: 'id',
show: true,
width: 80,
sortable: 'custom'
},
{
label: 'Name',
prop: 'name',
show: true,
width: 150
2021-04-13 20:33:12 +08:00
}, {
2021-05-12 09:47:28 +08:00
label: this.$t('alert.silence.matchers'),
2021-04-13 20:33:12 +08:00
prop: 'matchers',
show: true,
sortable: 'custom'
2021-04-13 20:33:12 +08:00
}, {
label: this.$t('alert.silence.startTime'),
2021-04-13 20:33:12 +08:00
prop: 'startAt',
show: true,
width: 300,
sortable: 'custom'
2021-04-13 20:33:12 +08:00
}, {
label: this.$t('config.terminallog.duration'),
prop: 'duration',
show: true,
width: 120
}, {
2021-05-11 17:20:22 +08:00
label: this.$t('alert.silence.remark'),
prop: 'remark',
2021-04-13 20:33:12 +08:00
show: true,
width: 120
}, {
label: this.$t('alert.silence.upTime'),
2021-04-13 20:33:12 +08:00
prop: 'utime',
show: false,
2021-04-13 20:33:12 +08:00
width: 120
}, {
label: this.$t('alert.silence.state'),
2021-04-13 20:33:12 +08:00
prop: 'state',
show: true,
width: 120
}
]
}
},
computed: {
getDuration () {
return function (record) {
if (record.endAt) {
return calcDurationByStringTimeB(record.startAt, record.endAt)
}
return calcDurationByStringTimeB(record.startAt, this.utcTimeToTimezoneStr(this.nowTime))
2021-04-13 20:33:12 +08:00
}
},
tagType () {
return (key) => {
if (sameLabels.find(item => item === key)) {
return 'normal'
} else {
return 'info'
}
}
}
},
methods: {
labelsSort (obj) {
obj = obj || []
const buildIn = sameLabels
if (typeof obj === 'string') obj = JSON.parse(obj)
const labels = JSON.parse(JSON.stringify(obj))
const result = []
const result2 = []
for (const key of buildIn) {
labels.forEach(item => {
if (item.name === key) {
result.push(item)
}
})
}
labels.forEach(item => {
if (buildIn.indexOf(item.name) === -1) {
result2.push(item)
}
})
return [...result, ...result2]
2021-04-13 20:33:12 +08:00
}
}
}
</script>
<style lang="scss" scoped>
.nz-silence-tag-box{
width: 100%;
height: 100%;
.nz-silence-tag{
/*float: left;*/
/*margin-top: 5px;*/
}
}
.nz-silence-tag{
min-width: 80px;
margin-right: 5px;
border-radius: 4px;
display: inline-flex;
width: auto;
height: 20px;
line-height: 20px;
.nz-silence-tag-title{
color: #fff;
text-align: center;
padding: 0 5px;
}
.nz-silence-tag-content{
padding: 0 10px;
max-width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
flex: 1;
}
}
.nz-silence-tag.blue{
border: 1px solid #3C92F1;
.nz-silence-tag-title{
background: #3C92F1;
}
}
.nz-silence-tag.rule-gray{
border: 1px solid #7F8696;
.nz-silence-tag-title{
background: #7F8696;
}
}
.silence-active{
background: #E3F2D9;
border-radius: 4px;
font-family: PingFangSC-Regular;
font-size: 14px;
color: #0AB000;
line-height: 14px;
font-weight: 400;
padding: 0 5px;
}
.silence-pending{
background: #FFECD9;
border-radius: 4px;
font-family: PingFangSC-Regular;
font-size: 14px;
color: #FA901C;
line-height: 20px;
font-weight: 400;
padding: 0 5px;
}
.silence-expired{
background: #9e9c98;
border-radius: 4px;
font-family: PingFangSC-Regular;
font-size: 14px;
color: #ffffff;
line-height: 14px;
font-weight: 400;
padding: 0 5px;
}
</style>