@@ -29,7 +29,7 @@ function dispatchEvent(el, event, type) {
29
29
30
30
Component ( {
31
31
didMount ( ) {
32
- this . onCanvasReady ( ) ;
32
+ this . createChart ( ) ;
33
33
} ,
34
34
didUpdate ( ) {
35
35
const { canvas, props } = this ;
@@ -59,43 +59,31 @@ Component({
59
59
} ,
60
60
methods : {
61
61
createChart ( ) {
62
- const query = my . createSelectorQuery ( ) ;
62
+ const { width , height } = this . props ;
63
63
const id = `f-web-canvas-${ this . $id } ` ;
64
- query
65
- . select ( `#${ id } ` )
66
- . boundingClientRect ( )
67
- . exec ( ( res ) => {
68
- if ( ! res [ 0 ] ) {
69
- return ;
70
- }
71
- const { width, height } = res [ 0 ] as {
72
- width : number ;
73
- height : number ;
74
- } ;
64
+ const { pixelRatio : drp = 2 , windowWidth = 375 } = my ?. getSystemInfoSync ( ) ;
75
65
76
- const { pixelRatio : drp = 2 , windowWidth = 375 } = my ?. getSystemInfoSync ( ) ;
77
- const rpx2px = windowWidth / 750 ;
78
- const pixelRatio = Math . ceil ( drp ) ;
66
+ const pixelRatio = Math . ceil ( drp ) ;
67
+ const rpx2px = windowWidth / 750 ;
79
68
80
- this . setData ( {
81
- width : width * rpx2px * pixelRatio ,
82
- height : height * rpx2px * pixelRatio ,
83
- } ) ;
69
+ this . setData ( {
70
+ width : width * rpx2px * pixelRatio ,
71
+ height : height * rpx2px * pixelRatio ,
72
+ } ) ;
84
73
85
- const { element : canvas , context } = createCanvasAdapter ( my . createCanvasContext ( id ) ) ;
86
- const fCanvas = this . createCanvas ( {
87
- width : width * rpx2px ,
88
- height : height * rpx2px ,
89
- pixelRatio,
90
- context,
91
- createImage : canvas . createImage . bind ( canvas ) ,
92
- requestAnimationFrame : canvas . requestAnimationFrame . bind ( canvas ) ,
93
- cancelAnimationFrame : canvas . cancelAnimationFrame . bind ( canvas ) ,
94
- } ) ;
95
- fCanvas . render ( ) . catch ( ( error ) => {
96
- this . catchError ( error ) ;
97
- } ) ;
98
- } ) ;
74
+ const { element : canvas , context } = createCanvasAdapter ( my . createCanvasContext ( id ) ) ;
75
+ const fCanvas = this . createCanvas ( {
76
+ width : width * rpx2px ,
77
+ height : height * rpx2px ,
78
+ pixelRatio,
79
+ context,
80
+ createImage : canvas . createImage . bind ( canvas ) ,
81
+ requestAnimationFrame : canvas . requestAnimationFrame . bind ( canvas ) ,
82
+ cancelAnimationFrame : canvas . cancelAnimationFrame . bind ( canvas ) ,
83
+ } ) ;
84
+ fCanvas . render ( ) . catch ( ( error ) => {
85
+ this . catchError ( error ) ;
86
+ } ) ;
99
87
} ,
100
88
101
89
catchError ( error ) {
@@ -136,10 +124,11 @@ Component({
136
124
const query = my . createSelectorQuery ( ) ;
137
125
query
138
126
. select ( `f-web-canvas-${ this . $id } ` )
127
+ //@ts -ignore
139
128
. node ( )
140
129
. exec ( ( time ) => {
141
130
// api 执行结束后的下一个通信才会上屏
142
- onCanvasRender ( time ) ;
131
+ onCanvasRender && onCanvasRender ( time ) ;
143
132
} ) ;
144
133
} ,
145
134
// @ts -ignore
0 commit comments