xuhuajiao
7 months ago
7 changed files with 281 additions and 143 deletions
-
117src/assets/styles/index.scss
-
7src/components/echart/barEcharts.vue
-
19src/components/echart/lineChart.vue
-
8src/components/echart/yearCircle.vue
-
55src/utils/resizeMixins.js
-
43src/views/map/index.vue
-
33src/views/pageThree/index.vue
@ -1,26 +1,55 @@ |
|||||
// 混入代码 resize-mixins.js
|
|
||||
import { debounce } from '@/utils/index' |
|
||||
const resizeChartMethod = '$__resizeChartMethod' |
|
||||
|
import { debounce } from '@/utils' |
||||
|
|
||||
export default { |
export default { |
||||
data() { |
data() { |
||||
// 在组件内部将图表init的引用映射到chart属性上
|
|
||||
return { |
return { |
||||
chart: null |
|
||||
|
$_sidebarElm: null, |
||||
|
$_resizeHandler: null |
||||
} |
} |
||||
}, |
}, |
||||
created() { |
|
||||
window.addEventListener('resize', this[resizeChartMethod], false) |
|
||||
|
mounted() { |
||||
|
this.$_resizeHandler = debounce(() => { |
||||
|
if (this.chart) { |
||||
|
this.chart.resize() |
||||
|
} |
||||
|
}, 100) |
||||
|
this.$_initResizeEvent() |
||||
|
this.$_initSidebarResizeEvent() |
||||
}, |
}, |
||||
beforeDestroy() { |
beforeDestroy() { |
||||
window.removeEventListener('reisze', this[resizeChartMethod]) |
|
||||
|
this.$_destroyResizeEvent() |
||||
|
this.$_destroySidebarResizeEvent() |
||||
|
}, |
||||
|
// to fixed bug when cached by keep-alive
|
||||
|
// https://github.com/PanJiaChen/vue-element-admin/issues/2116
|
||||
|
activated() { |
||||
|
this.$_initResizeEvent() |
||||
|
this.$_initSidebarResizeEvent() |
||||
|
}, |
||||
|
deactivated() { |
||||
|
this.$_destroyResizeEvent() |
||||
|
this.$_destroySidebarResizeEvent() |
||||
}, |
}, |
||||
methods: { |
methods: { |
||||
// 通过lodash的防抖函数来控制resize的频率
|
|
||||
[resizeChartMethod]: debounce(function() { |
|
||||
if (this.chart) { |
|
||||
this.chart.resize() |
|
||||
|
// use $_ for mixins properties
|
||||
|
// https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
|
||||
|
$_initResizeEvent() { |
||||
|
window.addEventListener('resize', this.$_resizeHandler) |
||||
|
}, |
||||
|
$_destroyResizeEvent() { |
||||
|
window.removeEventListener('resize', this.$_resizeHandler) |
||||
|
}, |
||||
|
$_sidebarResizeHandler(e) { |
||||
|
if (e.propertyName === 'width') { |
||||
|
this.$_resizeHandler() |
||||
|
} |
||||
|
}, |
||||
|
$_initSidebarResizeEvent() { |
||||
|
this.$_sidebarElm = document.getElementsByClassName('sidebar-container')[0] |
||||
|
this.$_sidebarElm && this.$_sidebarElm.addEventListener('transitionend', this.$_sidebarResizeHandler) |
||||
|
}, |
||||
|
$_destroySidebarResizeEvent() { |
||||
|
this.$_sidebarElm && this.$_sidebarElm.removeEventListener('transitionend', this.$_sidebarResizeHandler) |
||||
} |
} |
||||
}, 100) |
|
||||
} |
} |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue