Merge pull request #43 from huangyuanyin/main

优化 地图组件卸载的时候把相关事件移除
This commit is contained in:
街角小林 2022-10-17 09:20:38 +08:00 committed by GitHub
commit bca2912390

View File

@ -45,35 +45,45 @@ export default {
}; };
}, },
mounted() { mounted() {
this.$bus.$on("toggle_mini_map", (show) => { this.$bus.$on("toggle_mini_map", this.toggle_mini_map);
this.showMiniMap = show; this.$bus.$on("data_change", this.data_change);
this.$nextTick(() => { this.$bus.$on("view_data_change", this.view_data_change);
if (show) { },
this.init(); destroyed() {
this.drawMiniMap(); this.$bus.$off("toggle_mini_map", this.toggle_mini_map);
} this.$bus.$off("data_change", this.data_change);
}); this.$bus.$off("view_data_change", this.view_data_change);
});
this.$bus.$on("data_change", () => {
if (!this.showMiniMap) {
return;
}
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.drawMiniMap();
}, 500);
});
this.$bus.$on("view_data_change", () => {
if (!this.showMiniMap) {
return;
}
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.drawMiniMap();
}, 500);
});
}, },
methods: { methods: {
toggle_mini_map(show) {
this.showMiniMap = show;
this.$nextTick(() => {
if (this.$refs.navigatorBox) {
this.init();
}
if (this.$refs.svgBox) {
this.drawMiniMap();
}
});
},
data_change() {
if (!this.showMiniMap) {
return;
}
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.drawMiniMap();
}, 500);
},
view_data_change() {
if (!this.showMiniMap) {
return;
}
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.drawMiniMap();
}, 500);
},
init() { init() {
let { width, height } = this.$refs.navigatorBox.getBoundingClientRect(); let { width, height } = this.$refs.navigatorBox.getBoundingClientRect();
this.boxWidth = width; this.boxWidth = width;