2025-06-07 15:51:05 +08:00
|
|
|
import { debounce } from '@/utils';
|
2025-06-03 11:53:46 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
$_sidebarElm: null,
|
|
|
|
$_resizeHandler: null
|
2025-06-07 15:51:05 +08:00
|
|
|
};
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
mounted() {
|
2025-06-07 15:51:05 +08:00
|
|
|
this.initListener();
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
if (!this.$_resizeHandler) {
|
|
|
|
// avoid duplication init
|
2025-06-07 15:51:05 +08:00
|
|
|
this.initListener();
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// when keep-alive chart activated, auto resize
|
2025-06-07 15:51:05 +08:00
|
|
|
this.resize();
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2025-06-07 15:51:05 +08:00
|
|
|
this.destroyListener();
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
deactivated() {
|
2025-06-07 15:51:05 +08:00
|
|
|
this.destroyListener();
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
// use $_ for mixins properties
|
|
|
|
// https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
|
|
|
|
$_sidebarResizeHandler(e) {
|
|
|
|
if (e.propertyName === 'width') {
|
2025-06-07 15:51:05 +08:00
|
|
|
this.$_resizeHandler();
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
initListener() {
|
|
|
|
this.$_resizeHandler = debounce(() => {
|
2025-06-07 15:51:05 +08:00
|
|
|
this.resize();
|
|
|
|
}, 100);
|
|
|
|
window.addEventListener('resize', this.$_resizeHandler);
|
2025-06-03 11:53:46 +08:00
|
|
|
|
2025-06-07 15:51:05 +08:00
|
|
|
this.$_sidebarElm = document.getElementsByClassName('sidebar-container')[0];
|
|
|
|
this.$_sidebarElm && this.$_sidebarElm.addEventListener('transitionend', this.$_sidebarResizeHandler);
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
destroyListener() {
|
2025-06-07 15:51:05 +08:00
|
|
|
window.removeEventListener('resize', this.$_resizeHandler);
|
|
|
|
this.$_resizeHandler = null;
|
2025-06-03 11:53:46 +08:00
|
|
|
|
2025-06-07 15:51:05 +08:00
|
|
|
this.$_sidebarElm && this.$_sidebarElm.removeEventListener('transitionend', this.$_sidebarResizeHandler);
|
2025-06-03 11:53:46 +08:00
|
|
|
},
|
|
|
|
resize() {
|
2025-06-07 15:51:05 +08:00
|
|
|
const { chart } = this;
|
|
|
|
chart && chart.resize();
|
2025-06-03 11:53:46 +08:00
|
|
|
}
|
|
|
|
}
|
2025-06-07 15:51:05 +08:00
|
|
|
};
|