修复自定义下载失败无失败回调以及新增全局自定义下载接口

Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
zgf 2024-07-26 14:38:22 +08:00
parent 8793e8c91f
commit 3ce5305890
1 changed files with 27 additions and 1 deletions

View File

@ -36,6 +36,10 @@ struct LoadStatePage {
}, },
border: { radius: 50 } border: { radius: 50 }
} }
@State imageKnifeOption1: ImageKnifeOption = {
loadSrc: $r('app.media.startIcon')
}
@State message: string = ""
@State currentWidth: number = 200 @State currentWidth: number = 200
@State currentHeight: number = 200 @State currentHeight: number = 200
@State typeValue: string = "" @State typeValue: string = ""
@ -78,7 +82,22 @@ struct LoadStatePage {
Text(this.typeValue) Text(this.typeValue)
ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth) ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth)
.margin({ top: 20 }) .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%') .width('100%')
@ -86,3 +105,10 @@ struct LoadStatePage {
} }
} }
// 自定义下载方法
@Concurrent
async function custom(context: Context, src: string | PixelMap | Resource): Promise<ArrayBuffer | undefined> {
console.info("ImageKnife:: custom download" + src)
// 举例写死从本地文件读取,也可以自己请求网络图片
return undefined
}