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/dashboard/panel.vue

1217 lines
42 KiB
Vue
Raw Normal View History

<template>
2022-03-25 15:40:05 +08:00
<div class="panel list-page" v-my-loading="panelTabLoading">
2021-04-26 21:42:15 +08:00
<div class="main-list">
<div>
<transition name="el-zoom-in-center">
2021-11-01 17:23:01 +08:00
<div v-if="isLoading" class="panel-loading"></div>
</transition>
</div>
2021-11-15 14:00:54 +08:00
<div class="main-container">
<div class="top-tools panel-top-tools" :class="showTopLine? 'panel-top-tools-bottom' : ''">
2021-11-19 09:40:21 +08:00
<div v-if="panelData.length === 0" class="top-tool-left" style="margin-left: 10px;">
2021-04-26 21:42:15 +08:00
<button id="panel-add-panel" class="nz-btn nz-btn-style-light nz-btn-size-small" @click="toAdd"><i class="nz-icon nz-icon-create-square"></i>&nbsp;&nbsp;{{$t("dashboard.panel.createPanelTitleSec")}}</button>
</div>
2021-04-26 21:42:15 +08:00
<template v-else>
<div class="top-tool-left" style="cursor: pointer;">
<select-dashboard
ref="selectDashboard"
2022-06-02 10:57:33 +08:00
:panel-data="panelData"
:panel-lock="panelLock"
:placement="'bottom-start'"
:show-panel="showPanel"
style="display: inline-block;padding: 0"
@deletePanel="del"
@editPanel="edit"
@selectDashboard="panelChange">
2021-04-26 21:42:15 +08:00
<template v-slot:trigger>
<i style="color: #BEBEBE" class="el-icon-menu"></i>
<span :title="showPanel.name + ' (' + showPanel.chartNum +' charts)' " class="show-panel-name">{{showPanel.name}}</span>
<i @click.stop="delStarred(showPanel)" v-if="showPanel.starred===1" class="nz-icon nz-icon-a-xingzhuang2" :title ="$t('overall.starred')"></i>
<i @click.stop="addStarred(showPanel)" v-else class="nz-icon nz-icon-xingzhuang" :title ="$t('overall.unstarred')"></i>
2021-04-26 21:42:15 +08:00
</template>
</select-dashboard>
2021-04-26 21:42:15 +08:00
</div>
2021-04-26 21:42:15 +08:00
<div class="top-tool-right">
<!-- <div class="top-tool-search margin-r-20">
<el-input id="queryPanel" ref="queryPanel" v-model="filter.searchName" class="query-input-inactive" clearable size="small" @blur="blurInput" @clear="clearInput" @focus="focusInput">
<i slot="suffix" class="el-input__icon nz-icon nz-icon-search" style="float: right" @click="focusInput"></i>
</el-input>
</div> -->
<pick-time id="panel" ref="pickTime" v-model="searchTime" :refresh-data-func="dateChange" :use-chart-unit="false" class="margin-r-10" :sign="showPanel.id"></pick-time>
<!-- 切换查看模式 -->
<button slot="reference" class="top-tool-btn view-mode" :title="$t('overall.viewMode')" @click="cycle">
<i class="nz-icon nz-icon-moshiqiehuan"></i>
</button>
<button id="panel-add-chart" v-has="'main_add'" :title="$t('overall.createChart')" class="top-tool-btn margin-r-10" type="button" @click="addChartBefore">
<i class="nz-icon-create-square nz-icon"></i>
</button>
2021-11-02 15:47:17 +08:00
<top-tool-more-options
:delete-objs="batchDeleteObjs"
2022-05-24 15:04:46 +08:00
ref="topTool"
2021-04-26 21:42:15 +08:00
id="panel"
:params="filter"
:permissions="{
2022-01-11 11:00:03 +08:00
import: 'main_add',
2022-01-11 17:05:21 +08:00
export: 'main_edit'
2021-04-26 21:42:15 +08:00
}"
:paramsType="'dashboard'"
2021-04-26 21:42:15 +08:00
class="top-tool-export"
export-file-name="chart"
export-url="/visual/panel/export"
import-url="/visual/panel/import"
2022-05-24 15:04:46 +08:00
:exportBoxShow="true"
@export="exportType"
@afterImport="afterImport"
2021-04-26 21:42:15 +08:00
>
<template v-slot:before>
<el-dropdown-item>
<div id="panel-lock" @click="$store.dispatch('dispatchPanelLock',{flag:!panelLock})"><i :class="{'nz-icon nz-icon-lock':!panelLock,'nz-icon nz-icon-unlock':panelLock}"></i>{{!panelLock ? $t('overall.locked') : $t('overall.unlocked')}}</div>
</el-dropdown-item>
</template>
<template v-slot:after>
2022-01-11 11:00:03 +08:00
<el-dropdown-item v-has="'main_add'">
2021-05-19 23:17:24 +08:00
<div id="chart-temp-add" @click="addChartByTemp"><i class="nz-icon nz-icon-add"></i>{{$t('overall.AddByTemplate')}}</div>
</el-dropdown-item>
2022-01-11 17:05:21 +08:00
<el-dropdown-item v-has="'panel_view'">
<div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div>
</el-dropdown-item>
2022-05-27 09:29:59 +08:00
<el-dropdown-item v-has="'panel_view'">
2022-06-06 10:38:57 +08:00
<div id="chart-export-html" @click="exportType"><i class="nz-icon nz-icon-kuaizhao"></i>{{ $t('overall.snapshoot') }}</div>
2022-05-27 09:29:59 +08:00
</el-dropdown-item>
2021-04-26 21:42:15 +08:00
</template>
</top-tool-more-options>
2021-04-26 21:42:15 +08:00
</div>
</template>
</div>
2021-12-21 18:05:36 +08:00
<div id="tableList" class="table-list" style='overflow-y: unset'>
<div class="table-list-box">
<div id="dashboardScrollbar" class="box-content" v-my-loading="chartListLoading" ref="dashboardScrollbar" style='overflow-y: auto;display: flex;flex-direction: column;overflow-x: hidden'>
<panel-variables :labelArrs="variables" :time-range="searchTime" @getPanelData="getPanelData"></panel-variables>
2021-11-19 09:40:21 +08:00
<chart-list
ref="chartList"
2022-07-07 10:11:21 +08:00
:variablesInit="variablesInit"
2021-12-13 17:07:41 +08:00
name="panel"
:panelId="showPanel.id"
2022-07-05 18:45:03 +08:00
:class="{'show-top':showTopBtn, 'is-dashboard': true}"
:data-list="dataList"
:is-export-html="false"
:nowTimeType="nowTimeType"
2021-11-19 09:40:21 +08:00
:from="fromRoute.panel"
:time-range="searchTime"
2021-12-06 15:25:09 +08:00
@edit-chart="editChart"
2021-11-19 09:40:21 +08:00
@on-refresh-time="refreshTime"
@on-remove-chart="delChart"
@on-add-group-item-chart="addGroupItem"
@refreshPanel="refreshPanel"
:loading="chartListLoading"
2021-11-19 09:40:21 +08:00
></chart-list>
2021-04-26 21:42:15 +08:00
</div>
</div>
</div>
2020-12-14 20:25:24 +08:00
</div>
</div>
2021-04-26 21:42:15 +08:00
<button :class="{'to-top-is-hover': tableHover}" @click="toTop(scrollbarWrap)" class="to-top" style="bottom: 0;" v-show="showTopBtn" :title="$t('overall.backToTop')"><i class="nz-icon nz-icon-top"></i></button>
<transition name="right-box">
<chart-right-box
v-if="chartRightBoxShow"
2022-03-25 15:40:05 +08:00
v-my-loading="rightBox.loading"
ref="addChartModal"
:chart="chart"
:from="fromRoute.panel"
:panel-data="panelData"
:show-panel="showPanel"
:variables="variables"
@close="closeChartBox"
@reload="panelReload"
@reloadOnlyPanel="panelReloadOnlyPanel"
@delete-chart="delChart"
@on-create-success="createSuccess"
@on-delete-success="delChartOk"
></chart-right-box>
</transition>
<transition name="right-box">
<chart-temp-box v-if="rightBox.chartTemp.show" :from="fromRoute.panel" :obj="chart" :panel-data="panelData" :show-panel="showPanel" @close="closeChartTempBox" @on-create-success="createSuccess"></chart-temp-box>
</transition>
<transition name="right-box">
<panel-box v-if="rightBox.panel.show" ref="panelBox" :obj="panel" @close="closePanelBox" @reload="panelReload" @reloadForDel="panelReloadForDel" ></panel-box>
</transition>
</div>
</template>
2020-01-17 16:50:17 +08:00
<script>
import { chartCache } from '@/components/common/js/common'
2022-07-13 14:38:10 +08:00
import { data as le5leData, observers as le5leObservers } from 'le5le-store/store/data.js'
2021-11-30 16:39:21 +08:00
import chartRightBox from '@/components/common/rightBox/chart/chartRightBox'
2021-03-19 18:52:19 +08:00
import bus from '../../../libs/bus'
import pickTime from '../../common/pickTime'
import selectDashboard from '../../common/popBox/selectDashboard'
2021-04-09 15:07:15 +08:00
import panelBox from '@/components/common/rightBox/panelBox'
import chartTempBox from '@/components/common/rightBox/chartTempBox'
import topToolMoreOptions from '@/components/common/popBox/topToolMoreOptions'
import { fromRoute } from '@/components/common/js/constants'
2021-12-07 14:19:16 +08:00
import { randomcolor } from '@/components/common/js/radomcolor/randomcolor'
import routerPathParams from '@/components/common/mixin/routerPathParams'
2022-04-08 11:26:17 +08:00
import htmlToPdfMixin from '@/components/common/mixin/htmlToPdfMixin'
2022-04-11 15:49:10 +08:00
import exportHtmlMixin from '@/components/common/mixin/exportHtml'
import * as echarts from 'echarts'
import panelVariables from '@/components/common/panel/panelVariables'
// import FileSaver from 'file-saver'
// import chartData from './testData'
2021-03-19 18:52:19 +08:00
export default {
name: 'panel',
2022-04-11 15:49:10 +08:00
mixins: [routerPathParams, htmlToPdfMixin, exportHtmlMixin],
2021-03-19 18:52:19 +08:00
data () {
return {
fromRoute,
2022-04-08 11:26:17 +08:00
pdfId: 'pdfDom',
htmlTitle: 'panel',
panelTabLoading: false,
overScroll10: false,
isLoading: true,
2021-03-19 18:52:19 +08:00
showTopBtn: false, // top按钮
visible: false,
chartListLoading: true,
2021-03-19 18:52:19 +08:00
rightBox: { // 面板弹出框相关
chart: { show: false },
chartTemp: { show: false },
2021-12-09 14:15:06 +08:00
panel: { show: false },
loading: false
2021-03-19 18:52:19 +08:00
},
tableHover: false,
searchTime: bus.getTimezontDateRange(),
intervalTimer: null,
interval: 0,
showPanel: { // panel下拉列表
id: '',
name: '',
type: 'panel'
2021-03-19 18:52:19 +08:00
},
panel: { // 新增panel
id: '',
name: '',
remark: '',
param: {
report: {
enable: false,
receivers: [],
range: {
unit: ''
},
schedule: {
repeat: 0,
nums: [],
type: 0
}
}
}
2021-03-19 18:52:19 +08:00
},
chart: {},
blankChart: {
id: '',
2021-04-07 16:41:11 +08:00
name: '',
2021-03-19 18:52:19 +08:00
type: 'line',
span: 4,
2021-12-06 15:25:09 +08:00
datasource: 'metrics',
height: 4,
2021-03-19 18:52:19 +08:00
unit: 2,
param: {
stack: 0,
nullType: 'null',
legend: { placement: 'bottom', values: [], show: true },
enable: {
legend: true,
valueMapping: false,
thresholds: false,
visibility: false
},
thresholdShow: true,
2022-05-17 18:54:19 +08:00
thresholds: [{ value: undefined, color: randomcolor() }],
showHeader: 1,
visibility: {
varName: '',
operator: 'equal',
varValue: '',
result: 'show'
}
},
elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1 }],
2021-03-19 18:52:19 +08:00
panel: '',
2021-04-07 16:41:11 +08:00
sync: 0,
remark: '',
2021-12-06 15:25:09 +08:00
groupId: ''
2021-03-19 18:52:19 +08:00
},
pageObj: {
pageNo: 1,
pageSize: -1, // 此处获取所有数据,所以设置一个较大的值
total: 0
},
blankChartTemp: {
varType: 1,
pid: '',
panelId: '',
varIds: []
},
2021-03-19 18:52:19 +08:00
panelData: [],
panelDataDragTmp: [],
searchMsg: { // 给搜索框子组件传递的信息
searchLabelList: [
2021-05-10 15:59:39 +08:00
{
name: 'ID',
type: 'input',
label: 'ids',
disabled: false
},
{
name: this.$t('overall.name'),
type: 'input',
label: 'name',
disabled: false
},
{
name: this.$t('overall.type'),
type: 'selectString',
label: 'chartType',
disabled: false
},
{
name: this.$t('dashboard.panel.chartForm.varType'),
type: 'select',
label: 'varType',
disabled: false
}
2021-03-19 18:52:19 +08:00
]
},
searchLabel: {}, // 搜索参数
// ---图表相关参数--start
dataList: [], // 数据列表
filter: { // 过滤条件
panelId: 0,
2021-03-19 18:52:19 +08:00
start_time: '',
end_time: '',
2021-03-31 10:02:12 +08:00
searchName: '',
id: 4
2021-03-19 18:52:19 +08:00
},
panelId: 0,
// ---图表相关参数--end
2021-11-02 15:47:17 +08:00
scrollbarWrap: null,
batchDeleteObjs: [],
nowTimeType: {},
2022-05-24 15:04:46 +08:00
showTopLine: false,
// 导出html 以及 pdf的弹窗
exportBoxShow: false,
// 查看模式
mode: '',
variables: [],
variablesInit: false // 判断variables 是否加载完成
2021-03-19 18:52:19 +08:00
}
},
components: {
'pick-time': pickTime,
'panel-box': panelBox,
topToolMoreOptions,
selectDashboard,
2021-11-30 16:39:21 +08:00
chartTempBox,
chartRightBox,
panelVariables // 处理panel变量的组件
2021-03-19 18:52:19 +08:00
},
computed: {
chartRightBoxShow () {
return this.$store.getters.getShowRightBox
},
delChartFlag () {
return this.$store.getters.getDelChart
},
panelLock () {
return this.$store.getters.getPanelLock
}
},
2021-03-19 18:52:19 +08:00
methods: {
// 新增收藏
addStarred (data) {
this.$refs.selectDashboard.addStarred(data)
},
// 删除收藏
delStarred (data) {
this.$refs.selectDashboard.delStarred(data)
},
2021-03-19 18:52:19 +08:00
// 刷新
refreshPanel () {
this.getData(this.filter)
2021-03-19 18:52:19 +08:00
},
// 面板相关操作
panelChange (val) {
if (!val) {
return false
}
this.variablesInit = false
2021-03-19 18:52:19 +08:00
this.filter.searchName = ''
// this.$refs.searchInput.select();
this.showPanel = val
this.variables = this.$loadsh.get(this, 'showPanel.param.variables', []) || []
this.showPanel.type = 'dashboard'
2021-03-19 18:52:19 +08:00
this.filter.panelId = this.showPanel.id
this.panelId = this.showPanel.id
const param = {
2021-12-23 20:22:40 +08:00
panelId: this.panelId,
nowTimeType: JSON.stringify(this.nowTimeType),
2022-06-02 10:57:33 +08:00
searchTime: JSON.stringify(this.searchTime),
mode: this.mode
}
// this.getTableData()
// this.getData(this.filter)
const path = this.fromRoute.panel
this.updatePath(param, path)
this.dateChange()
2021-03-19 18:52:19 +08:00
this.$refs.chartList.cleanData()
},
2021-01-12 20:39:59 +08:00
2021-03-19 18:52:19 +08:00
del (u) {
this.$confirm(this.$t('tip.confirmDelete'), {
confirmButtonText: this.$t('tip.yes'),
cancelButtonText: this.$t('tip.no'),
type: 'warning'
}).then(() => {
this.$delete('visual/panel?ids=' + u.id).then(response => {
2021-03-19 18:52:19 +08:00
if (response.code === 200) {
this.$message({
duration: 1000,
type: 'success',
message: this.$t('tip.deleteSuccess')
})
const param = {
panelId: 0,
nowTimeType: JSON.stringify(this.nowTimeType),
searchTime: JSON.stringify(this.searchTime),
mode: this.mode
}
const path = this.fromRoute.panel
this.updatePath(param, path)
2021-03-19 18:52:19 +08:00
this.getTableData(true)
} else {
this.$message.error(response.msg)
this.$store.dispatch('clearPanel')
2021-03-19 18:52:19 +08:00
}
})
}).catch(() => {
this.$store.dispatch('clearPanel')
2021-03-19 18:52:19 +08:00
})
},
edit (u) {
this.$get('visual/panel/' + u.id).then(res => {
if (res.code === 200) {
this.panel = res.data
if (!this.$loadsh.get(this.panel, 'param.report', '')) {
this.panel = {
...this.panel,
param: {
report: {
enable: false,
range: {
2022-07-06 13:51:36 +08:00
unit: 'day'
},
schedule: {
2022-07-06 13:51:36 +08:00
type: '2',
repeat: 1,
nums: [],
stime: '',
etime: ''
},
receivers: []
},
chartShare: 'none'
}
}
}
this.panel.param.report.schedule.type = this.panel.param.report.schedule.type + ''
const startTime = this.$loadsh.get(this.panel, 'param.report.schedule.stime', '')
if (startTime !== '') {
this.panel.param.report.schedule.stime = this.utcTimeToTimezoneStr(this.panel.param.report.schedule.stime, 'YYYY-MM-DD HH:mm:ss')
} else {
this.panel.param.report.schedule.stime = ''
}
const endTime = this.$loadsh.get(this.panel, 'param.report.schedule.etime', '')
if (endTime !== '') {
this.panel.param.report.schedule.etime = this.utcTimeToTimezoneStr(this.panel.param.report.schedule.etime, 'YYYY-MM-DD HH:mm:ss')
} else {
this.panel.param.report.schedule.etime = ''
}
this.rightBox.panel.show = true
}
})
// this.panel = Object.assign({}, u)
2021-03-19 18:52:19 +08:00
},
toAdd () {
if (!this.hasButton('panel_view')) {
return
}
2021-05-12 16:19:43 +08:00
this.rightBox.panel.show = true
// 关闭selectDashboard弹框
this.$refs.selectDashboard && this.$refs.selectDashboard.esc()
2021-03-19 18:52:19 +08:00
this.panel = {
id: '',
name: '',
remark: '',
param: {
report: {
enable: false,
receivers: [],
range: {
2022-07-06 13:51:36 +08:00
unit: 'day'
},
schedule: {
stime: '',
etime: '',
nums: [],
2022-07-06 13:51:36 +08:00
type: 2 + '',
repeat: 1
}
},
2022-06-27 10:28:29 +08:00
chartShare: 'none'
}
2021-03-19 18:52:19 +08:00
}
// this.$refs.panelBox.setTitle(this.$t('dashboard.panel.createPanelTitle'))
2021-03-19 18:52:19 +08:00
},
panelReload (clearShowPanel) {
this.getTableData(clearShowPanel)
},
refreshTime (st, et) {
const startTime = bus.timeFormate(st, 'yyyy-MM-dd hh:mm')
const endTime = bus.timeFormate(et, 'yyyy-MM-dd hh:mm')
2021-03-31 10:02:12 +08:00
this.searchTime = [startTime, endTime, '']
2021-03-19 18:52:19 +08:00
},
panelReloadForDel: function () {
if (this.showPanel.id === this.panel.id) {
this.showPanel.id = ''
}
this.getTableData()
},
/* 图表相关操作--start */
addChart () {
this.chart = this.newChart()
this.chart.param.thresholds = [{ value: undefined, color: randomcolor() }]
this.chart.panelId = this.showPanel.id
this.chart.panelName = this.showPanel.name
2021-03-19 18:52:19 +08:00
},
addChartByTemp () {
2021-12-08 15:15:18 +08:00
this.chart = JSON.parse(JSON.stringify(this.blankChartTemp))
this.chart.panelId = this.showPanel.id
this.rightBox.chartTemp.show = true
},
chartBySync () {
this.panelTabLoading = true
this.$post('visual/panel/chart/syncTmpl', { panelId: this.showPanel.id }).then(res => {
this.panelTabLoading = false
if (res.code === 200) {
this.getData(this.filter)
this.$message.success(this.$t('tip.syncSuccess'))
} else {
this.$message.error(res.msg)
}
})
},
addGroupItem (groupId) {
this.chart = this.newChart()
this.chart.groupId = groupId
this.chart.panelId = this.showPanel.id
this.chart.panelName = this.showPanel.name
this.chart.isGroup = true
},
2021-03-19 18:52:19 +08:00
newChart () {
return JSON.parse(JSON.stringify(this.blankChart))
},
// 编辑图表信息,打开编辑弹窗
editChart (data, copy) {
if (copy) {
this.chart = JSON.parse(JSON.stringify(data))
2021-12-29 16:18:46 +08:00
this.chart.x = 0
this.chart.y = 0
this.chart.panelId = this.showPanel.id
this.chart.panelName = this.showPanel.name
this.chart.id = ''
this.chart.elements.forEach((item) => {
item.id = ''
item.chartId = ''
delete item.seq
})
if (this.chart.datasource !== 'metrics' && this.chart.datasource !== 'logs') {
2021-12-29 16:18:46 +08:00
delete this.chart.elements
}
if (!this.chart.groupId || this.chart.groupId == -1) {
this.chart.groupId = ''
}
} else {
2021-12-09 14:15:06 +08:00
this.rightBox.loading = true
this.$get('visual/panel/chart/' + data.id).then(res => {
2021-12-09 14:15:06 +08:00
this.rightBox.loading = false
if (res.code === 200) {
const chartData = res.data
this.chart = JSON.parse(JSON.stringify(chartData))
this.chart.panelId = this.showPanel.id
this.chart.panelName = this.showPanel.name
2022-03-10 11:08:40 +08:00
if (this.chart.param) {
this.chart.param = JSON.parse(this.chart.param)
} else {
this.chart.param = {}
}
2021-12-06 15:25:09 +08:00
if (!this.chart.groupId || this.chart.groupId == -1) {
this.chart.groupId = ''
}
if (this.chart.type == 'table') {
2021-12-15 17:55:56 +08:00
const arr = this.chart.param.indexs ? this.chart.param.indexs.split(',') : []
this.chart.param.tags = arr.map((item) => {
return {
text: item,
tiClasses: ['ti-valid']
}
})
}
} else {
this.$message.error(res.msg)
}
})
}
2021-03-19 18:52:19 +08:00
},
closeChartBox (refresh) {
// this.rightBox.chart.show = false
2021-12-09 14:15:06 +08:00
this.chart = {}
this.$store.dispatch('clearPanel')
2021-03-19 18:52:19 +08:00
/* if (refresh) {
2021-05-18 19:18:14 +08:00
this.getData(this.filter)
2021-03-19 18:52:19 +08:00
} */
},
2021-05-18 19:18:14 +08:00
closeChartTempBox (refresh) {
this.rightBox.chartTemp.show = false
2021-05-18 19:18:14 +08:00
if (refresh) {
this.getData(this.filter)
}
},
2021-03-19 18:52:19 +08:00
closePanelBox (refresh) {
this.rightBox.panel.show = false
2021-05-12 16:19:43 +08:00
if (refresh) {
this.getTableData()
}
2021-03-19 18:52:19 +08:00
},
// 移除图表:弹出确认框询问
delChart (data, from) {
this.$confirm(this.$t('tip.confirmDelete'), {
confirmButtonText: this.$t('tip.yes'),
cancelButtonText: this.$t('tip.no'),
type: 'warning'
}).then(() => {
this.$delete('visual/panel/chart?ids=' + data.id).then(response => {
2021-03-19 18:52:19 +08:00
if (response.code === 200) {
this.$message({
duration: 2000,
type: 'success',
message: this.$t('tip.deleteSuccess')
})
this.getData(this.filter)
2021-12-09 14:15:06 +08:00
this.chart = {}
this.$store.dispatch('clearPanel')
2021-11-30 16:39:21 +08:00
// this.$refs.chartList.loadChartData(this.scrollbarWrap.scrollTop)
2021-03-19 18:52:19 +08:00
// if(nextChart&&prevChart){ //删除图表为中间位置
// prevChart.next = nextChart.id;
// nextChart.prev = prevChart.id;
// }else{
// if(!nextChart) prevChart.next = -1;
// if(!prevChart) nextChart.prev = 0;
// }
// this.getTableData(); //删除相关图表后,刷新面板数据
} else {
this.$message.error(response.msg)
this.$store.dispatch('clearPanel')
}
2021-03-19 18:52:19 +08:00
})
}).catch(() => {
this.chart = {}
this.$store.dispatch('clearPanel')
2021-03-19 18:52:19 +08:00
})
},
delChartOk () {
this.filter.panelId = this.showPanel.id
this.getData(this.filter)
},
// 图表创建成功回调panel页面进行图表的刷新
createSuccess (msg, data, params, panel) {
this.filter.panelId = this.showPanel.id
this.getData(this.filter)
this.$store.dispatch('clearPanel')
2021-03-19 18:52:19 +08:00
},
// 获取数据,用在子页面
getData (params) {
if (!this.hasButton('panel_view')) {
return
}
2022-07-13 14:38:10 +08:00
this.dataList = []
2021-11-19 09:40:21 +08:00
this.chartListLoading = true
2021-03-19 18:52:19 +08:00
if (params.start_time === '' || params.end_time === '') {
const now = bus.getTimezontDateRange()
const endTimeTmp = bus.timeFormate(now[1].getTime(), this.panelDateFormatTime)
const startTimeTmp = bus.timeFormate(now[0].getTime(), this.panelDateFormatTime)
2021-03-19 18:52:19 +08:00
params.start_time = startTimeTmp
params.end_time = endTimeTmp
}
2022-07-13 14:38:10 +08:00
if (le5leData) {
Object.keys(le5leData).forEach(key => {
le5leData[key] = null
delete le5leData[key]
})
}
if (le5leObservers) {
Object.keys(le5leObservers).forEach(key => {
le5leObservers[key] = null
delete le5leObservers[key]
})
}
2021-11-19 09:40:21 +08:00
this.$get('visual/panel/chart?panelId=' + params.panelId + '&groupId=0' + '&pageSize=-1').then(response => {
if (response.code === 200) {
this.chartListLoading = false
this.dataList = response.data.list.map(item => {
2021-11-19 09:40:21 +08:00
return {
...item,
hide: item.name.indexOf(this.filter.searchName) === -1, // 搜索条件
loaded: false
}
})
}
})
2021-03-19 18:52:19 +08:00
},
/* 图表相关操作--end */
/* 时间条件查询--start */
// 选择日期变化
dateChange (val) {
const nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType
this.nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType
2021-03-31 10:02:12 +08:00
this.setSearchTime(nowTimeType.type, nowTimeType.value, nowTimeType)
this.filter.start_time = bus.timeFormate(this.searchTime[0], this.panelDateFormatTime)
this.filter.end_time = bus.timeFormate(this.searchTime[1], this.panelDateFormatTime)
this.filter.end_time = bus.timeFormate(this.searchTime[1], this.panelDateFormatTime)
2021-03-31 10:02:12 +08:00
this.filter.value = this.searchTime[2]
this.filter.id = this.$refs.pickTime.$refs.timePicker.showTime.id
2021-12-23 20:22:40 +08:00
// this.getTableData()
2022-07-07 10:11:21 +08:00
this.getData(this.filter)
2021-12-23 20:22:40 +08:00
const param = {
panelId: this.panelId,
nowTimeType: JSON.stringify(this.nowTimeType),
2022-06-02 10:57:33 +08:00
searchTime: JSON.stringify(this.searchTime),
mode: this.mode
2021-12-23 20:22:40 +08:00
}
const path = this.fromRoute.panel
this.updatePath(param, path)
this.$store.dispatch('dispatchPanelTime', {
2021-12-09 16:59:46 +08:00
time: this.searchTime,
nowTimeType: this.nowTimeType
})
2021-03-19 18:52:19 +08:00
},
2021-03-31 10:02:12 +08:00
setSearchTime (type, val, nowTimeType) { // 设置searchTime
2021-03-19 18:52:19 +08:00
if (type === 'minute') {
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setMinutes(new Date(bus.computeTimezone(new Date().getTime())).getMinutes() - val), this.panelDateFormatTime)
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())), this.panelDateFormatTime)
2021-03-19 18:52:19 +08:00
this.$set(this.searchTime, 0, startTime)
this.$set(this.searchTime, 1, endTime)
this.$set(this.searchTime, 2, val + 'm')
} else if (type === 'hour') {
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setHours(new Date(bus.computeTimezone(new Date().getTime())).getHours() - val), this.panelDateFormatTime)
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())), this.panelDateFormatTime)
2021-03-19 18:52:19 +08:00
this.$set(this.searchTime, 0, startTime)
this.$set(this.searchTime, 1, endTime)
this.$set(this.searchTime, 2, val + 'h')
} else if (type === 'date') {
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setDate(new Date(bus.computeTimezone(new Date().getTime())).getDate() - val), this.panelDateFormatTime)
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())), this.panelDateFormatTime)
2021-03-19 18:52:19 +08:00
this.$set(this.searchTime, 0, startTime)
this.$set(this.searchTime, 1, endTime)
this.$set(this.searchTime, 2, val + 'd')
}
2021-12-23 20:22:40 +08:00
this.$refs.pickTime && (this.$refs.pickTime.$refs.timePicker.searchTime = this.searchTime)
2021-03-19 18:52:19 +08:00
},
/* 时间条件查询--end */
// 公用操作
jumpTo (data, id) {
bus.$emit('menu-change', data)
this.$router.push({
path: '/' + data,
query: {
t: +new Date()
}
2021-03-19 18:52:19 +08:00
})
},
panelReloadOnlyPanel () { // 仅刷新panel数据
if (!this.hasButton('panel_view')) {
return
}
this.$get('visual/panel?pageSize=-1').then(response => {
2021-03-19 18:52:19 +08:00
if (response.code === 200) {
this.panelData = response.data.list
for (let i = 0; i < this.panelData.length; i++) {
if (this.panelData[i].id == this.showPanel.id) {
this.showPanel = this.panelData[i]
2021-03-19 18:52:19 +08:00
break
}
}
2021-03-19 18:52:19 +08:00
}
})
},
2021-03-19 18:52:19 +08:00
getTableData (clearShowPanel) {
const vm = this
this.$get('visual/panel?type=dashboard&pageSize=-1').then(response => {
2021-03-19 18:52:19 +08:00
if (response.code === 200) {
let isInitData = false
this.panelData = JSON.parse(JSON.stringify(response.data.list))
2021-03-19 18:52:19 +08:00
if (response.data.list.length > 0) {
if (this.$store.state.showPanel.id > 0 && this.$store.state.showPanel.name) {
this.showPanel = JSON.parse(JSON.stringify(this.$store.state.showPanel))
}
2021-03-19 18:52:19 +08:00
if (clearShowPanel) {
this.showPanel.id = ''
}
2021-03-19 18:52:19 +08:00
if (!this.showPanel.id) {
this.showPanel = response.data.list[0]
this.filter.panelId = this.showPanel.id
2022-07-07 10:11:21 +08:00
this.getData(this.filter)
2021-03-19 18:52:19 +08:00
isInitData = true
} else {
handler(response.data.list)
this.filter.panelId = this.showPanel.id
}
this.isLoading = false
2021-03-19 18:52:19 +08:00
} else {
this.showPanel.id = ''
this.filter.panelId = ''
this.isLoading = !response.data.list.length === 0
}
2021-03-19 18:52:19 +08:00
this.pageObj.total = response.data.total
if (!isInitData && (this.panel.id === '' || this.panel.id === this.showPanel.id)) {
2022-07-07 10:11:21 +08:00
this.getData(this.filter)
}
2021-03-19 18:52:19 +08:00
this.$store.state.showPanel.id = 0
this.$store.state.showPanel.name = ''
this.$store.state.showPanel.type = 'dashboard'
} else {
if (response.msg) {
this.$message.error(response.msg)
} else if (response.error) {
this.$message.error(response.error)
} else {
this.$message.error(response)
}
}
this.variables = this.$loadsh.get(this, 'showPanel.param.variables', []) || []
2021-03-19 18:52:19 +08:00
}).catch((error) => {
// console.log('error................'+JSON.stringify(error));
if (error) {
console.error(error)
this.$message.error(error.toString())
}
2021-03-19 18:52:19 +08:00
})
function handler (panelData) {
panelData.forEach(panel => {
if (panel.id == vm.showPanel.id) {
vm.showPanel = panel
} else {
if (panel.children && panel.children.length > 0) {
handler(panel.children)
}
}
})
}
},
// 定期刷新
selectInterval (val) {
this.visible = false
clearInterval(this.intervalTimer)
if (val) {
this.interval = val
const start = new Date(this.searchTime[1])
const now = new Date()
const interval = Math.floor((now.getTime() - start.getTime()) / 1000) // 计算当前结束时间到现在的间隔(秒)
if (interval >= 60) { // 如果结束时间到现在超过1分钟
this.getIntervalData(interval)
}
2021-03-19 18:52:19 +08:00
this.intervalTimer = setInterval(() => {
this.getIntervalData(this.interval)
}, val * 1000)
}
},
getIntervalData (interval) { // interval:结束时间到现在的秒数
const start = new Date(this.searchTime[0])
const end = new Date(this.searchTime[1])
start.setSeconds(start.getSeconds() + interval)
end.setSeconds(end.getSeconds() + interval)
const startTime = bus.timeFormate(start, 'yyyy-MM-dd hh:mm')
const endTime = bus.timeFormate(end, 'yyyy-MM-dd hh:mm')
this.searchTime = [startTime, endTime]
// 刷新数据
this.dateChange()
},
pageNo (val) {
this.pageObj.pageNo = val
this.getTableData()
},
pageSize (val) {
this.pageObj.pageSize = val
this.getTableData()
},
search: function () {
if (this.$refs.chartList) {
2021-11-19 09:40:21 +08:00
// this.$refs.chartList.searchCharts(this.filter.searchName)
2021-03-19 18:52:19 +08:00
}
},
// 滚动事件触发下拉加载
onScroll () {
const _self = this
this.scrollbarWrap.addEventListener('scroll', bus.debounce(function () {
_self.showTopBtn = _self.scrollbarWrap.scrollTop > 50
_self.overScroll10 = _self.scrollbarWrap.scrollTop > 50
2021-12-21 18:05:36 +08:00
_self.$refs.chartList.onScroll(_self.scrollbarWrap.scrollTop)
}, 300, function () {
_self.showTopLine = _self.scrollbarWrap.scrollTop > 10
}))
2021-03-19 18:52:19 +08:00
},
focusInput () {
let classVal = document.getElementById('queryPanel').parentElement.getAttribute('class')
classVal = classVal.replace('query-input-inactive', 'query-input-active')
document.getElementById('queryPanel').parentElement.setAttribute('class', classVal)
this.$refs.queryPanel.focus()
},
blurInput () {
if (!this.filter.searchName || this.filter.searchName == '') {
setTimeout(function () {
let classVal = document.getElementById('queryPanel').parentElement.getAttribute('class')
classVal = classVal.replace('query-input-active', 'query-input-inactive')
document.getElementById('queryPanel').parentElement.setAttribute('class', classVal)
}, 100)
}
},
clearInput () {
this.$refs.queryPanel.focus()
},
tableListEnter () {
this.tableHover = true
},
2021-03-19 18:52:19 +08:00
tableListLeave () {
this.tableHover = false
},
toTop (wrap) {
let currentTop = wrap.scrollTop
const interval = currentTop / 10
const intervalFunc = setInterval(function () { // 花200ms分10次回到顶部模拟动画效果
if (currentTop === 0) {
clearInterval(intervalFunc)
} else {
currentTop = (currentTop - interval) < interval * 0.5 ? 0 : currentTop - interval
wrap.scrollTop = currentTop
}
}, 20)
2021-11-30 16:39:21 +08:00
},
load () {
},
addChartBefore () {
this.$store.dispatch('dispatchEditChart', {
chart: '',
type: 'add'
})
},
disposeChart () {
const chartInfo = this.$store.getters.getChart
const groupId = this.$store.getters.getGroupId
const type = this.$store.getters.getType
if (type === 'add') {
this.addChart()
}
if (type === 'edit') {
this.editChart(chartInfo)
}
if (type === 'addGroupItem') {
this.addGroupItem(groupId)
}
if (type === 'delete') {
this.delChart(chartInfo)
}
if (type === 'duplicate') {
this.editChart(chartInfo, true)
}
},
afterImport () {
this.dateChange()
this.panelReloadOnlyPanel()
2022-04-08 11:26:17 +08:00
},
htmlToPdf () {
2022-04-11 15:49:10 +08:00
const dom = document.getElementsByClassName(this.pdfId)[0]
2022-04-08 11:26:17 +08:00
if (dom) {
// dom = dom.getElementsByClassName('vue-grid-layout')[0]
2022-04-15 16:29:23 +08:00
this.htmlTitle = this.showPanel.name
2022-04-08 11:26:17 +08:00
this.scrollbarWrap.scrollTop = this.scrollbarWrap.scrollHeight
this.$refs.chartList.onScroll(this.scrollbarWrap.scrollTop)
2022-04-13 09:31:18 +08:00
// const div = document.createElement('div')
// div.setAttribute('class', 'el-loading-spinner')
// div.innerText = '12321312312312321'
// dom.insertBefore(div,)
2022-04-08 11:26:17 +08:00
let flag = true
this.showScreenLoading(true)
let timer = setInterval(() => {
flag = true
this.$refs.chartList.copyDataList.forEach(chart => {
if (chart.type !== 'group') {
flag = flag && chart.loaded
} else if (chart.collapse) {
chart.children.forEach(groupChart => {
flag = flag && groupChart.loaded
})
}
})
if (flag) {
clearInterval(timer)
timer = null
setTimeout(() => {
document.body.style.height = 'auto'
2022-04-12 10:30:33 +08:00
document.getElementsByClassName('left-menu')[0].style.height = '100vh'
// document.getElementsByTagName('html')[0].style.overflow = 'visible'
2022-04-08 11:26:17 +08:00
const position = dom.getBoundingClientRect()
2022-04-13 10:48:00 +08:00
this.getPdf(dom, -1 * position.left, -1 * position.top, this.searchTime)
// this.getPdf(dom, 0, 0)
}, 2000)
2022-04-08 11:26:17 +08:00
}
}, 200)
} else {
this.showScreenLoading(false)
}
2022-05-24 15:04:46 +08:00
this.$refs.topTool.closeDialog()
2022-04-11 17:13:56 +08:00
},
2022-05-24 15:04:46 +08:00
exportType (type) {
if (type === 'PDF') {
this.htmlToPdf()
} else {
this.exportToHtml(this.showPanel.name)
}
},
// 切换查看模式
cycle () {
if (!this.mode) {
// TV模式隐藏 menuheader
this.mode = 'tv'
} else if (this.mode === 'tv') {
// 简易模式(隐藏 menuheader 和 操作栏)
this.mode = 'se'
this.$message({
type: 'success',
message: this.$t('overall.toExit')
})
} else if (this.mode === 'se') {
// 默认模式
this.mode = ''
}
this.$store.commit('setMode', this.mode)
const param = {
panelId: this.panelId,
nowTimeType: JSON.stringify(this.nowTimeType),
searchTime: JSON.stringify(this.searchTime),
mode: this.mode
}
const path = this.fromRoute.panel
this.updatePath(param, path)
this.$store.dispatch('dispatchPanelTime', {
time: this.searchTime,
nowTimeType: this.nowTimeType
})
},
// 按ESC键退出查看模式
escExit (e) {
const message = document.querySelectorAll('.el-message-box__wrapper')
const showMessage = message.length && Array.from(message).some(item => {
return item.style.display !== 'none'
})
const showFullscreen = document.querySelector('.chart-fullscreen')
// 防止ESC键冲突
if (showMessage || showFullscreen) {
return false
}
if (e.keyCode === 27 && this.mode) {
// 默认模式
this.mode = ''
this.$store.commit('setMode', this.mode)
const param = {
panelId: this.panelId,
nowTimeType: JSON.stringify(this.nowTimeType),
searchTime: JSON.stringify(this.searchTime),
mode: this.mode
}
const path = this.fromRoute.panel
this.updatePath(param, path)
}
},
getPanelData () {
this.variablesInit = true
2022-07-07 10:11:21 +08:00
this.$refs.chartList.onScroll(this.scrollbarWrap.scrollTop)
2021-03-19 18:52:19 +08:00
}
},
created () {
const searchKeys = {
// key: path 键
// value: vue set 参数
2021-12-23 20:22:40 +08:00
panelId: { target: this, propertyName: 'panelId', type: 'number' },
searchTime: { target: this, propertyName: 'searchTime', type: 'jsonParse' },
nowTimeType: { target: this, propertyName: 'nowTimeType', type: 'jsonParse' },
mode: { target: this, propertyName: 'mode', type: 'string' }
}
this.initQueryFromPath(searchKeys)
setTimeout(() => {
this.showPanel.id = this.panelId
this.filter.panelId = this.panelId
})
// 设置查看模式
this.$store.commit('setMode', this.mode)
2021-12-23 20:22:40 +08:00
if (this.nowTimeType.type) {
this.setSearchTime(this.nowTimeType.type, this.nowTimeType.value, this.nowTimeType)
this.filter.start_time = bus.timeFormate(this.searchTime[0], this.panelDateFormatTime)
this.filter.end_time = bus.timeFormate(this.searchTime[1], this.panelDateFormatTime)
this.filter.end_time = bus.timeFormate(this.searchTime[1], this.panelDateFormatTime)
2021-12-23 20:22:40 +08:00
this.filter.value = this.searchTime[2]
}
2021-03-19 18:52:19 +08:00
this.getTableData()
this.$store.dispatch('dispatchPanelTime', {
2021-12-09 16:59:46 +08:00
time: this.searchTime,
2021-12-23 20:22:40 +08:00
nowTimeType: this.nowTimeType
2021-12-09 16:59:46 +08:00
})
2021-03-19 18:52:19 +08:00
},
mounted () {
// 监听键盘ESC事件
document.addEventListener('keydown', this.escExit)
bus.$on('refreshPanel', this.refreshPanel)
2021-03-19 18:52:19 +08:00
this.scrollbarWrap = this.$refs.dashboardScrollbar
this.onScroll()
document.querySelector('#tableList').addEventListener('mouseenter', this.tableListEnter)
document.querySelector('#tableList').addEventListener('mouseleave', this.tableListLeave)
2021-12-23 20:22:40 +08:00
if (this.nowTimeType) {
this.nowTimeType.start_time = this.searchTime[0]
this.nowTimeType.end_time = this.searchTime[1]
setTimeout(() => {
2022-03-10 11:08:40 +08:00
if (this.$refs.pickTime && this.$refs.pickTime.$refs.timePicker) {
this.$refs.pickTime.$refs.timePicker.setCustomTime(this.nowTimeType)
}
2021-12-23 20:22:40 +08:00
}, 100)
}
2021-03-19 18:52:19 +08:00
},
watch: {
'showPanel.param.chartShare': {
handler (value) {
// 每次切换联动模式 tooltip设置显示
const option = {
tooltip: {
className: 'chart-time-series'
}
}
for (const key in chartCache) {
if (!chartCache[key] || chartCache[key].group !== 'timeSeriesGroup') {
continue
}
chartCache[key].setOption(option)
}
this.$store.commit('setCurrentMousemove', 0)
if (value && value !== 'none') {
this.$store.commit('setConnect', value)
echarts.connect('timeSeriesGroup')
} else {
this.$store.commit('setConnect', value)
echarts.disconnect('timeSeriesGroup')
}
}
},
2021-03-19 18:52:19 +08:00
'filter.searchName': function (n, o) {
const temp = this
setTimeout(function () {
temp.search()
}, 1000)
2021-05-12 16:19:43 +08:00
},
searchTime: {
immediate: true,
deep: true,
handler (n) {
localStorage.setItem('panelTime', JSON.stringify(n))
}
},
chartRightBoxShow: {
immediate: false,
deep: true,
handler (n) {
if (n) {
this.disposeChart()
}
}
},
delChartFlag: {
immediate: false,
deep: true,
handler (n) {
if (n) {
this.disposeChart()
}
}
},
2021-05-12 16:19:43 +08:00
$route: {
immediate: true,
handler () {
// 是否弹出侧滑
const add = this.$route.query.add
this.$nextTick(() => {
if (add) {
if (add === 'chart') {
2021-12-09 14:15:06 +08:00
this.addChartBefore()
2021-05-12 16:19:43 +08:00
}
if (add === 'panel') {
this.toAdd()
}
}
})
}
2021-03-19 18:52:19 +08:00
}
},
beforeDestroy () {
// 移除键盘ESC事件
document.removeEventListener('keydown', this.escExit)
2022-04-13 10:48:00 +08:00
this.$store.dispatch('dispatchPanelLock', { flag: true })
2021-03-19 18:52:19 +08:00
if (document.querySelector('#tableList')) {
document.querySelector('#tableList').removeEventListener('mouseenter', this.tableListEnter)
document.querySelector('#tableList').removeEventListener('mouseleave', this.tableListLeave)
}
2021-03-19 18:52:19 +08:00
if (this.scrollbarWrap) {
this.scrollbarWrap.removeEventListener('scroll', bus.debounce)
2021-11-01 17:23:01 +08:00
}
localStorage.removeItem('panelTime')
if (!document.onmousemove) { // 添加鼠标移动事件监听
document.onmousemove = null
}
// 页面销毁 清除图表联动
this.$store.commit('setCurrentMousemove', 0)
this.$store.commit('setConnect', 'none')
echarts.disconnect('timeSeriesGroup')
}
2021-03-19 18:52:19 +08:00
}
</script>
<style scoped>
.view-mode{
margin-right: 10px;
display: flex;
align-items: center;
justify-content: center;
}
.view-mode .el-icon-monitor{
display: flex;
align-items: center;
font-size: 20px;
}
</style>