From 41cc00b81bb1c1b42c6e7be075c75cf8b88a5d07 Mon Sep 17 00:00:00 2001 From: ysn <2126564605@qq.com> Date: Mon, 25 May 2026 14:47:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BF=80=E5=85=89=E7=AC=94-=E5=8F=B3=E9=94=AE?= =?UTF-8?q?=E6=92=A4=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../realTimeConsultation.vue | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/src/views/videoCommunication/realTimeConsultation.vue b/src/views/videoCommunication/realTimeConsultation.vue index d057c7b..07a25dc 100644 --- a/src/views/videoCommunication/realTimeConsultation.vue +++ b/src/views/videoCommunication/realTimeConsultation.vue @@ -383,7 +383,7 @@ export default { camOn: true, localStream: null, - // 音频说话波形 + // 音频说话音量波形 audioContext: null, analyser: null, voiceLevels: Array(12).fill(1), @@ -398,6 +398,7 @@ export default { brushLineWidth: 3, brushLineDash: [5, 5], ctx: null, + drawHistory: [], // 画笔历史记录(用于撤销) // ==================== 激光笔工具 ==================== isLaserMode: false, @@ -751,15 +752,55 @@ export default { this.ctx.setLineDash(this.brushLineDash); }, - // 画笔开关 + // 画笔开关(打开时自动清空画布) toggleDraw() { this.isDrawingMode = !this.isDrawingMode; - this.$message.info(this.isDrawingMode ? "画笔开启" : "画笔关闭"); + if (this.isDrawingMode) { + this.clearCanvas(); // 打开画笔 → 清空 + this.$message.info("画笔开启(画布已清空)"); + } else { + this.$message.info("画笔关闭"); + } + }, + + // 清空画布 + clearCanvas() { + const canvas = this.$refs.drawingCanvas; + if (!canvas || !this.ctx) return; + this.ctx.clearRect(0, 0, canvas.width, canvas.height); + this.drawHistory = []; + }, + + // 撤销上一笔(右键) + undoLastDraw() { + if (this.drawHistory.length === 0) return; + this.drawHistory.pop(); + this.ctx.clearRect(0, 0, this.$refs.drawingCanvas.width, this.$refs.drawingCanvas.height); + this.redrawAll(); + this.$message.info("已撤销上一笔"); + }, + + // 重新绘制所有历史 + redrawAll() { + this.drawHistory.forEach((item) => { + this.ctx.beginPath(); + this.ctx.moveTo(item.fromX, item.fromY); + this.ctx.lineTo(item.toX, item.toY); + this.ctx.strokeStyle = item.color; + this.ctx.lineWidth = item.width; + this.ctx.stroke(); + }); }, // 开始绘制 startDrawing(e) { if (!this.isDrawingMode) return; + // 右键 → 撤销 + if (e.button === 2) { + e.preventDefault(); + this.undoLastDraw(); + return; + } this.drawing = true; const c = this.getCoord(e); this.lastX = c.x; @@ -774,6 +815,17 @@ export default { this.ctx.moveTo(this.lastX, this.lastY); this.ctx.lineTo(c.x, c.y); this.ctx.stroke(); + + // 保存历史 + this.drawHistory.push({ + fromX: this.lastX, + fromY: this.lastY, + toX: c.x, + toY: c.y, + color: this.brushColor, + width: this.brushLineWidth, + }); + this.lastX = c.x; this.lastY = c.y; }, @@ -1137,7 +1189,6 @@ export default { }, }; -