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