80 lines
2.6 KiB
Plaintext
80 lines
2.6 KiB
Plaintext
/*
|
|
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/libraryimageknife"
|
|
import matrix4 from '@ohos.matrix4'
|
|
|
|
@Entry
|
|
@Component
|
|
struct LoadStatePage {
|
|
|
|
starTime:number = new Date().getTime()
|
|
|
|
@State ImageKnifeOption: ImageKnifeOption = {
|
|
loadSrc: $r("app.media.rabbit"),
|
|
placeholderSrc: $r("app.media.loading"),
|
|
errorholderSrc: $r("app.media.app_icon"),
|
|
objectFit: ImageFit.Contain,
|
|
onLoadListener: {
|
|
onLoadFailed: (err) => {
|
|
console.error("Load Failed Reason: " + err);
|
|
},
|
|
onLoadSuccess: (data) => {
|
|
return data;
|
|
},
|
|
},
|
|
border: { radius: 50 }
|
|
}
|
|
|
|
build() {
|
|
Column() {
|
|
Text('测试失败场景请先关闭网络,并保证本地没有此网络图片的缓存')
|
|
.margin({ top: 20 })
|
|
Row() {
|
|
Button('测试失败/成功场景')
|
|
.onClick(() => {
|
|
this.ImageKnifeOption = {
|
|
loadSrc: "https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png",
|
|
placeholderSrc: $r("app.media.loading"),
|
|
errorholderSrc: $r("app.media.app_icon"),
|
|
objectFit: ImageFit.Contain,
|
|
onLoadListener: {
|
|
onLoadStart:()=>{
|
|
this.starTime = new Date().getTime()
|
|
console.info("Load start: ");
|
|
},
|
|
onLoadFailed: (err) => {
|
|
console.error("Load Failed Reason: " + err + " cost " + (new Date().getTime() - this.starTime) + " milliseconds");
|
|
},
|
|
onLoadSuccess: (data) => {
|
|
console.info("Load Successful: cost " + (new Date().getTime() - this.starTime) + " milliseconds");
|
|
return data;
|
|
},
|
|
},
|
|
border: { radius: 50 }
|
|
}
|
|
})
|
|
}
|
|
.margin({ top: 20 })
|
|
|
|
ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(200).width(200)
|
|
.margin({ top: 20 })
|
|
|
|
}
|
|
|
|
.width('100%')
|
|
.height('100%')
|
|
}
|
|
|
|
} |