激光笔-右键撤回

main
ysn 3 weeks ago
parent 8456e0bb71
commit 41cc00b81b
  1. 59
      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 {
},
};
</script>
<style lang="scss">
.meeting-container {
display: flex;

Loading…
Cancel
Save