fix: 修复实体详情tabs和group中的图表有时宽度丢失的问题

This commit is contained in:
chenjinsong
2022-07-12 17:05:15 +08:00
parent 463232972c
commit a026d80088
10 changed files with 49 additions and 26 deletions

View File

@@ -1,4 +1,8 @@
.entity-detail.cn-home { .entity-detail.cn-home {
.panel-chart {
width: 100%;
}
flex-direction: column; flex-direction: column;
.entity-detail__header { .entity-detail__header {
@@ -45,9 +49,6 @@
.chart-header { .chart-header {
border: none; border: none;
} }
.chart-drawing {
width: 530px;
}
} }
} }
} }

View File

@@ -391,7 +391,6 @@ export default {
deep: true, deep: true,
handler (n) { handler (n) {
if (!_.isEmpty(n)) { if (!_.isEmpty(n)) {
console.info(n)
this.metaList = n this.metaList = n
} }
} }

View File

@@ -73,11 +73,9 @@ export default {
const errorList = parser.validateStr(str) const errorList = parser.validateStr(str)
if (_.isEmpty(errorList)) { if (_.isEmpty(errorList)) {
const metaList = parser.parseStr(str) const metaList = parser.parseStr(str)
console.info(metaList)
this.$emit('changeMode', 'tag', metaList) this.$emit('changeMode', 'tag', metaList)
} else { } else {
this.$emit('changeMode', 'tag', { metaList: [], str: '' }) this.$emit('changeMode', 'tag', { metaList: [], str: '' })
console.info(errorList)
} }
} else { } else {
this.$emit('changeMode', 'tag', { str: '', metaList: [] }) this.$emit('changeMode', 'tag', { str: '', metaList: [] })

View File

@@ -149,6 +149,7 @@
:time-filter="timeFilter" :time-filter="timeFilter"
:query-params="queryParams" :query-params="queryParams"
:entity="entity" :entity="entity"
:need-timeout="needTimeout"
></chart-relation-ship> ></chart-relation-ship>
<chart-san-key <chart-san-key
@@ -166,6 +167,7 @@
:chart-data="chartData" :chart-data="chartData"
:result-type="resultType" :result-type="resultType"
:time-filter="timeFilter" :time-filter="timeFilter"
:need-timeout="needTimeout"
:query-params="queryParams" :query-params="queryParams"
@showLoading="showLoading" @showLoading="showLoading"
></chart-echart> ></chart-echart>
@@ -400,7 +402,8 @@ export default {
table: Object, table: Object,
timeFilter: Object, timeFilter: Object,
orderPieTable: String, orderPieTable: String,
tabHandleClickType: String tabHandleClickType: String,
needTimeout: Boolean
}, },
computed: { computed: {
isNoData () { isNoData () {
@@ -437,13 +440,13 @@ export default {
this.$emit('showLoading', show) this.$emit('showLoading', show)
}, },
getAlarmInfo (url, extraParams, isRefresh, timeFilter) { getAlarmInfo (url, extraParams, isRefresh, timeFilter) {
this.$emit('getChartData', url, extraParams, isRefresh, timeFilter) this.$emit('getChartData', url, extraParams, timeFilter, isRefresh)
}, },
getChartData (url, extraParams) { getChartData (url, extraParams) {
this.$emit('getChartData', url, extraParams) this.$emit('getChartData', url, extraParams)
}, },
getDetectionData (url, extraParams, isRefresh, timeFilter) { getDetectionData (url, extraParams, isRefresh, timeFilter) {
this.$emit('getChartData', url, extraParams, isRefresh, timeFilter) this.$emit('getChartData', url, extraParams, timeFilter, isRefresh)
}, },
initEchartsWithTable () { initEchartsWithTable () {
this.$refs['chart' + this.chartInfo.id] && this.$refs['chart' + this.chartInfo.id] &&

View File

@@ -38,6 +38,7 @@
:table="table" :table="table"
:is-fullscreen="isFullscreen" :is-fullscreen="isFullscreen"
:order-pie-table="orderPieTable" :order-pie-table="orderPieTable"
:need-timeout="needTimeout"
:time-filter="timeFilter" :time-filter="timeFilter"
@getChartData="getChartData" @getChartData="getChartData"
@showLoading="showLoading" @showLoading="showLoading"
@@ -102,7 +103,8 @@ export default {
timeFilter: Object, // 时间范围 timeFilter: Object, // 时间范围
isFullscreen: Boolean, isFullscreen: Boolean,
panelLock: Boolean, panelLock: Boolean,
entity: Object entity: Object,
needTimeout: Boolean
}, },
data () { data () {
return { return {
@@ -170,7 +172,7 @@ export default {
this.getChartData() this.getChartData()
}, },
/* 参数 extraParams 额外请求参数 */ /* 参数 extraParams 额外请求参数 */
getChartData (url, extraParams = {}, chartTimeFilter, num) { getChartData (url, extraParams = {}, chartTimeFilter, isRefresh) {
this.loading = true this.loading = true
try { try {
if (chartTimeFilter) { if (chartTimeFilter) {
@@ -267,7 +269,13 @@ export default {
this.errorInfo = response.msg || response.message || 'Unknown' this.errorInfo = response.msg || response.message || 'Unknown'
} }
}).finally(() => { }).finally(() => {
if (this.needTimeout) {
setTimeout(() => {
this.loading = false this.loading = false
}, 3000)
} else {
this.loading = false
}
}) })
} else if (this.isGroup || this.isTabs) { } else if (this.isGroup || this.isTabs) {
this.$refs.chart && this.$refs.chart.$refs.chart && this.$refs.chart.$refs.chart.reload() this.$refs.chart && this.$refs.chart.$refs.chart && this.$refs.chart.$refs.chart.reload()

View File

@@ -1,5 +1,5 @@
<template> <template>
<div :id='`chartList${(isGroup ? "Group" : "") + timestamp}`' class="chart-list" ref="layoutBox"> <div :id='`chartList${timestamp}`' class="chart-list" ref="layoutBox">
<grid-layout <grid-layout
id="gridLayout" id="gridLayout"
ref="layout" ref="layout"
@@ -22,7 +22,6 @@
:y="item.y" :y="item.y"
:static="item.static" :static="item.static"
:ref="'grid-item' + item.id" :ref="'grid-item' + item.id"
:isResizable="isGroup ? false: null"
dragAllowFrom=".chart-header" dragAllowFrom=".chart-header"
dragIgnoreFrom=".chart-header__tools" dragIgnoreFrom=".chart-header__tools"
v-bind="anchorPoint(item)" v-bind="anchorPoint(item)"
@@ -32,6 +31,7 @@
:chart-info="item" :chart-info="item"
:time-filter="timeFilter" :time-filter="timeFilter"
:entity="entity" :entity="entity"
:need-timeout="needTimeout"
@groupShow="groupShow" @groupShow="groupShow"
@showFullscreen="showFullscreen" @showFullscreen="showFullscreen"
></panel-chart> ></panel-chart>
@@ -56,6 +56,7 @@
:is-fullscreen="true" :is-fullscreen="true"
:panelLock="panelLock" :panelLock="panelLock"
:time-filter="timeFilter" :time-filter="timeFilter"
:need-timeout="needTimeout"
@showFullscreen="showFullscreen" @showFullscreen="showFullscreen"
></panel-chart> ></panel-chart>
</el-dialog> </el-dialog>
@@ -68,8 +69,6 @@ import VueGridLayout from 'vue-grid-layout'
import { getGroupHeight, isGroup, getTypeCategory } from './charts/tools' import { getGroupHeight, isGroup, getTypeCategory } from './charts/tools'
import _ from 'lodash' import _ from 'lodash'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import DnsScreen from '@/views/charts/wholeScreenScroll/DnsScreen'
import { wholeScreenRouterMapping } from '@/utils/constants'
import { ref } from 'vue' import { ref } from 'vue'
export default { export default {
@@ -82,9 +81,9 @@ export default {
props: { props: {
timeFilter: Object, // 时间范围 timeFilter: Object, // 时间范围
panelLock: { type: Boolean, default: true }, panelLock: { type: Boolean, default: true },
isGroup: Boolean,
entity: Object, entity: Object,
dataList: Array // 看板中所有图表信息 dataList: Array, // 看板中所有图表信息
needTimeout: Boolean // 对于tab和group需要延迟渲染避免丢失宽度
}, },
data () { data () {
return { return {
@@ -108,7 +107,7 @@ export default {
}, },
methods: { methods: {
init () { init () {
const dom = document.getElementById(this.isGroup ? `chartListGroup${this.timestamp}` : `chartList${this.timestamp}`) const dom = document.getElementById(`chartList${this.timestamp}`)
if (dom) { if (dom) {
this.stepWidth = Math.floor(dom.offsetWidth / 12) this.stepWidth = Math.floor(dom.offsetWidth / 12)
} }

View File

@@ -5,6 +5,7 @@
:data-list="dataList" :data-list="dataList"
:panel-lock="true" :panel-lock="true"
:entity="entity" :entity="entity"
:need-timeout="true"
> >
</panel-chart-list> </panel-chart-list>
</template> </template>

View File

@@ -114,7 +114,7 @@
<script> <script>
import * as echarts from 'echarts' import * as echarts from 'echarts'
import loadsh from 'lodash' import _ from 'lodash'
import { relationShip } from './options/sankey' import { relationShip } from './options/sankey'
import ChartRelationShip from '@/views/charts/charts/chart-relation-ship' import ChartRelationShip from '@/views/charts/charts/chart-relation-ship'
import { api } from '@/utils/api' import { api } from '@/utils/api'
@@ -173,11 +173,11 @@ export default {
chartData: [Array, Object], chartData: [Array, Object],
resultType: Object, resultType: Object,
queryParams: Object, queryParams: Object,
entity: Object entity: Object,
needTimeout: Boolean
}, },
methods: { methods: {
init (id) { init (id) {
const chartParams = this.chartInfo.params
const name = this.$route.query.name const name = this.$route.query.name
const path = window.location.protocol + '//' + window.location.host const path = window.location.protocol + '//' + window.location.host
const dom = document.getElementById(id) const dom = document.getElementById(id)
@@ -233,10 +233,10 @@ export default {
if (item && !data.some(d => d.name === item.name)) { if (item && !data.some(d => d.name === item.name)) {
data.push({ name: item.name, ...handleStyle(item) }) data.push({ name: item.name, ...handleStyle(item) })
} }
if (item && !loadsh.isEmpty(item.from) && !loadsh.isEmpty(item.to)) { if (item && !_.isEmpty(item.from) && !_.isEmpty(item.to)) {
links.push({ target: item.to, source: item.from }) links.push({ target: item.to, source: item.from })
} }
if (item && !loadsh.isEmpty(item.leaf)) { if (item && !_.isEmpty(item.leaf)) {
item.leaf.forEach(i => { item.leaf.forEach(i => {
handleData(data, links, i) handleData(data, links, i)
}) })
@@ -296,7 +296,13 @@ export default {
chartData: { chartData: {
deep: true, deep: true,
handler (n) { handler (n) {
if (this.needTimeout) {
setTimeout(() => {
this.init(`chart${this.chartInfo.id}`) this.init(`chart${this.chartInfo.id}`)
}, 3000)
} else {
this.init(`chart${this.chartInfo.id}`)
}
} }
} }
}, },

View File

@@ -17,6 +17,7 @@
:data-list="tab.children" :data-list="tab.children"
:active-tab="activeTab" :active-tab="activeTab"
:panel-lock="true" :panel-lock="true"
:need-timeout="true"
:entity="entity" :entity="entity"
> >
</panel-chart-list> </panel-chart-list>

View File

@@ -13,6 +13,7 @@ import {
import { handleEchartFontSize, getEchartsFontSize } from '@/utils/tools' import { handleEchartFontSize, getEchartsFontSize } from '@/utils/tools'
export default { export default {
props: { props: {
needTimeout: Boolean,
chartInfo: Object, chartInfo: Object,
chartData: [Object, Array, String] // 数据在父组件查询后传入,本组件内不查询,只根据接传递的数据来渲染 chartData: [Object, Array, String] // 数据在父组件查询后传入,本组件内不查询,只根据接传递的数据来渲染
}, },
@@ -238,9 +239,15 @@ export default {
deep: true, deep: true,
handler (n) { handler (n) {
if (this.chartData && this.chartData.length > 0) { if (this.chartData && this.chartData.length > 0) {
if (this.needTimeout) {
setTimeout(() => {
this.initEcharts(`chart${this.chartInfo.id}`)
}, 3000)
} else {
this.initEcharts(`chart${this.chartInfo.id}`) this.initEcharts(`chart${this.chartInfo.id}`)
} }
} }
} }
} }
}
} }