diff --git a/nezha-fronted/src/components/charts/chart-list.vue b/nezha-fronted/src/components/charts/chart-list.vue index 07f750ca2..fca04778f 100644 --- a/nezha-fronted/src/components/charts/chart-list.vue +++ b/nezha-fronted/src/components/charts/chart-list.vue @@ -60,17 +60,83 @@ export default { }, panelId: '', timer: null, + dataTotalList:[],//懒加载:总记录数 + isPage:true,//是否分页懒加载 + currentRecordNum:0,//懒加载:本次取记录的index,第一次从0开始取,每次取3行 + lineNum:3,//每页加载的行数 + pagePanelId:''//当前分页的panelId }; }, computed: {}, watch: {}, methods: { + initCurrentRecordNum(){ + this.currentRecordNum = 0; + }, + cleanData(){ + if (this.dataList.length > 0 && this.$refs.editChart) { + this.$refs.editChart.forEach((item) => { + item.clearData(); + }); + } + this.dataList = []; + }, initData(filter) { this.dataList = []; // 内含 panelId,开始时间,结束时间 this.filter = filter; + this.pagePanelId = this.filter.panelId; this.getData(this.filter); }, + pageDataList(isAdd,panelId){ + if(panelId!==this.pagePanelId){ + this.currentRecordNum = 0; + } + if(this.dataTotalList && this.dataTotalList.length>0){ + if(this.currentRecordNum>=this.dataTotalList.length){ + //alert('数据加载完毕!'); + }else { + let dataTmpList = []; + let spanSum = 0; + let line = 0;//行数 + let isDataFull=false; + let curRecNum = this.currentRecordNum; + let len = this.dataTotalList.length; + for(let i=curRecNum;!isDataFull && i { if (response.code === 200) { if(response.data.list){ - this.dataList = response.data.list; + this.dataTotalList = response.data.list; }else { - this.dataList = response.data; + this.dataTotalList = response.data; + } + if(this.isPage){ + this.pageDataList(); + }else { + this.dataList = this.dataTotalList; } if (this.dataList.length > 0 && this.$refs.editChart) { this.$refs.editChart.forEach((item) => { item.showLoad();//之后要实现 }); } - //alert(JSON.stringify(response)); 查着,返回的内容就没有图表表达式了?? this.dataSetFirst(this.dataList); } }); }, // arr: 该panel下图表list,生成该看板下所有图表 - dataSetFirst(arr) { + dataSetFirst(arr,oldDataListLen) { if (arr.length) { arr.forEach((item, index) => { - this.getChartData(item, index); + let realIndex = index; + if(oldDataListLen){ + realIndex += oldDataListLen; + } + this.getChartData(item, realIndex); }); } }, @@ -136,11 +210,9 @@ export default { startTime = this.filter.start_time; endTime = this.filter.end_time; } - //this.$emit('@on-refresh-time', startTime,endTime); } else if(filterType==='searchTime'){ startTime = this.filter.start_time; endTime = this.filter.end_time; - //this.$emit('@on-refresh-time', startTime,endTime); this.$parent.refreshTime(startTime,endTime); }else { startTime = this.filter.start_time; @@ -248,7 +320,6 @@ export default { } } }); - // chartData, seriesItem, panelsId, filter if (chartItem.type === 'table') {//表格 this.$refs.editChart[index].setData(chartItem, tableData, this.filter.panelId, this.filter); @@ -285,7 +356,6 @@ export default { this.$nextTick(() => { const chartBox = document.getElementsByClassName('chartBox'); chartBox[index].style.width = `${(size / 12) * 100}%`; - //chartBox[index].style.height = height; }); }, diff --git a/nezha-fronted/src/components/charts/chart-table.vue b/nezha-fronted/src/components/charts/chart-table.vue index 92a9c3bd4..675a1ea9e 100644 --- a/nezha-fronted/src/components/charts/chart-table.vue +++ b/nezha-fronted/src/components/charts/chart-table.vue @@ -43,7 +43,7 @@ - +
{{data.title}} @@ -65,10 +65,7 @@
- - {{$t('dashboard.panel.cancel')}} - {{$t('dashboard.panel.confirm')}} - +
@@ -218,6 +215,8 @@ export default { computed: {}, watch: {}, methods: { + clearData(){ + }, showLoad() { this.tableLoading = true; }, diff --git a/nezha-fronted/src/components/charts/line-chart-block.vue b/nezha-fronted/src/components/charts/line-chart-block.vue index ff419fc39..509e34c40 100644 --- a/nezha-fronted/src/components/charts/line-chart-block.vue +++ b/nezha-fronted/src/components/charts/line-chart-block.vue @@ -33,8 +33,8 @@
@@ -53,10 +53,7 @@
- - {{$t('dashboard.panel.cancel')}} - {{$t('dashboard.panel.confirm')}} - + @@ -212,6 +209,11 @@ export default { }, watch: {}, methods: { + clearData(){ + if(this.echartStore){ + this.echartStore.clear(); + } + }, // chartSite用于区分是全屏显示还是局部显示 initChart(chartInfo, dataArg, ele, chartSite,legend) { this.firstShow = true; // 展示操作按键 diff --git a/nezha-fronted/src/components/page/dashboard/panel.vue b/nezha-fronted/src/components/page/dashboard/panel.vue index 55b29f426..bc0f7c590 100644 --- a/nezha-fronted/src/components/page/dashboard/panel.vue +++ b/nezha-fronted/src/components/page/dashboard/panel.vue @@ -87,7 +87,7 @@
-
+
@@ -287,6 +287,8 @@ export default { //this.$refs.searchInput.select(); this.showPanel = val this.filter.panelId = this.showPanel.id; + this.$refs.chartList.initCurrentRecordNum(); + this.$refs.chartList.cleanData(); this.getData(this.filter); }, @@ -513,7 +515,17 @@ export default { } this.filter.panelId = this.showPanel.id; this.getData(this.filter); - } + }, + // 滚动事件触发下拉加载 + onScroll () { + let dom = document.getElementById('tableList'); + let scrollHeight = dom.scrollHeight;//整个可滑动区域高度 + let clientHeight = dom.clientHeight;//可视高度 + let scrollTop = dom.scrollTop;//滚动条顶部与整个scrollHeight顶部的距离 + if (scrollHeight - clientHeight - scrollTop <= 20) {//滚动到底部,才加载新数据 + this.$refs.chartList.pageDataList(true,this.showPanel.id); + } + }, }, created() { this.getTableData();