diff --git a/pages/component/canvas/canvas.uvue b/pages/component/canvas/canvas.uvue index 084621b574a7e990a9eb95cafe27f56f63b7fd6b..e0dfd7914dfb9172076a9f57bc22cde026f3b40b 100644 --- a/pages/component/canvas/canvas.uvue +++ b/pages/component/canvas/canvas.uvue @@ -1,11 +1,27 @@ @@ -67,9 +62,9 @@ renderingContext: null as CanvasRenderingContext2D | null, canvasWidth: 0, canvasHeight: 0, - dataBase64: '', - taskId: 0, - lastTime: 0, + dataBase64: '', + taskId: 0, + lastTime: 0, frameCount: 0, // 仅测试 testCanvasContext: false, @@ -94,7 +89,7 @@ hidpi(this.canvas!); this.canvasWidth = this.canvas!.width; - this.canvasHeight = this.canvas!.height; + this.canvasHeight = this.canvas!.height; // #ifdef WEB context.toBlob((blob : Blob) => { @@ -113,11 +108,11 @@ // this.canvas = canvas; // this.canvasWidth = canvas.width; // this.canvasHeight = canvas.height; - }, - onUnload() { - if (this.taskId > 0) { - this.stopAnimationFrame() - } + }, + onUnload() { + if (this.taskId > 0) { + this.stopAnimationFrame() + } }, methods: { // #ifdef WEB @@ -130,7 +125,7 @@ canvasToDataURL() { this.dataBase64 = this.canvasContext!.toDataURL() }, - onCreateImage() { + onCreateImage() { this.renderingContext!.clearRect(0, 0, this.canvasWidth, this.canvasHeight) let image = this.canvasContext!.createImage(); image.src = "../../static/logo.png" @@ -159,27 +154,27 @@ path2D.bezierCurveTo(x2, y2, x3, y3, x4, y4); } context.stroke(path2D); - }, - startAnimationFrame() { - this.taskId = this.canvasContext!.requestAnimationFrame((timestamp : number) => { - this.testFrameCount++ - this.updateFPS(timestamp) - this.startAnimationFrame() - }) - }, - stopAnimationFrame() { - this.canvasContext!.cancelAnimationFrame(this.taskId) - this.taskId = 0 - }, - updateFPS(timestamp : number) { - this.frameCount++ - if (timestamp - this.lastTime >= 1000) { - const timeOfFrame = (1000 / this.frameCount) - this.renderingContext!.clearRect(0, 0, this.canvasWidth, this.canvasHeight) - this.renderingContext!.fillText(`${this.frameCount} / ${timeOfFrame.toFixed(3)}ms`, 10, 18) - this.frameCount = 0 - this.lastTime = timestamp - } + }, + startAnimationFrame() { + this.taskId = this.canvasContext!.requestAnimationFrame((timestamp : number) => { + this.testFrameCount++ + this.updateFPS(timestamp) + this.startAnimationFrame() + }) + }, + stopAnimationFrame() { + this.canvasContext!.cancelAnimationFrame(this.taskId) + this.taskId = 0 + }, + updateFPS(timestamp : number) { + this.frameCount++ + if (timestamp - this.lastTime >= 1000) { + const timeOfFrame = (1000 / this.frameCount) + this.renderingContext!.clearRect(0, 0, this.canvasWidth, this.canvasHeight) + this.renderingContext!.fillText(`${this.frameCount} / ${timeOfFrame.toFixed(3)}ms`, 10, 18) + this.frameCount = 0 + this.lastTime = timestamp + } } } }