From 41e2792b8f921a61cacd9d3b4d14fd469b1fd6c0 Mon Sep 17 00:00:00 2001 From: zhangyu Date: Tue, 29 Sep 2020 09:25:43 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=85=BC=E5=AE=B9=E7=81=AB?= =?UTF-8?q?=E7=8B=90=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0window=E3=80=82eve?= =?UTF-8?q?nt=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/charts/line-chart-block.vue | 13 ++++++++----- nezha-fronted/src/components/common/js/common.js | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/nezha-fronted/src/components/charts/line-chart-block.vue b/nezha-fronted/src/components/charts/line-chart-block.vue index 2c0158cdc..bcf94b875 100644 --- a/nezha-fronted/src/components/charts/line-chart-block.vue +++ b/nezha-fronted/src/components/charts/line-chart-block.vue @@ -186,7 +186,7 @@ import {randomcolor} from '../common/js/radomcolor/randomcolor.js'; import timePicker from '../common/timePicker'; import chartConfig from "../page/dashboard/overview/chartConfig"; - import {getChart, setChart} from "../common/js/common"; + import {getChart, setChart,lineChartMove,getMousePoint} from "../common/js/common"; export default { name: 'lineChartBlock', @@ -544,10 +544,7 @@ dom.style.transform = "translateZ(0)"; var windowWidth=window.innerWidth;//窗口宽度 var windowHeight=window.innerHeight;//窗口高度 - var windowMouse={ - x:window.event.pageX, - y:window.event.pageY, - } + var windowMouse=getMousePoint(); //提示框位置 var x=0; var y=0; @@ -1684,10 +1681,16 @@ }, mounted() { this.firstLoad = false; + if(!document.onmousemove){// 添加鼠标移动事件监听 + document.onmousemove=lineChartMove + } }, beforeDestroy() { this.clearChart(); getChart(this.chartIndex).dispose(); + if(!document.onmousemove){// 移除鼠标移动事件监听 + document.onmousemove=null; + } }, }; diff --git a/nezha-fronted/src/components/common/js/common.js b/nezha-fronted/src/components/common/js/common.js index fa04882c3..2fc3abc07 100644 --- a/nezha-fronted/src/components/common/js/common.js +++ b/nezha-fronted/src/components/common/js/common.js @@ -25,3 +25,18 @@ export function getChart(key) { export function setChart(key, value) { chartCache[`chart${key}`] = value; } + +const mousePoint={ //在echart tooltip中获取不到鼠标在窗口的位置,在火狐没有window。event 在此兼容火狐 获取鼠标在窗口位置 + x:'', + y:'' +}; + +export function lineChartMove(e){ + let event=e|| window.event; + mousePoint.x=event.pageX; + mousePoint.y=event.pageY; +} + +export function getMousePoint(){ + return mousePoint +}