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/page/alert/alertRule.vue

480 lines
15 KiB
Vue
Raw Normal View History

2021-04-13 20:33:12 +08:00
<template>
<div>
<nzDetailView
2022-03-25 15:40:05 +08:00
v-my-loading="detailViewLoading || tools.loading"
v-if="detailType !== 'list'"
:api="url"
ref="detailList"
:layout="['searchInput', 'elementSet', 'pagination','detailViewSet']"
:from="fromRoute.alertRule"
:search-msg="searchMsg"
:detailType="detailType"
:detailViewRightObj="detailViewRightObj"
:dataLength="tableData.length"
@search="search"
@changeDetailType="changeDetailType"
>
<template v-slot:top-tool-left>
<!-- <detailViewTopSearch :selectValue.sync="selectValue" :detailSearchList="detailSearchList" @reload="reloadTable" />-->
</template>
<template v-slot:top-tool-right>
<button id="asset-create-asset" v-has="'asset_add'" :title="$t('asset.createAsset')" class="top-tool-btn" @click.stop="add">
<i class="nz-icon nz-icon-create-square"></i>
</button>
<top-tool-more-options
2021-11-02 15:47:17 +08:00
:delete-objs="batchDeleteObjs"
ref="export"
id="model"
:params="searchLabel"
:params2="searchCheckBox"
2022-01-11 17:05:21 +08:00
:permissions="{import: 'alertRule_add', export: 'alertRule_edit'}"
class="top-tool-export margin-l-10 margin-r-10"
export-file-name="AlertRule"
export-url="/alert/rule/export"
import-url="/alert/rule/import"
@afterImport="getTableData"
>
</top-tool-more-options>
</template>
<template v-slot:nz-detail-view-list>
<alertRuleDetail
class="data-detail"
ref="dataDetail"
:orderByFa="orderBy"
2022-03-25 15:40:05 +08:00
v-my-loading="tools.loading"
:loading="tools.loading"
:detailViewRightObj="detailViewRightObj"
:api="url"
:table-data="tableData"
@detailViewRightShow = 'detailViewRightShow'
@orderDetail="orderDetail"
>
</alertRuleDetail>
</template>
<!-- 分页组件 -->
<template v-slot:pagination>
<el-pagination
@current-change="pageNo"
:current-page.sync="pageObj.pageNo"
:page-size="20"
:total="pageObj.total"
layout="prev, slot, next"
small
>
<template>
<el-input-number ref="jumpInput" v-model="pageObj.pageNo" :controls="false" :min="1" :max="pageObj.pages" class="jump-input" @change="getTableData" @keyup.enter.native="getTableData" size="mini"/>
<span class="jump-pages">/&nbsp{{pageObj.pages}}</span>
</template>
</el-pagination>
</template>
</nzDetailView>
2021-04-13 20:33:12 +08:00
<nz-data-list
ref="dataList"
:api="url"
:custom-table-title.sync="tools.customTableTitle"
:from="fromRoute.alertRule"
:layout="['searchInput', 'elementSet', 'pagination','detailViewSet']"
:search-msg="searchMsg"
@search="search"
:detailType="detailType"
@changeDetailType="changeDetailType"
@getTableData="getTableData"
>
2021-04-13 20:33:12 +08:00
<template v-slot:top-tool-right>
<button id="alert-add" v-has="'alertRule_add'" :title="$t('overall.createAlertRule')" class="top-tool-btn"
@click="add">
<i class="nz-icon-create-square nz-icon"></i>
</button>
<top-tool-more-options
2021-11-02 15:47:17 +08:00
:delete-objs="batchDeleteObjs"
ref="export"
2021-04-13 20:33:12 +08:00
id="alert-rule"
:params="searchLabel"
2022-01-11 17:05:21 +08:00
:permissions="{import: 'alertRule_add', export: 'alertRule_edit'}"
class="top-tool-export margin-l-10 margin-r-10"
2021-04-13 20:33:12 +08:00
export-file-name="AlertRule"
export-url="/alert/rule/export"
import-url="/alert/rule/import"
@afterImport="getTableData"
>
<template v-slot:before>
<div>
<el-dropdown-item>
<delete-button :type="'link'" :title="$t('overall.batchDel')" id="alert-rule-batch-delete" v-has="'alertRule_delete'" :api="url" :delete-objs="batchDeleteObjs" @after="getTableData" @before="delFlag=true"></delete-button>
</el-dropdown-item>
</div>
2021-04-13 20:33:12 +08:00
</template>
</top-tool-more-options>
2021-04-13 20:33:12 +08:00
</template>
<template v-slot:default="slotProps">
<alert-rule-table
ref="dataTable"
:orderByFa="orderBy"
2022-03-25 15:40:05 +08:00
v-my-loading="tools.loading"
:loading="tools.loading"
2021-04-13 20:33:12 +08:00
:api="url"
:custom-table-title="tools.customTableTitle"
:height="mainTableHeight"
:table-data="tableData"
@del="del"
@edit="edit"
@copy="copy"
2021-04-13 20:33:12 +08:00
@orderBy="tableDataSort"
@queryMessage="queryMessage"
@reload="getTableData"
@addSilence="addSilence"
@statusChange='statusChange'
2021-04-13 20:33:12 +08:00
@selectionChange="selectionChange"
@showBottomBox="(targetTab, object) => { $refs.dataList.showBottomBox(targetTab, object) }"></alert-rule-table>
</template>
<!-- 分页组件 -->
<template v-slot:pagination>
<Pagination ref="Pagination" :pageObj="pageObj" :tableId="tableId" @pageNo='pageNo' @pageSize='pageSize'></Pagination>
</template>
</nz-data-list>
<transition name="right-box">
<alert-rule-box v-if="rightBox.show" ref="alertConfigBox" :severityData="severityData" :alert-rule="object" @close="closeRightBox"></alert-rule-box>
2021-04-13 20:33:12 +08:00
</transition>
2021-06-01 15:19:47 +08:00
<transition name="right-box"><alert-silence-box v-if='silenceBoxShow' :alert-silence="objectSilence" @close="closeSilenceBox"></alert-silence-box>
</transition>
2021-04-13 20:33:12 +08:00
</div>
</template>
<script>
import bus from '@/libs/bus'
import exportXLSX from '@/components/common/exportXLSX'
import alertRuleBox from '@/components/common/rightBox/alertRuleBox'
import deleteButton from '@/components/common/deleteButton'
import nzDataList from '@/components/common/table/nzDataList'
import dataListMixin from '@/components/common/mixin/dataList'
import alertRuleTable from '@/components/common/table/alert/alertRuleTable'
import topToolMoreOptions from '@/components/common/popBox/topToolMoreOptions'
2021-06-01 15:19:47 +08:00
import alertSilenceBox from '@/components/common/rightBox/alertSilenceBox'
import nzDetailView from '@/components/common/detailView/nzDetailView'
import detailViewMixin from '@/components/common/mixin/detailViewMixin'
import alertRuleDetail from '@/components/common/detailView/list/alertRule/alertRuleDetail'
import detailViewTopSearch from '@/components/common/detailView/detailViewTopSearch'
import routerPathParams from '@/components/common/mixin/routerPathParams'
2021-04-13 20:33:12 +08:00
export default {
name: 'alertRule',
2021-04-13 20:33:12 +08:00
components: {
deleteButton,
alertRuleBox,
alertRuleTable,
nzDataList,
'export-excel': exportXLSX,
topToolMoreOptions,
alertSilenceBox,
nzDetailView,
alertRuleDetail,
detailViewTopSearch
2021-04-13 20:33:12 +08:00
},
mixins: [dataListMixin, detailViewMixin, routerPathParams],
2021-04-13 20:33:12 +08:00
data () {
return {
url: 'alert/rule',
tableId: 'alertRuleTable', // 需要分页的table的id用于记录每页数量
orderBy: 'id',
searchLabel: {},
2021-04-13 20:33:12 +08:00
blankObject: {
id: '',
alertName: '',
linkObject: { id: '', name: '' },
expr: '',
state: 1,
type: 1,
2021-04-13 20:33:12 +08:00
unit: 2,
operator: '>',
last: 60,
// severityId: '',
2021-04-13 20:33:12 +08:00
summary: '',
2021-05-08 09:40:53 +08:00
description: '',
method: [],
name: '',
// threshold: '',
receiver: [],
autoExpired: 1,
schedEnable: 0,
schedDays: '',
schedStime: '00:00',
schedEtime: '23:59',
2021-09-10 14:46:08 +08:00
notifyActive: 0,
notifyExpired: 0,
timeout: 300,
trbShot: '',
condition: []
2021-04-13 20:33:12 +08:00
},
blankSilenceObject: {
id: '',
startAt: '',
endAt: '',
ruleId: '',
type: 'asset',
linkId: '',
remark: '',
time: [],
matchers: [
{ name: '', value: '', regex: 0 }
],
name: ''
},
objectSilence: {},
silenceBoxShow: false,
2021-04-13 20:33:12 +08:00
searchMsg: { // 给搜索框子组件传递的信息
zheze_none: true,
searchLabelList: [
{
id: 1,
name: 'ID',
type: 'input',
label: 'ids',
disabled: false
},
{
id: 2,
name: this.$t('alert.alertName'),
type: 'input',
label: 'name',
disabled: false
},
// {
// id: 4,
// name: this.$t('alert.severity'),
// type: 'severity',
// label: 'severityIds',
// readonly: true,
// disabled: false
// },
{
id: 5,
name: this.$t('overall.type'),
type: 'alertTypes',
label: 'type',
readonly: true,
disabled: false
}
]
2021-04-13 20:33:12 +08:00
},
2022-02-25 14:31:36 +08:00
searchTime: bus.getTimezontDateRange(),
needAlertDaysData: true,
trendKey: 'ruleId'
2021-04-13 20:33:12 +08:00
}
},
methods: {
queryMessage (alertRule) {
if (!this.hasButton('alertMessage_view')) {
return
}
this.$refs.dataList.showBottomBox('alertRuleAlertMessage', alertRule)
2021-04-13 20:33:12 +08:00
},
getTableData () {
if (this.orderBy) {
this.$set(this.searchLabel, 'orderBy', this.orderBy)
} else {
delete this.searchLabel.orderBy
}
2021-04-13 20:33:12 +08:00
this.$set(this.searchLabel, 'pageNo', this.pageObj.pageNo)
this.$set(this.searchLabel, 'pageSize', this.pageObj.pageSize)
this.tools.loading = true
const param = {
...this.searchLabel
}
const path = this.fromRoute.alertRule
this.updatePath(param, path)
2021-04-13 20:33:12 +08:00
this.$get(this.url, this.searchLabel).then(response => {
this.tools.loading = false
if (response.code === 200) {
response.data.list.forEach(item => {
let temp = []
if (item.receiver) {
temp = item.receiver.split(',').map(t => {
return parseInt(t)
})
}
item.receiverShow = temp
})
2022-02-25 14:31:36 +08:00
if (this.needAlertDaysData) {
response.data.list.forEach(item => {
item.trendLoading = true
item.left = 0
item.top = 0
item.alertNumtooltipShow = false
2022-02-25 14:31:36 +08:00
item.alertDaysData = [
{
metric: { priority: 'P1' },
values: [[0, 0]]
},
{
metric: { priority: 'P2' },
values: [[0, 0]]
},
{
metric: { priority: 'P3' },
values: [[0, 0]]
}
]
})
}
2021-04-13 20:33:12 +08:00
this.tableData = response.data.list
const globalSearchId = this.$store.getters.getGlobalSearchId
let detailViewRightObj = ''
if (globalSearchId) {
detailViewRightObj = this.tableData.find(item => item.id === globalSearchId)
} else {
detailViewRightObj = this.tableData[0]
}
this.detailViewRightObj = detailViewRightObj
2021-04-13 20:33:12 +08:00
this.pageObj.total = response.data.total
this.pageObj.pages = response.data.pages
if (!this.scrollbarWrap && this.$refs.dataTable && this.$refs.dataTable.$refs.dataTable) {
2021-04-13 20:33:12 +08:00
this.$nextTick(() => {
this.scrollbarWrap = this.$refs.dataTable.$refs.dataTable.bodyWrapper
this.toTopBtnHandler(this.scrollbarWrap)
})
}
}
})
},
statusChange (alertRule) {
const params = { ...alertRule, severity: null }
this.$put(this.url, params).then(response => {
if (response.code === 200) {
this.rightBox.show = false
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
} else {
this.$message.error(response.msg)
}
this.getTableData()
})
},
edit (u, copyFlag) {
2021-05-08 09:40:53 +08:00
this.$get(`${this.url}/${u.id}`).then(response => {
if (response.code === 200) {
this.object = {
...response.data,
2021-05-12 19:07:07 +08:00
method: response.data.method ? response.data.method.split(',').map(item => Number(item)) : [],
schedDays: response.data.schedDays ? response.data.schedDays.split(',').map(item => Number(item)) : [],
2021-05-12 19:07:07 +08:00
receiverShow: response.data.receiver ? response.data.receiver.split(',').map(item => Number(item)) : []
2021-05-08 09:40:53 +08:00
}
if (this.object.inr == 0) {
this.object.inr = undefined
}
if (copyFlag) {
this.object.id = ''
this.object.name = this.object.name + '-copy'
if (this.object.name.length > 64) {
const length = this.object.name.length - 64
this.object.name = u.name.substring(0, u.name.length - length) + '-copy'
}
}
2021-05-08 09:40:53 +08:00
this.rightBox.show = true
}
})
},
copy (u) {
this.edit(u, true)
},
getSeverityData () {
this.$get('alert/severity', { pageNo: 1, pageSize: -1 }).then(response => {
if (response.code == 200) {
this.severityData = response.data.list
}
})
2021-04-13 20:33:12 +08:00
}
},
created () {
const searchKeys = {
// key: path 键
// value: vue set 参数
pageNo: { target: this.pageObj, propertyName: 'pageNo', type: 'number' },
pageSize: { target: this.pageObj, propertyName: 'pageSize', type: 'number' },
orderBy: { target: this.$data, propertyName: 'orderBy', type: 'string' },
ids: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'ids',
type: 'string',
defaultJson: {
disabled: false,
id: 1,
label: 'ids',
name: 'ID',
type: 'input',
val: ''
},
jsonKey: 'val'
},
// severityIds: {
// target: this.searchLabel,
// isSearchInput: true,
// propertyName: 'severityIds',
// type: 'string',
// defaultJson: {
// disabled: false,
// id: 4,
// label: 'severityIds',
// name: 'Priority',
// readonly: true,
// type: 'severity',
// val: '',
// valnum: '',
// valString: '',
// listStr: 'severitySelect'
// },
// jsonKey: 'valnum'
// },
type: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'type',
type: 'number',
defaultJson: {
name: 'Type',
id: 5,
type: 'alertTypes',
label: 'type',
disabled: false,
readonly: true,
val: '',
valnum: '',
listStr: 'alertTypesSelect'
},
jsonKey: 'valnum'
},
name: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'name',
type: 'string',
defaultJson: {
disabled: false,
id: 2,
label: 'name',
name: 'Name',
type: 'input',
val: ''
},
jsonKey: 'val'
}
}
this.initQueryFromPath(searchKeys)
this.getSeverityData()
},
2021-04-13 20:33:12 +08:00
mounted () {
2021-05-12 16:19:43 +08:00
},
watch: {
$route: {
immediate: true,
handler () {
const add = this.$route.query.add
if (add) {
if (add === 'alertRule') {
this.add()
}
}
2021-05-11 22:29:14 +08:00
}
}
2021-04-13 20:33:12 +08:00
}
}
</script>