From d141e4bb90c5034530361751d96d4c98fe71ca23 Mon Sep 17 00:00:00 2001 From: ZhangQ <12903047+zq-kexin@user.noreply.gitee.com> Date: Mon, 8 Sep 2025 07:39:15 +0000 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZhangQ <12903047+zq-kexin@user.noreply.gitee.com> --- entry/src/main/ets/pages/Index.ets | 41 ++++++++++-------- entry/src/main/ets/viewmodel/DrawInvoker.ets | 45 ++++++++++++++++---- 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index a2c295c..246e3dd 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -21,6 +21,8 @@ import NormalBrush from '../viewmodel/IBrush'; import Paint from '../viewmodel/Paint'; import { CommonConstants } from '../common/CommonConstants'; import { myPaintSheet } from '../view/myPaintSheet'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component @@ -57,23 +59,28 @@ struct DrawCanvas { this.mPaint.setColor(CommonConstants.BLACK); this.mPaint.setGlobalAlpha(CommonConstants.ONE); this.mBrush = new NormalBrush(); - display.on('foldStatusChange', (data: display.FoldStatus) => { - if (data === 2) { - this.scaleValueX = 0.5; - this.pinchValueX = 0.5; - this.scaleValueY = 1; - this.pinchValueY = 1; - this.context.clearRect(0, 0, this.context.width, this.context.height); - this.drawInvoker.execute(this.context); - } else if (data === 1) { - this.scaleValueX = 1; - this.scaleValueY = 1; - this.pinchValueX = 1; - this.pinchValueY = 1; - this.context.clearRect(0, 0, this.context.width, this.context.height); - this.drawInvoker.execute(this.context); - } - }) + try { + display.on('foldStatusChange', (data: display.FoldStatus) => { + if (data === 2) { + this.scaleValueX = 0.5; + this.pinchValueX = 0.5; + this.scaleValueY = 1; + this.pinchValueY = 1; + this.context.clearRect(0, 0, this.context.width, this.context.height); + this.drawInvoker.execute(this.context); + } else if (data === 1) { + this.scaleValueX = 1; + this.scaleValueY = 1; + this.pinchValueX = 1; + this.pinchValueY = 1; + this.context.clearRect(0, 0, this.context.width, this.context.height); + this.drawInvoker.execute(this.context); + } + }) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'Index', `listen foldStatusChange failed. code=${err.code}, message=${err.message}`); + } } createDraw() { diff --git a/entry/src/main/ets/viewmodel/DrawInvoker.ets b/entry/src/main/ets/viewmodel/DrawInvoker.ets index c82999f..4ad0b22 100644 --- a/entry/src/main/ets/viewmodel/DrawInvoker.ets +++ b/entry/src/main/ets/viewmodel/DrawInvoker.ets @@ -15,6 +15,8 @@ import { List } from '@kit.ArkTS'; import DrawPath from './IDraw'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; export default class DrawInvoker { // Draw list. @@ -23,22 +25,37 @@ export default class DrawInvoker { private redoList: Array = new Array(); add(command: DrawPath): void { - this.drawPathList.add(command); + try { + this.drawPathList.add(command); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `list add failed. code=${err.code}, message=${err.message}`); + } this.redoList = []; } clear(): void { if (this.drawPathList.length > 0 || this.redoList.length > 0) { - this.drawPathList.clear(); + try { + this.drawPathList.clear(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `list clear failed. code=${err.code}, message=${err.message}`); + } this.redoList = []; } } undo(): void { if (this.drawPathList.length > 0) { - let undo: DrawPath = this.drawPathList.get(this.drawPathList.length - 1); - this.drawPathList.removeByIndex(this.drawPathList.length - 1); - this.redoList.push(undo) + try { + let undo: DrawPath = this.drawPathList.get(this.drawPathList.length - 1); + this.drawPathList.removeByIndex(this.drawPathList.length - 1); + this.redoList.push(undo) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `undo failed. code=${err.code}, message=${err.message}`); + } } } @@ -46,15 +63,25 @@ export default class DrawInvoker { if (this.redoList.length > 0) { let redoCommand = this.redoList[this.redoList.length - 1]; this.redoList.pop(); - this.drawPathList.add(redoCommand); + try { + this.drawPathList.add(redoCommand); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `list add failed. code=${err.code}, message=${err.message}`); + } } } execute(context: CanvasRenderingContext2D): void { if (this.drawPathList !== null) { - this.drawPathList.forEach((element: DrawPath) => { - element.draw(context); - }); + try { + this.drawPathList.forEach((element: DrawPath) => { + element.draw(context); + }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `execute failed. code=${err.code}, message=${err.message}`); + } } } -- Gitee