From 68672e1dc7c10e87bfe20998b106f5bcaa5c9aa5 Mon Sep 17 00:00:00 2001 From: zgf Date: Fri, 6 Dec 2024 18:31:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E5=92=8C=E7=BD=91=E7=BB=9C=E8=AF=B7=E6=B1=82=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- CHANGELOG.md | 4 ++++ README_zh.md | 1 + entry/src/main/ets/pages/LongImagePage.ets | 4 ++++ library/index.ets | 2 +- library/oh-package.json5 | 2 +- library/src/main/ets/ImageKnifeDispatcher.ets | 10 ++++++---- library/src/main/ets/ImageKnifeLoader.ets | 4 ++-- library/src/main/ets/model/ImageKnifeData.ets | 2 ++ library/src/main/ets/model/ImageKnifeOption.ets | 9 +++++---- library/src/main/ets/utils/LogUtil.ets | 16 ++++++++++++---- sharedlibrary/Index.ets | 2 +- 11 files changed, 39 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89ec477..96673e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.0-rc.6 +- Support LogUtil to turn off log +- Support set network request readTimeout and connectTimeout through ImageKnifeOption + ## 3.2.0-rc.5 - Enhance: ImageFit.Auto support adaptive height after component width change - Fix bug: call onLoadStart 2 times(import from 3.2.0-rc.0) diff --git a/README_zh.md b/README_zh.md index 8032d64..eaec8d0 100644 --- a/README_zh.md +++ b/README_zh.md @@ -377,6 +377,7 @@ async function custom(context: Context, src: string | PixelMap | Resource,header | onComplete | (event:EventImage、undefined) => void | 图片成功回调事件(可选) | | onLoadListener | onLoadStart?: (req?: ImageKnifeRequest) => void,onLoadSuccess?: (data: string \| PixelMap \| undefined, imageData: ImageKnifeData, req?: ImageKnifeRequest) => void,onLoadFailed?: (err: string, req?: ImageKnifeRequest) => void,onLoadCancel?: (res: string, req?: ImageKnifeRequest) => void | 监听图片加载成功与失败 | | downsampleOf | DownsampleStrategy | 降采样(可选) | +| httpOption | httpRequestOption | 网络请求配置(可选) | ### 降采样类型 | 类型 | 相关描述 | diff --git a/entry/src/main/ets/pages/LongImagePage.ets b/entry/src/main/ets/pages/LongImagePage.ets index 34d38fa..1dc5740 100644 --- a/entry/src/main/ets/pages/LongImagePage.ets +++ b/entry/src/main/ets/pages/LongImagePage.ets @@ -30,6 +30,10 @@ struct LongImagePage { //src:$r('app.media.aaa'), placeholderSrc: $r('app.media.loading'), errorholderSrc: $r('app.media.failed'), + httpOption: { + connectTimeout: 60000, + readTimeout: 60000 + }, objectFit: ImageFit.Auto } }) diff --git a/library/index.ets b/library/index.ets index 6f44833..28fc8d8 100644 --- a/library/index.ets +++ b/library/index.ets @@ -18,7 +18,7 @@ export { ImageKnifeAnimatorComponent } from './src/main/ets/components/ImageKnif export { ImageKnife } from './src/main/ets/ImageKnife' -export { ImageKnifeOption , AnimatorOption } from './src/main/ets/model/ImageKnifeOption' +export { ImageKnifeOption , AnimatorOption,httpRequestOption,HeaderOptions } from './src/main/ets/model/ImageKnifeOption' export { ImageKnifeRequest } from './src/main/ets/model/ImageKnifeRequest' diff --git a/library/oh-package.json5 b/library/oh-package.json5 index 428e958..b1c00f6 100644 --- a/library/oh-package.json5 +++ b/library/oh-package.json5 @@ -14,7 +14,7 @@ "main": "index.ets", "repository": "https://gitee.com/openharmony-tpc/ImageKnife", "type": "module", - "version": "3.2.0-rc.5", + "version": "3.2.0-rc.6", "dependencies": { "@ohos/gpu_transform": "^1.0.2" }, diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 4de0eb2..37a399a 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -245,13 +245,15 @@ export class ImageKnifeDispatcher { isAnimator:isAnimator, moduleName: moduleName == '' ? undefined : moduleName, resName: resName == '' ? undefined : resName, - caPath: currentRequest.imageKnifeOption.caPath, + caPath: currentRequest.imageKnifeOption.httpOption?.caPath, targetWidth: currentRequest.componentWidth, targetHeight: currentRequest.componentHeight, downsampType: currentRequest.imageKnifeOption.downsampleOf == undefined ? DownsampleStrategy.DEFAULT : currentRequest.imageKnifeOption.downsampleOf, isAutoImageFit: currentRequest.imageKnifeOption.objectFit == ImageFit.Auto, componentId: currentRequest.componentId, - componentVersion: currentRequest.componentVersion + componentVersion: currentRequest.componentVersion, + connectTimeout: currentRequest.imageKnifeOption.httpOption?.connectTimeout, + readTimeout: currentRequest.imageKnifeOption.httpOption?.readTimeout } if(request.customGetImage == undefined) { @@ -361,10 +363,10 @@ export class ImageKnifeDispatcher { let pixelmap = requestJobResult.pixelMap; if (pixelmap === undefined) { - LogUtil.error('getAndShowImage_CallBack.pixelmap failed:' + currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion + " error: " + requestJobResult.loadFail) + this.executingJobMap.remove(memoryKey); requestList.forEach((requestWithSource: ImageKnifeRequestWithSource) => { requestWithSource.request.requestState = ImageKnifeRequestState.ERROR - this.executingJobMap.remove(memoryKey); + LogUtil.error('getAndShowImage_CallBack.pixelmap failed:' + currentRequest.componentId + ',srcType:' + requestSource + ',version:' + currentRequest.componentVersion + " error: " + requestJobResult.loadFail) // 回调请求失败 if (requestWithSource.source === ImageKnifeRequestSource.SRC && requestWithSource.request.imageKnifeOption.onLoadListener?.onLoadFailed !== undefined && diff --git a/library/src/main/ets/ImageKnifeLoader.ets b/library/src/main/ets/ImageKnifeLoader.ets index d520784..f85d655 100644 --- a/library/src/main/ets/ImageKnifeLoader.ets +++ b/library/src/main/ets/ImageKnifeLoader.ets @@ -525,8 +525,8 @@ export class ImageKnifeLoader { header: headerObj, method: http.RequestMethod.GET, expectDataType: http.HttpDataType.ARRAY_BUFFER, - connectTimeout: 60000, - readTimeout: 30000, + connectTimeout: request.connectTimeout == undefined ? 60000 : request.connectTimeout, + readTimeout: request.readTimeout == undefined ? 30000 : request.readTimeout, // usingProtocol:http.HttpProtocol.HTTP1_1 // header: new Header('application/json') caPath: request.caPath === undefined ? undefined : request.caPath, diff --git a/library/src/main/ets/model/ImageKnifeData.ets b/library/src/main/ets/model/ImageKnifeData.ets index bddfbe4..93b1e17 100644 --- a/library/src/main/ets/model/ImageKnifeData.ets +++ b/library/src/main/ets/model/ImageKnifeData.ets @@ -154,5 +154,7 @@ export interface RequestJobRequest { isAutoImageFit: boolean, componentId?: number, componentVersion?: number + connectTimeout?: number + readTimeout?: number } diff --git a/library/src/main/ets/model/ImageKnifeOption.ets b/library/src/main/ets/model/ImageKnifeOption.ets index 9e9b100..2c1ba36 100644 --- a/library/src/main/ets/model/ImageKnifeOption.ets +++ b/library/src/main/ets/model/ImageKnifeOption.ets @@ -45,9 +45,10 @@ export class AnimatorOption { onRepeat?:()=>void } -interface ImageOption { - // 自定义证书路径 - caPath?: string, +export interface httpRequestOption { + caPath?: string // 自定义证书路径 + connectTimeout?: number // 连接超时 + readTimeout?: number // 读取超时 } @Observed export class ImageKnifeOption { @@ -81,7 +82,7 @@ export class ImageKnifeOption { drawingColorFilter?: ColorFilter | drawing.ColorFilter downsampleOf?: DownsampleStrategy // 降采样 // 自定义证书路径 - caPath?: string + httpOption?: httpRequestOption constructor() { } diff --git a/library/src/main/ets/utils/LogUtil.ets b/library/src/main/ets/utils/LogUtil.ets index 7c802a2..4732978 100644 --- a/library/src/main/ets/utils/LogUtil.ets +++ b/library/src/main/ets/utils/LogUtil.ets @@ -17,17 +17,25 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; export class LogUtil { public static readonly DOMAIN: number = 0xD002220; public static readonly TAG: string = 'ImageKnife::'; - + public static ON: boolean = true + public static OFF: boolean = false + public static mLogLevel:boolean = LogUtil.ON public static debug(message: string, ...args: Object[]) { - hilog.debug(LogUtil.DOMAIN, LogUtil.TAG, message, args) + if (LogUtil.mLogLevel == LogUtil.ON) { + hilog.debug(LogUtil.DOMAIN, LogUtil.TAG, message, args) + } } public static info(message: string, ...args: Object[]) { - hilog.info(LogUtil.DOMAIN, LogUtil.TAG, message, args) + if (LogUtil.mLogLevel == LogUtil.ON) { + hilog.info(LogUtil.DOMAIN, LogUtil.TAG, message, args) + } } public static log(message: string, ...args: Object[]) { - hilog.debug(LogUtil.DOMAIN, LogUtil.TAG, message, args) + if (LogUtil.mLogLevel == LogUtil.ON) { + hilog.debug(LogUtil.DOMAIN, LogUtil.TAG, message, args) + } } public static warn(message: string, ...args: Object[]) { diff --git a/sharedlibrary/Index.ets b/sharedlibrary/Index.ets index 99a925e..d426419 100644 --- a/sharedlibrary/Index.ets +++ b/sharedlibrary/Index.ets @@ -22,7 +22,7 @@ export { ImageKnifeComponent,ImageKnifeAnimatorComponent } from '@ohos/imageknif export { ImageKnife } from '@ohos/imageknife' -export { ImageKnifeOption,AnimatorOption } from '@ohos/imageknife' +export { ImageKnifeOption,AnimatorOption,httpRequestOption,HeaderOptions } from '@ohos/imageknife' export { DownsampleStrategy } from "@ohos/imageknife" -- Gitee