添加测试多张相同内容不同链接图片样例

Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
zgf 2024-07-04 14:35:16 +08:00
parent 414e335a3a
commit 7ecc9faf9f
4 changed files with 78 additions and 5 deletions

View File

@ -20,7 +20,14 @@ export class CustomEngineKeyImpl implements IEngineKey {
// 生成内存缓存key
generateMemoryKey(loadSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource,
imageKnifeOption: ImageKnifeOption, width?: number, height?: number): string {
let key = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";"
let key = ""
if(imageKnifeOption.signature == "aaa" && typeof loadSrc == "string") {
let num = loadSrc.indexOf("?")
let src = loadSrc.substring(0,num)
key = "loadSrc=" + src
} else {
key = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";"
}
if (requestSource === ImageKnifeRequestSource.SRC) {
if (imageKnifeOption.signature !== undefined && imageKnifeOption.signature !== "") {
key += "signature=" + imageKnifeOption.signature + ";"
@ -34,7 +41,14 @@ export class CustomEngineKeyImpl implements IEngineKey {
// 生成文件缓存key
generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string): string {
let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";"
let src = ""
if(signature == "aaa" && typeof loadSrc == "string") {
let num = loadSrc.indexOf("?")
let key = loadSrc.substring(0,num)
src = "loadSrc=" + key
} else {
src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";"
}
if (signature !== undefined && signature !== "") {
src += "signature=" + signature + ";"
}

View File

@ -26,13 +26,19 @@ struct Index {
build() {
Scroll(){
Column() {
Button("测试HSP场景预加载").onClick(()=>{
Button("测试加载多张相同图片").onClick(()=>{
router.push({
uri: 'pages/TestCommonImage',
});
})
Button("测试HSP场景预加载").margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/TestHspPreLoadImage',
});
})
Button("单个图片使用").onClick(()=>{
Button("单个图片使用").margin({top:10}).onClick(()=>{
router.push({
uri: 'pages/SingleImage',

View File

@ -0,0 +1,52 @@
/*
* 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 } from '@ohos/libraryimageknife';
@Entry
@Component
struct TestCommonImage {
private data: Array<string> = []
aboutToAppear(): void {
for (let index = 0; index < 30; index++) {
this.data.push(`https://img-blog.csdn.net/20140514114029140?${index}`)
}
}
build() {
Column() {
WaterFlow() {
ForEach(this.data,(item: string)=>{
FlowItem() {
Column(){
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: item,
placeholderSrc: $r("app.media.loading"),
errorholderSrc: $r("app.media.failed"),
objectFit: ImageFit.Contain,
signature: "aaa"
}
}).width("50%").height(200)
}
}.height(200)
.backgroundColor("#95efd2")
},(item: string) => item)
}.columnsTemplate("1fr 1fr")
.columnsGap(10)
.rowsGap(5)
.backgroundColor(0xFAEEE0)
.width("100%").height("100%")
}
}
}

View File

@ -18,6 +18,7 @@
"pages/LoadStatePage",
"pages/TestHspPreLoadImage",
"pages/TestRemoveCache",
"pages/dataShareUriLoadPage"
"pages/dataShareUriLoadPage",
"pages/TestCommonImage"
]
}