@@ -5,20 +5,23 @@ export default {
55 return {
66 x_mixin: null ,
77 y_mixin: null ,
8- pageWidth: 0 ,
9- pageHeight: 0 ,
10- }
11- },
12- mounted () {
13- const page = this .$el .closest (' .page' )
14- if (page) {
15- const canvas = page .querySelector (' canvas' )
16- this .pageWidth = canvas .width
17- this .pageHeight = canvas .height
188 }
199 },
2010 created () {},
2111 methods: {
12+ getCurrentPageDimensions () {
13+ const page = this .$el ? .closest (' .page' )
14+ if (page) {
15+ const canvas = page .querySelector (' canvas' )
16+ if (canvas) {
17+ return {
18+ pageWidth: canvas .width ,
19+ pageHeight: canvas .height ,
20+ }
21+ }
22+ }
23+ return { pageWidth: 0 , pageHeight: 0 }
24+ },
2225 handleMousedown (event ) {
2326 this .x_mixin = event .clientX
2427 this .y_mixin = event .clientY
@@ -46,8 +49,9 @@ export default {
4649 this .y_mixin = event .clientY
4750 window .removeEventListener (' mousemove' , this .handlePanMove )
4851 window .removeEventListener (' mouseup' , this .handlePanEnd )
49- const x = Math .max (0 , Math .min (this .x + this .dx , this .pageWidth - this .width ))
50- const y = Math .max (0 , Math .min (this .y + this .dy , this .pageHeight - this .height ))
52+ const { pageWidth , pageHeight } = this .getCurrentPageDimensions ()
53+ const x = Math .max (0 , Math .min (this .x + this .dx , pageWidth - this .width ))
54+ const y = Math .max (0 , Math .min (this .y + this .dy , pageHeight - this .height ))
5155 return {
5256 detail: { x, y },
5357 }
@@ -86,15 +90,17 @@ export default {
8690
8791 window .removeEventListener (' touchmove' , this .handlePanMove )
8892 window .removeEventListener (' touchend' , this .handlePanEnd )
89- const x = Math .max (0 , Math .min (this .x + this .dx , this .pageWidth - this .width ))
90- const y = Math .max (0 , Math .min (this .y + this .dy , this .pageHeight - this .height ))
93+ const { pageWidth , pageHeight } = this .getCurrentPageDimensions ()
94+ const x = Math .max (0 , Math .min (this .x + this .dx , pageWidth - this .width ))
95+ const y = Math .max (0 , Math .min (this .y + this .dy , pageHeight - this .height ))
9196 return {
9297 detail: { x, y },
9398 }
9499 },
95100 translateCoordinates () {
96- const x = Math .max (0 , Math .min (this .x + this .dx , this .pageWidth - this .width ))
97- const y = Math .max (0 , Math .min (this .y + this .dy , this .pageHeight - this .height ))
101+ const { pageWidth , pageHeight } = this .getCurrentPageDimensions ()
102+ const x = Math .max (0 , Math .min (this .x + this .dx , pageWidth - this .width ))
103+ const y = Math .max (0 , Math .min (this .y + this .dy , pageHeight - this .height ))
98104 return ' translate(' + x + ' px, ' + y + ' px)'
99105 }
100106 },
0 commit comments