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/project/popData/alertTable.vue

407 lines
11 KiB
Vue
Raw Normal View History

<template>
<div class="mc" @click.self="clickOutside">
<div class="right-box right-box-project-alert">
<div class="right-box-title">{{ moduleName }} / {{$t('dashboard.overview.alert.alertMessage')}}</div>
<nz-data-list
ref="dataList"
:api="url"
:custom-table-title.sync="tableTitle"
:from="fromRoute.alertMessage"
:layout="['searchInput']"
:search-msg="searchMsg"
@search="search"
v-loading="tools.loading"
>
<template v-slot:top-tool-right>
<el-select v-model="state" class="margin-r-10" size="small" value-key="value" @change="getTableData">
<el-option v-for="item in stateOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
</el-select>
</template>
<template v-slot:default="slotProps">
<alert-message-table
ref="dataTable"
:api="url"
:custom-table-title="tableTitle"
:height="mainTableHeight"
:now-time="nowTime"
:table-data="tableData"
:showOption="false"
@del="del"
@edit="edit"
@orderBy="tableDataSort"
@reload="getTableData"
@selectionChange="selectionChange"></alert-message-table>
</template>
<!-- 分页组件 -->
<template v-slot:pagination>
<Pagination ref="Pagination" :pageObj="pageObj" :tableId="tableId" @pageNo='pageNo' @pageSize='pageSize'></Pagination>
</template>
</nz-data-list>
</div>
</div>
</template>
<script>
2021-03-19 18:52:19 +08:00
import bus from '@/libs/bus'
import nzAlertTag from '@/components/page/alert/nzAlertTag'
import alertRuleInfo from '@/components/common/alert/alertRuleInfo'
import alertLabel from '@/components/common/alert/alertLabel'
import nzDataList from '@/components/common/table/nzDataList'
import dataListMixin from '@/components/common/mixin/dataList'
import alertMessageTable from '@/components/common/table/alert/alertMessageTable.vue'
import { alertMessage as alertMessageConstant } from '@/components/common/js/constants'
2021-03-19 18:52:19 +08:00
export default {
name: 'alertTable',
props: {
moduleId: {},
projectId: {},
moduleName: String
2021-03-19 18:52:19 +08:00
},
components: {
'nz-alert-tag': nzAlertTag,
alertRuleInfo: alertRuleInfo,
alertLabel: alertLabel,
nzDataList,
alertMessageTable
2021-03-19 18:52:19 +08:00
},
mixins: [dataListMixin],
2021-03-19 18:52:19 +08:00
watch: {
},
computed: {
tagType () {
return (key) => {
if (key == 'asset' || key == 'module' || key == 'project' || key == 'datacenter' || key == 'endpoint') {
return 'normal'
} else {
return 'info'
}
}
2020-08-26 11:28:09 +08:00
},
2021-03-19 18:52:19 +08:00
tagValue () {
return (key, value) => {
if (key == 'type') {
if (value == 1) {
value = this.$t('project.project.projectName')
2021-03-19 18:52:19 +08:00
} else if (value == 2) {
value = this.$t('module.module.module')
} else if (value == 3) {
value = this.$t('asset.asset')
}
2020-08-26 11:28:09 +08:00
}
2021-03-19 18:52:19 +08:00
return key + '' + value
}
}
},
data () {
return {
url: 'alert/message',
state: '1',
tableId: '',
stateOptions: alertMessageConstant.states,
2021-03-19 18:52:19 +08:00
pageObj: {
pageNo: 1,
pageSize: this.$CONSTANTS.defaultPageSize,
total: 0
2020-08-26 11:28:09 +08:00
},
2021-03-19 18:52:19 +08:00
tableTitle: [
{
label: this.$t('alert.alertName'),
prop: 'alertRule',
show: true,
width: 180
}, {
label: this.$t('alert.list.labels'),
prop: 'labels',
show: true,
NotSet: true,
minWidth: 200
}, {
label: this.$t('alert.severity'),
prop: 'severity',
show: true,
width: 110
}, {
label: this.$t('alert.summary'),
prop: 'summary',
show: true,
minWidth: 100
},{
2021-03-19 18:52:19 +08:00
label: this.$t('alert.list.state'),
prop: 'state',
show: true,
width: 100
}, {
label: this.$t('alert.startAt'),
prop: 'startAt',
show: true,
width: 150
2020-08-26 11:28:09 +08:00
}
2021-03-19 18:52:19 +08:00
],
searchTime: [],
searchMsg: { // 给搜索框子组件传递的信息
searchLabelList: [
{
name: this.$t('alert.alertRule'),
type: 'input',
label: 'ruleName',
disabled: false
}, {
name: this.$t('asset.asset'),
type: 'input',
label: 'assetName',
disabled: false
}, {
name: 'Endpoint',
type: 'input',
label: 'endpointName',
disabled: false
}, {
name: this.$t('alert.summary'),
type: 'input',
label: 'summary',
disabled: false
}, {
name: this.$t('alert.list.labels'),
type: 'input',
label: 'labels',
disabled: false
}
]
2021-03-19 18:52:19 +08:00
},
tableData: [],
loading: false,
tableHeight: '100%',
searchLabel: {
2020-08-26 11:28:09 +08:00
2021-03-19 18:52:19 +08:00
},
deleteBox: {},
nowTime: ''
}
},
created () {
// 是否存在分页缓存
const pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId)
if (pageSize != 'undefined' && pageSize != null) {
this.pageObj.pageSize = pageSize
}
},
mounted () {
this.getTableData()
2021-03-19 18:52:19 +08:00
},
methods: {
getTableData: function () {
this.tools.loading = true
2021-03-19 18:52:19 +08:00
this.$set(this.searchLabel, 'pageNo', this.pageObj.pageNo)
this.$set(this.searchLabel, 'pageSize', this.pageObj.pageSize)
this.$set(this.searchLabel, 'moduleIds', this.moduleId)
2021-03-19 18:52:19 +08:00
if (this.searchTime && this.searchTime.length > 1) {
this.$set(this.searchLabel, 'startAt', bus.timeFormate(this.searchTime[0], 'yyyy-MM-dd hh:mm:ss'))
this.$set(this.searchLabel, 'endAt', bus.timeFormate(this.searchTime[1], 'yyyy-MM-dd hh:mm:ss'))
} else {
delete this.searchLabel.startAt
delete this.searchLabel.endAt
}
this.$get(this.url, { state: this.state, ...this.searchLabel }).then(response => {
this.tools.loading = false
2021-03-19 18:52:19 +08:00
if (response.code == 200) {
this.nowTime = this.utcTimeToTimezoneStr(response.time)
this.tableData = response.data.list
this.tableData.forEach((item) => {
item.labels = JSON.parse(item.labels)
})
this.deleteBox.ids = ''
this.pageObj.total = response.data.total
}
})
},
2021-03-19 18:52:19 +08:00
labelsSort: function (obj) {
const buildIn = ['asset', 'endpoint', 'module', 'project', 'datacenter']
const labels = JSON.parse(JSON.stringify(obj))
const result = []
for (const key of buildIn) {
if (key in labels) {
result.push({ label: key, value: labels[key] })
delete labels[key]
}
}
2021-03-19 18:52:19 +08:00
Object.keys(labels).sort().forEach(key => {
result.push({ label: key, value: labels[key] })
})
return result
},
2021-03-19 18:52:19 +08:00
labelsClassName (row) {
if (row.column.label == this.$t('alert.list.labels')) {
return 'alert-message-list-labels'
} else {
return ''
}
},
2021-03-19 18:52:19 +08:00
pageNo (val) {
this.pageObj.pageNo = val
this.getTableData()
2021-03-19 18:52:19 +08:00
},
pageSize (val) {
this.pageObj.pageSize = val
localStorage.setItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId, val)
this.getTableData()
2021-03-19 18:52:19 +08:00
},
selectChange (s) {
const ids = []
this.deleteBox.ids = ''
s.forEach(item => {
ids.push(item.id)
})
this.deleteBox.ids = ids.join(',')
},
// alertNmae鼠标划入
alertMessagehover (item, loading, e) {
if (e) {
const dom = e.currentTarget
const position = dom.getBoundingClientRect()
this.$set(item, 'position', position)
}
this.$set(item, 'loading', loading)
// item.loading = true;
// this.$set(this.tableData,index,item);// 调用父组件
},
// label 鼠标划入
labelHover (item, index, type, loading, e) {
if (this.labelToolTipDis(type)) {
return
}
if (e) {
const dom = e.currentTarget
const position = dom.getBoundingClientRect()
this.$set(item[type], 'position', position)
}
this.$set(item[type], 'loading', loading)
this.$set(this.tableData, index, item)// 调用父组件
},
// label tooltip是否显示
labelToolTipDis (labelType) {
switch (labelType) {
case 'asset':
case 'module':
case 'project':
return false
default: return true
}
},
// Severity Label
returnSeverityLabel (key) {
return this.$CONSTANTS.alertMessage.severityData.find(s => { return s.value == key }).label
},
tableDataSort (item) {
let orderBy = ''
if (item.order === 'ascending') {
orderBy = item.prop
}
if (item.order === 'descending') {
orderBy = '-' + item.prop
}
this.pageObj.orderBy = orderBy
this.$set(this.searchLabel, 'orderBy', orderBy)
this.getTableData()
2021-03-19 18:52:19 +08:00
},
/* 关闭弹框 */
esc (refresh) {
this.$emit('close', refresh)
},
clickOutside () {
this.esc(false)
},
search (searchObj) {
let orderBy = ''
if (this.searchLabel.orderBy) {
orderBy = this.searchLabel.orderBy
}
this.searchLabel = {}
this.pageObj.pageNo = 1
for (const item in searchObj) {
if (searchObj[item]) {
if (item == 'alertMessageState') {
this.$set(this.searchLabel, 'state', searchObj[item])
} else {
this.$set(this.searchLabel, item, searchObj[item])
2020-09-09 15:32:44 +08:00
}
}
2021-03-19 18:52:19 +08:00
}
if (orderBy) {
this.$set(this.searchLabel, 'orderBy', orderBy)
}
if (this.$refs.alertListTable && this.$refs.alertListTable.bodyWrapper) {
this.$refs.alertListTable.bodyWrapper.scrollTop = 0
}
this.getTableData()
},
2021-03-19 18:52:19 +08:00
showExportDialog () {
this.importBox.show = true
}
2021-03-19 18:52:19 +08:00
},
beforeDestroy () {
}
2021-03-19 18:52:19 +08:00
}
</script>
<style scoped>
2020-08-26 11:28:09 +08:00
.right-box-project-alert{
2020-10-12 13:46:31 +08:00
width: 850px;
2020-09-07 10:42:10 +08:00
padding-right: 30px;
}
.right-box-title{
font-weight: bold;
padding-left: 20px;
position: absolute;
z-index: 1;
2020-08-26 11:28:09 +08:00
}
.mc{
position: fixed;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
2020-08-26 11:28:09 +08:00
z-index: 11;
}
2020-09-09 15:32:44 +08:00
.top-tools{
float: right;
}
/deep/ .top-tools>div{
2020-09-10 09:18:37 +08:00
margin-top: 6px;
}
/deep/.el-tooltip{
display: inline-block;
2020-09-09 15:32:44 +08:00
}
.red,.green{
color: white;
padding: 2px 5px;
border-radius: 4px;
}
.severity .P1{
background: #F5846A;
2020-10-12 11:02:30 +08:00
border-radius: 2px;
font-size: 12px;
color: #FFFFFF;
padding: 2px 6px;
}
.severity .P2{
background: #F7A54A;
2020-10-12 11:02:30 +08:00
border-radius: 2px;
font-size: 12px;
color: #FFFFFF;
padding: 2px 6px;
}
.severity .P3{
background: #F1C13D;
2020-10-12 11:02:30 +08:00
border-radius: 2px;
font-size: 12px;
color: #FFFFFF;
padding: 2px 6px;
}
.right-box /deep/ .list-page .main-container{
background: #fff;
}
/* end--table*/
</style>