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/bottomBox/tabs/panelTabNew.vue

833 lines
30 KiB
Vue
Raw Normal View History

<template>
2022-03-25 15:40:05 +08:00
<div class="full-width-height chart-list panel-tab-new asset-detail" v-my-loading="panelTabLoading">
<nz-bottom-data-list
:showTitle='showTitle'
:obj='obj'
:layout="[]"
:tabs="tabs"
:targetTab="targetTab"
@changeTab="changeTab"
class="full-width-height"
2021-04-27 19:24:26 +08:00
:showPagination="false"
>
<template v-slot:title><span :title="obj.name">{{obj.name}}</span></template>
<template v-slot:top-tool-right>
2021-05-19 23:17:24 +08:00
<div v-if="from === fromRoute.asset" style="display: flex">
<pick-time ref="pickTime" v-model="searchTime" :refresh-data-func="dateChange" :use-chart-unit="false"></pick-time>
2022-01-11 11:00:03 +08:00
<button id="panel-add-chart" v-has="'main_add'" :title="$t('overall.createChart')" class="top-tool-btn margin-r-10"
type="button" @click="addChart">
<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"
id="asset-list"
:params="filter"
:params-type="paramsType"
:permissions="{import: 'main_add', export: 'main_edit'}"
class="top-tool-export margin-r-10"
export-file-name="asset-charts"
export-url="visual/panel/export"
import-url="visual/panel/import"
@afterImport="getTableData"
:showCur="false"
:link="obj"
:showLock="from === fromRoute.asset"
@panelLockChange="panelLockChange"
>
2021-05-19 23:17:24 +08:00
<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 11:00:03 +08:00
<el-dropdown-item v-has="'main_edit'">
<div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div>
</el-dropdown-item>
2022-04-11 17:54:38 +08:00
<el-dropdown-item v-has="'main_edit'">
<div id="chart-htmltopdf" @click="htmlToPdf"><i class="nz-icon nz-icon-download1"></i>{{ $t('overall.downloadToPdf') }}</div>
</el-dropdown-item>
2021-05-19 23:17:24 +08:00
</template>
</top-tool-more-options>
</div>
<div v-else-if="from === fromRoute.endpoint" style="display: flex">
<pick-time ref="pickTime" v-model="searchTime" :refresh-data-func="dateChange" :use-chart-unit="false"></pick-time>
2022-01-11 11:00:03 +08:00
<button id="endpoint-create-chart" v-has="'main_add'" :title="$t('overall.createChart')" class="top-tool-btn margin-r-10" @click.stop="addChart">
2021-05-19 23:17:24 +08:00
<i class="nz-icon nz-icon-create-square"></i>
</button>
2021-11-02 15:47:17 +08:00
<top-tool-more-options
:delete-objs="batchDeleteObjs"
2021-05-19 23:17:24 +08:00
id="asset-list"
:link="obj"
:params="filter"
2022-01-11 17:05:21 +08:00
:permissions="{import: 'main_add', export: 'main_edit'}"
2021-05-19 23:17:24 +08:00
:showCur="false"
:params-type="paramsType"
2021-05-19 23:17:24 +08:00
:showLock="from === fromRoute.endpoint"
class="top-tool-export margin-r-10"
export-file-name="endpoint-charts"
:export-url="'visual/panel/export'"
:import-url="'visual/panel/import'"
2021-05-19 23:17:24 +08:00
@afterImport="getTableData"
@panelLockChange="panelLockChange"
>
<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 11:00:03 +08:00
<el-dropdown-item v-has="'main_edit'">
<div id="chart-temp-sync" @click="chartBySync"><i class="nz-icon nz-icon-sync"></i>{{ $t('overall.syncChart') }}</div>
</el-dropdown-item>
2022-04-11 17:54:38 +08:00
<el-dropdown-item v-has="'main_edit'">
<div id="chart-htmltopdf" @click="htmlToPdf"><i class="nz-icon nz-icon-download1"></i>{{ $t('overall.downloadToPdf') }}</div>
</el-dropdown-item>
2021-05-19 23:17:24 +08:00
</template>
</top-tool-more-options>
</div>
<div v-else-if="from === fromRoute.chartTemp">
<button id="panel-lock" :title='panelLock ? $t("overall.unlocked") : $t("overall.locked")' class="top-tool-btn margin-r-10" @click="panelLockChange(!panelLock)" type="button">
<i :class="{'nz-icon nz-icon-lock':!panelLock,'nz-icon nz-icon-unlock':panelLock}"></i>
</button>
<button @click="chartBySync" id="chart-sync" :title="$t('overall.syncChart')" class="top-tool-btn margin-r-10"
type="button">
<i class="nz-icon nz-icon-sync"></i>
</button>
</div>
2021-04-26 21:42:15 +08:00
</template>
<!--图表-->
<div id="tableList" class="table-list" style="padding-top: 0;overflow: hidden">
<div id="dashboardScrollbar" class="table-list-box">
2022-03-25 15:40:05 +08:00
<div class="box-content" ref="dashboardScrollbar" v-my-loading="chartListLoading" style="overflow-y: auto">
<chart-list
ref="chartList"
name="panel"
:panelId="showPanel.id"
:class="{'show-top':showTopBtn}"
:data-list="dataList"
:nowTimeType="nowTimeType"
:from="from"
:time-range="searchTime"
@edit-chart="editChart"
@on-refresh-time="refreshTime"
@on-remove-chart="delChart"
@on-add-group-item-chart="addGroupItem"
@refreshPanel="refreshPanel"
:loading="chartListLoading"
:chart-detail-info="chartDetailInfo"
></chart-list>
</div>
</div>
</div>
</nz-bottom-data-list>
2021-05-19 23:17:24 +08:00
<transition name="right-box">
<!-- <chart-box v-if="rightBox.chart.show" ref="addChartModal" :chart="chart" :from="from" :panel-data="panelData" :show-panel="showPanel" @close="closeRightBox" @delete-chart="delChart" @on-create-success="createSuccess" @on-delete-success="delChartOk"></chart-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="from"
:panel-data="panelData"
:show-panel="showPanel"
@close="closeRightBox"
@reload="panelReload"
@reloadOnlyPanel="panelReloadOnlyPanel"
@delete-chart="delChart"
@on-create-success="createSuccess"
@on-delete-success="delChartOk"
></chart-right-box>
2021-05-19 23:17:24 +08:00
</transition>
<transition name="right-box">
<chart-temp-box v-if="rightBox.chartTemp.show" :from="from" :obj="chart" :panel-data="panelData" :show-panel="showPanel" @close="closeRightBox" @on-create-success="createSuccess"></chart-temp-box>
</transition>
</div>
</template>
<script>
// import chartBox from '../../../page/dashboard/chartBox'
import chartRightBox from '@/components/common/rightBox/chart/chartRightBox'
import chartList from '@/components/chart/chartList'
import bus from '../../../../libs/bus'
import subDataListMixin from '@/components/common/mixin/subDataList'
import nzBottomDataList from '@/components/common/bottomBox/nzBottomDataList'
2021-04-26 21:42:15 +08:00
import { fromRoute } from '@/components/common/js/constants'
2021-05-19 23:17:24 +08:00
import chartTempBox from '@/components/common/rightBox/chartTempBox'
import topToolMoreOptions from '@/components/common/popBox/topToolMoreOptions'
import detailViewRightMixin from '@/components/common/mixin/detailViewRightMixin'
2021-12-21 18:42:17 +08:00
import { randomcolor } from '@/components/common/js/radomcolor/randomcolor'
2022-04-11 17:54:38 +08:00
import htmlToPdfMixin from '@/components/common/mixin/htmlToPdfMixin'
export default {
name: 'panelTabNew',
2022-04-11 17:54:38 +08:00
mixins: [subDataListMixin, detailViewRightMixin, htmlToPdfMixin],
props: {
from: String,
obj: Object,
draggable: { type: Boolean, default: true },
paramsType: {
type: String,
default: 'dashboard'
}
},
computed: {
chartRightBoxShow () {
return this.$store.getters.getShowRightBox
},
delChartFlag () {
return this.$store.getters.getDelChart
},
panelLock () {
return this.$store.getters.getPanelLock
}
},
data () {
return {
2021-04-26 21:42:15 +08:00
fromRoute,
2022-04-11 17:54:38 +08:00
pdfId: 'pdfDom',
panelTabLoading: false,
showTopBtn: false, // top按钮
visible: false,
chartListLoading: true,
rightBox: { // 面板弹出框相关
2021-05-19 23:17:24 +08:00
chart: {
show: false
},
chartTemp: {
show: false
}
},
tableHover: false,
searchTime: bus.getTimezontDateRange(),
intervalTimer: null,
interval: 0,
panel: { // 新增panel
id: '',
name: ''
},
chart: {},
blankChart: {
id: '',
2021-12-21 18:42:17 +08:00
name: '',
type: 'line',
2021-12-21 18:42:17 +08:00
span: 4,
datasource: 'metrics',
height: 4,
unit: 2,
param: {
2021-12-21 18:42:17 +08:00
stack: 0,
nullType: 'null',
legend: { placement: 'bottom', values: [], show: true },
enable: {
legend: true,
valueMapping: false,
thresholds: false
},
thresholdShow: true,
thresholds: [{ value: undefined, color: randomcolor() }]
},
2021-12-21 18:42:17 +08:00
elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A' }],
panel: '',
2021-04-26 21:42:15 +08:00
sync: 0,
2021-12-21 18:42:17 +08:00
remark: '',
groupId: ''
},
pageObj: {
pageNo: 1,
pageSize: -1, // 此处获取所有数据,所以设置一个较大的值
total: 0
},
chartsData: [], // 中间部分图表相关数据
panelData: [],
searchMsg: { // 给搜索框子组件传递的信息
zheze_none: true,
searchLabelList: [
]
},
searchLabel: {}, // 搜索参数
// ---图表相关参数--start
dataList: [], // 数据列表
// searchName: '', // 搜索名称
filter: { // 过滤条件
// productId: 0,
panelId: 0,
start_time: '',
end_time: '',
searchName: ''
},
showPanel: {
name: '',
type: this.from,
2021-05-19 23:17:24 +08:00
id: null
},
blankChartTemp: {
varType: 1,
pid: '',
panelId: null,
varIds: []
},
// removeModal: false, // 删除弹出
// deleteObj: {}, // 删除对象
// ---图表相关参数--end
scrollbarWrap: null,
panelDataList: [],
batchDeleteObjs: [],
nowTimeType: {},
chartDetailInfo: {}
}
},
components: {
chartRightBox,
2021-04-26 21:42:15 +08:00
chartList,
nzBottomDataList,
2021-05-19 23:17:24 +08:00
topToolMoreOptions,
chartTempBox
},
methods: {
// 刷新
refresh () {
this.getTableData(this.obj.id)
},
refreshPanel () {
this.getData(this.filter)
},
refreshTime (st, et) {
const startTime = bus.timeFormate(st, 'yyyy-MM-dd hh:mm')
const endTime = bus.timeFormate(et, 'yyyy-MM-dd hh:mm')
this.searchTime = [startTime, endTime]
},
panelReloadForDel () {
this.getTableData(this.obj.id)
},
panelReload (clearShowPanel) {
this.getTableData(clearShowPanel)
},
panelReloadOnlyPanel () { // 仅刷新panel数据
if (!this.hasButton('panel_view')) {
return
}
this.$get('visual/panel?pageSize=-1').then(response => {
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]
break
}
}
}
})
},
/* 图表相关操作--start */
addChart () {
this.chart = this.newChart()
this.$store.dispatch('dispatchEditChart', {
chart: '',
type: 'add'
})
2021-05-19 23:17:24 +08:00
},
addChartByTemp () {
2021-12-08 15:15:18 +08:00
this.chart = JSON.parse(JSON.stringify(this.blankChartTemp))
2021-05-19 23:17:24 +08:00
this.chart.panelId = this.showPanel.id
if (this.from === fromRoute.endpoint) {
this.chart.varType = 2
}
if (this.from === fromRoute.asset || this.from === fromRoute.endpoint) {
this.chart.varIds.push(this.obj.id)
}
this.rightBox.chartTemp.show = true
},
newChart () {
return JSON.parse(JSON.stringify(this.blankChart))
},
// 切换tab
changeTab (tab) {
this.$emit('changeTab', tab)
},
closeRightBox (refresh) {
2021-05-19 23:17:24 +08:00
this.rightBox.chart.show = false
this.rightBox.chartTemp.show = false
this.$store.dispatch('clearPanel')
this.chart = {}
if (refresh) {
this.refresh()
if (this.from === fromRoute.chartTemp) {
2021-05-21 22:15:40 +08:00
this.$get('/visual/panel/chart', { ids: this.obj.id }).then(res => {
res.data.list.forEach(item => {
if (!item.children) {
item.children = []
}
})
this.panelDataList = res.data.list
if (this.panelDataList.length > 0) {
this.showPanel.id = this.filter.panelId = 0
this.getData(this.filter)
}
})
this.$emit('getTableData')
}
}
},
// 编辑图表信息,打开编辑弹窗
2021-12-29 16:18:46 +08:00
editChart (data, copy) {
if (copy) {
this.chart = JSON.parse(JSON.stringify(data))
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 !== 'log') {
delete this.chart.elements
}
if (!this.chart.groupId || this.chart.groupId == -1) {
this.chart.groupId = ''
}
2021-12-29 16:18:46 +08:00
} else {
this.rightBox.loading = true
this.$get('visual/panel/chart/' + data.id).then(res => {
this.rightBox.loading = false
if (res.code === 200) {
const chartData = res.data
2021-12-29 16:18:46 +08:00
this.chart = JSON.parse(JSON.stringify(chartData))
this.chart.panelId = this.showPanel.id
this.chart.panelName = this.showPanel.name
this.chart.param = JSON.parse(this.chart.param)
if (!this.chart.groupId || this.chart.groupId == -1) {
this.chart.groupId = ''
}
if (this.chart.type == 'table') {
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)
}
})
}
},
// 移除图表:弹出确认框询问
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 => {
if (response.code === 200) {
this.$message({
duration: 2000,
type: 'success',
message: this.$t('tip.deleteSuccess')
})
this.closeRightBox(true)
} else {
this.$message.error(response.msg)
this.$store.dispatch('clearPanel')
}
})
}).catch(() => {
this.$store.dispatch('clearPanel')
})
},
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-05-19 23:17:24 +08:00
this.rightBox.chart.show = true
},
delChartOk () {
this.getData(this.filter)
},
// 图表创建成功回调panel页面进行图表的刷新
createSuccess (msg, data, params) {
this.getData(this.filter)
},
// 获取数据,用在子页面
getData (params) {
if (!this.hasButton('panel_view')) {
return
}
this.chartListLoading = true
if (params.start_time === '' || params.end_time === '') {
const now = bus.getTimezontDateRange()
2021-12-31 16:41:30 +08:00
const endTimeTmp = bus.timeFormate(now[1].getTime(), 'YYYY-MM-DD HH:mm:ss')
const startTimeTmp = bus.timeFormate(now[0].getTime(), 'YYYY-MM-DD HH:mm:ss')
params.start_time = startTimeTmp
params.end_time = endTimeTmp
params.from = this.from
}
if (this.from !== 'chartTemp') {
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 => {
return {
...item,
hide: item.name.indexOf(this.filter.searchName) === -1, // 搜索条件
loaded: false
}
})
}
})
} else {
this.chartListLoading = false
this.dataList = this.panelDataList
}
},
/* 图表相关操作--end */
/* 时间条件查询--start */
// 选择日期变化
dateChange (val) {
// this.searchTime = [...val];
2021-05-25 19:47:22 +08:00
if (this.$refs.pickTime) {
const nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType
this.nowTimeType = this.$refs.pickTime.$refs.timePicker.nowTimeType
2021-05-25 19:47:22 +08:00
this.setSearchTime(nowTimeType.type, nowTimeType.value)
2021-12-31 16:41:30 +08:00
this.filter.start_time = bus.timeFormate(this.searchTime[0], 'YYYY-MM-DD HH:mm:ss')
this.filter.end_time = bus.timeFormate(this.searchTime[1], 'YYYY-MM-DD HH:mm:ss')
2021-05-25 19:47:22 +08:00
this.filter.panelId = this.showPanel.id
this.getData(this.filter)
this.$store.dispatch('dispatchPanelTime', {
time: this.searchTime,
nowTimeType: this.nowTimeType
})
2021-05-25 19:47:22 +08:00
}
},
/* 时间条件查询--end */
setSearchTime (type, val) { // 设置searchTime
if (type === 'minute') {
2021-12-31 16:41:30 +08:00
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setMinutes(new Date(bus.computeTimezone(new Date().getTime())).getMinutes() - val), 'YYYY-MM-DD HH:mm:ss')
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())), 'YYYY-MM-DD HH:mm:ss')
this.$set(this.searchTime, 0, startTime)
this.$set(this.searchTime, 1, endTime)
this.$set(this.searchTime, 2, val + 'm')
} else if (type === 'hour') {
2021-12-31 16:41:30 +08:00
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setHours(new Date(bus.computeTimezone(new Date().getTime())).getHours() - val), 'YYYY-MM-DD HH:mm:ss')
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())), 'YYYY-MM-DD HH:mm:ss')
this.$set(this.searchTime, 0, startTime)
this.$set(this.searchTime, 1, endTime)
this.$set(this.searchTime, 2, val + 'h')
} else if (type === 'date') {
2021-12-31 16:41:30 +08:00
const startTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setDate(new Date(bus.computeTimezone(new Date().getTime())).getDate() - val), 'YYYY-MM-DD HH:mm:ss')
const endTime = bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())), 'YYYY-MM-DD HH:mm:ss')
this.$set(this.searchTime, 0, startTime)
this.$set(this.searchTime, 1, endTime)
this.$set(this.searchTime, 2, val + 'd')
}
this.$refs.pickTime.$refs.timePicker.searchTime = this.searchTime
},
2021-04-26 21:42:15 +08:00
getVarType (from) {
if (from === this.fromRoute.asset) {
return 1
}
},
// 公用操作
getTableData (linkId) {
2021-05-19 23:17:24 +08:00
if (this.from === this.fromRoute.alertRule) {
this.getData(this.filter)
} else {
2021-05-19 23:17:24 +08:00
if (this.from === this.fromRoute.chartTemp) {
if (this.obj.type === 'group') {
2021-05-21 22:15:40 +08:00
this.$get('/visual/panel/chart', { ids: this.obj.id }).then(res => {
2021-04-27 19:24:26 +08:00
this.panelDataList = res.data.list
if (this.panelDataList.length > 0) {
this.showPanel.id = this.filter.panelId = 0
this.getData(this.filter)
}
})
2021-04-27 19:24:26 +08:00
return
}
2021-04-27 19:24:26 +08:00
this.panelDataList = [this.obj]
if (this.panelDataList.length > 0) {
this.showPanel.id = this.filter.panelId = 0
this.getData(this.filter)
}
} else {
2021-04-26 21:42:15 +08:00
this.$get('visual/panel', { type: this.from, link: linkId }).then(response => {
if (response.code === 200) {
this.panelData = response.data.list
if (this.panelData.length > 0) {
this.showPanel.id = this.filter.panelId = this.panelData[0].id
this.getData(this.filter)
}
} else {
if (response.msg) {
console.error(response.msg)
this.$message.error(response.msg)
} else if (response.error) {
console.error(response.error)
this.$message.error(response.error)
} else {
console.error(response)
this.$message.error(response)
}
}
}).catch((error) => {
if (error) {
console.error(error)
this.$message.error(error.toString())
}
})
}
}
},
// 定期刷新
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)
}
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(this.obj.id)
},
pageSize (val) {
this.pageObj.pageSize = val
this.getTableData(this.obj.id)
},
search () {
if (this.$refs.chartList) {
this.$refs.chartList.searchCharts(this.filter.searchName)
}
},
// 滚动事件触发下拉加载
onScroll () {
const _self = this
this.scrollbarWrap.addEventListener('scroll', bus.debounce(function () {
_self.showTopBtn = _self.scrollbarWrap.scrollTop > 50
// _self.$refs.chartList.loadChartData(_self.scrollbarWrap.scrollTop)
_self.$refs.chartList.onScroll(_self.scrollbarWrap.scrollTop)
}, 300))
},
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()
},
syncChart () {
2021-04-26 21:42:15 +08:00
if (this.from == this.fromRoute.asset || this.from == this.fromRoute.model) {
this.$confirm(this.$t('tip.syncTip'), {
confirmButtonText: this.$t('tip.yes'),
cancelButtonText: this.$t('tip.no'),
type: 'warning'
}).then(() => {
const param = {
2021-04-26 21:42:15 +08:00
modelId: this.from == this.fromRoute.model ? this.obj.id : null,
assetId: this.from == this.fromRoute.asset ? this.obj.id : null
}
this.$put('/model/syncChart', param).then(response => {
if (response.code == 200) {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.syncSuccess') })
2021-04-26 21:42:15 +08:00
if (this.from == this.fromRoute.asset) {
this.refresh()
}
} else {
console.error(response.msg)
this.$message.error(response.msg)
}
})
})
}
},
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)
},
tableListEnter () {
this.tableHover = true
},
tableListLeave () {
this.tableHover = false
2021-05-13 19:02:23 +08:00
},
panelLockChange (boolean) {
this.$store.dispatch('dispatchPanelLock', { flag: boolean })
},
chartBySync () {
this.panelTabLoading = true
const params = {}
if (this.from === 'chartTemp') {
params.pid = this.obj.id
} else {
params.panelId = this.showPanel.id
}
this.$post('visual/panel/chart/syncTmpl', params).then(res => {
this.panelTabLoading = false
if (res.code === 200) {
this.getTableData(this.obj.id)
this.$message.success(this.$t('tip.syncSuccess'))
} else {
this.$message.error(res.msg)
}
})
},
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)
}
2022-04-11 17:54:38 +08:00
},
htmlToPdf () {
const dom = document.getElementsByClassName(this.pdfId)[0]
2022-04-12 10:30:33 +08:00
this.htmlTitle = this.obj.name || 'pdf'
2022-04-11 17:54:38 +08:00
if (dom) {
// dom = dom.getElementsByClassName('vue-grid-layout')[0]
this.scrollbarWrap.scrollTop = this.scrollbarWrap.scrollHeight
this.$refs.chartList.onScroll(this.scrollbarWrap.scrollTop)
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'
// document.getElementsByTagName('html')[0].style.overflow = 'visible'
const position = dom.getBoundingClientRect()
console.log(position)
this.getPdf(dom, -1 * position.left, -1 * position.top)
// this.getPdf(dom, 0, 0)
}, 2000)
}
}, 200)
} else {
this.showScreenLoading(false)
}
}
},
mounted () {
bus.$on('refreshPanel', this.refreshPanel)
this.scrollbarWrap = this.$refs.dashboardScrollbar
this.onScroll()
document.querySelector('#tableList').addEventListener('mouseenter', this.tableListEnter)
document.querySelector('#tableList').addEventListener('mouseleave', this.tableListLeave)
this.$store.dispatch('dispatchPanelTime', {
time: this.searchTime,
nowTimeType: this.nowTimeType
})
},
watch: {
'filter.searchName' (n, o) {
const temp = this
setTimeout(function () {
temp.search()
}, 1000)
},
obj: {
immediate: true,
handler (n, o) {
setTimeout(() => {
if (n && n.id) {
this.getTableData(n.id)
if (this.from === fromRoute.asset) {
this.searchLabel.assetIds = n.id
}
}
this.chartDetailInfo = n
}, 500)
}
},
chartRightBoxShow: {
immediate: false,
deep: true,
handler (n) {
if (n) {
this.disposeChart()
}
}
},
delChartFlag: {
immediate: false,
deep: true,
handler (n) {
if (n) {
this.disposeChart()
}
}
}
},
beforeDestroy () {
2021-08-05 22:25:55 +08:00
document.querySelector('#tableList') && document.querySelector('#tableList').removeEventListener('mouseenter', this.tableListEnter)
document.querySelector('#tableList') && document.querySelector('#tableList').removeEventListener('mouseleave', this.tableListLeave)
this.scrollbarWrap && this.scrollbarWrap.removeEventListener('scroll', bus.debounce)
this.$store.dispatch('dispatchPanelLock', { flag: true })
}
}
</script>