42eeff85c7e8beffd5c2855898312d7e3ab35724.svn-base 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { debounce } from '@/utils'
  2. export default {
  3. data() {
  4. return {
  5. $_sidebarElm: null
  6. }
  7. },
  8. mounted() {
  9. this.$_initResizeEvent()
  10. this.$_initSidebarResizeEvent()
  11. },
  12. beforeDestroy() {
  13. this.$_destroyResizeEvent()
  14. this.$_destroySidebarResizeEvent()
  15. },
  16. // to fixed bug when cached by keep-alive
  17. // https://github.com/PanJiaChen/vue-element-admin/issues/2116
  18. activated() {
  19. this.$_initResizeEvent()
  20. this.$_initSidebarResizeEvent()
  21. },
  22. deactivated() {
  23. this.$_destroyResizeEvent()
  24. this.$_destroySidebarResizeEvent()
  25. },
  26. methods: {
  27. // use $_ for mixins properties
  28. // https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
  29. $_resizeHandler() {
  30. return debounce(() => {
  31. if (this.chart) {
  32. this.chart.resize()
  33. }
  34. }, 100)()
  35. },
  36. $_initResizeEvent() {
  37. window.addEventListener('resize', this.$_resizeHandler)
  38. },
  39. $_destroyResizeEvent() {
  40. window.removeEventListener('resize', this.$_resizeHandler)
  41. },
  42. $_sidebarResizeHandler(e) {
  43. if (e.propertyName === 'width') {
  44. this.$_resizeHandler()
  45. }
  46. },
  47. $_initSidebarResizeEvent() {
  48. this.$_sidebarElm = document.getElementsByClassName('sidebar-container')[0]
  49. this.$_sidebarElm && this.$_sidebarElm.addEventListener('transitionend', this.$_sidebarResizeHandler)
  50. },
  51. $_destroySidebarResizeEvent() {
  52. this.$_sidebarElm && this.$_sidebarElm.removeEventListener('transitionend', this.$_sidebarResizeHandler)
  53. }
  54. }
  55. }