From 884b06bb327c80365ed144fe531a1758e7568e9d Mon Sep 17 00:00:00 2001 From: zhoulisheng1 Date: Thu, 15 Dec 2022 00:59:59 -0800 Subject: [PATCH] 1.LogUtil add grade all print log; 2.clean others codecheck problems Signed-off-by: zhoulisheng1 --- .../ets/pages/basicTestFeatureAbilityPage.ets | 2 +- .../imageknife/ImageKnifeComponent.ets | 12 +++--- .../components/imageknife/utils/LogUtil.ets | 39 ++++++++++++------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets b/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets index 85c4084..ee87e56 100644 --- a/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets +++ b/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets @@ -1,6 +1,6 @@ /* * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License", + * 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 * diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets index e8543d5..7b5a2ce 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -84,7 +84,7 @@ export struct ImageKnifeComponent { } private canvasHasReady:boolean = false; private firstDrawFlag:boolean = false; - private onReadyNext:Function = undefined + private onReadyNext:()=>void = undefined build() { Canvas(this.context) .width('100%') @@ -98,7 +98,7 @@ export struct ImageKnifeComponent { // 前提:宽高值均有效,值>0. 条件1:当前宽高与上一次宽高不同 条件2:当前是第一次绘制 if( (this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth) || this.firstDrawFlag){ this.firstDrawFlag = false; - LogUtil.log('ImageKnifeComponent onAreaChange isValid Canvas currentWidth =' + this.currentWidth + ' currentHeight=' + this.currentHeight) + LogUtil.log('ImageKnifeComponent onAreaChange And Next To Execute. Canvas currentWidth =' + this.currentWidth + ' currentHeight=' + this.currentHeight) this.lastWidth = this.currentWidth this.lastHeight = this.currentHeight this.imageKnifeExecute() @@ -126,11 +126,11 @@ export struct ImageKnifeComponent { watchImageKnifeOption() { LogUtil.log('ImageKnifeComponent watchImageKnifeOption is happened!') - this.whetherWaitSize(); + this.whetherWaitSize(); } /** - * 判断当前是否由宽高,有直接重绘,没有则等待onAreaChange回调,当出现aboutToAppear第一次绘制的时候 + * 判断当前是否有宽高,有直接重绘,没有则等待onAreaChange回调,当出现aboutToAppear第一次绘制的时候 * 给firstDrawFlag置为true,保证size即使没有变化也要进入 请求绘制流程 * @param drawFirst 是否是aboutToAppear第一次绘制 */ @@ -157,7 +157,7 @@ export struct ImageKnifeComponent { * 待onReady执行的时候执行 * @param nextFunction 下一个方法 */ - runNextFunction(nextFunction:Function){ + runNextFunction(nextFunction:()=>void){ if(!this.canvasHasReady){ // canvas未初始化完成 this.onReadyNext = nextFunction; @@ -309,8 +309,6 @@ export struct ImageKnifeComponent { }) } } - - } displayMainSource(data: ImageKnifeData) { diff --git a/imageknife/src/main/ets/components/imageknife/utils/LogUtil.ets b/imageknife/src/main/ets/components/imageknife/utils/LogUtil.ets index 21add41..27ff820 100644 --- a/imageknife/src/main/ets/components/imageknife/utils/LogUtil.ets +++ b/imageknife/src/main/ets/components/imageknife/utils/LogUtil.ets @@ -13,34 +13,43 @@ * limitations under the License. */ export class LogUtil { - public static isDebug = false; + public static OFF: number = 1 + public static LOG: number = 2 + public static DEBUG: number = 3 + public static INFO: number = 4 + public static WARN: number = 5 + public static ERROR: number = 6 + public static ALL: number = 7 + public static mLogLevel:number = LogUtil.OFF; - public static debug(info: string) { - if (this.isDebug) { - console.debug(info) + public static debug(message: string, ...args: any[]) { + if (LogUtil.mLogLevel >= LogUtil.DEBUG) { + console.debug(message, args) } } - public static info(info: string) { - if (this.isDebug) { - console.info(info) + public static info(message: string, ...args: any[]) { + if (LogUtil.mLogLevel >= LogUtil.INFO) { + console.info(message, args) } } - public static log(info: string) { - if (this.isDebug) { - console.log(info) + public static log(message: string, ...args: any[]) { + if (LogUtil.mLogLevel >= LogUtil.LOG) { + console.log(message, args) } } - public static warn(info: string) { - if (this.isDebug) { - console.warn(info) + public static warn(message: string, ...args: any[]) { + if (LogUtil.mLogLevel >= LogUtil.WARN) { + console.warn(message, args) } } // error 不做拦截 - public static error(info: string) { - console.error(info) + public static error(message: string, ...args: any[]) { + if(LogUtil.mLogLevel >= LogUtil.ERROR) { + console.error(message, args) + } } } \ No newline at end of file