@@ -21,9 +21,13 @@ Component({
21
21
customStyle : {
22
22
type : String ,
23
23
} ,
24
+ // 运行自定义选择框和删除缩放按钮
25
+ customActionStyle : {
26
+ type : Object ,
27
+ } ,
24
28
palette : {
25
29
type : Object ,
26
- observer : function ( newVal , oldVal ) {
30
+ observer : function ( newVal , oldVal ) {
27
31
if ( this . isNeedRefresh ( newVal , oldVal ) ) {
28
32
this . paintCount = 0 ;
29
33
this . startPaint ( ) ;
@@ -32,7 +36,7 @@ Component({
32
36
} ,
33
37
dancePalette : {
34
38
type : Object ,
35
- observer : function ( newVal , oldVal ) {
39
+ observer : function ( newVal , oldVal ) {
36
40
if ( ! this . isEmpty ( newVal ) ) {
37
41
this . initDancePalette ( newVal ) ;
38
42
}
@@ -49,7 +53,7 @@ Component({
49
53
} ,
50
54
action : {
51
55
type : Object ,
52
- observer : function ( newVal , oldVal ) {
56
+ observer : function ( newVal , oldVal ) {
53
57
if ( newVal ) {
54
58
this . doAction ( newVal )
55
59
}
@@ -84,7 +88,7 @@ Component({
84
88
} ,
85
89
86
90
getBox ( rect ) {
87
- return [ {
91
+ const boxArea = {
88
92
type : 'rect' ,
89
93
css : {
90
94
height : `${ rect . bottom - rect . top } px` ,
@@ -95,31 +99,66 @@ Component({
95
99
borderColor : '#0000ff' ,
96
100
color : 'transparent'
97
101
}
98
- } , {
99
- type : 'rect' ,
100
- css : {
101
- height : `${ 2 * ACTION_POINT_RADIUS } px` ,
102
- width : `${ 2 * ACTION_POINT_RADIUS } px` ,
103
- borderRadius : `${ ACTION_POINT_RADIUS } px` ,
104
- color : '#0000ff' ,
105
- left : `${ rect . right - ACTION_POINT_RADIUS } px` ,
106
- top : `${ rect . bottom - ACTION_POINT_RADIUS } px`
102
+ }
103
+ if ( this . properties . customActionStyle && this . properties . customActionStyle . border ) {
104
+ boxArea . css = Object . assign ( { } , boxArea . css , this . properties . customActionStyle . border )
105
+ }
106
+ Object . assign ( boxArea , {
107
+ id : 'box'
108
+ } )
109
+ return boxArea
110
+ } ,
111
+
112
+ getScaleIcon ( rect ) {
113
+ let scaleArea = { }
114
+ if ( this . properties . customActionStyle && this . properties . customActionStyle . scale ) {
115
+ scaleArea = this . properties . customActionStyle . scale
116
+ } else {
117
+ scaleArea = {
118
+ type : 'rect' ,
119
+ css : {
120
+ height : `${ 2 * ACTION_POINT_RADIUS } px` ,
121
+ width : `${ 2 * ACTION_POINT_RADIUS } px` ,
122
+ borderRadius : `${ ACTION_POINT_RADIUS } px` ,
123
+ color : '#0000ff' ,
124
+ }
107
125
}
108
- } ]
126
+ }
127
+ scaleArea . css = Object . assign ( { } , scaleArea . css , {
128
+ align : 'center' ,
129
+ left : `${ rect . right } px` ,
130
+ top : `${ rect . bottom - scaleArea . css . height . toPx ( ) / 2 } px`
131
+ } )
132
+ Object . assign ( scaleArea , {
133
+ id : 'scale'
134
+ } )
135
+ return scaleArea
109
136
} ,
110
137
111
138
getDeleteIcon ( rect ) {
112
- return {
113
- type : 'rect' ,
114
- css : {
115
- height : `${ 2 * ACTION_POINT_RADIUS } px` ,
116
- width : `${ 2 * ACTION_POINT_RADIUS } px` ,
117
- borderRadius : `${ ACTION_POINT_RADIUS } px` ,
118
- color : '#0000ff' ,
119
- left : `${ rect . left - ACTION_POINT_RADIUS } px` ,
120
- top : `${ rect . top - ACTION_POINT_RADIUS } px`
139
+ let deleteArea = { }
140
+ if ( this . properties . customActionStyle && this . properties . customActionStyle . delete ) {
141
+ deleteArea = this . properties . customActionStyle . delete
142
+ } else {
143
+ deleteArea = {
144
+ type : 'rect' ,
145
+ css : {
146
+ height : `${ 2 * ACTION_POINT_RADIUS } px` ,
147
+ width : `${ 2 * ACTION_POINT_RADIUS } px` ,
148
+ borderRadius : `${ ACTION_POINT_RADIUS } px` ,
149
+ color : '#0000ff' ,
150
+ }
121
151
}
122
152
}
153
+ deleteArea . css = Object . assign ( { } , deleteArea . css , {
154
+ align : 'center' ,
155
+ left : `${ rect . left } px` ,
156
+ top : `${ rect . top - deleteArea . css . height . toPx ( ) / 2 } px`
157
+ } )
158
+ Object . assign ( deleteArea , {
159
+ id : 'delete'
160
+ } )
161
+ return deleteArea
123
162
} ,
124
163
125
164
doAction ( action , callback , isMoving ) {
@@ -173,41 +212,51 @@ Component({
173
212
const {
174
213
rect
175
214
} = doView
176
- const block = {
215
+ this . block = {
177
216
width : this . currentPalette . width ,
178
217
height : this . currentPalette . height ,
179
- views : this . isEmpty ( doView ) ? [ ] : [ ...this . getBox ( rect ) ]
218
+ views : this . isEmpty ( doView ) ? [ ] : [ this . getBox ( rect ) ]
219
+ }
220
+ if ( this . touchedView . css && this . touchedView . css . scalable ) {
221
+ this . block . views . push ( this . getScaleIcon ( rect ) )
180
222
}
181
- if ( this . touchedView . type === 'text' ) {
182
- block . views . push ( this . getDeleteIcon ( rect ) )
223
+ if ( this . touchedView . css && this . touchedView . css . deletable ) {
224
+ this . block . views . push ( this . getDeleteIcon ( rect ) )
183
225
}
184
- const topBlock = new Pen ( this . frontContext , block )
226
+ const topBlock = new Pen ( this . frontContext , this . block )
185
227
topBlock . paint ( ) ;
186
228
} ,
187
229
188
- inArea ( x , y , rect , hasTouchedView ) {
189
- return ( hasTouchedView &&
190
- ( ( x > rect . left &&
191
- y > rect . top &&
192
- x < rect . right &&
193
- y < rect . bottom ) ||
194
- ( x > rect . right - ACTION_POINT_RADIUS &&
195
- y > rect . bottom - ACTION_POINT_RADIUS &&
196
- x < rect . right + ACTION_POINT_RADIUS &&
197
- y < rect . bottom + ACTION_POINT_RADIUS ) )
198
- ) ||
199
- ( x > rect . left &&
200
- y > rect . top &&
201
- x < rect . right &&
202
- y < rect . bottom
203
- )
230
+ isInView ( x , y , rect ) {
231
+ return ( x > rect . left &&
232
+ y > rect . top &&
233
+ x < rect . right &&
234
+ y < rect . bottom
235
+ )
204
236
} ,
205
237
206
- isDelete ( x , y , rect ) {
207
- return ( x > rect . left - ACTION_POINT_RADIUS &&
208
- y > rect . top - ACTION_POINT_RADIUS &&
209
- x < rect . left + ACTION_POINT_RADIUS &&
210
- y < rect . top + ACTION_POINT_RADIUS )
238
+ isInDelete ( x , y ) {
239
+ for ( const view of this . block . views ) {
240
+ if ( view . id === 'delete' ) {
241
+ return ( x > view . rect . left &&
242
+ y > view . rect . top &&
243
+ x < view . rect . right &&
244
+ y < view . rect . bottom )
245
+ }
246
+ }
247
+ return false
248
+ } ,
249
+
250
+ isInScale ( x , y ) {
251
+ for ( const view of this . block . views ) {
252
+ if ( view . id === 'scale' ) {
253
+ return ( x > view . rect . left &&
254
+ y > view . rect . top &&
255
+ x < view . rect . right &&
256
+ y < view . rect . bottom )
257
+ }
258
+ }
259
+ return false
211
260
} ,
212
261
213
262
touchedView : { } ,
@@ -224,13 +273,13 @@ Component({
224
273
const {
225
274
rect
226
275
} = view
227
- if ( this . touchedView && this . touchedView . id && this . touchedView . id === view . id && this . isDelete ( x , y , rect ) ) {
276
+ if ( this . touchedView && this . touchedView . id && this . touchedView . id === view . id && this . isInDelete ( x , y , rect ) ) {
228
277
canBeTouched . length = 0
229
278
deleteIndex = i
230
279
isDelete = true
231
280
break
232
281
}
233
- if ( this . inArea ( x , y , rect , ! this . isEmpty ( this . touchedView ) ) ) {
282
+ if ( this . isInView ( x , y , rect ) ) {
234
283
canBeTouched . push ( {
235
284
view,
236
285
index : i
@@ -341,7 +390,7 @@ Component({
341
390
const {
342
391
rect
343
392
} = this . touchedView
344
- if ( rect . right - ACTION_POINT_RADIUS < x && x < rect . right + ACTION_POINT_RADIUS && rect . bottom - ACTION_POINT_RADIUS < y && y < rect . bottom + ACTION_POINT_RADIUS ) {
393
+ if ( this . isInScale ( x , y , rect ) ) {
345
394
this . isScale = true
346
395
this . movingCache = { }
347
396
this . startH = rect . bottom - rect . top
@@ -355,7 +404,7 @@ Component({
355
404
onTouchEnd ( e ) {
356
405
const current = new Date ( ) . getTime ( )
357
406
if ( ( current - this . startTimeStamp ) <= 500 && ! this . hasMove ) {
358
- this . onClick ( e )
407
+ ! this . isScale && this . onClick ( e )
359
408
} else if ( this . touchedView && ! this . isEmpty ( this . touchedView ) ) {
360
409
this . triggerEvent ( 'touchEnd' , {
361
410
view : this . touchedView ,
@@ -575,10 +624,10 @@ Component({
575
624
setTimeout ( ( ) => {
576
625
wx . canvasToTempFilePath ( {
577
626
canvasId : 'photo' ,
578
- success : function ( res ) {
627
+ success : function ( res ) {
579
628
that . getImageInfo ( res . tempFilePath ) ;
580
629
} ,
581
- fail : function ( error ) {
630
+ fail : function ( error ) {
582
631
console . error ( `canvasToTempFilePath failed, ${ JSON . stringify ( error ) } ` ) ;
583
632
that . triggerEvent ( 'imgErr' , {
584
633
error : error
@@ -652,4 +701,4 @@ function setStringPrototype(screenK, scale) {
652
701
}
653
702
return res ;
654
703
} ;
655
- }
704
+ }
0 commit comments