@tarojs/plugin-platform-harmony-ets 4.0.0-beta.113 → 4.0.0-beta.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,8 +16,7 @@ import { Current } from '@tarojs/runtime'
16
16
  import { isNull } from '@tarojs/shared'
17
17
 
18
18
  import { getSystemInfoSync } from '../../base'
19
- import { callAsyncFail, callAsyncSuccess, requestPermissions, temporarilyNotSupport, validateParams } from '../../utils'
20
- import { IMAGE_PERMISSION } from '../../utils/permissions'
19
+ import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../../utils'
21
20
 
22
21
  import type Taro from '@tarojs/taro/types'
23
22
 
@@ -113,117 +112,143 @@ async function saveImage(compressedImageData, compressedImageUri) {
113
112
 
114
113
  export const compressImage: typeof Taro.compressImage = function (options) {
115
114
  return new Promise((resolve, reject) => {
116
- requestPermissions(IMAGE_PERMISSION).then(() => {
117
- try {
118
- validateParams('compressImage', options, compressImageSchema)
119
- } catch (error) {
120
- const res = { errMsg: error.message }
121
- return callAsyncFail(reject, res, options)
122
- }
123
- const { src, quality = 80, compressedWidth, compressedHeight } = options
124
- const srcAfterCompress = src.includes('_after_compress') ? src : src.split('.').join('_after_compress.')
125
- const file = fs.openSync(src, fs.OpenMode.READ_ONLY)
126
-
127
- // const stat = fs.statSync(file.fd)
128
- // console.log('[Taro] 压缩前图片的大小为:', stat.size)
129
-
130
- const source = image.createImageSource(file.fd)
131
- if (isNull(source)) {
132
- const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' }
133
- callAsyncFail(reject, createImageSourceError, options)
134
- return
135
- }
115
+ try {
116
+ validateParams('compressImage', options, compressImageSchema)
117
+ } catch (error) {
118
+ const res = { errMsg: error.message }
119
+ return callAsyncFail(reject, res, options)
120
+ }
121
+ const { src, quality = 80, compressedWidth, compressedHeight } = options
122
+ const srcAfterCompress = src.includes('_after_compress') ? src : src.split('.').join('_after_compress.')
123
+ const file = fs.openSync(src, fs.OpenMode.READ_ONLY)
136
124
 
137
- const width = source.getImageInfoSync().size.width
138
- const height = source.getImageInfoSync().size.height
139
- let wantWidth = compressedWidth || compressedHeight || 0
140
- let wantHeight = compressedHeight || compressedWidth || 0
125
+ // const stat = fs.statSync(file.fd)
126
+ // console.log('[Taro] 压缩前图片的大小为:', stat.size)
141
127
 
142
- if (width > wantWidth || height > wantHeight) {
143
- const heightRatio = height / wantHeight
144
- const widthRatio = width / wantWidth
145
- const finalRatio = heightRatio < widthRatio ? heightRatio : widthRatio
128
+ const source = image.createImageSource(file.fd)
129
+ if (isNull(source)) {
130
+ const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' }
131
+ callAsyncFail(reject, createImageSourceError, options)
132
+ return
133
+ }
146
134
 
147
- wantWidth = Math.round(width / finalRatio)
148
- wantHeight = Math.round(height / finalRatio)
149
- }
135
+ const width = source.getImageInfoSync().size.width
136
+ const height = source.getImageInfoSync().size.height
137
+ let wantWidth = compressedWidth || compressedHeight || 0
138
+ let wantHeight = compressedHeight || compressedWidth || 0
150
139
 
151
- const decodingOptions = {
152
- editable: true,
153
- desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
154
- desiredSize: { width: wantWidth, height: wantHeight }
155
- }
156
- source.createPixelMap(decodingOptions, (error, pixelMap) => {
157
- if (error !== undefined) {
140
+ if (width > wantWidth || height > wantHeight) {
141
+ const heightRatio = height / wantHeight
142
+ const widthRatio = width / wantWidth
143
+ const finalRatio = heightRatio < widthRatio ? heightRatio : widthRatio
144
+
145
+ wantWidth = Math.round(width / finalRatio)
146
+ wantHeight = Math.round(height / finalRatio)
147
+ }
148
+
149
+ const decodingOptions = {
150
+ editable: true,
151
+ desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
152
+ desiredSize: { width: wantWidth, height: wantHeight }
153
+ }
154
+ source.createPixelMap(decodingOptions, (error, pixelMap) => {
155
+ if (error !== undefined) {
156
+ fs.closeSync(file)
157
+ const res = { errMsg: error }
158
+ callAsyncFail(reject, res, options)
159
+ } else {
160
+ const packer = image.createImagePacker(file.fd)
161
+ if (isNull(packer)) {
158
162
  fs.closeSync(file)
159
- const res = { errMsg: error }
160
- callAsyncFail(reject, res, options)
161
- } else {
162
- const packer = image.createImagePacker(file.fd)
163
- if (isNull(packer)) {
164
- fs.closeSync(file)
165
- const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' }
166
- callAsyncFail(reject, createImagePackerError, options)
167
- return
168
- }
163
+ const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' }
164
+ callAsyncFail(reject, createImagePackerError, options)
165
+ return
166
+ }
169
167
 
170
- const isPNG = src.endsWith('.png')
171
- const packingOptionsOHOS: IPackingOptionOHOS = {
172
- format: isPNG ? 'image/png' : 'image/jpeg',
173
- quality: quality
174
- }
175
- packer.packing(pixelMap, packingOptionsOHOS).then((value) => {
176
- fs.closeSync(file)
177
- saveImage(value, srcAfterCompress).then(result => {
178
- callAsyncSuccess(resolve, { tempFilePath: result.imageUri }, options)
179
- })
180
- }).catch((error) => {
181
- fs.closeSync(file)
182
- callAsyncFail(reject, error, options)
183
- })
168
+ const isPNG = src.endsWith('.png')
169
+ const packingOptionsOHOS: IPackingOptionOHOS = {
170
+ format: isPNG ? 'image/png' : 'image/jpeg',
171
+ quality: quality
184
172
  }
185
- })
186
- }, (error: string) => {
187
- const res = { errMsg: error }
188
- return callAsyncFail(reject, res, options)
173
+ packer.packing(pixelMap, packingOptionsOHOS).then((value) => {
174
+ fs.closeSync(file)
175
+ saveImage(value, srcAfterCompress).then(result => {
176
+ callAsyncSuccess(resolve, { tempFilePath: result.imageUri }, options)
177
+ })
178
+ }).catch((error) => {
179
+ fs.closeSync(file)
180
+ callAsyncFail(reject, error, options)
181
+ })
182
+ }
189
183
  })
190
184
  })
191
185
  }
192
186
 
193
187
  export const chooseImage: typeof Taro.chooseImage = function (options) {
194
188
  return new Promise((resolve, reject) => {
195
- requestPermissions(IMAGE_PERMISSION).then(() => {
196
- try {
197
- validateParams('chooseImage', options, chooseImageSchema)
198
- } catch (error) {
199
- const res = { errMsg: error.message }
200
- return callAsyncFail(reject, res, options)
201
- }
189
+ try {
190
+ validateParams('chooseImage', options, chooseImageSchema)
191
+ } catch (error) {
192
+ const res = { errMsg: error.message }
193
+ return callAsyncFail(reject, res, options)
194
+ }
202
195
 
203
- const { count = 9 } = options
204
- const photoViewPicker = new picker.PhotoViewPicker()
205
- let sizeType = options.sizeType
196
+ const { count = 9 } = options
197
+ const photoViewPicker = new picker.PhotoViewPicker()
198
+ let sizeType = options.sizeType
206
199
 
207
- if (!sizeType || !sizeType.length) {
208
- sizeType = ['compressed', 'original']
209
- }
200
+ if (!sizeType || !sizeType.length) {
201
+ sizeType = ['compressed', 'original']
202
+ }
203
+
204
+ photoSelectOptions.maxSelectNumber = count // 选择媒体文件的最大数目
205
+ photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE // 过滤选择媒体文件类型为IMAGE
206
+
207
+ photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
208
+ const result: IChooseImageData = {}
209
+ const isOrigin = photoSelectResult.isOriginalPhoto
210
210
 
211
- photoSelectOptions.maxSelectNumber = count // 选择媒体文件的最大数目
212
- photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE // 过滤选择媒体文件类型为IMAGE
211
+ if (isOrigin) {
212
+ const tempFilePaths: string[] = []
213
+ const tempFiles = photoSelectResult.photoUris.map(uri => {
214
+ const file = fs.openSync(uri, fs.OpenMode.READ_ONLY)
215
+ const stat = fs.statSync(file.fd)
216
+ const size = stat.size
213
217
 
214
- photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
215
- const result: IChooseImageData = {}
216
- const isOrigin = photoSelectResult.isOriginalPhoto
218
+ fs.closeSync(file)
219
+ tempFilePaths.push(uri)
220
+
221
+ return {
222
+ size,
223
+ path: uri,
224
+ }
225
+ })
226
+
227
+ result.tempFiles = tempFiles
228
+ result.tempFilePaths = tempFilePaths
229
+
230
+ callAsyncSuccess(resolve, result, options)
231
+ } else {
232
+ const actions: Promise<string>[] = photoSelectResult.photoUris.map(uri => {
233
+ return new Promise<string>(resolve => {
234
+ compressImage({
235
+ src: uri,
236
+ compressedWidth: getSystemInfoSync().screenWidth / 2,
237
+ compressedHeight: getSystemInfoSync().screenHeight / 2,
238
+ success: (compressResult) => {
239
+ resolve(compressResult.tempFilePath)
240
+ }
241
+ })
242
+ })
243
+ })
217
244
 
218
- if (isOrigin) {
219
- const tempFilePaths: string[] = []
220
- const tempFiles = photoSelectResult.photoUris.map(uri => {
245
+ Promise.all(actions).then(tempFilePaths => {
246
+ const tempFiles = tempFilePaths.map(uri => {
221
247
  const file = fs.openSync(uri, fs.OpenMode.READ_ONLY)
222
248
  const stat = fs.statSync(file.fd)
223
- const size = stat.size
249
+ const size: number = stat.size
224
250
 
225
251
  fs.closeSync(file)
226
- tempFilePaths.push(uri)
227
252
 
228
253
  return {
229
254
  size,
@@ -231,53 +256,17 @@ export const chooseImage: typeof Taro.chooseImage = function (options) {
231
256
  }
232
257
  })
233
258
 
234
- result.tempFiles = tempFiles
235
259
  result.tempFilePaths = tempFilePaths
260
+ result.tempFiles = tempFiles
236
261
 
237
262
  callAsyncSuccess(resolve, result, options)
238
- } else {
239
- const actions: Promise<string>[] = photoSelectResult.photoUris.map(uri => {
240
- return new Promise<string>(resolve => {
241
- compressImage({
242
- src: uri,
243
- compressedWidth: getSystemInfoSync().screenWidth / 2,
244
- compressedHeight: getSystemInfoSync().screenHeight / 2,
245
- success: (compressResult) => {
246
- resolve(compressResult.tempFilePath)
247
- }
248
- })
249
- })
250
- })
251
-
252
- Promise.all(actions).then(tempFilePaths => {
253
- const tempFiles = tempFilePaths.map(uri => {
254
- const file = fs.openSync(uri, fs.OpenMode.READ_ONLY)
255
- const stat = fs.statSync(file.fd)
256
- const size: number = stat.size
257
-
258
- fs.closeSync(file)
259
-
260
- return {
261
- size,
262
- path: uri,
263
- }
264
- })
265
-
266
- result.tempFilePaths = tempFilePaths
267
- result.tempFiles = tempFiles
268
-
269
- callAsyncSuccess(resolve, result, options)
270
- }).catch(error => {
271
- const res = { errMsg: error }
272
- return callAsyncFail(reject, res, options)
273
- })
274
- }
275
- }).catch((error) => {
276
- callAsyncFail(reject, error, options)
277
- })
278
- }, (error: string) => {
279
- const res = { errMsg: error }
280
- return callAsyncFail(reject, res, options)
263
+ }).catch(error => {
264
+ const res = { errMsg: error }
265
+ return callAsyncFail(reject, res, options)
266
+ })
267
+ }
268
+ }).catch((error) => {
269
+ callAsyncFail(reject, error, options)
281
270
  })
282
271
  })
283
272
  }
@@ -231,14 +231,18 @@ export class TaroMovableViewElement extends TaroElement<MovableViewProps & { ani
231
231
  public callTouchEventFnFromGesture(eventName: string, gestureEvent: GestureEvent) {
232
232
  const touchFns = (this?.__listeners?.[eventName] || []) as Function[]
233
233
  touchFns.forEach(fn => {
234
- fn({
235
- _hmEvent: gestureEvent,
236
- target: this,
237
- changedTouches: gestureEvent.fingerList.map(finger => ({
238
- clientX: finger.globalX,
239
- clientY: finger.globalY
240
- }))
241
- })
234
+ try {
235
+ fn({
236
+ _hmEvent: gestureEvent,
237
+ target: this,
238
+ changedTouches: gestureEvent.fingerList.map(finger => ({
239
+ clientX: finger.globalX,
240
+ clientY: finger.globalY
241
+ }))
242
+ })
243
+ } catch (error) {
244
+ console.error(error)
245
+ }
242
246
  })
243
247
  }
244
248
  }
@@ -1,7 +1,7 @@
1
1
  import { isFunction, isString, isArray, isObject, isNull, isNumber, isUndefined, queryToJson, PLATFORM_TYPE, singleQuote, internalComponents } from '@tarojs/shared';
2
2
  import _display from '@ohos.display';
3
3
  import { Current, window, eventSource, hooks, document as document$1, getPageScrollerOrNode, findChildNodeWithDFS, setNodeEventCallbackAndTriggerComponentUpdate, AREA_CHANGE_EVENT_NAME, disconnectEvent, VISIBLE_CHANGE_EVENT_NAME, getCurrentInstance } from '@tarojs/runtime';
4
- import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
4
+ import '@ohos.abilityAccessCtrl';
5
5
  import { eventCenter, Events, History } from '@tarojs/runtime/dist/runtime.esm';
6
6
  import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
7
7
  import deviceInfo from '@ohos.deviceInfo';
@@ -176,21 +176,6 @@ const validateParams = function (name, params, schema) {
176
176
  }
177
177
  };
178
178
 
179
- function requestPermissions(permissions) {
180
- return new Promise((resolve, reject) => {
181
- const context = getContext(Current === null || Current === void 0 ? void 0 : Current.page);
182
- const atManager = abilityAccessCtrl.createAtManager();
183
- atManager.requestPermissionsFromUser(context, permissions, (err, _) => {
184
- if (err) {
185
- // eslint-disable-next-line prefer-promise-reject-errors
186
- reject(`[Taro] 请求用户授权 ${permissions.join('、')} 失败:${JSON.stringify(err)}`);
187
- }
188
- else {
189
- resolve();
190
- }
191
- });
192
- });
193
- }
194
179
  function object2String(obj) {
195
180
  let str = '';
196
181
  for (const item in obj) {
@@ -2279,12 +2264,6 @@ const chooseMedia = function (options) {
2279
2264
  });
2280
2265
  };
2281
2266
 
2282
- const READ_IMAGEVIDEO_PERMISSIONS = 'ohos.permission.READ_IMAGEVIDEO';
2283
- const READ_MEDIA_PERMISSIONS = 'ohos.permission.READ_MEDIA';
2284
- const WRITE_MEDIA_PERMISSIONS = 'ohos.permission.WRITE_MEDIA';
2285
- const MEDIA_LOCATION_PERMISSIONS = 'ohos.permission.MEDIA_LOCATION';
2286
- const IMAGE_PERMISSION = [READ_IMAGEVIDEO_PERMISSIONS, READ_MEDIA_PERMISSIONS, WRITE_MEDIA_PERMISSIONS, MEDIA_LOCATION_PERMISSIONS];
2287
-
2288
2267
  // HarmonyOS 图片模块首批接口从API version 7开始支持。
2289
2268
  // HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-image-0000001122977382
2290
2269
  // WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.saveImageToPhotosAlbum.html
@@ -2360,153 +2339,143 @@ function saveImage(compressedImageData, compressedImageUri) {
2360
2339
  }
2361
2340
  const compressImage = function (options) {
2362
2341
  return new Promise((resolve, reject) => {
2363
- requestPermissions(IMAGE_PERMISSION).then(() => {
2364
- try {
2365
- validateParams('compressImage', options, compressImageSchema);
2366
- }
2367
- catch (error) {
2368
- const res = { errMsg: error.message };
2369
- return callAsyncFail(reject, res, options);
2370
- }
2371
- const { src, quality = 80, compressedWidth, compressedHeight } = options;
2372
- const srcAfterCompress = src.includes('_after_compress') ? src : src.split('.').join('_after_compress.');
2373
- const file = fs.openSync(src, fs.OpenMode.READ_ONLY);
2374
- // const stat = fs.statSync(file.fd)
2375
- // console.log('[Taro] 压缩前图片的大小为:', stat.size)
2376
- const source = image.createImageSource(file.fd);
2377
- if (isNull(source)) {
2378
- const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' };
2379
- callAsyncFail(reject, createImageSourceError, options);
2380
- return;
2381
- }
2382
- const width = source.getImageInfoSync().size.width;
2383
- const height = source.getImageInfoSync().size.height;
2384
- let wantWidth = compressedWidth || compressedHeight || 0;
2385
- let wantHeight = compressedHeight || compressedWidth || 0;
2386
- if (width > wantWidth || height > wantHeight) {
2387
- const heightRatio = height / wantHeight;
2388
- const widthRatio = width / wantWidth;
2389
- const finalRatio = heightRatio < widthRatio ? heightRatio : widthRatio;
2390
- wantWidth = Math.round(width / finalRatio);
2391
- wantHeight = Math.round(height / finalRatio);
2342
+ try {
2343
+ validateParams('compressImage', options, compressImageSchema);
2344
+ }
2345
+ catch (error) {
2346
+ const res = { errMsg: error.message };
2347
+ return callAsyncFail(reject, res, options);
2348
+ }
2349
+ const { src, quality = 80, compressedWidth, compressedHeight } = options;
2350
+ const srcAfterCompress = src.includes('_after_compress') ? src : src.split('.').join('_after_compress.');
2351
+ const file = fs.openSync(src, fs.OpenMode.READ_ONLY);
2352
+ // const stat = fs.statSync(file.fd)
2353
+ // console.log('[Taro] 压缩前图片的大小为:', stat.size)
2354
+ const source = image.createImageSource(file.fd);
2355
+ if (isNull(source)) {
2356
+ const createImageSourceError = { errMsg: 'compressImage fail: createImageSource has failed.' };
2357
+ callAsyncFail(reject, createImageSourceError, options);
2358
+ return;
2359
+ }
2360
+ const width = source.getImageInfoSync().size.width;
2361
+ const height = source.getImageInfoSync().size.height;
2362
+ let wantWidth = compressedWidth || compressedHeight || 0;
2363
+ let wantHeight = compressedHeight || compressedWidth || 0;
2364
+ if (width > wantWidth || height > wantHeight) {
2365
+ const heightRatio = height / wantHeight;
2366
+ const widthRatio = width / wantWidth;
2367
+ const finalRatio = heightRatio < widthRatio ? heightRatio : widthRatio;
2368
+ wantWidth = Math.round(width / finalRatio);
2369
+ wantHeight = Math.round(height / finalRatio);
2370
+ }
2371
+ const decodingOptions = {
2372
+ editable: true,
2373
+ desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
2374
+ desiredSize: { width: wantWidth, height: wantHeight }
2375
+ };
2376
+ source.createPixelMap(decodingOptions, (error, pixelMap) => {
2377
+ if (error !== undefined) {
2378
+ fs.closeSync(file);
2379
+ const res = { errMsg: error };
2380
+ callAsyncFail(reject, res, options);
2392
2381
  }
2393
- const decodingOptions = {
2394
- editable: true,
2395
- desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
2396
- desiredSize: { width: wantWidth, height: wantHeight }
2397
- };
2398
- source.createPixelMap(decodingOptions, (error, pixelMap) => {
2399
- if (error !== undefined) {
2382
+ else {
2383
+ const packer = image.createImagePacker(file.fd);
2384
+ if (isNull(packer)) {
2400
2385
  fs.closeSync(file);
2401
- const res = { errMsg: error };
2402
- callAsyncFail(reject, res, options);
2386
+ const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' };
2387
+ callAsyncFail(reject, createImagePackerError, options);
2388
+ return;
2403
2389
  }
2404
- else {
2405
- const packer = image.createImagePacker(file.fd);
2406
- if (isNull(packer)) {
2407
- fs.closeSync(file);
2408
- const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' };
2409
- callAsyncFail(reject, createImagePackerError, options);
2410
- return;
2411
- }
2412
- const isPNG = src.endsWith('.png');
2413
- const packingOptionsOHOS = {
2414
- format: isPNG ? 'image/png' : 'image/jpeg',
2415
- quality: quality
2416
- };
2417
- packer.packing(pixelMap, packingOptionsOHOS).then((value) => {
2418
- fs.closeSync(file);
2419
- saveImage(value, srcAfterCompress).then(result => {
2420
- callAsyncSuccess(resolve, { tempFilePath: result.imageUri }, options);
2421
- });
2422
- }).catch((error) => {
2423
- fs.closeSync(file);
2424
- callAsyncFail(reject, error, options);
2390
+ const isPNG = src.endsWith('.png');
2391
+ const packingOptionsOHOS = {
2392
+ format: isPNG ? 'image/png' : 'image/jpeg',
2393
+ quality: quality
2394
+ };
2395
+ packer.packing(pixelMap, packingOptionsOHOS).then((value) => {
2396
+ fs.closeSync(file);
2397
+ saveImage(value, srcAfterCompress).then(result => {
2398
+ callAsyncSuccess(resolve, { tempFilePath: result.imageUri }, options);
2425
2399
  });
2426
- }
2427
- });
2428
- }, (error) => {
2429
- const res = { errMsg: error };
2430
- return callAsyncFail(reject, res, options);
2400
+ }).catch((error) => {
2401
+ fs.closeSync(file);
2402
+ callAsyncFail(reject, error, options);
2403
+ });
2404
+ }
2431
2405
  });
2432
2406
  });
2433
2407
  };
2434
2408
  const chooseImage = function (options) {
2435
2409
  return new Promise((resolve, reject) => {
2436
- requestPermissions(IMAGE_PERMISSION).then(() => {
2437
- try {
2438
- validateParams('chooseImage', options, chooseImageSchema);
2439
- }
2440
- catch (error) {
2441
- const res = { errMsg: error.message };
2442
- return callAsyncFail(reject, res, options);
2443
- }
2444
- const { count = 9 } = options;
2445
- const photoViewPicker = new picker.PhotoViewPicker();
2446
- let sizeType = options.sizeType;
2447
- if (!sizeType || !sizeType.length) {
2448
- sizeType = ['compressed', 'original'];
2410
+ try {
2411
+ validateParams('chooseImage', options, chooseImageSchema);
2412
+ }
2413
+ catch (error) {
2414
+ const res = { errMsg: error.message };
2415
+ return callAsyncFail(reject, res, options);
2416
+ }
2417
+ const { count = 9 } = options;
2418
+ const photoViewPicker = new picker.PhotoViewPicker();
2419
+ let sizeType = options.sizeType;
2420
+ if (!sizeType || !sizeType.length) {
2421
+ sizeType = ['compressed', 'original'];
2422
+ }
2423
+ photoSelectOptions.maxSelectNumber = count; // 选择媒体文件的最大数目
2424
+ photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
2425
+ photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
2426
+ const result = {};
2427
+ const isOrigin = photoSelectResult.isOriginalPhoto;
2428
+ if (isOrigin) {
2429
+ const tempFilePaths = [];
2430
+ const tempFiles = photoSelectResult.photoUris.map(uri => {
2431
+ const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
2432
+ const stat = fs.statSync(file.fd);
2433
+ const size = stat.size;
2434
+ fs.closeSync(file);
2435
+ tempFilePaths.push(uri);
2436
+ return {
2437
+ size,
2438
+ path: uri,
2439
+ };
2440
+ });
2441
+ result.tempFiles = tempFiles;
2442
+ result.tempFilePaths = tempFilePaths;
2443
+ callAsyncSuccess(resolve, result, options);
2449
2444
  }
2450
- photoSelectOptions.maxSelectNumber = count; // 选择媒体文件的最大数目
2451
- photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
2452
- photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
2453
- const result = {};
2454
- const isOrigin = photoSelectResult.isOriginalPhoto;
2455
- if (isOrigin) {
2456
- const tempFilePaths = [];
2457
- const tempFiles = photoSelectResult.photoUris.map(uri => {
2445
+ else {
2446
+ const actions = photoSelectResult.photoUris.map(uri => {
2447
+ return new Promise(resolve => {
2448
+ compressImage({
2449
+ src: uri,
2450
+ compressedWidth: getSystemInfoSync().screenWidth / 2,
2451
+ compressedHeight: getSystemInfoSync().screenHeight / 2,
2452
+ success: (compressResult) => {
2453
+ resolve(compressResult.tempFilePath);
2454
+ }
2455
+ });
2456
+ });
2457
+ });
2458
+ Promise.all(actions).then(tempFilePaths => {
2459
+ const tempFiles = tempFilePaths.map(uri => {
2458
2460
  const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
2459
2461
  const stat = fs.statSync(file.fd);
2460
2462
  const size = stat.size;
2461
2463
  fs.closeSync(file);
2462
- tempFilePaths.push(uri);
2463
2464
  return {
2464
2465
  size,
2465
2466
  path: uri,
2466
2467
  };
2467
2468
  });
2468
- result.tempFiles = tempFiles;
2469
2469
  result.tempFilePaths = tempFilePaths;
2470
+ result.tempFiles = tempFiles;
2470
2471
  callAsyncSuccess(resolve, result, options);
2471
- }
2472
- else {
2473
- const actions = photoSelectResult.photoUris.map(uri => {
2474
- return new Promise(resolve => {
2475
- compressImage({
2476
- src: uri,
2477
- compressedWidth: getSystemInfoSync().screenWidth / 2,
2478
- compressedHeight: getSystemInfoSync().screenHeight / 2,
2479
- success: (compressResult) => {
2480
- resolve(compressResult.tempFilePath);
2481
- }
2482
- });
2483
- });
2484
- });
2485
- Promise.all(actions).then(tempFilePaths => {
2486
- const tempFiles = tempFilePaths.map(uri => {
2487
- const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
2488
- const stat = fs.statSync(file.fd);
2489
- const size = stat.size;
2490
- fs.closeSync(file);
2491
- return {
2492
- size,
2493
- path: uri,
2494
- };
2495
- });
2496
- result.tempFilePaths = tempFilePaths;
2497
- result.tempFiles = tempFiles;
2498
- callAsyncSuccess(resolve, result, options);
2499
- }).catch(error => {
2500
- const res = { errMsg: error };
2501
- return callAsyncFail(reject, res, options);
2502
- });
2503
- }
2504
- }).catch((error) => {
2505
- callAsyncFail(reject, error, options);
2506
- });
2507
- }, (error) => {
2508
- const res = { errMsg: error };
2509
- return callAsyncFail(reject, res, options);
2472
+ }).catch(error => {
2473
+ const res = { errMsg: error };
2474
+ return callAsyncFail(reject, res, options);
2475
+ });
2476
+ }
2477
+ }).catch((error) => {
2478
+ callAsyncFail(reject, error, options);
2510
2479
  });
2511
2480
  });
2512
2481
  };