电子签名

This commit is contained in:
bb_pan 2025-08-30 17:36:41 +08:00
parent 30a1fce82a
commit 4b3e10b980
1 changed files with 36 additions and 23 deletions

View File

@ -1,17 +1,18 @@
<template> <template>
<view <view
class="whole canvas-autograph flexc" class="whole canvas-autograph flex"
@touchmove.prevent.stop @touchmove.prevent.stop
@wheel.prevent.stop @wheel.prevent.stop
v-show="modelValue" v-show="modelValue"
style="overflow: hidden"
> >
<canvas <canvas
class="scroll-view" class="scroll-view"
id="mycanvas" id="mycanvas"
canvas-id="mycanvas" canvas-id="mycanvas"
@touchstart="touchstart" @touchstart.prevent.stop="touchstart"
@touchmove="touchmove" @touchmove.prevent.stop="touchmove"
@touchend="touchend" @touchend.prevent.stop="touchend"
disable-scroll="true" disable-scroll="true"
/> />
<view class="fun-box"> <view class="fun-box">
@ -130,7 +131,8 @@ const drawBackground = (ctx, width = 100, height = 100) => {
ctx.stroke() ctx.stroke()
// //
ctx.setFontSize(190) const fontSize = nickName.value.length == 5 ? 140 : 190
ctx.setFontSize(fontSize)
ctx.setFillStyle('rgba(180,180,180,0.25)') ctx.setFillStyle('rgba(180,180,180,0.25)')
ctx.setTextAlign('center') ctx.setTextAlign('center')
ctx.setTextBaseline('middle') ctx.setTextBaseline('middle')
@ -168,28 +170,39 @@ const touchstart = (e) => {
canvaCtx.draw(true) canvaCtx.draw(true)
} }
let isDrawing = false
let lastMoveTime = 0
const throttleInterval = 6 // 50ms
const touchmove = (e) => { const touchmove = (e) => {
const now = Date.now()
if (now - lastMoveTime > throttleInterval) {
lastMoveTime = now
const x = e.changedTouches[0].x const x = e.changedTouches[0].x
const y = e.changedTouches[0].y const y = e.changedTouches[0].y
const p = { X: x, Y: y } const p = { X: x, Y: y }
//
const cur = paths.value[paths.value.length - 1] const cur = paths.value[paths.value.length - 1]
if (cur) cur.push(p) if (cur) cur.push(p)
// if (cur && cur.length >= 2) {
const prev = cur[cur.length - 2]
canvaCtx.setLineWidth(PEN.width) canvaCtx.setLineWidth(PEN.width)
canvaCtx.setStrokeStyle(PEN.color) canvaCtx.setStrokeStyle(PEN.color)
canvaCtx.setLineCap('round') canvaCtx.setLineCap('round')
canvaCtx.setLineJoin('round') canvaCtx.setLineJoin('round')
if (cur && cur.length >= 2) {
const prev = cur[cur.length - 2]
canvaCtx.beginPath() canvaCtx.beginPath()
canvaCtx.moveTo(prev.X, prev.Y) canvaCtx.moveTo(prev.X, prev.Y)
canvaCtx.lineTo(p.X, p.Y) canvaCtx.lineTo(p.X, p.Y)
canvaCtx.stroke() canvaCtx.stroke()
canvaCtx.draw(true)
//
if (!isDrawing) {
isDrawing = true
canvaCtx.draw(true, () => {
isDrawing = false //
})
}
}
} }
} }