From da60b4ca8a0430a2d5cc4aec4279cdd673779422 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Fri, 8 Sep 2023 15:48:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=BF=87=E6=BB=A4=E5=99=A8-=E6=97=A5?= =?UTF-8?q?=E6=9C=9F):=20=E5=8A=A8=E6=80=81=E6=97=B6=E9=97=B4=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E9=A2=91=E7=8E=87=E8=AE=BE=E7=BD=AE=E4=B8=BA=E6=AF=8F?= =?UTF-8?q?=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/widget/deWidget/DeDate.vue | 74 +++++++++++-------- .../views/chart/components/ChartComponent.vue | 14 +++- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/core/frontend/src/components/widget/deWidget/DeDate.vue b/core/frontend/src/components/widget/deWidget/DeDate.vue index c0f516aa2b..af5e9b7634 100644 --- a/core/frontend/src/components/widget/deWidget/DeDate.vue +++ b/core/frontend/src/components/widget/deWidget/DeDate.vue @@ -60,7 +60,8 @@ export default { values: null, onFocus: false, show: true, - timer: null + outTimer: null, + innerTimer: null } }, computed: { @@ -134,12 +135,7 @@ export default { }, watch: { - canvasStyleData: { - handler(newVal, oldVla) { - this.canvasStyleDataInit() - }, - deep: true - }, + 'viewIds': function(value, old) { if (typeof value === 'undefined' || value === old) return this.setCondition() @@ -174,7 +170,9 @@ export default { }, created() { this.loadInit() - this.canvasStyleDataInit() + this.$nextTick(() => { + this.dynamicRefresh() + }) }, mounted() { bus.$on('onScroll', this.onScroll) @@ -183,18 +181,14 @@ export default { } }, beforeDestroy() { - this.timer && clearInterval(this.timer) + this.clearTime() bus.$off('onScroll', this.onScroll) bus.$off('reset-default-value', this.resetDefaultValue) }, methods: { loadInit() { - if (this.element.options.attrs.default && this.element.options.attrs.default.isDynamic) { - if (this.element.options.attrs.default) { - const widget = ApplicationContext.getService(this.element.serviceName) - this.values = widget.dynamicDateFormNow(this.element) - this.dateChange(this.values) - } + this.clearTime() + if (this.refreshHandler()) { return } if (this.element.options.value) { @@ -202,22 +196,42 @@ export default { this.dateChange(this.values) } }, - canvasStyleDataInit() { - if (this.inDraw && this.canvasStyleData.refreshViewEnable && this.element.options.attrs.default && this.element.options.attrs.default.isDynamic) { - this.searchCount = 0 - this.timer && clearInterval(this.timer) - let refreshTime = 300000 - if (this.canvasStyleData.refreshTime && this.canvasStyleData.refreshTime > 0) { - if (this.canvasStyleData.refreshUnit === 'second') { - refreshTime = this.canvasStyleData.refreshTime * 1000 - } else { - refreshTime = this.canvasStyleData.refreshTime * 60000 + refreshHandler() { + if (this.element.options.attrs.default?.isDynamic) { + const widget = ApplicationContext.getService(this.element.serviceName) + this.values = widget.dynamicDateFormNow(this.element) + this.dateChange(this.values) + return true + } + return false + }, + clearTime() { + if (this.outTimer) { + clearTimeout(this.outTimer) + this.outTimer = null + } + if (this.innerTimer) { + clearInterval(this.innerTimer) + this.innerTimer = null + } + }, + dynamicRefresh() { + if (this.inDraw && this.element.options.attrs.default?.isDynamic) { + const nowDate = new Date() + const nowTime = nowDate.getTime() + const tomorrow = new Date(`${nowDate.getFullYear()}-${nowDate.getMonth() + 1}-${nowDate.getDate() + 1} 00:00:01`) + const tomorrowTime = tomorrow.getTime() + this.clearTime() + this.outTimer = setTimeout(() => { + if (this.inDraw) { + this.refreshHandler() } - } - this.timer = setInterval(() => { - this.loadInit() - this.searchCount++ - }, refreshTime) + this.innerTimer = setInterval(() => { + if (this.inDraw) { + this.refreshHandler() + } + }, 24 * 3600 * 1000) + }, tomorrowTime - nowTime) } }, clearHandler() { diff --git a/core/frontend/src/views/chart/components/ChartComponent.vue b/core/frontend/src/views/chart/components/ChartComponent.vue index 460fa635e1..9a82351f7c 100644 --- a/core/frontend/src/views/chart/components/ChartComponent.vue +++ b/core/frontend/src/views/chart/components/ChartComponent.vue @@ -189,13 +189,19 @@ export default { }, mounted() { bus.$on('change-series-id', this.changeSeriesId) - document.getElementById(this.chartId).addEventListener('mouseover', this.bodyMouseover) - document.getElementById(this.chartId).addEventListener('mouseout', this.bodyMouseout) + const dom = document.getElementById(this.chartId) + if (dom) { + dom.addEventListener('mouseover', this.bodyMouseover) + dom.addEventListener('mouseout', this.bodyMouseout) + } this.preDraw() }, beforeDestroy() { - document.getElementById(this.chartId).removeEventListener('mouseover', this.bodyMouseover) - document.getElementById(this.chartId).removeEventListener('mouseout', this.bodyMouseout) + const dom = document.getElementById(this.chartId) + if (dom) { + dom.removeEventListener('mouseover', this.bodyMouseover) + dom.removeEventListener('mouseout', this.bodyMouseout) + } bus.$off('change-series-id', this.changeSeriesId) window.removeEventListener('resize', this.myChart.resize) this.myChart.dispose()