feat:alert silence 列表页面增加 alerts 列

This commit is contained in:
likexuan
2022-04-15 13:06:02 +08:00
parent e9d1e6ce9c
commit 4f5e25bfb6
4 changed files with 429 additions and 272 deletions

View File

@@ -14,7 +14,8 @@
:resizable="false"
align="center"
type="selection"
width="55">
width="55"
>
</el-table-column>
<el-table-column
v-for="(item, index) in customTableTitle"
@@ -31,70 +32,131 @@
class="data-column"
>
<template slot="header">
<span class="data-column__span">{{item.label}}</span>
<span class="data-column__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">
<el-tooltip
:disabled="!scope.row.endAt"
effect="light"
placement="right"
>
<div slot="content">
{{$t('config.terminallog.endTime')}}<br/>
{{utcTimeToTimezoneStr(scope.row.endAt)}}
{{ $t("config.terminallog.endTime") }}<br />
{{ utcTimeToTimezoneStr(scope.row.endAt) }}
</div>
<span>{{getDuration(scope.row)}}</span>
<span>{{ getDuration(scope.row) }}</span>
</el-tooltip>
</template>
<template v-else-if="item.prop === 'alertNum'">
<span style="cursor: pointer" @click="$emit('showBottomBox', 'alertMessageTab', scope.row)">
<i
:class="scope.row.alertNum > 0 ? 'gray' : 'green'"
class="nz-icon nz-icon-overview-alert vertical-align-top;"
@mouseenter="tooltipHover(scope.row, true, $event)"
@mouseleave="tooltipHover(scope.row, false, $event)"
></i><span>{{scope.row.alerts}}</span>
</span>
</template>
<template v-else-if="item.prop === 'matchers'">
<span v-for="(item1, i) in labelsSort(scope.row.matchers)" :key="i">
<span >
<nz-alert-tag
: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>
<nz-alert-tag
: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>
</template>
<template v-else-if="item.prop === 'state'">
<span v-if="scope.row.state===1" class="silence-active">active</span>
<span v-if="scope.row.state===2" class="silence-pending">pending</span>
<span v-if="scope.row.state===3" class="silence-expired">expired</span>
<span v-if="scope.row.state === 1" class="silence-active"
>active</span
>
<span v-if="scope.row.state === 2" class="silence-pending"
>pending</span
>
<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])}}
{{ utcTimeToTimezoneStr(scope.row[item.prop]) }}
</template>
<template v-else-if="item.prop === 'startAt'">
{{utcTimeToTimezoneStr(scope.row[item.prop])}}
{{ utcTimeToTimezoneStr(scope.row[item.prop]) }}
</template>
<span v-else-if="scope.row[item.prop]">{{scope.row[item.prop] || '-'}}</span>
<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>
<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&#45;&#45;disable': scope.row.state === 3}" class="table-operation-item" v-has="'alertSilence_edit'" @click="$emit('edit', scope.row)" :disabled="scope.row.state === 3"><i class="nz-icon nz-icon-edit"></i></button>-->
<button class="table-operation-item" @click="$emit('showBottomBox', 'alertMessageTab', scope.row)"><i class="nz-icon nz-icon-view1"></i></button>
<el-dropdown size="medium" v-has="['alertSilence_expire', 'alertSilence_edit']" trigger="click" @command="tableOperation">
<!-- <button :class="{'table-operation-item&#45;&#45;disable': scope.row.state === 3}" class="table-operation-item" v-has="'alertSilence_edit'" @click="$emit('edit', scope.row)" :disabled="scope.row.state === 3"><i class="nz-icon nz-icon-edit"></i></button>-->
<button
class="table-operation-item"
@click="$emit('showBottomBox', 'alertMessageTab', scope.row)"
>
<i class="nz-icon nz-icon-view1"></i>
</button>
<el-dropdown
size="medium"
v-has="['alertSilence_expire', 'alertSilence_edit']"
trigger="click"
@command="tableOperation"
>
<div class="table-operation-item table-operation-item--more">
<i class="nz-icon nz-icon-more3"></i>
</div>
<el-dropdown-menu slot="dropdown" class="right-box-select-top right-public-box-dropdown-top">
<el-dropdown-item :command="['edit', scope.row]" :class="{'table-operation-item--disable': scope.row.state === 3}" class="table-operation-item" v-has="'alertSilence_edit'" :disabled="scope.row.state === 3"><i class="nz-icon nz-icon-edit"></i><span class="operation-dropdown-text">{{$t('overall.edit')}}</span></el-dropdown-item>
<el-dropdown-item v-has="'alertSilence_edit'" :command="['copy', scope.row]"><i class="nz-icon nz-icon-override"></i><span class="operation-dropdown-text">{{$t('overall.duplicate')}}</span></el-dropdown-item>
<el-dropdown-item v-has="'alertSilence_expire'" :command="['delete', scope.row]"><i class="nz-icon nz-icon-delete"></i><span class="operation-dropdown-text">{{$t('buttons.delete')}}</span></el-dropdown-item>
<el-dropdown-menu
slot="dropdown"
class="right-box-select-top right-public-box-dropdown-top"
>
<el-dropdown-item
:command="['edit', scope.row]"
:class="{
'table-operation-item--disable': scope.row.state === 3,
}"
class="table-operation-item"
v-has="'alertSilence_edit'"
:disabled="scope.row.state === 3"
><i class="nz-icon nz-icon-edit"></i
><span class="operation-dropdown-text">{{
$t("overall.edit")
}}</span></el-dropdown-item
>
<el-dropdown-item
v-has="'alertSilence_edit'"
:command="['copy', scope.row]"
><i class="nz-icon nz-icon-override"></i
><span class="operation-dropdown-text">{{
$t("overall.duplicate")
}}</span></el-dropdown-item
>
<el-dropdown-item
v-has="'alertSilence_expire'"
:command="['delete', scope.row]"
><i class="nz-icon nz-icon-delete"></i
><span class="operation-dropdown-text">{{
$t("buttons.delete")
}}</span></el-dropdown-item
>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-table-column>
<template slot="empty">
<template slot="empty">
<div v-if="!loading" class="table-no-data">
<svg class="icon" aria-hidden="true">
<use xlink:href="#nz-icon-no-data-list"></use>
@@ -107,114 +169,130 @@
</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'
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";
export default {
name: 'alertSilenceTable',
name: "alertSilenceTable",
components: {
nzAlertTag
nzAlertTag,
},
mixins: [table],
props: {
loading: Boolean,
nowTime: {}
nowTime: {},
},
data () {
data() {
return {
/* 表格相关 */
tableTitle: [
{
label: 'ID',
prop: 'id',
label: "ID",
prop: "id",
show: true,
width: 80,
sortable: 'custom'
sortable: "custom",
},
{
label: this.$t('alert.silence.name'),
prop: 'name',
label: this.$t("alert.silence.name"),
prop: "name",
show: true,
minWidth: 150
}, {
label: this.$t('alert.silence.matchers'),
prop: 'matchers',
minWidth: 150,
},
{
label: this.$t("alert.silence.matchers"),
prop: "matchers",
show: true,
minWidth: 200,
sortable: 'custom'
}, {
label: this.$t('alert.silence.startTime'),
prop: 'startAt',
sortable: "custom",
},
{
label: this.$t("alert.alert"),
prop: "alertNum",
show: true,
minWidth: 120,
sortable: "custom",
},
{
label: this.$t("alert.silence.startTime"),
prop: "startAt",
show: true,
width: 300,
sortable: 'custom'
}, {
label: this.$t('config.terminallog.duration'),
prop: 'duration',
sortable: "custom",
},
{
label: this.$t("config.terminallog.duration"),
prop: "duration",
show: true,
width: 120
}, {
label: this.$t('alert.silence.remark'),
prop: 'remark',
width: 120,
},
{
label: this.$t("alert.silence.remark"),
prop: "remark",
show: true,
width: 120
}, {
label: this.$t('alert.silence.upTime'),
prop: 'utime',
width: 120,
},
{
label: this.$t("alert.silence.upTime"),
prop: "utime",
show: false,
width: 300
}, {
label: this.$t('alert.silence.state'),
prop: 'state',
width: 300,
},
{
label: this.$t("alert.silence.state"),
prop: "state",
show: true,
width: 120
}
]
}
width: 120,
},
],
};
},
computed: {
getDuration () {
getDuration() {
return function (record) {
if (record.endAt) {
return calcDurationByStringTimeB(record.startAt, record.endAt)
return calcDurationByStringTimeB(record.startAt, record.endAt);
}
return calcDurationByStringTimeB(record.startAt, this.utcTimeToTimezoneStr(this.nowTime))
}
return calcDurationByStringTimeB(
record.startAt,
this.utcTimeToTimezoneStr(this.nowTime)
);
};
},
tagType () {
tagType() {
return (key) => {
if (sameLabels.find(item => item === key)) {
return 'normal'
if (sameLabels.find((item) => item === key)) {
return "normal";
} else {
return 'info'
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 = []
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 => {
labels.forEach((item) => {
if (item.name === key) {
result.push(item)
result.push(item);
}
})
});
}
labels.forEach(item => {
labels.forEach((item) => {
if (buildIn.indexOf(item.name) === -1) {
result2.push(item)
result2.push(item);
}
})
});
// console.log([...result, ...result2])
return [...result, ...result2]
}
}
}
return [...result, ...result2];
},
},
};
</script>