From 3595190083bac7ff18d017d17f50fb6f97eb55d1 Mon Sep 17 00:00:00 2001 From: zhoulisheng1 Date: Tue, 19 Sep 2023 16:51:01 +0800 Subject: [PATCH] =?UTF-8?q?1.ArkTs=E6=95=B4=E6=94=B911=20=E6=95=B4?= =?UTF-8?q?=E6=94=B9imageknife->resourcemanager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng1 --- .../resourcemanage/IResourceFetch.ets | 7 +++---- .../resourcemanage/ParseResClient.ets | 11 +++++----- .../resourcemanage/ParseResClientBase64.ets | 21 ++++++++++--------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets index 3ed14c4..70057e5 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets @@ -13,9 +13,8 @@ * limitations under the License. */ -import {RequestOption} from "../RequestOption" - +import { BusinessError } from '@ohos.base' // 本地资源解析抽象接口 -export interface IResourceFetch { - loadResource(res: Resource, onCompleteFunction, onErrorFunction); +export interface IResourceFetch { + loadResource:(res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void)=>void; } \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets index 44a0586..21fd348 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets @@ -13,14 +13,13 @@ * limitations under the License. */ -import type {IResourceFetch} from '../resourcemanage/IResourceFetch' +import {IResourceFetch} from '../resourcemanage/IResourceFetch' import {ResourceTypeEts} from '../../imageknife/constants/ResourceTypeEts' - import resourceManager from '@ohos.resourceManager'; import { ImageKnifeGlobal } from '../ImageKnifeGlobal'; - -export class ParseResClient implements IResourceFetch { - loadResource(res: Resource, onCompleteFunction, onErrorFunction) { +import { BusinessError } from '@ohos.base' +export class ParseResClient implements IResourceFetch { + loadResource(res: Resource, onCompleteFunction:(value:ArrayBuffer)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void) { let resId = res.id; let resType = res.type; if (resType == ResourceTypeEts.MEDIA) { @@ -30,7 +29,7 @@ export class ParseResClient implements IResourceFetch { let arrayBuffer = this.typedArrayToBuffer(data); onCompleteFunction(arrayBuffer) }) - .catch(err => { + .catch( (err:BusinessError) => { onErrorFunction(err) }) } diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets index 03dbc09..6f563b5 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets @@ -13,31 +13,32 @@ * limitations under the License. */ -import type {IResourceFetch} from '../resourcemanage/IResourceFetch' -import {ResourceTypeEts} from '../../imageknife/constants/ResourceTypeEts' -import {Base64} from '../../cache/Base64' - +import { IResourceFetch } from '../resourcemanage/IResourceFetch' +import { ResourceTypeEts } from '../../imageknife/constants/ResourceTypeEts' +import { Base64 } from '../../cache/Base64' +import { BusinessError } from '@ohos.base' import resourceManager from '@ohos.resourceManager'; import { ImageKnifeGlobal } from '../ImageKnifeGlobal'; -export class ParseResClientBase64 implements IResourceFetch { - loadResource(res: Resource, onCompleteFunction, onErrorFunction) { +export class ParseResClientBase64 implements IResourceFetch { + loadResource(res: Resource, onCompleteFunction: (value: ArrayBuffer) => void | PromiseLike, onErrorFunction: (reason?: BusinessError | string) => void) { let resId = res.id; let resType = res.type; if (resType == ResourceTypeEts.MEDIA) { - ((ImageKnifeGlobal.getInstance().getHapContext() as Record).resourceManager as resourceManager.ResourceManager) + ((ImageKnifeGlobal.getInstance() + .getHapContext() as Record).resourceManager as resourceManager.ResourceManager) .getMediaContentBase64(resId) .then(data => { let matchReg = ';base64,'; - var firstIndex = data.indexOf(matchReg) + let firstIndex = data.indexOf(matchReg) data = data.substring(firstIndex + matchReg.length, data.length) let arrayBuffer = Base64.getInstance() .decode(data); onCompleteFunction(arrayBuffer) }) - .catch(err => { + .catch((err: BusinessError) => { onErrorFunction(err) - }) + }) } else if (resType == ResourceTypeEts.RAWFILE) { onErrorFunction('ParseResClientBase64 本地资源是rawfile暂时无法解析出错')