2020-05-15 17:15:13 +08:00
|
|
|
|
<style lang="scss">
|
2020-05-31 22:33:16 +08:00
|
|
|
|
@import '../../charts/chart';
|
2020-05-15 17:15:13 +08:00
|
|
|
|
</style>
|
2019-12-06 17:36:33 +08:00
|
|
|
|
<template>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<nz-data-list
|
|
|
|
|
|
ref="dataList"
|
|
|
|
|
|
:api="url"
|
|
|
|
|
|
:custom-table-title.sync="tools.customTableTitle"
|
|
|
|
|
|
:from="fromRoute.alertMessage"
|
2021-08-23 18:50:08 +08:00
|
|
|
|
:layout="['searchInput', 'elementSet', 'pagination']"
|
2021-04-29 22:24:38 +08:00
|
|
|
|
:search-msg="searchMsg"
|
|
|
|
|
|
@search="search"
|
2021-05-19 11:32:41 +08:00
|
|
|
|
v-loading="tools.loading"
|
2021-04-29 22:24:38 +08:00
|
|
|
|
>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
<template v-slot:top-tool-right>
|
2021-09-26 09:14:07 +08:00
|
|
|
|
<el-select v-model="state" class="margin-r-10" size="small" value-key="value" @change="getTableData" popper-class="right-box-select-top right-box-dropdown-top">
|
2021-05-10 15:59:39 +08:00
|
|
|
|
<el-option v-for="item in stateOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
|
|
|
|
|
</el-select>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
<pick-time v-model="searchTime" :default-pick="12" :refresh-data-func="getTableData" :show-empty="true" :use-chart-unit="false" :use-refresh="false"></pick-time>
|
|
|
|
|
|
<button id="roles-add" v-has="'alertMessage_view'" :title="$t('overall.exportExcelLower')" class="top-tool-btn margin-r-10"
|
|
|
|
|
|
type="button" @click="showExportDialog">
|
|
|
|
|
|
<i class="nz-icon-download1 nz-icon"></i>
|
|
|
|
|
|
</button>
|
2021-05-20 16:27:46 +08:00
|
|
|
|
<delete-button id="alert-msg-batch-delete" v-has="'alertMessage_expired'" :api="url" :clickFunction="batchDel" :delete-objs="batchDeleteObjs" @after="getTableData" @before="delFlag=true"></delete-button>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<template v-slot:default="slotProps">
|
|
|
|
|
|
<alert-message-table
|
|
|
|
|
|
ref="dataTable"
|
|
|
|
|
|
:api="url"
|
|
|
|
|
|
:custom-table-title="tools.customTableTitle"
|
|
|
|
|
|
:height="mainTableHeight"
|
|
|
|
|
|
:now-time="nowTime"
|
|
|
|
|
|
:table-data="tableData"
|
|
|
|
|
|
@del="del"
|
|
|
|
|
|
@edit="edit"
|
2021-09-09 16:00:37 +08:00
|
|
|
|
@showText="showText"
|
2021-04-13 20:33:12 +08:00
|
|
|
|
@orderBy="tableDataSort"
|
2021-05-08 15:04:17 +08:00
|
|
|
|
@queryMessage='queryMessage'
|
2021-05-08 12:45:23 +08:00
|
|
|
|
@reload="getTableData"
|
2021-06-01 14:26:09 +08:00
|
|
|
|
@addSilence="addSilence"
|
2021-04-13 20:33:12 +08:00
|
|
|
|
@selectionChange="selectionChange"
|
|
|
|
|
|
@showBottomBox="(targetTab, object) => { $refs.dataList.showBottomBox(targetTab, object) }"
|
2021-05-10 15:59:39 +08:00
|
|
|
|
@messageDetail="messageDetail"></alert-message-table>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<!-- 分页组件 -->
|
|
|
|
|
|
<template v-slot:pagination>
|
|
|
|
|
|
<Pagination ref="Pagination" :pageObj="pageObj" :tableId="tableId" @pageNo='pageNo' @pageSize='pageSize'></Pagination>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</nz-data-list>
|
2020-04-09 12:19:21 +08:00
|
|
|
|
<!--导出-->
|
2020-04-08 20:27:07 +08:00
|
|
|
|
<div class="export-xlsx">
|
2021-04-13 20:33:12 +08:00
|
|
|
|
<el-dialog :modal-append-to-body='false' :show-close="true" :title="importBox.title" :visible.sync="importBox.show" class="nz-dialog" width="300px" @close="closeDialog">
|
2020-04-08 20:27:07 +08:00
|
|
|
|
<div class="upload-body">
|
2021-04-13 20:33:12 +08:00
|
|
|
|
<button id="alert-msg-exportcur" class="el-button el-button--default el-button--small" @click="exportCur">
|
2020-04-08 20:27:07 +08:00
|
|
|
|
<span>{{$t('overall.exportCur')}}</span>
|
|
|
|
|
|
</button>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
<button id="alert-msg-exportall" class="el-button el-button--default el-button--small" @click="exportAll">
|
2020-04-08 20:27:07 +08:00
|
|
|
|
<span>{{$t('overall.exportAll')}}</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
<!--删除弹窗-->
|
|
|
|
|
|
<div class="export-xlsx">
|
2021-06-08 09:44:32 +08:00
|
|
|
|
<el-dialog :modal-append-to-body='false' :show-close="true" :title="$t('overall.remark')" :visible.sync="deleteBox.show" class="nz-message" width="450px" @close="closeDialog" @opened="openedDialog">
|
2021-04-13 20:33:12 +08:00
|
|
|
|
<div class="upload-body">
|
|
|
|
|
|
<el-form ref="remarkForm" :model="deleteBox">
|
|
|
|
|
|
<el-form-item :rules="[{required:true,message: $t('validate.required'), trigger: 'change'}]" prop="remark">
|
2021-06-07 18:28:07 +08:00
|
|
|
|
<el-input v-model="deleteBox.remark" :placeholder="$t('overall.remark')" type="textarea"></el-input>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<div style="text-align: right; margin-top: 10px;">
|
|
|
|
|
|
<button class="el-button el-button--default el-button--small" @click="closeDialog">
|
|
|
|
|
|
<span>{{$t('tip.no')}}</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button class="el-button el-button--default el-button--small el-button--primary" @click="deleteMessage">
|
|
|
|
|
|
<span>{{$t('tip.yes')}}</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-dialog id="viewGraphDialog"
|
|
|
|
|
|
:modal-append-to-body='false'
|
2021-07-14 10:37:20 +08:00
|
|
|
|
destroy-on-close
|
2021-04-13 20:33:12 +08:00
|
|
|
|
:title="$t('overall.detail')"
|
|
|
|
|
|
:visible.sync="graphShow"
|
|
|
|
|
|
class="line-chart-block-modal nz-dialog endpoint-dialog"
|
|
|
|
|
|
width="90%"
|
|
|
|
|
|
@close="dialogClose">
|
|
|
|
|
|
<div slot="title">
|
|
|
|
|
|
{{$t("project.endpoint.dialogTitle")}}
|
|
|
|
|
|
<div class="float-right panel-calendar dialog-tool" style="display: flex">
|
2021-09-10 14:46:08 +08:00
|
|
|
|
<pick-time v-model="searchTimeDialog" :refresh-data-func="queryDate" :use-chart-unit="false" :use-refresh="false" style="height: 28px;"></pick-time>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2021-09-09 17:23:53 +08:00
|
|
|
|
<div style="width: 100%;height: 100%" v-loading="chartLoading">
|
|
|
|
|
|
<chart v-if="resultType === 'matrix'" ref="messageChart" :unit="chartUnit" name="alertMessageChart"></chart>
|
|
|
|
|
|
<log-tab v-if="resultType === 'streamsFormat'" ref="logDetailScreen" :log-data="logData" :showSwitch="false" :tab-index="tabIndex" @exportLog="exportLog" @limitChange="queryLogData"></log-tab>
|
|
|
|
|
|
</div>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
</el-dialog>
|
2021-09-09 16:00:37 +08:00
|
|
|
|
<!--全屏-->
|
|
|
|
|
|
<el-dialog class="nz-dialog table-chart-dialog" :title="$t('alert.config.trbShot')"
|
|
|
|
|
|
:visible.sync="dialogShowText"
|
|
|
|
|
|
width="96%" @close="dialogShowText = false" :modal-append-to-body="false">
|
|
|
|
|
|
<div slot="title">
|
|
|
|
|
|
<span class="nz-dialog-title">{{$t('alert.config.trbShot')}}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="rich-text-screen-container" >
|
|
|
|
|
|
<div id="chartScreenContainer" ref="chartScreenContainer" class="text-content" >
|
|
|
|
|
|
<el-scrollbar style="height: 100%;" class="el-scrollbar-normal">
|
|
|
|
|
|
<div style="height: 100%;" v-html="dialogText" ></div>
|
|
|
|
|
|
</el-scrollbar>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
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>
|
2021-09-09 17:23:53 +08:00
|
|
|
|
</transition>
|
2020-01-19 18:31:18 +08:00
|
|
|
|
</div>
|
2019-12-06 17:36:33 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<script>
|
2021-04-13 20:33:12 +08:00
|
|
|
|
import bus from '@/libs/bus'
|
2021-03-19 18:52:19 +08:00
|
|
|
|
import axios from 'axios'
|
2021-04-13 20:33:12 +08:00
|
|
|
|
import pickTime from '@/components/common/pickTime'
|
|
|
|
|
|
import { getTime } from '@/components/common/js/tools'
|
|
|
|
|
|
import alertMessageTable from '@/components/common/table/alert/alertMessageTable.vue'
|
|
|
|
|
|
import deleteButton from '@/components/common/deleteButton'
|
|
|
|
|
|
import nzDataList from '@/components/common/table/nzDataList'
|
|
|
|
|
|
import dataListMixin from '@/components/common/mixin/dataList'
|
|
|
|
|
|
import chartDataFormat from '@/components/charts/chartDataFormat'
|
2021-05-10 19:47:29 +08:00
|
|
|
|
import chart from '@/components/page/dashboard/overview/chart'
|
2021-09-09 16:00:37 +08:00
|
|
|
|
import { alertMessage as alertMessageConstant, fromRoute } from '@/components/common/js/constants'
|
2021-06-01 15:19:47 +08:00
|
|
|
|
import alertSilenceBox from '@/components/common/rightBox/alertSilenceBox'
|
2021-09-09 16:00:37 +08:00
|
|
|
|
import logsTempData from '@/components/charts/logsTempData'
|
2021-03-19 18:52:19 +08:00
|
|
|
|
export default {
|
2021-06-17 11:24:38 +08:00
|
|
|
|
name: 'alertMessage',
|
2021-03-19 18:52:19 +08:00
|
|
|
|
components: {
|
2021-04-13 20:33:12 +08:00
|
|
|
|
alertMessageTable,
|
|
|
|
|
|
pickTime,
|
2021-05-10 19:47:29 +08:00
|
|
|
|
chart,
|
2021-04-13 20:33:12 +08:00
|
|
|
|
nzDataList,
|
2021-06-01 14:26:09 +08:00
|
|
|
|
deleteButton,
|
|
|
|
|
|
alertSilenceBox
|
2021-03-19 18:52:19 +08:00
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
mixins: [dataListMixin],
|
2021-03-19 18:52:19 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2021-09-09 16:00:37 +08:00
|
|
|
|
chartLoading: false,
|
2021-05-10 15:59:39 +08:00
|
|
|
|
stateOptions: alertMessageConstant.states,
|
|
|
|
|
|
state: '1',
|
2021-09-09 16:00:37 +08:00
|
|
|
|
dialogShowText: false,
|
|
|
|
|
|
dialogText: '',
|
2021-04-13 20:33:12 +08:00
|
|
|
|
url: 'alert/message',
|
2021-03-19 18:52:19 +08:00
|
|
|
|
// 导出相关
|
|
|
|
|
|
importBox: { show: false, title: this.$t('overall.exportExcel') },
|
|
|
|
|
|
deleteBox: { show: false, ids: '', remark: '', state: 2 },
|
|
|
|
|
|
// 详情相关
|
|
|
|
|
|
graphShow: false,
|
|
|
|
|
|
chartDatas: [],
|
|
|
|
|
|
sameLabels: ['instance', 'module', 'project', 'asset', 'endpoint', 'datacenter'],
|
|
|
|
|
|
legend: [],
|
|
|
|
|
|
searchTime: [],
|
2021-05-14 15:24:32 +08:00
|
|
|
|
searchTimeDialog: [],
|
2021-03-19 18:52:19 +08:00
|
|
|
|
searchTimeSelect: bus.getTimezontDateRange(),
|
|
|
|
|
|
currentMsg: {},
|
|
|
|
|
|
chartUnit: 5,
|
2021-06-01 14:26:09 +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
|
|
|
|
tableId: 'alertMessageTable', // 需要分页的table的id,用于记录每页数量
|
2021-03-19 18:52:19 +08:00
|
|
|
|
searchMsg: { // 给搜索框子组件传递的信息
|
2021-05-10 15:59:39 +08:00
|
|
|
|
searchLabelList: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 26,
|
|
|
|
|
|
name: this.$t('alert.list.id'),
|
|
|
|
|
|
type: 'id',
|
2021-05-19 18:41:00 +08:00
|
|
|
|
label: 'ids',
|
2021-05-10 15:59:39 +08:00
|
|
|
|
disabled: false
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: this.$t('alert.alertRule'),
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
label: 'ruleName',
|
|
|
|
|
|
disabled: false
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: this.$t('asset.asset'),
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
label: 'assetName',
|
2020-01-19 18:31:18 +08:00
|
|
|
|
disabled: false
|
2021-05-10 15:59:39 +08:00
|
|
|
|
}, {
|
|
|
|
|
|
name: 'Endpoint',
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
label: 'endpointName',
|
|
|
|
|
|
disabled: false
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: this.$t('alert.summary'),
|
|
|
|
|
|
type: 'input',
|
|
|
|
|
|
label: 'summary',
|
|
|
|
|
|
disabled: false
|
|
|
|
|
|
}, {
|
2021-05-20 11:39:12 +08:00
|
|
|
|
name: this.$t('overall.labels'),
|
2021-05-10 15:59:39 +08:00
|
|
|
|
type: 'input',
|
|
|
|
|
|
label: 'labels',
|
|
|
|
|
|
disabled: false
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
2021-03-19 18:52:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
requestIndex: 0,
|
|
|
|
|
|
viewAssetState: false,
|
2021-09-09 16:00:37 +08:00
|
|
|
|
nowTime: '',
|
|
|
|
|
|
logData: [],
|
|
|
|
|
|
resultType: ''
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
tagType () {
|
|
|
|
|
|
return (key) => {
|
|
|
|
|
|
if (key == 'asset' || key == 'module' || key == 'project' || key == 'datacenter' || key == 'endpoint') {
|
|
|
|
|
|
return 'normal'
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return 'info'
|
|
|
|
|
|
}
|
2020-01-08 10:17:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
tagValue () {
|
|
|
|
|
|
return (key, value) => {
|
|
|
|
|
|
if (key == 'type') {
|
|
|
|
|
|
if (value == 1) {
|
2021-05-14 15:24:32 +08:00
|
|
|
|
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-04-06 22:11:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
return key + ':' + value
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2021-04-13 20:33:12 +08:00
|
|
|
|
labelsSort (obj) {
|
2021-07-23 16:16:01 +08:00
|
|
|
|
const buildIn = ['asset', 'endpoint', 'module', 'cpu', 'project', 'datacenter', 'parent_asset', 'user']
|
2021-03-19 18:52:19 +08:00
|
|
|
|
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]
|
2020-04-09 17:00:32 +08:00
|
|
|
|
}
|
2020-04-06 22:11:25 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
Object.keys(labels).sort().forEach(key => {
|
|
|
|
|
|
result.push({ label: key, value: labels[key] })
|
|
|
|
|
|
})
|
|
|
|
|
|
return result
|
2020-04-06 22:11:25 +08:00
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
chartUnitChange (unit) {
|
|
|
|
|
|
this.chartUnit = unit
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.queryChartDate()
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2021-05-20 16:27:46 +08:00
|
|
|
|
batchDel () {
|
|
|
|
|
|
this.$confirm(this.$t('tip.confirmDelete'), {
|
|
|
|
|
|
confirmButtonText: this.$t('tip.yes'),
|
|
|
|
|
|
cancelButtonText: this.$t('tip.no'),
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
this.$delete(this.url + '?ids=' + this.batchDeleteObjs.map(m => m.id).join(',') + '&state=' + this.state).then(response => {
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
this.delFlag = true
|
|
|
|
|
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.deleteSuccess') })
|
|
|
|
|
|
this.getTableData()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2021-05-20 09:18:05 +08:00
|
|
|
|
del (row) {
|
|
|
|
|
|
this.$confirm(this.$t('tip.confirmDelete'), {
|
|
|
|
|
|
confirmButtonText: this.$t('tip.yes'),
|
|
|
|
|
|
cancelButtonText: this.$t('tip.no'),
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
}).then(() => {
|
2021-05-20 16:27:46 +08:00
|
|
|
|
this.$delete(this.url + '?ids=' + row.id + '&state=' + this.state).then(response => {
|
2021-05-20 09:18:05 +08:00
|
|
|
|
if (response.code === 200) {
|
2021-05-20 16:27:46 +08:00
|
|
|
|
this.delFlag = true
|
2021-05-20 09:18:05 +08:00
|
|
|
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.deleteSuccess') })
|
2021-05-20 16:27:46 +08:00
|
|
|
|
this.getTableData()
|
2021-05-20 09:18:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2021-05-10 15:59:39 +08:00
|
|
|
|
messageDetail (row) {
|
2021-05-14 12:32:47 +08:00
|
|
|
|
this.$get('/alert/rule/' + row.alertRule.id).then(res => {
|
|
|
|
|
|
this.currentMsg = { ...row, alertRule: { ...res.data } }
|
|
|
|
|
|
this.graphShow = true
|
|
|
|
|
|
this.$nextTick(() => {
|
2021-09-07 11:03:58 +08:00
|
|
|
|
this.searchTimeDialog = [bus.computeTimezoneTime(new Date().getTime() - 1 * 60 * 60 * 1000), bus.computeTimezoneTime(new Date().getTime())]
|
2021-09-09 16:00:37 +08:00
|
|
|
|
this.queryDate()
|
2021-05-14 12:32:47 +08:00
|
|
|
|
})
|
2021-05-10 19:47:29 +08:00
|
|
|
|
})
|
2021-05-10 15:59:39 +08:00
|
|
|
|
},
|
2021-05-08 15:04:17 +08:00
|
|
|
|
queryMessage (alertMessage) {
|
|
|
|
|
|
if (!this.hasButton('alertMessage_view')) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.$refs.dataList.showBottomBox(alertMessage, alertRule)
|
|
|
|
|
|
},
|
2021-09-09 16:00:37 +08:00
|
|
|
|
queryDate () {
|
|
|
|
|
|
this.chartLoading = true
|
|
|
|
|
|
if (this.currentMsg.alertRule.type === 1) {
|
|
|
|
|
|
this.resultType = 'matrix'
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.queryChartDate()
|
|
|
|
|
|
})
|
|
|
|
|
|
} else if (this.currentMsg.alertRule.type === 2) {
|
|
|
|
|
|
this.queryLogData(1000)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
queryChartDate () {
|
|
|
|
|
|
const $temp = this
|
2021-09-07 11:03:58 +08:00
|
|
|
|
const start = this.searchTimeDialog[0] ? this.searchTimeDialog[0] : bus.computeTimezoneTime(new Date().getTime() - 1 * 60 * 60 * 1000)
|
2021-07-14 10:37:20 +08:00
|
|
|
|
const end = this.searchTimeDialog[1] ? this.searchTimeDialog[1] : bus.computeTimezoneTime(new Date().getTime())
|
2021-05-14 15:24:32 +08:00
|
|
|
|
this.searchTimeDialog = [start, end]
|
2021-04-13 20:33:12 +08:00
|
|
|
|
const timeDiff = (new Date(end).getTime() - new Date(start).getTime()) / 1000 / (24 * 60 * 60)
|
|
|
|
|
|
let step = '15s'
|
|
|
|
|
|
if (timeDiff < 1) {
|
|
|
|
|
|
step = '15s'
|
|
|
|
|
|
} else if (timeDiff < 7) {
|
|
|
|
|
|
step = '5m'
|
|
|
|
|
|
} else if (timeDiff < 30) {
|
|
|
|
|
|
step = '10m'
|
|
|
|
|
|
} else {
|
|
|
|
|
|
step = '30m'
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.$refs.messageChart) {
|
|
|
|
|
|
this.$refs.messageChart.startLoading()
|
|
|
|
|
|
const axiosArr = []
|
|
|
|
|
|
const paramStr = JSON.stringify(this.promQueryParamConvert(this.currentMsg))
|
2021-06-03 16:50:47 +08:00
|
|
|
|
axiosArr.push(axios.get('/prom/api/v1/query_range?query=' + paramStr.substring(1, paramStr.length - 1) + '&start=' + this.$stringTimeParseToUnix(start) + '&end=' + this.$stringTimeParseToUnix(end) + '&step=' + step))
|
2021-04-13 20:33:12 +08:00
|
|
|
|
this.legend = []
|
|
|
|
|
|
this.chartDatas = []
|
|
|
|
|
|
axios.all(axiosArr).then(res => {
|
2021-09-09 16:00:37 +08:00
|
|
|
|
this.chartLoading = false
|
2021-04-13 20:33:12 +08:00
|
|
|
|
try {
|
|
|
|
|
|
res.forEach((response, promIndex) => {
|
2021-05-10 19:47:29 +08:00
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
|
if (response.data.status === 'success') {
|
2021-04-13 20:33:12 +08:00
|
|
|
|
const queryData = response.data.data.result[0]
|
|
|
|
|
|
if (queryData) {
|
|
|
|
|
|
const chartData = {
|
|
|
|
|
|
type: 'line',
|
|
|
|
|
|
symbol: 'none', // 去掉点
|
|
|
|
|
|
smooth: 0.2, // 曲线变平滑
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
lineStyle: {
|
|
|
|
|
|
width: 1,
|
|
|
|
|
|
opacity: 0.9
|
|
|
|
|
|
},
|
|
|
|
|
|
markLine: {
|
|
|
|
|
|
silent: true,
|
|
|
|
|
|
symbol: ['circle', 'circle'],
|
|
|
|
|
|
label: {
|
|
|
|
|
|
distance: this.computeDistance(chartDataFormat.getUnit(this.currentMsg.alertRule.unit ? this.currentMsg.alertRule.unit : 2).compute(this.currentMsg.alertRule.threshold)),
|
|
|
|
|
|
formatter (params) {
|
|
|
|
|
|
return chartDataFormat.getUnit($temp.currentMsg.alertRule.unit ? $temp.currentMsg.alertRule.unit : 2).compute(params.value)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
lineStyle: {
|
|
|
|
|
|
color: '#d64f40',
|
|
|
|
|
|
width: 2,
|
|
|
|
|
|
type: 'dotted'
|
|
|
|
|
|
},
|
|
|
|
|
|
data: [{
|
|
|
|
|
|
yAxis: Number(this.currentMsg.alertRule.threshold)
|
|
|
|
|
|
}]
|
|
|
|
|
|
},
|
|
|
|
|
|
markArea: {
|
|
|
|
|
|
itemStyle: {
|
|
|
|
|
|
color: '#d64f40',
|
|
|
|
|
|
opacity: 0.1
|
|
|
|
|
|
},
|
|
|
|
|
|
data: [this.returnMarkArea()]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.currentMsg.alertRule.operator == '==' || this.currentMsg.alertRule.operator == '!=') {
|
|
|
|
|
|
delete chartData.markArea
|
|
|
|
|
|
}
|
|
|
|
|
|
let alias = chartData.name
|
|
|
|
|
|
chartData.name += '{'
|
|
|
|
|
|
alias += '{'
|
|
|
|
|
|
Object.keys(queryData.metric).forEach((item, index) => {
|
|
|
|
|
|
const label = item
|
|
|
|
|
|
const value = queryData.metric[label]
|
|
|
|
|
|
chartData.name += label + "='" + value + "',"
|
|
|
|
|
|
})
|
|
|
|
|
|
chartData.name = chartData.name.charAt(chartData.name.length - 1) == ',' ? chartData.name.substr(0, chartData.name.length - 1) : chartData.name
|
|
|
|
|
|
chartData.name += '}'
|
|
|
|
|
|
const legend = {
|
|
|
|
|
|
name: chartData.name,
|
2021-05-14 15:24:32 +08:00
|
|
|
|
alias: chartData.name,
|
2021-04-13 20:33:12 +08:00
|
|
|
|
isGray: false
|
|
|
|
|
|
}
|
|
|
|
|
|
this.legend.push(legend)
|
|
|
|
|
|
chartData.data = queryData.values.map((dpsItem, dpsIndex) => {
|
|
|
|
|
|
return [dpsItem[0] * 1000, parseFloat(dpsItem[1]).toFixed(2)]
|
|
|
|
|
|
})
|
|
|
|
|
|
this.chartDatas.push(chartData)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(response.data.error)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$refs.messageChart.setRandomColors(this.chartDatas.length)
|
|
|
|
|
|
this.$refs.messageChart.setLegend(this.legend)
|
|
|
|
|
|
this.$refs.messageChart.setSeries(this.chartDatas)
|
|
|
|
|
|
this.$refs.messageChart.endLoading()
|
2021-09-09 16:00:37 +08:00
|
|
|
|
this.$refs.messageChart.resize()
|
2021-04-13 20:33:12 +08:00
|
|
|
|
})
|
|
|
|
|
|
} catch (err) {
|
2021-05-14 15:24:32 +08:00
|
|
|
|
// this.$message.error(err)
|
2021-04-13 20:33:12 +08:00
|
|
|
|
this.$refs.messageChart.endLoading()
|
2021-09-09 16:00:37 +08:00
|
|
|
|
this.chartLoading = false
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
exportLog ({ limit, descending }) {
|
|
|
|
|
|
const start = this.searchTimeDialog[0] ? this.searchTimeDialog[0] : bus.computeTimezoneTime(new Date().getTime() - 1 * 60 * 60 * 1000)
|
|
|
|
|
|
const end = this.searchTimeDialog[1] ? this.searchTimeDialog[1] : bus.computeTimezoneTime(new Date().getTime())
|
|
|
|
|
|
const params = {
|
|
|
|
|
|
logql: this.expressions,
|
|
|
|
|
|
start: start,
|
|
|
|
|
|
end: end,
|
|
|
|
|
|
direction: descending ? 'backward' : 'forward',
|
|
|
|
|
|
limit
|
|
|
|
|
|
}
|
|
|
|
|
|
axios.get('/logs/loki/export', { responseType: 'blob', params: params }).then(res => {
|
|
|
|
|
|
if (window.navigator.msSaveOrOpenBlob) {
|
|
|
|
|
|
// 兼容ie11
|
|
|
|
|
|
const blobObject = new Blob([res.data])
|
|
|
|
|
|
window.navigator.msSaveOrOpenBlob(blobObject, 'log')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const url = URL.createObjectURL(new Blob([res.data]))
|
|
|
|
|
|
const a = document.createElement('a')
|
|
|
|
|
|
document.body.appendChild(a) // 此处增加了将创建的添加到body当中
|
|
|
|
|
|
a.href = url
|
|
|
|
|
|
a.download = 'log'
|
|
|
|
|
|
a.target = '_blank'
|
|
|
|
|
|
a.click()
|
|
|
|
|
|
a.remove() // 将a标签移除
|
|
|
|
|
|
}
|
|
|
|
|
|
}, error => {
|
|
|
|
|
|
const $self = this
|
|
|
|
|
|
const reader = new FileReader()
|
|
|
|
|
|
reader.onload = function (event) {
|
|
|
|
|
|
const responseText = reader.result
|
|
|
|
|
|
const exception = JSON.parse(responseText)
|
|
|
|
|
|
if (exception.message) {
|
|
|
|
|
|
$self.$message.error(exception.message)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.error(error)
|
2021-04-13 20:33:12 +08:00
|
|
|
|
}
|
2021-09-09 16:00:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
reader.readAsText(error.response.data)
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
queryLogData (limit) { // log的chart和table是一个请求
|
|
|
|
|
|
if (!limit) {
|
|
|
|
|
|
limit = 1000
|
|
|
|
|
|
}
|
|
|
|
|
|
const start = this.searchTimeDialog[0] ? this.searchTimeDialog[0] : bus.computeTimezoneTime(new Date().getTime() - 1 * 60 * 60 * 1000)
|
|
|
|
|
|
const end = this.searchTimeDialog[1] ? this.searchTimeDialog[1] : bus.computeTimezoneTime(new Date().getTime())
|
|
|
|
|
|
this.expressions = [this.currentMsg.alertRule.expr]
|
|
|
|
|
|
this.$get('/logs/loki/api/v1/query_range?format=1&query=' + this.currentMsg.alertRule.expr + '&start=' + this.$stringTimeParseToUnix(start) + '&end=' + this.$stringTimeParseToUnix(end) + '&limit=' + limit).then(res => {
|
|
|
|
|
|
this.chartLoading = false
|
|
|
|
|
|
const logData = [res.data]
|
|
|
|
|
|
this.resultType = res.data.resultType
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
if (this.$refs.logDetail) {
|
|
|
|
|
|
this.$refs.logDetail.time = this.chartData.param.time
|
|
|
|
|
|
this.$refs.logDetail.wrapLines = this.chartData.param.wrapLines
|
|
|
|
|
|
this.$refs.logDetail.operations.descending = this.chartData.param.descending
|
|
|
|
|
|
}
|
|
|
|
|
|
// logData.forEach((item, index) => {
|
|
|
|
|
|
// item.result.forEach(result => {
|
|
|
|
|
|
// result.elements = this.expressions[index]
|
|
|
|
|
|
// })
|
|
|
|
|
|
// })
|
|
|
|
|
|
this.logData = logData
|
|
|
|
|
|
this.resultType === 'matrix' && this.loadLogGraph()
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
loadLogGraph () {
|
|
|
|
|
|
const graphData = this.logData.filter(l => l.resultType === 'matrix')
|
|
|
|
|
|
if (graphData && graphData.length > 0) {
|
|
|
|
|
|
this.$refs.messageChart.startLoading()
|
|
|
|
|
|
const queryExpression = []
|
|
|
|
|
|
let series = []
|
|
|
|
|
|
const legend = []
|
|
|
|
|
|
this.expressions.forEach((item, index) => {
|
|
|
|
|
|
if (item !== '') {
|
|
|
|
|
|
queryExpression.push(item)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
this.logData.forEach((response, index) => {
|
|
|
|
|
|
if (response.resultType === 'matrix') {
|
|
|
|
|
|
const data = response.result
|
|
|
|
|
|
if (!data || data.length < 1) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
data.forEach((result, i) => {
|
|
|
|
|
|
const seriesItem = {
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
symbol: 'emptyCircle', // 去掉点
|
|
|
|
|
|
symbolSize: [2, 2],
|
|
|
|
|
|
showSymbol: false,
|
|
|
|
|
|
smooth: 0.2, // 曲线变平滑
|
|
|
|
|
|
data: [],
|
|
|
|
|
|
lineStyle: {
|
|
|
|
|
|
width: 1,
|
|
|
|
|
|
opacity: 0.9
|
|
|
|
|
|
},
|
|
|
|
|
|
type: 'line'
|
|
|
|
|
|
}
|
|
|
|
|
|
seriesItem.data = result.values.map((item) => {
|
|
|
|
|
|
return [item[0] * 1000, item[1]]
|
|
|
|
|
|
})
|
|
|
|
|
|
let host = ''// up,
|
|
|
|
|
|
let alias = ''
|
|
|
|
|
|
if (result.metric && Object.keys(result.metric).length > 0) {
|
|
|
|
|
|
const metric = Object.keys(result.metric)
|
|
|
|
|
|
if (metric.__name__) {
|
|
|
|
|
|
host = `${metric.__name__}{`// up,
|
|
|
|
|
|
}
|
|
|
|
|
|
metric.forEach((tag, i) => {
|
|
|
|
|
|
if (tag !== '__name__') {
|
|
|
|
|
|
host += `${tag}="${result.metric[tag]}",`
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
if (host.endsWith(',')) {
|
|
|
|
|
|
host = host.substr(0, host.length - 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (metric.__name__) {
|
|
|
|
|
|
host += '}'
|
|
|
|
|
|
}
|
|
|
|
|
|
// 处理legend别名
|
|
|
|
|
|
// alias = this.dealLegendAlias(host, this.chartData.elements[index].legend)
|
|
|
|
|
|
if (!alias || alias === '') {
|
|
|
|
|
|
alias = host
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
alias = queryExpression[index]
|
|
|
|
|
|
}
|
|
|
|
|
|
seriesItem.name = alias + '-' + index
|
|
|
|
|
|
series.push(seriesItem)
|
|
|
|
|
|
legend.push({ name: seriesItem.name, alias: alias, isGray: false })
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
this.$refs.messageChart.setLegend(legend)
|
|
|
|
|
|
this.$refs.messageChart.setRandomColors(series.length)
|
|
|
|
|
|
if (!series.length) {
|
|
|
|
|
|
series = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
this.$refs.messageChart.setSeries(series)
|
|
|
|
|
|
this.defaultChartVisible = true
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$refs.messageChart.endLoading()
|
|
|
|
|
|
this.$refs.messageChart.resize()
|
2021-04-13 20:33:12 +08:00
|
|
|
|
})
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
2021-04-13 20:33:12 +08:00
|
|
|
|
},
|
2021-05-10 15:59:39 +08:00
|
|
|
|
getTableData (state) {
|
|
|
|
|
|
if (state) {
|
|
|
|
|
|
this.state = state
|
2021-05-08 12:45:23 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.$set(this.searchLabel, 'pageNo', this.pageObj.pageNo)
|
|
|
|
|
|
this.$set(this.searchLabel, 'pageSize', this.pageObj.pageSize)
|
2021-06-07 15:09:11 +08:00
|
|
|
|
this.$set(this.searchLabel, 'state', this.state)
|
2021-03-19 18:52:19 +08:00
|
|
|
|
if (this.searchTime && this.searchTime.length > 1) {
|
|
|
|
|
|
this.$set(this.searchLabel, 'startAt', this.timezoneToUtcTimeStr(this.searchTime[0]))
|
|
|
|
|
|
this.$set(this.searchLabel, 'endAt', this.timezoneToUtcTimeStr(this.searchTime[1]))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
delete this.searchLabel.startAt
|
|
|
|
|
|
delete this.searchLabel.endAt
|
|
|
|
|
|
}
|
|
|
|
|
|
this.tools.loading = true
|
2021-05-10 15:59:39 +08:00
|
|
|
|
if (state) {
|
2021-05-08 12:45:23 +08:00
|
|
|
|
delete this.searchLabel.startAt
|
|
|
|
|
|
delete this.searchLabel.endAt
|
|
|
|
|
|
}
|
2021-06-07 15:09:11 +08:00
|
|
|
|
this.$get(this.url, this.searchLabel).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.tools.loading = false
|
|
|
|
|
|
if (response.code == 200) {
|
|
|
|
|
|
this.nowTime = this.utcTimeToTimezoneStr(response.time)
|
|
|
|
|
|
this.tableData = response.data.list
|
2021-05-10 15:59:39 +08:00
|
|
|
|
/* const axiosAll = []
|
2021-09-09 17:23:53 +08:00
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.tableData.forEach((item) => {
|
|
|
|
|
|
item.labels = JSON.parse(item.labels)
|
|
|
|
|
|
if (!this.isBuildIn(item.alertRule)) {
|
|
|
|
|
|
const paramStr = JSON.stringify(this.promQueryParamConvert(item))
|
|
|
|
|
|
axiosAll.push(axios.get('/prom/api/v1/query?query=' + paramStr.substring(1, paramStr.length - 1).replace(/\+/g, '%2B').replace(/ /g, '%20').replace(/\\/g, '')))
|
2021-03-19 18:52:19 +08:00
|
|
|
|
} else {
|
2021-09-09 17:23:53 +08:00
|
|
|
|
axiosAll.push('')
|
2020-10-15 10:03:08 +08:00
|
|
|
|
}
|
2020-11-25 11:53:37 +08:00
|
|
|
|
})
|
2021-09-09 17:23:53 +08:00
|
|
|
|
axios.all(axiosAll).then(res => {
|
|
|
|
|
|
res.forEach((item, index) => {
|
|
|
|
|
|
let current = []
|
|
|
|
|
|
const response2 = item.data
|
|
|
|
|
|
if (response2.data && response2.data.result && response2.data.result.length > 0) {
|
|
|
|
|
|
current = response2.data.result[0].value.map((item, i) => {
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
|
return bus.computeTimezone(item)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return parseFloat(item).toFixed(2)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
current = [null, null]
|
|
|
|
|
|
}
|
|
|
|
|
|
this.tableData[index].current = current
|
|
|
|
|
|
})
|
|
|
|
|
|
this.$set(this.tableData, [...this.tableData])
|
|
|
|
|
|
})
|
|
|
|
|
|
}) */
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.deleteBox.ids = ''
|
|
|
|
|
|
this.pageObj.total = response.data.total
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2021-07-14 10:37:20 +08:00
|
|
|
|
promQueryParamConvert (alert) {
|
|
|
|
|
|
const obj = { ...alert }
|
2021-06-03 16:50:47 +08:00
|
|
|
|
let r = '(' + obj.alertRule.expr.replace(/\"/g, '\'') + ')'
|
2021-03-19 18:52:19 +08:00
|
|
|
|
let intoLabels = false
|
2021-05-14 12:32:47 +08:00
|
|
|
|
obj.labels = JSON.parse(obj.labels)
|
2021-03-19 18:52:19 +08:00
|
|
|
|
if (Object.keys(obj.labels).length > 0) {
|
|
|
|
|
|
r += (function () {
|
|
|
|
|
|
let group = ' and ' + '(group({'
|
|
|
|
|
|
let by = ' by ('
|
2020-11-16 17:57:48 +08:00
|
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
|
for (const k in obj.labels) {
|
2021-09-09 10:30:03 +08:00
|
|
|
|
if (k != 'alertname' && k != 'severity' && k != 'severity_id' && k != 'rule_type') {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
intoLabels = true
|
|
|
|
|
|
group += k
|
|
|
|
|
|
group += '='
|
|
|
|
|
|
group += ("'" + obj.labels[k] + "',")
|
|
|
|
|
|
by += k
|
|
|
|
|
|
by += ','
|
2020-11-16 17:57:48 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (intoLabels) {
|
|
|
|
|
|
group = group.substring(0, group.length - 1)
|
|
|
|
|
|
by = by.substring(0, by.length - 1)
|
|
|
|
|
|
group += '})'
|
|
|
|
|
|
by += ')'
|
|
|
|
|
|
return group + by + ')'
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
|
|
|
|
|
}())
|
|
|
|
|
|
}
|
|
|
|
|
|
return r
|
|
|
|
|
|
},
|
|
|
|
|
|
// asset弹框控制
|
|
|
|
|
|
tabControl (data) {
|
|
|
|
|
|
if (data === 'close') {
|
|
|
|
|
|
this.viewAssetState = false
|
|
|
|
|
|
this.$refs.assetEditUnit.tabView = false
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
openedDialog () {
|
|
|
|
|
|
this.$refs.remarkForm.clearValidate()
|
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
showExportDialog () {
|
|
|
|
|
|
this.importBox.show = true
|
|
|
|
|
|
},
|
|
|
|
|
|
closeDialog () {
|
|
|
|
|
|
this.importBox.show = false
|
|
|
|
|
|
this.deleteBox.show = false
|
|
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
dialogClose () {
|
|
|
|
|
|
this.graphShow = false
|
|
|
|
|
|
},
|
|
|
|
|
|
exportCur () {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
const searchLabel = Object.assign({}, this.searchLabel)
|
|
|
|
|
|
this.$set(searchLabel, 'language', localStorage.getItem('nz-language') ? localStorage.getItem('nz-language') : 'en')
|
2021-05-12 19:07:07 +08:00
|
|
|
|
this.exportExcel({ ...searchLabel, state: this.state })
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.closeDialog()
|
|
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
exportAll () {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
const temp = JSON.parse(JSON.stringify(this.searchLabel))
|
|
|
|
|
|
temp.pageSize = -1
|
|
|
|
|
|
this.$set(temp, 'language', localStorage.getItem('nz-language') ? localStorage.getItem('nz-language') : 'en')
|
2021-05-12 19:07:07 +08:00
|
|
|
|
this.exportExcel({ ...temp, state: this.state })
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.closeDialog()
|
|
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
getTimeString () {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
const split = '-'
|
|
|
|
|
|
const date = new Date()
|
|
|
|
|
|
const year = date.getFullYear()
|
|
|
|
|
|
const month = this.formatNum(date.getMonth() + 1)
|
|
|
|
|
|
const day = this.formatNum(date.getDate())
|
|
|
|
|
|
const hours = this.formatNum(date.getHours())
|
|
|
|
|
|
const minutes = this.formatNum(date.getMinutes())
|
|
|
|
|
|
const seconds = this.formatNum(date.getSeconds())
|
|
|
|
|
|
return year + split + month + split + day + ' ' + hours + split + minutes + split + seconds
|
|
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
formatNum (num) {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
return num > 9 ? num : '0' + num
|
|
|
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
|
exportExcel (params) {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
for (const item in params) {
|
|
|
|
|
|
if (params[item]) {
|
2021-04-13 20:33:12 +08:00
|
|
|
|
if (item === 'alertMessageState') {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.$set(params, 'state', params[item])
|
2020-04-09 12:19:21 +08:00
|
|
|
|
} else {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.$set(params, item, params[item])
|
2020-04-09 12:19:21 +08:00
|
|
|
|
}
|
2020-04-06 22:11:25 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
const temp = this
|
|
|
|
|
|
if (!params) {
|
|
|
|
|
|
params = temp.params
|
|
|
|
|
|
}
|
|
|
|
|
|
axios.get('alert/message/export', { responseType: 'blob', params: params }).then(res => {
|
|
|
|
|
|
const fileName = 'alert-message-' + temp.getTimeString() + '.xlsx'
|
|
|
|
|
|
if (window.navigator.msSaveOrOpenBlob) {
|
|
|
|
|
|
// 兼容ie11
|
|
|
|
|
|
const blobObject = new Blob([res.data])
|
|
|
|
|
|
window.navigator.msSaveOrOpenBlob(blobObject, fileName)
|
2020-04-06 22:11:25 +08:00
|
|
|
|
} else {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
const url = URL.createObjectURL(new Blob([res.data]))
|
|
|
|
|
|
const a = document.createElement('a')
|
|
|
|
|
|
document.body.appendChild(a) // 此处增加了将创建的添加到body当中
|
|
|
|
|
|
a.href = url
|
|
|
|
|
|
a.download = fileName
|
|
|
|
|
|
a.target = '_blank'
|
|
|
|
|
|
a.click()
|
|
|
|
|
|
a.remove() // 将a标签移除
|
2020-04-06 22:11:25 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}, error => {
|
|
|
|
|
|
const $self = this
|
|
|
|
|
|
const reader = new FileReader()
|
|
|
|
|
|
reader.onload = function (event) {
|
|
|
|
|
|
const responseText = reader.result
|
|
|
|
|
|
const exception = JSON.parse(responseText)
|
|
|
|
|
|
if (exception.message) {
|
|
|
|
|
|
$self.$message.error(exception.message)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.error(error)
|
2020-01-19 18:31:18 +08:00
|
|
|
|
}
|
2020-01-06 19:03:38 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
reader.readAsText(error.response.data)
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
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-12-29 15:38:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
if (orderBy) {
|
|
|
|
|
|
this.$set(this.searchLabel, 'orderBy', orderBy)
|
|
|
|
|
|
}
|
2021-04-29 22:24:38 +08:00
|
|
|
|
if (this.$refs.dataTable) {
|
|
|
|
|
|
this.$refs.dataTable.$refs.dataTable.bodyWrapper.scrollTop = 0
|
|
|
|
|
|
}
|
2021-04-13 20:33:12 +08:00
|
|
|
|
this.getTableData()
|
2021-05-14 15:24:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
computeDistance (str) {
|
|
|
|
|
|
let width = 0
|
|
|
|
|
|
const html = document.createElement('span')
|
|
|
|
|
|
html.innerText = str
|
|
|
|
|
|
html.className = 'getTextWidth'
|
|
|
|
|
|
document.querySelector('body').appendChild(html)
|
|
|
|
|
|
width = document.querySelector('.getTextWidth').offsetWidth
|
|
|
|
|
|
document.querySelector('.getTextWidth').remove()
|
|
|
|
|
|
return Number('-' + (width + 5))
|
|
|
|
|
|
},
|
|
|
|
|
|
returnMarkArea () {
|
|
|
|
|
|
if (this.currentMsg) {
|
|
|
|
|
|
if (this.currentMsg.alertRule.operator == '>' || this.currentMsg.alertRule.operator == '>=') {
|
|
|
|
|
|
return [{ yAxis: this.currentMsg.alertRule.threshold }, {}]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return [{}, { yAxis: this.currentMsg.alertRule.threshold }]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-05-25 14:21:14 +08:00
|
|
|
|
deleteMessage () {}
|
2019-12-06 17:36:33 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
2019-12-06 17:36:33 +08:00
|
|
|
|
</script>
|
2021-05-08 09:29:25 +08:00
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.active{
|
|
|
|
|
|
border-bottom: 3px solid #fa901c;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
cursor: default;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
}
|
2021-05-08 05:06:45 +00:00
|
|
|
|
</style>
|