File tree Expand file tree Collapse file tree 5 files changed +62
-49
lines changed
src/views/dashboard/admin/components Expand file tree Collapse file tree 5 files changed +62
-49
lines changed Original file line number Diff line number Diff line change 55<script >
66import echarts from ' echarts'
77require (' echarts/theme/macarons' ) // echarts theme
8- import { debounce } from ' @/utils '
8+ import resize from ' ./mixins/resize '
99
1010const animationDuration = 6000
1111
1212export default {
13+ mixins: [resize],
1314 props: {
1415 className: {
1516 type: String ,
@@ -33,18 +34,11 @@ export default {
3334 this .$nextTick (() => {
3435 this .initChart ()
3536 })
36- this .__resizeHandler = debounce (() => {
37- if (this .chart ) {
38- this .chart .resize ()
39- }
40- }, 100 )
41- window .addEventListener (' resize' , this .__resizeHandler )
4237 },
4338 beforeDestroy () {
4439 if (! this .chart ) {
4540 return
4641 }
47- window .removeEventListener (' resize' , this .__resizeHandler )
4842 this .chart .dispose ()
4943 this .chart = null
5044 },
Original file line number Diff line number Diff line change 55<script >
66import echarts from ' echarts'
77require (' echarts/theme/macarons' ) // echarts theme
8- import { debounce } from ' @/utils '
8+ import resize from ' ./mixins/resize '
99
1010export default {
11+ mixins: [resize],
1112 props: {
1213 className: {
1314 type: String ,
@@ -48,39 +49,15 @@ export default {
4849 this .$nextTick (() => {
4950 this .initChart ()
5051 })
51-
52- if (this .autoResize ) {
53- this .__resizeHandler = debounce (() => {
54- if (this .chart ) {
55- this .chart .resize ()
56- }
57- }, 100 )
58- window .addEventListener (' resize' , this .__resizeHandler )
59- }
60-
61- // 监听侧边栏的变化
62- this .sidebarElm = document .getElementsByClassName (' sidebar-container' )[0 ]
63- this .sidebarElm && this .sidebarElm .addEventListener (' transitionend' , this .sidebarResizeHandler )
6452 },
6553 beforeDestroy () {
6654 if (! this .chart ) {
6755 return
6856 }
69- if (this .autoResize ) {
70- window .removeEventListener (' resize' , this .__resizeHandler )
71- }
72-
73- this .sidebarElm && this .sidebarElm .removeEventListener (' transitionend' , this .sidebarResizeHandler )
74-
7557 this .chart .dispose ()
7658 this .chart = null
7759 },
7860 methods: {
79- sidebarResizeHandler (e ) {
80- if (e .propertyName === ' width' ) {
81- this .__resizeHandler ()
82- }
83- },
8461 setOptions ({ expectedData, actualData } = {}) {
8562 this .chart .setOption ({
8663 xAxis: {
Original file line number Diff line number Diff line change 55<script >
66import echarts from ' echarts'
77require (' echarts/theme/macarons' ) // echarts theme
8- import { debounce } from ' @/utils '
8+ import resize from ' ./mixins/resize '
99
1010export default {
11+ mixins: [resize],
1112 props: {
1213 className: {
1314 type: String ,
@@ -31,18 +32,11 @@ export default {
3132 this .$nextTick (() => {
3233 this .initChart ()
3334 })
34- this .__resizeHandler = debounce (() => {
35- if (this .chart ) {
36- this .chart .resize ()
37- }
38- }, 100 )
39- window .addEventListener (' resize' , this .__resizeHandler )
4035 },
4136 beforeDestroy () {
4237 if (! this .chart ) {
4338 return
4439 }
45- window .removeEventListener (' resize' , this .__resizeHandler )
4640 this .chart .dispose ()
4741 this .chart = null
4842 },
Original file line number Diff line number Diff line change 55<script >
66import echarts from ' echarts'
77require (' echarts/theme/macarons' ) // echarts theme
8- import { debounce } from ' @/utils '
8+ import resize from ' ./mixins/resize '
99
1010const animationDuration = 3000
1111
1212export default {
13+ mixins: [resize],
1314 props: {
1415 className: {
1516 type: String ,
@@ -33,18 +34,11 @@ export default {
3334 this .$nextTick (() => {
3435 this .initChart ()
3536 })
36- this .__resizeHandler = debounce (() => {
37- if (this .chart ) {
38- this .chart .resize ()
39- }
40- }, 100 )
41- window .addEventListener (' resize' , this .__resizeHandler )
4237 },
4338 beforeDestroy () {
4439 if (! this .chart ) {
4540 return
4641 }
47- window .removeEventListener (' resize' , this .__resizeHandler )
4842 this .chart .dispose ()
4943 this .chart = null
5044 },
Original file line number Diff line number Diff line change 1+ import { debounce } from '@/utils'
2+
3+ export default {
4+ data ( ) {
5+ return {
6+ $_sidebarElm : null
7+ }
8+ } ,
9+ mounted ( ) {
10+ this . $_initResizeEvent ( )
11+ this . $_initSidebarResizeEvent ( )
12+ } ,
13+ beforeDestroy ( ) {
14+ this . $_destroyResizeEvent ( )
15+ this . $_destroySidebarResizeEvent ( )
16+ } ,
17+ activated ( ) {
18+ this . $_initResizeEvent ( )
19+ this . $_initSidebarResizeEvent ( )
20+ } ,
21+ deactivated ( ) {
22+ this . $_destroyResizeEvent ( )
23+ this . $_destroySidebarResizeEvent ( )
24+ } ,
25+ methods : {
26+ // use $_ for mixins properties
27+ // https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
28+ $_sidebarResizeHandler ( e ) {
29+ if ( e . propertyName === 'width' ) {
30+ this . $_resizeHandler ( )
31+ }
32+ } ,
33+ $_resizeHandler ( ) {
34+ return debounce ( ( ) => {
35+ if ( this . chart ) {
36+ this . chart . resize ( )
37+ }
38+ } , 100 ) ( )
39+ } ,
40+ $_initResizeEvent ( ) {
41+ window . addEventListener ( 'resize' , this . $_resizeHandler )
42+ } ,
43+ $_destroyResizeEvent ( ) {
44+ window . removeEventListener ( 'resize' , this . $_resizeHandler )
45+ } ,
46+ $_initSidebarResizeEvent ( ) {
47+ this . $_sidebarElm = document . getElementsByClassName ( 'sidebar-container' ) [ 0 ]
48+ this . $_sidebarElm && this . $_sidebarElm . addEventListener ( 'transitionend' , this . $_sidebarResizeHandler )
49+ } ,
50+ $_destroySidebarResizeEvent ( ) {
51+ this . $_sidebarElm && this . $_sidebarElm . removeEventListener ( 'transitionend' , this . $_sidebarResizeHandler )
52+ }
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments