From 598b3eaf58f1a5a675b01e6ca8e499d72d8945ef Mon Sep 17 00:00:00 2001 From: zenggaofeng Date: Fri, 22 Mar 2024 10:42:24 +0800 Subject: [PATCH] =?UTF-8?q?master=E5=88=86=E6=94=AF=E5=90=88=E5=B9=B6taskp?= =?UTF-8?q?ool=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zenggaofeng --- .../main/ets/pages/basicTestFileIOPage.ets | 19 ++++++++++++------- .../ets/components/cache/DiskLruCache.ets | 2 +- .../main/ets/components/cache/FileReader.ets | 2 +- .../ets/components/imageknife/ImageKnife.ets | 12 ++++++------ .../components/imageknife/RequestOption.ets | 2 +- .../requestmanage/DiskCacheProxy.ets | 4 ++-- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/entry/src/main/ets/pages/basicTestFileIOPage.ets b/entry/src/main/ets/pages/basicTestFileIOPage.ets index 22d8873..eb987e2 100644 --- a/entry/src/main/ets/pages/basicTestFileIOPage.ets +++ b/entry/src/main/ets/pages/basicTestFileIOPage.ets @@ -109,13 +109,18 @@ struct basicTestFileIOPage { this.imageHint2 = 'appFilePath未取到值,请按顺序从上往下,从左往右依次测试' return } - let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif'; - let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif'; - FileUtils.getInstance().createFolder(this.appFilePath + '/Folder1') - FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2') - FileUtils.getInstance().copyFile(filePath1, filePath2); - this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif' - console.log('Folder2 imaeFile =' + this.imageFile) + try { + let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif'; + let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif'; + FileUtils.getInstance().createFolder(this.appFilePath + '/Folder1') + FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2') + FileUtils.getInstance().copyFile(filePath1, filePath2); + this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif' + console.log('Folder2 imaeFile =' + this.imageFile) + } catch (e) { + console.log('appFilePath未取到值,请按顺序从上往下,从左往右依次测试:'+JSON.stringify(e)) + } + }) Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Button('显示空PixelMap') diff --git a/library/src/main/ets/components/cache/DiskLruCache.ets b/library/src/main/ets/components/cache/DiskLruCache.ets index a78cc9a..1b84789 100644 --- a/library/src/main/ets/components/cache/DiskLruCache.ets +++ b/library/src/main/ets/components/cache/DiskLruCache.ets @@ -19,7 +19,7 @@ import { FileReader } from './FileReader' import { DiskCacheEntry } from './DiskCacheEntry' import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5' import { Context } from '@ohos.abilityAccessCtrl' -import { common } from '@kit.AbilityKit' +import common from '@ohos.app.ability.common' export class DiskLruCache { // 默认缓存数据最大值 diff --git a/library/src/main/ets/components/cache/FileReader.ets b/library/src/main/ets/components/cache/FileReader.ets index 53938b2..5c00198 100644 --- a/library/src/main/ets/components/cache/FileReader.ets +++ b/library/src/main/ets/components/cache/FileReader.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import fs, { ReadOptions } from '@ohos.file.fs'; +import fs from '@ohos.file.fs'; import { RequestOption } from '../imageknife/RequestOption'; export class FileReader { diff --git a/library/src/main/ets/components/imageknife/ImageKnife.ets b/library/src/main/ets/components/imageknife/ImageKnife.ets index 3f1f5e5..57ec07b 100644 --- a/library/src/main/ets/components/imageknife/ImageKnife.ets +++ b/library/src/main/ets/components/imageknife/ImageKnife.ets @@ -39,8 +39,8 @@ import { MethodMutex } from './utils/base/MethodMutex' import worker from '@ohos.worker' import common from '@ohos.app.ability.common' import { MemoryLruCache } from '../cache/MemoryLruCache' -import { BusinessError } from '@kit.BasicServicesKit' -import { taskpool } from '@kit.ArkTS' +import { BusinessError } from '@ohos.base' +import taskpool from '@ohos.taskpool' import { GIFFrame } from './utils/gif/GIFFrame' import emitter from '@ohos.events.emitter'; @@ -588,16 +588,16 @@ export class ImageKnife { retryholderSrc: request.retryholderSrc, }); //使用taskpool多线程执行资源下载 - let task = new taskpool.Task(taskExecute, taskParams, loadSrcJson) + let task:ESObject = new taskpool.Task(taskExecute, taskParams, loadSrcJson) task.setTransferList([]) - emitter.on(Constants.PROGRESS_EMITTER, (data) => { + emitter.on(Constants.PROGRESS_EMITTER as ESObject, (data:ESObject) => { if (request.progressFunc && data?.data?.value) { let percent = data.data.value as number; request.progressFunc.asyncSuccess(percent); } }); - taskpool.execute(task).then((data) => { + taskpool.execute(task).then((data: ESObject) => { if (usageType == Constants.PLACE_HOLDER) { if ((typeof (data as PixelMap).isEditable) == 'boolean') { let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, data as PixelMap); @@ -718,7 +718,7 @@ async function taskExecute(taskParams: TaskParams, loadSrcJson: string): Promise "value": percentValue, } }; - emitter.emit(Constants.PROGRESS_EMITTER, eventData) + emitter.emit(Constants.PROGRESS_EMITTER as ESObject, eventData) } let transformations = taskParams.transformations; diff --git a/library/src/main/ets/components/imageknife/RequestOption.ets b/library/src/main/ets/components/imageknife/RequestOption.ets index b6e3a09..a2b3c84 100644 --- a/library/src/main/ets/components/imageknife/RequestOption.ets +++ b/library/src/main/ets/components/imageknife/RequestOption.ets @@ -56,7 +56,7 @@ import common from '@ohos.app.ability.common' import { GIFFrame } from './utils/gif/GIFFrame' import { MemoryCacheProxy } from './requestmanage/MemoryCacheProxy' import { DiskCacheProxy } from './requestmanage/DiskCacheProxy' -import { DiskLruCache } from '../cache/disklrucache' +import { DiskLruCache } from '../cache/DiskLruCache' import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5' import { FileUtils } from '../cache/FileUtils' diff --git a/library/src/main/ets/components/imageknife/requestmanage/DiskCacheProxy.ets b/library/src/main/ets/components/imageknife/requestmanage/DiskCacheProxy.ets index efffcfe..552d607 100644 --- a/library/src/main/ets/components/imageknife/requestmanage/DiskCacheProxy.ets +++ b/library/src/main/ets/components/imageknife/requestmanage/DiskCacheProxy.ets @@ -14,7 +14,7 @@ */ import { ICache } from "../requestmanage/ICache" -import { DiskLruCache } from "../../cache/disklrucache" +import { DiskLruCache } from "../../cache/DiskLruCache" export class DiskCacheProxy implements ICache { private mDiskLruCache: DiskLruCache; @@ -29,7 +29,7 @@ export class DiskCacheProxy implements ICache { } getCachePath():string{ - let folderPath = this.mDiskLruCache.getPath(); + let folderPath:string = this.mDiskLruCache.getPath(); if (folderPath.endsWith('/')) { return folderPath; } else {