@tarojs/plugin-platform-harmony-ets 4.0.0-beta.112 → 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.
- package/dist/apis/media/image/index.ts +144 -97
- package/dist/apis/utils/permissions.ts +5 -0
- package/dist/runtime-ets/dom/element/movableView.ts +12 -8
- package/dist/runtime-ets/dom/stylesheet/type.ts +4 -4
- package/dist/runtime-utils.js +130 -108
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +130 -108
- package/dist/runtime.js.map +1 -1
- package/package.json +9 -9
package/dist/runtime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isFunction, isString, isArray, isObject, isNull, isNumber, isUndefined, queryToJson, PLATFORM_TYPE, singleQuote, internalComponents, mergeReconciler, mergeInternalComponents } 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
|
|
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,8 +2264,6 @@ const chooseMedia = function (options) {
|
|
|
2279
2264
|
});
|
|
2280
2265
|
};
|
|
2281
2266
|
|
|
2282
|
-
const READ_IMAGEVIDEO_PERMISSIONS = 'ohos.permission.READ_IMAGEVIDEO';
|
|
2283
|
-
|
|
2284
2267
|
// HarmonyOS 图片模块首批接口从API version 7开始支持。
|
|
2285
2268
|
// HarmonyOS 文档链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-image-0000001122977382
|
|
2286
2269
|
// WX 文档链接:https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.saveImageToPhotosAlbum.html
|
|
@@ -2326,12 +2309,17 @@ class CompressedImageInfo {
|
|
|
2326
2309
|
}
|
|
2327
2310
|
function saveImage(compressedImageData, compressedImageUri) {
|
|
2328
2311
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2329
|
-
|
|
2312
|
+
const tempArr = compressedImageUri.split('/');
|
|
2313
|
+
const name = tempArr[tempArr.length - 1];
|
|
2314
|
+
const context = getContext(Current === null || Current === void 0 ? void 0 : Current.page);
|
|
2315
|
+
const applicationContext = context.getApplicationContext();
|
|
2316
|
+
const tempDir = applicationContext.tempDir;
|
|
2317
|
+
const filePath = `${tempDir}/${name}`;
|
|
2330
2318
|
try {
|
|
2331
|
-
const res = fs.accessSync(
|
|
2319
|
+
const res = fs.accessSync(filePath);
|
|
2332
2320
|
if (res) {
|
|
2333
2321
|
// 如果图片afterCompressiona.jpeg已存在,则删除
|
|
2334
|
-
fs.unlinkSync(
|
|
2322
|
+
fs.unlinkSync(filePath);
|
|
2335
2323
|
}
|
|
2336
2324
|
}
|
|
2337
2325
|
catch (err) {
|
|
@@ -2339,121 +2327,155 @@ function saveImage(compressedImageData, compressedImageUri) {
|
|
|
2339
2327
|
}
|
|
2340
2328
|
// 知识点:保存图片。获取最终图片压缩数据compressedImageData,保存图片。
|
|
2341
2329
|
// 压缩图片数据写入文件
|
|
2342
|
-
const file = fs.openSync(
|
|
2330
|
+
const file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
|
2343
2331
|
fs.writeSync(file.fd, compressedImageData);
|
|
2344
2332
|
fs.closeSync(file);
|
|
2345
2333
|
// 获取压缩图片信息
|
|
2346
2334
|
const compressedImageInfo = new CompressedImageInfo();
|
|
2347
|
-
compressedImageInfo.imageUri =
|
|
2335
|
+
compressedImageInfo.imageUri = filePath;
|
|
2348
2336
|
compressedImageInfo.imageByteLength = compressedImageData.byteLength;
|
|
2349
2337
|
return compressedImageInfo;
|
|
2350
2338
|
});
|
|
2351
2339
|
}
|
|
2352
2340
|
const compressImage = function (options) {
|
|
2353
2341
|
return new Promise((resolve, reject) => {
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
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);
|
|
2377
2381
|
}
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2382
|
+
else {
|
|
2383
|
+
const packer = image.createImagePacker(file.fd);
|
|
2384
|
+
if (isNull(packer)) {
|
|
2385
|
+
fs.closeSync(file);
|
|
2386
|
+
const createImagePackerError = { errMsg: 'compressImage fail: createImagePacker has failed.' };
|
|
2387
|
+
callAsyncFail(reject, createImagePackerError, options);
|
|
2388
|
+
return;
|
|
2389
|
+
}
|
|
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);
|
|
2399
|
+
});
|
|
2400
|
+
}).catch((error) => {
|
|
2401
|
+
fs.closeSync(file);
|
|
2402
|
+
callAsyncFail(reject, error, options);
|
|
2386
2403
|
});
|
|
2387
|
-
}
|
|
2388
|
-
callAsyncFail(reject, error, options);
|
|
2389
|
-
});
|
|
2390
|
-
fs.closeSync(file);
|
|
2391
|
-
}, (error) => {
|
|
2392
|
-
const res = { errMsg: error };
|
|
2393
|
-
return callAsyncFail(reject, res, options);
|
|
2404
|
+
}
|
|
2394
2405
|
});
|
|
2395
2406
|
});
|
|
2396
2407
|
};
|
|
2397
2408
|
const chooseImage = function (options) {
|
|
2398
2409
|
return new Promise((resolve, reject) => {
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
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);
|
|
2412
2444
|
}
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
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 => {
|
|
2419
2460
|
const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
|
|
2420
2461
|
const stat = fs.statSync(file.fd);
|
|
2421
2462
|
const size = stat.size;
|
|
2463
|
+
fs.closeSync(file);
|
|
2422
2464
|
return {
|
|
2423
2465
|
size,
|
|
2424
2466
|
path: uri,
|
|
2425
2467
|
};
|
|
2426
2468
|
});
|
|
2469
|
+
result.tempFilePaths = tempFilePaths;
|
|
2427
2470
|
result.tempFiles = tempFiles;
|
|
2428
|
-
}
|
|
2429
|
-
if (sizeType.includes('compressed')) {
|
|
2430
|
-
const actions = photoSelectResult.photoUris.map(uri => {
|
|
2431
|
-
return new Promise(resolve => {
|
|
2432
|
-
compressImage({
|
|
2433
|
-
src: uri,
|
|
2434
|
-
success: (compressResult) => {
|
|
2435
|
-
resolve(compressResult.tempFilePath);
|
|
2436
|
-
}
|
|
2437
|
-
});
|
|
2438
|
-
});
|
|
2439
|
-
});
|
|
2440
|
-
Promise.all(actions).then(tempFilePaths => {
|
|
2441
|
-
result.tempFilePaths = tempFilePaths;
|
|
2442
|
-
callAsyncSuccess(resolve, result, options);
|
|
2443
|
-
}).catch(error => {
|
|
2444
|
-
const res = { errMsg: error };
|
|
2445
|
-
return callAsyncFail(reject, res, options);
|
|
2446
|
-
});
|
|
2447
|
-
}
|
|
2448
|
-
else {
|
|
2449
2471
|
callAsyncSuccess(resolve, result, options);
|
|
2450
|
-
}
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2472
|
+
}).catch(error => {
|
|
2473
|
+
const res = { errMsg: error };
|
|
2474
|
+
return callAsyncFail(reject, res, options);
|
|
2475
|
+
});
|
|
2476
|
+
}
|
|
2477
|
+
}).catch((error) => {
|
|
2478
|
+
callAsyncFail(reject, error, options);
|
|
2457
2479
|
});
|
|
2458
2480
|
});
|
|
2459
2481
|
};
|