From 3ce5305890ee9207c588b182cf6f89103378e9e8 Mon Sep 17 00:00:00 2001 From: zgf Date: Fri, 26 Jul 2024 14:38:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5=E6=97=A0=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E4=BB=A5=E5=8F=8A=E6=96=B0=E5=A2=9E=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E8=87=AA=E5=AE=9A=E4=B9=89=E4=B8=8B=E8=BD=BD=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- entry/src/main/ets/pages/LoadStatePage.ets | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/LoadStatePage.ets b/entry/src/main/ets/pages/LoadStatePage.ets index e863e7c..af8689a 100644 --- a/entry/src/main/ets/pages/LoadStatePage.ets +++ b/entry/src/main/ets/pages/LoadStatePage.ets @@ -36,6 +36,10 @@ struct LoadStatePage { }, border: { radius: 50 } } + @State imageKnifeOption1: ImageKnifeOption = { + loadSrc: $r('app.media.startIcon') + } + @State message: string = "" @State currentWidth: number = 200 @State currentHeight: number = 200 @State typeValue: string = "" @@ -78,11 +82,33 @@ struct LoadStatePage { Text(this.typeValue) ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth) .margin({ top: 20 }) - + Button("自定义下载失败").onClick(()=>{ + this.imageKnifeOption1 = { + loadSrc: "abc", + placeholderSrc:$r('app.media.loading'), + errorholderSrc:$r('app.media.failed'), + customImage:custom, + onLoadListener: { + onLoadFailed:(err)=>{ + this.message = "err:" + err + } + } + } + }).margin({ top: 20 }) + Text(this.message).fontSize(20).margin({ top: 20 }) + ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).height(this.currentHeight).width(this.currentWidth) + .margin({ top: 20 }) } .width('100%') .height('100%') } +} +// 自定义下载方法 +@Concurrent +async function custom(context: Context, src: string | PixelMap | Resource): Promise { + console.info("ImageKnife:: custom download:" + src) + // 举例写死从本地文件读取,也可以自己请求网络图片 + return undefined } \ No newline at end of file