1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- function debounce(func, wait, immediate) {
- let timeout, args, context, timestamp, result
-
- const later = function () {
-
- const last = +new Date() - timestamp
-
-
- if (last < wait && last > 0) {
- timeout = setTimeout(later, wait - last)
- } else {
- timeout = null
-
- if (!immediate) {
- result = func.apply(context, args)
- if (!timeout) context = args = null
- }
- }
- }
-
- return function (...args) {
- context = this
- timestamp = +new Date()
- const callNow = immediate && !timeout
-
- if (!timeout) timeout = setTimeout(later, wait)
- if (callNow) {
- result = func.apply(context, args)
- context = args = null
- }
-
- return result
- }
- }
-
-
- export default {
- data() {
- return {
- $_sidebarElm: null,
- $_resizeHandler: null
- }
- },
- mounted() {
- this.initListener()
- },
- activated() {
- if (!this.$_resizeHandler) {
-
- this.initListener()
- }
-
-
- this.resize()
- },
- beforeDestroy() {
- this.destroyListener()
- },
- deactivated() {
- this.destroyListener()
- },
- methods: {
-
-
- $_sidebarResizeHandler(e) {
- if (e.propertyName === 'width') {
- this.$_resizeHandler()
- }
- },
- initListener() {
- this.$_resizeHandler = debounce(() => {
- this.resize()
- }, 100)
- this.resize()
- window.addEventListener('resize', this.$_resizeHandler)
-
-
-
- },
- destroyListener() {
- window.removeEventListener('resize', this.$_resizeHandler)
- this.$_resizeHandler = null
-
-
- },
- resize() {
- const { chart } = this
- chart && chart.resize()
- }
- }
- }
-
|