@@ -49,10 +49,11 @@ Component({
49
49
} ,
50
50
sizeType : {
51
51
// 该写法经测试有效
52
- type : Array | String ,
52
+ type : Array | String ,
53
53
value : [ 'original' , 'compressed' ]
54
54
} ,
55
55
// 所选图片最大限制,单位字节
56
+ // 0 为无限制
56
57
maxImageSize : {
57
58
type : Number ,
58
59
value : 0 ,
@@ -69,13 +70,20 @@ Component({
69
70
type : Boolean ,
70
71
value : false
71
72
} ,
73
+ // 存放图片 url 的数组
74
+ // 放在 properties 中是因为引入了 behaviors: ['wx://form-field'],
75
+ // wx://form-field 中的 value 为 null,会引起很多报错
76
+ // value 放在 data 中没有 properties 优先级高,覆盖不了
77
+ // 所以只能放在此处
78
+ value : {
79
+ type : Array ,
80
+ value : [ ]
81
+ }
72
82
} ,
73
83
74
84
data : {
75
85
// 根据 size 不同,计算的图片显示大小不同
76
- itemSizePercentage : null ,
77
- // 存放图片 url 的数组
78
- value : null
86
+ itemSizePercentage : null
79
87
} ,
80
88
81
89
observers : {
@@ -207,7 +215,7 @@ Component({
207
215
* @returns {Promise<void> }
208
216
*/
209
217
async onTapAdd ( ) {
210
- let { value, count, sizeType} = this . data ;
218
+ let { value, count, sizeType, maxImageSize } = this . data ;
211
219
const remainCount = count - value . length ;
212
220
if ( value . length >= count || remainCount <= 0 ) {
213
221
return ;
@@ -227,7 +235,7 @@ Component({
227
235
228
236
chooseImageRes . tempFiles . forEach ( ( tempFile ) => {
229
237
const { path, size} = tempFile ;
230
- if ( size > this . data . maxImageSize ) {
238
+ if ( size > maxImageSize && maxImageSize > 0 ) {
231
239
oversizeImageUrlArray . push ( path ) ;
232
240
} else {
233
241
addImageUrlArray . push ( path ) ;
@@ -255,7 +263,7 @@ Component({
255
263
* 供 Form 组件调用的取值方法
256
264
* @returns {* }
257
265
*/
258
- getValue ( ) {
266
+ getValues ( ) {
259
267
return this . data . value ;
260
268
} ,
261
269
0 commit comments