diff --git a/entry/src/main/ets/common/CustomEngineKeyImpl.ets b/entry/src/main/ets/common/CustomEngineKeyImpl.ets index 4354e1c..6fe7c37 100644 --- a/entry/src/main/ets/common/CustomEngineKeyImpl.ets +++ b/entry/src/main/ets/common/CustomEngineKeyImpl.ets @@ -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 + ";" } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 816bdeb..2053dc2 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -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', diff --git a/entry/src/main/ets/pages/TestCommonImage.ets b/entry/src/main/ets/pages/TestCommonImage.ets new file mode 100644 index 0000000..669220c --- /dev/null +++ b/entry/src/main/ets/pages/TestCommonImage.ets @@ -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 = [] + 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%") + } + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 84072cb..b522a2e 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -18,6 +18,7 @@ "pages/LoadStatePage", "pages/TestHspPreLoadImage", "pages/TestRemoveCache", - "pages/dataShareUriLoadPage" + "pages/dataShareUriLoadPage", + "pages/TestCommonImage" ] } \ No newline at end of file