feat: 添加 panel的懒加载

This commit is contained in:
zhangyu
2021-12-21 18:05:36 +08:00
parent 8de08a6ead
commit 5da36256c4
19 changed files with 93 additions and 37 deletions

View File

@@ -265,7 +265,6 @@ export default {
} }
}, },
mounted () { mounted () {
console.log(this.chartInfo.type)
} }
} }
</script> </script>

View File

@@ -168,7 +168,7 @@ export default {
try { try {
this.isStack = this.chartInfo.param.stack this.isStack = this.chartInfo.param.stack
} catch (e) {} } catch (e) {}
this.initChart(this.chartOption) this.chartInfo.loaded && this.initChart(this.chartOption)
} }
} }
</script> </script>

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="chart-diagram"> <div class="chart-diagram" v-if="chartInfo.loaded">
<diagram <diagram
style="height: 100%;width: 100%" style="height: 100%;width: 100%"
:topoData="chartInfo.param.topo" :topoData="chartInfo.param.topo"

View File

@@ -3,7 +3,7 @@
<div <div
v-for="(item,index) in gaugeData" :key="index" v-for="(item,index) in gaugeData" :key="index"
class="chart-gauge-item" class="chart-gauge-item"
:id="'chart-gauge-' + chartInfo.id + '-' + index" :id="this.isFullscreen?('chart-gauge-screen-' + chartInfo.id + '-' + index):('chart-gauge-' + chartInfo.id + '-' + index)"
:style="{height:item.height+'px',width:item.width + 'px'}" :style="{height:item.height+'px',width:item.width + 'px'}"
> >
<!-- :style="{background:item.mapping ? item.mapping.color.bac : false,height:item.height+'px',width:item.width + 'px'}"--> <!-- :style="{background:item.mapping ? item.mapping.color.bac : false,height:item.height+'px',width:item.width + 'px'}"-->
@@ -156,7 +156,8 @@ export default {
this.chartInstances = [] this.chartInstances = []
const self = this const self = this
this.gaugeData.forEach((item, index) => { this.gaugeData.forEach((item, index) => {
const myChart = echarts.init(document.getElementById('chart-gauge-' + this.chartInfo.id + '-' + index)) const chartId = this.isFullScreen ? 'chart-gauge-screen-' : 'chart-gauge-'
const myChart = echarts.init(document.getElementById(chartId + this.chartInfo.id + '-' + index))
const option = lodash.cloneDeep(this.chartOption) const option = lodash.cloneDeep(this.chartOption)
option.tooltip = {} option.tooltip = {}
option.series[0].data.push(item) option.series[0].data.push(item)
@@ -166,7 +167,6 @@ export default {
fontWeight: 'bolder', fontWeight: 'bolder',
formatter: (params) => { formatter: (params) => {
let showValue = chartDataFormat.getUnit(self.chartInfo.unit ? self.chartInfo.unit : 2).compute(params, null, -1, 2).trim() let showValue = chartDataFormat.getUnit(self.chartInfo.unit ? self.chartInfo.unit : 2).compute(params, null, -1, 2).trim()
console.log(showValue)
if (item.mapping) { if (item.mapping) {
showValue = self.handleDisplay(item.mapping.display, { ...item.label, value: showValue }) showValue = self.handleDisplay(item.mapping.display, { ...item.label, value: showValue })
} }
@@ -222,7 +222,7 @@ export default {
mounted () { mounted () {
this.chartOption.color || (this.chartOption.color = initColor(20)) this.chartOption.color || (this.chartOption.color = initColor(20))
this.colorList = this.chartOption.color this.colorList = this.chartOption.color
this.initChart() this.chartInfo.loaded && this.initChart()
console.log(this.isFullscreen , 'isFullscreen') console.log(this.isFullscreen , 'isFullscreen')
}, },
beforeDestroy () { beforeDestroy () {

View File

@@ -47,6 +47,15 @@ export default {
methods: { methods: {
refreshTime () { refreshTime () {
},
initChart () {
this.dataList = this.dataList.map(item => {
return {
...item,
hide: item.name.indexOf(this.filter.searchName) === -1, // 搜索条件
loaded: true
}
})
} }
}, },
watch: { watch: {
@@ -54,7 +63,14 @@ export default {
immediate: true, immediate: true,
handler (n) { handler (n) {
this.$nextTick(() => { this.$nextTick(() => {
this.dataList = JSON.parse(JSON.stringify(n)) const arr = JSON.parse(JSON.stringify(n))
this.dataList = arr.map(item => {
return {
...item,
hide: item.name.indexOf(this.filter.searchName) === -1, // 搜索条件
loaded: false
}
})
}) })
} }
} }

View File

@@ -277,7 +277,7 @@ export default {
} }
}, },
mounted () { mounted () {
this.initChart() this.chartInfo.loaded && this.initChart()
}, },
watch: { watch: {
chartData: { chartData: {

View File

@@ -38,9 +38,12 @@ export default {
} }
}, },
mounted () { mounted () {
this.initMap() this.chartInfo.loaded && this.initChart()
}, },
methods: { methods: {
initChart () {
this.initMap()
},
initMap () { initMap () {
if (this.timer) { if (this.timer) {
clearTimeout(this.timer) clearTimeout(this.timer)
@@ -72,7 +75,6 @@ export default {
this.map.remove() this.map.remove()
this.map = null this.map = null
} }
console.log(1212)
const mapId = document.getElementById('map' + this.chartInfo.id) const mapId = document.getElementById('map' + this.chartInfo.id)
const map = L.map(mapId, { const map = L.map(mapId, {
minZoom: mapConfig.minZoom, minZoom: mapConfig.minZoom,

View File

@@ -151,7 +151,7 @@ export default {
try { try {
this.isStack = this.chartInfo.param.stack this.isStack = this.chartInfo.param.stack
} catch (e) {} } catch (e) {}
this.initChart(this.chartOption) this.chartInfo.loaded && this.initChart(this.chartOption)
} }
} }
</script> </script>

View File

@@ -46,6 +46,9 @@ export default {
methods: { methods: {
initChart () { initChart () {
this.initStatData(this.chartInfo, this.chartData).then(() => { this.initStatData(this.chartInfo, this.chartData).then(() => {
if (this.isNoData) {
return
}
this.getLayout().then(layout => { this.getLayout().then(layout => {
this.renderStat(layout) this.renderStat(layout)
}) })
@@ -54,7 +57,6 @@ export default {
initStatData (chartInfo, originalDatas) { initStatData (chartInfo, originalDatas) {
return new Promise(resolve => { return new Promise(resolve => {
let colorIndex = 0 let colorIndex = 0
console.log(originalDatas)
originalDatas.forEach((originalData, expressionIndex) => { originalDatas.forEach((originalData, expressionIndex) => {
originalData.forEach((data, dataIndex) => { originalData.forEach((data, dataIndex) => {
this.isNoData = false this.isNoData = false
@@ -137,7 +139,7 @@ export default {
} }
}, },
mounted () { mounted () {
this.initChart() this.chartInfo.loaded && this.initChart()
} }
} }
</script> </script>

View File

@@ -216,7 +216,7 @@ export default {
} }
}, },
mounted () { mounted () {
this.initChart() this.chartInfo.loaded && this.initChart()
} }
} }
</script> </script>

View File

@@ -256,7 +256,7 @@ export default {
try { try {
this.isStack = this.chartInfo.param.stack this.isStack = this.chartInfo.param.stack
} catch (e) {} } catch (e) {}
this.initChart(this.chartOption) this.chartInfo.loaded && this.initChart(this.chartOption)
} }
} }
</script> </script>

View File

@@ -159,7 +159,7 @@ export default {
try { try {
this.isStack = this.chartInfo.param.stack this.isStack = this.chartInfo.param.stack
} catch (e) {} } catch (e) {}
this.initChart(this.chartOption) this.chartInfo.loaded && this.initChart(this.chartOption)
} }
} }
</script> </script>

View File

@@ -126,7 +126,6 @@ export default {
immediate: true, immediate: true,
handler (n) { handler (n) {
if (n) { if (n) {
console.log(this.chartData)
this.errorText = this.chartData.filter(item => item.error).map(item => item.error).join('\n') this.errorText = this.chartData.filter(item => item.error).map(item => item.error).join('\n')
} }
} }

View File

@@ -1,5 +1,5 @@
<template> <template>
<div :id='`chartList${(isGroup ? "Group" : "") + timestamp}`' class="chart-list" :loading="gridLayoutLoading"> <div :id='`chartList${(isGroup ? "Group" : "") + timestamp}`' class="chart-list" :loading="gridLayoutLoading" ref="layoutBox">
<grid-layout <grid-layout
ref="layout" ref="layout"
v-if="gridLayoutShow" v-if="gridLayoutShow"
@@ -32,6 +32,7 @@
'group-hide-header':item.type === 'group' && item.param.collapse, 'group-hide-header':item.type === 'group' && item.param.collapse,
'opacityItem': item.static 'opacityItem': item.static
}" }"
:ref="'grid-item' + item.id"
:isResizable = "item.type === 'group' ? false: null" :isResizable = "item.type === 'group' ? false: null"
dragAllowFrom=".chart-header" dragAllowFrom=".chart-header"
dragIgnoreFrom=".chart-header__tools" dragIgnoreFrom=".chart-header__tools"
@@ -268,11 +269,42 @@ export default {
charts: charts charts: charts
} }
// console.log(this.copyDataList) // console.log(this.copyDataList)
// this.$put('/visual/panel/chart/weights', params).then(() => { this.$put('/visual/panel/chart/weights', params).then(() => {
// const position = getLayoutPosition(this.copyDataList) const position = getLayoutPosition(this.copyDataList)
// this.$store.commit('setChartLastPosition', position) this.$store.commit('setChartLastPosition', position)
// }) })
}, 300) }, 300)
},
onScroll (scrollTop = 0) {
this.$nextTick(() => {
this.copyDataList.forEach(item => {
if (item.loaded) {
return
}
const dom = this.$refs['grid-item' + item.id][0].$el
if (dom) {
const itemHeight = dom.offsetHeight
// 1.元素距离页面顶部的距离
// console.log(dom.style.transform)
let top = dom.style.transform.split(',')[1]
top = top.substring(0, top.length - 2)
const mainOffsetTop = top - this.stepWidth + 14// transform: grid组件 通过 tranfrom 控制位置 中间的为y的值 通过截取获得 - 父元素 marginTop的 值。
// console.log(mainOffsetTop)
// 2.元素的高度
const mainHeight = itemHeight // ele.offsetHeight;//itemHeight;
// 3.页面滚动的距离
const windowScrollTop = scrollTop// document.documentElement.scrollTop || document.body.scrollTop;
// 4.浏览器可见区域的高度
const windowHeight = (window.innerHeight || document.documentElement.clientHeight) - 50 - 70
// console.log(this.$refs['chart' + item.id][0].$el.offsetHeight, scrollTop,'scrollTop',windowHeight,mainOffsetTop + mainHeight / 4,(windowScrollTop + windowHeight))
if ((mainOffsetTop + mainHeight / 4) < (windowScrollTop + windowHeight)) {
item.loaded = true
this.$refs['chart' + item.id][0].getChartData()
}
}
})
})
} }
}, },
created () { created () {
@@ -335,6 +367,7 @@ export default {
this.copyDataList = JSON.parse(JSON.stringify(tempList)) this.copyDataList = JSON.parse(JSON.stringify(tempList))
setTimeout(() => { setTimeout(() => {
this.gridLayoutShow = true this.gridLayoutShow = true
this.onScroll()
}) })
setTimeout(() => { setTimeout(() => {
this.firstInit = false this.firstInit = false

View File

@@ -38,7 +38,6 @@ export default {
handleTimeSeries (chartInfo, seriesTemplate, originalDatas) { handleTimeSeries (chartInfo, seriesTemplate, originalDatas) {
const series = [] const series = []
let colorIndex = 0 let colorIndex = 0
console.log(this.chartData)
originalDatas.forEach((originalData, expressionIndex) => { originalDatas.forEach((originalData, expressionIndex) => {
originalData.forEach((data, dataIndex) => { originalData.forEach((data, dataIndex) => {
if (colorIndex >= 20 && !this.showAllData) { if (colorIndex >= 20 && !this.showAllData) {
@@ -53,7 +52,6 @@ export default {
if (chartInfo.param.stack) { // 堆叠 if (chartInfo.param.stack) { // 堆叠
s.stack = 'Total' s.stack = 'Total'
} }
console.log(chartInfo.param.enable && chartInfo.param.enable.thresholds && !lodash.isEmpty(chartInfo.param.thresholds) && chartInfo.param.thresholds.length)
if (chartInfo.param.enable && chartInfo.param.enable.thresholds && !lodash.isEmpty(chartInfo.param.thresholds) && chartInfo.param.thresholds.length) { // 阈值 if (chartInfo.param.enable && chartInfo.param.enable.thresholds && !lodash.isEmpty(chartInfo.param.thresholds) && chartInfo.param.thresholds.length) { // 阈值
s.markLine = { s.markLine = {
symbol: 'circle', symbol: 'circle',
@@ -75,7 +73,6 @@ export default {
} }
}) })
}) })
console.log(this.isNoData)
this.$emit('chartIsNoData', this.isNoData) this.$emit('chartIsNoData', this.isNoData)
return series return series
}, },
@@ -191,7 +188,6 @@ export default {
const boxHeight = size.contentSize[1] const boxHeight = size.contentSize[1]
if (!this.isFullscreen) { // 本地显示 if (!this.isFullscreen) { // 本地显示
const chartDom = document.getElementById('chart-local-' + this.chartInfo.id) const chartDom = document.getElementById('chart-local-' + this.chartInfo.id)
console.log(point, params, dom, rect, size)
if (chartDom) { if (chartDom) {
if (windowMouse.x < (windowWidth / 2)) { // 说明鼠标在左边放不下提示框 if (windowMouse.x < (windowWidth / 2)) { // 说明鼠标在左边放不下提示框
x = pointX + 15 x = pointX + 15
@@ -243,6 +239,15 @@ export default {
this.initChart(this.chartOption) this.initChart(this.chartOption)
} }
} }
},
'chartInfo.loaded': {
immediate: true,
deep: true,
handler (n) {
if (n) {
this.initChart(this.chartOption)
}
}
} }
}, },
mounted () { mounted () {

View File

@@ -1,6 +1,6 @@
<template> <template>
<!-- chart外层箱子 --> <!-- chart外层箱子 -->
<div :class="{'panel-chart--fullscreen': isFullscreen}" class="panel-chart" :id="isFullscreen ? ('chart-screen-' + chartInfo.id ) : ('chart-local-' + chartInfo.id)"> <div :class="{'panel-chart--fullscreen': isFullscreen}" class="panel-chart" :id="isFullscreen ? ('chart-screen-' + chartInfo.id ) : ('chart-local-' + chartInfo.id)" v-loading="loading">
<!-- title和工具栏支持浮动 --> <!-- title和工具栏支持浮动 -->
<chart-header <chart-header
v-if="!isFullscreen" v-if="!isFullscreen"
@@ -22,8 +22,8 @@
:panelLock="panelLock" :panelLock="panelLock"
:from="from" :from="from"
:isError="isError" :isError="isError"
:is-fullscreen="isFullscreen"
:loading="loading" :loading="loading"
:is-fullscreen="isFullscreen"
v-if="!isGroup(chartInfo.type) || !chartInfo.param.collapse" v-if="!isGroup(chartInfo.type) || !chartInfo.param.collapse"
></chart> ></chart>
</div> </div>
@@ -96,7 +96,7 @@ export default {
endTime = this.$stringTimeParseToUnix(endTime) endTime = this.$stringTimeParseToUnix(endTime)
const elements = this.chartInfo.elements || [] const elements = this.chartInfo.elements || []
this.query(elements, startTime, endTime, step) this.chartInfo.loaded && this.query(elements, startTime, endTime, step)
}, },
query (elements, startTime, endTime, step) { query (elements, startTime, endTime, step) {
this.isError = false this.isError = false

View File

@@ -290,8 +290,8 @@ export default {
this.firstInit = false this.firstInit = false
}, 500) }, 500)
}) })
}).catch(() => { }).catch((res) => {
console.log(123123) console.info(res)
}) })
}, },
reload () { reload () {

View File

@@ -208,7 +208,7 @@ export default {
}) })
} }
}).catch(res => { }).catch(res => {
console.log(res) console.info(res)
}) })
}, },
selectPanel (panel) { selectPanel (panel) {

View File

@@ -79,9 +79,9 @@
</div> </div>
</template> </template>
</div> </div>
<div id="tableList" class="table-list"> <div id="tableList" class="table-list" style='overflow-y: unset'>
<div id="dashboardScrollbar" ref="dashboardScrollbar" class="table-list-box"> <div id="dashboardScrollbar" class="table-list-box">
<div class="box-content" v-loading="chartListLoading"> <div class="box-content" v-loading="chartListLoading" ref="dashboardScrollbar" style='overflow-y: auto'>
<chart-list <chart-list
ref="chartList" ref="chartList"
name="panel" name="panel"
@@ -715,7 +715,7 @@ export default {
this.scrollbarWrap.addEventListener('scroll', bus.debounce(function () { this.scrollbarWrap.addEventListener('scroll', bus.debounce(function () {
_self.showTopBtn = _self.scrollbarWrap.scrollTop > 50 _self.showTopBtn = _self.scrollbarWrap.scrollTop > 50
_self.overScroll10 = _self.scrollbarWrap.scrollTop > 50 _self.overScroll10 = _self.scrollbarWrap.scrollTop > 50
// _self.$refs.chartList.loadChartData(_self.scrollbarWrap.scrollTop) _self.$refs.chartList.onScroll(_self.scrollbarWrap.scrollTop)
}, 300)) }, 300))
}, },
focusInput () { focusInput () {