Uniapp 之手写签名

news/2024/9/7 12:16:36/文章来源:https://www.cnblogs.com/yang-2018/p/18327062

一、效果图

二、代码示例

qianming.js

export const qianming = {data() {return {windowWidth: 0,pixelRatio: 0,context: null,points: [],oldPoints: [],qm_width: 280,qm_height: 120,qm_img: ''}},methods: {qm_start() {const systemInfo = uni.getSystemInfoSync()this.windowWidth = systemInfo.windowWidththis.pixelRatio = systemInfo.pixelRatiothis.context = uni.createCanvasContext('canvasId', this)this.context.fillStyle = '#fff'; //背景色
uni.createSelectorQuery().in(this).select("#qianming-box").boundingClientRect((data) => {const width = data.widthconst height = data.heightconst lineWidth = 4 / 750 * this.windowWidththis.context.fillRect(0, 0, width, height)this.context.lineWidth = lineWidththis.context.strokeStyle = '#000' //画笔颜色this.context.lineCap = 'round'this.context.lineJoin = 'round'this.context.stroke()this.context.draw(true)}).exec();},qm_touchstart(e) {this.points.push({x: e.changedTouches[0].x,y: e.changedTouches[0].y})this.context.beginPath()},qm_touchmove(e) {this.points.push({x: e.changedTouches[0].x,y: e.changedTouches[0].y})this.oldPoints = JSON.parse(JSON.stringify(this.points))if (this.points.length > 1) {this.context.moveTo(this.points[0].x, this.points[0].y)this.context.lineTo(this.points[1].x, this.points[1].y)this.points.splice(0, 1)this.context.stroke()this.context.draw(true)}},qm_touchend(e) {this.points = []},qm_reset() {this.context = nullthis.points = []this.oldPoints = []this.qm_start()},qm_save() {if (this.oldPoints.length == 0) {uni.showToast({title: '请进行签名!',icon: 'none'})return}let self = thisuni.canvasToTempFilePath({canvasId: 'canvasId',fileType: self.fileType,quality: 1,width: self.qm_width,height: self.qm_height,destWidth: self.qm_width * self.pixelRatio,destHeight: self.qm_height * self.pixelRatio,success: (res) => {//res.tempFilePath// #ifdef MP-WEIXINlet fileManager = uni.getFileSystemManager();fileManager.readFile({filePath: res.tempFilePath,encoding: 'base64',success: function(data) {// data.data就是base64字符串let base64Data = 'data:image/png;base64,' + data.data;self.qm_img = base64Data},fail: function(err) {console.error(err);}});// #endif// #ifdef APP-PLUSconst path = plus.io.convertLocalFileSystemURL(res.tempFilePath) //绝对路径const fileReader = new plus.io.FileReader()fileReader.readAsDataURL(path)fileReader.onloadend = (res) => { //读取文件成功完成的回调函数console.log(res.target.result) //输出base64内容let base64Data = 'data:image/png;base64,' +res.target.result;self.qm_img = base64Data}// #endifself.toHidePopup('qianming')},fail: (err) => {console.log('生成图片失败:', err)}}, self)},qm_error(e) {console.log('错误信息:', e)}}
}
<my-popup position="qita" :show="qianming" :closeType="true"><view class="prompt-box"><view class="prompt-head">请在空白区域写上你的姓名</view><view class="prompt-body"><view class="prompt-input-box" id="qianming-box"style="height: 240upx;border: 1px dashed rgb(204, 204, 204);"><canvas v-if="qianming" style="width:100%;height:240upx;" class="canvas-item"disable-scroll="true" canvas-id="canvasId" @touchstart="qm_touchstart"@touchmove="qm_touchmove" @touchend="qm_touchend" @error="qm_error"></canvas></view></view><view class="prompt-foot"><view class="prompt-btn mr15" @click.stop="qm_save">确定签名</view><view class="prompt-btn mr15" @click.stop="qm_reset">重写</view><view class="prompt-btn prompt-btn-cancel" @click.stop="toHidePopup('qianming')">取消</view></view></view>
</my-popup>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/772638.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

代码随想录day11 || 150 逆表达式求值 239 滑动窗口最大值 347 前k最高频元素

150 逆波兰表达式计算func evalRPN(tokens []string) int {// 自己想是真的想不出来,看了视频之后有了思路// 本质上逻辑就是遇到数字入栈,遇到运算符号 出栈两个元素然后计算再入栈,最终就是计算结果stack := Constructor()for _, val := range tokens{// 如果数字入栈if i…

计算机组成与体系结构-校验码

奇偶校验码 奇偶校验是一种简单有效的校验方法,这种方法通过在编码中增加一位校验位来使编码中1的个数为奇数(奇校验)或者为偶数(偶校验),只能发现奇数个数据位 出错的情况.循环冗余校验码 CRC(Cyclic RedundancyCheck)循环冗余校验是一种常用的错误检测技术,用于在数据传输…

CAD快捷键命令大全(最全)

勇者无惧,强者无敌。

电影《抓娃娃》迅雷/百度云下载[超清版BT种子][MP4/2.89GB]分享

电影《抓娃娃》是一部由闫非、彭大魔联合执导,沈腾、马丽领衔主演的喜剧电影。该片于2024年7月16日在中国大陆正式上映,以其独特的剧情设定和深刻的主题探讨,迅速吸引了广大观众的关注。影片不仅延续了“沈马组合”一贯的幽默风格,更在喜剧外壳下包裹了深刻的教育主题,让人…

PWM波形生成

背景 方法 定时器 (1)高级定时器timer1, timer8以及通用定时器timer9, timer10, timer11的时钟来源是APB2总线 (2)通用定时器timer2~timer5,通用定时器timer12~timer14以及基本定时器timer6,timer7的时钟来源是APB1总线 (3)当APB1和APB2分频数为1的时候,TIM1、TIM8~TIM…

ComfyUI插件:ComfyUI Impact 节点(一)

前言: 学习ComfyUI是一场持久战,而 ComfyUI Impact 是一个庞大的模块节点库,内置许多非常实用且强大的功能节点 ,例如检测器、细节强化器、预览桥、通配符、Hook、图片发送器、图片接收器等等。通过这些节点的组合运用,我们可以实现的工作有很多,例如自动人脸检测和优化修…

ComfyUI进阶:Comfyroll节点 (最终篇)+应用实例

前言: 学习ComfyUI是一场持久战,而Comfyroll 是一款功能强大的自定义节点集合,专为 ComfyUI 用户打造,旨在提供更加丰富和专业的图像生成与编辑工具。借助这些节点,用户可以在静态图像的精细调整和动态动画的复杂构建方面进行深入探索。Comfyroll 的节点设计简洁易用,功能…

松灵机器人scout mini小车 自主导航(4)——运行lio-sam建图

松灵机器人Scout mini小车运行lio-sam 在之前的工作中,我们已经实现了用小车搭载传感器,采用gmapping建图和navigation导航实现小车在2D环境中自主导航,但是实际我们采用的激光雷达多为三维激光雷达。因此决定采用lio-sam来建图。具体操作步骤如下。 1.下载雷达仿真 1.1下载…

[题解]P2672 [NOIP2015 普及组] 推销员

P2672 [NOIP2015 普及组] 推销员 为了便于操作,将住户信息按疲劳值从大到小排序。 那么对于选\(X\)个住户,有\(2\)种情况:选疲劳值前\(X\)大的住户,答案即为\(\sum\limits_{i=1}^X a[i] + 2\times \max\limits_{i=1}^X s[i]\)。 选疲劳值前\(X-1\)大的住户,然后在剩下的住…

LockSupport

LockSupprot 用来阻塞和唤醒线程,底层实现依赖于 Unsafe 类(后面会细讲)。 该类包含一组用于阻塞和唤醒线程的静态方法,这些方法主要是围绕 park 和 unpark 展开。 public class Main {public static void main(String[] args) {Thread mainThread = Thread.currentThread(…

计算机组成与体系结构-浮点数表示

定点数: 是一种在计算机中表示和处理实数的方法,其中,小数点的位置是固定的,不会随着数值的大小而变化。浮点数: 是计算机中用于表示实数的一种数据类型。小数点 位置浮动浮点数表示阶码(指数部分): 决定了浮点数可以表示的范围。阶码越长,可以表示的指数范围就越大 尾数(有…

渗透

渗透测试 一、简介 ​ 渗透测试(Penetration Testing)是一种通过模拟攻击的技术与方法,挫败目标系统的安全控制措施并获得控制访问权的安全测试方法。 ​ 网络渗透测试主要依据CVE(Common Vulnerabilities and Exposures,通用漏洞与披露)已经发现的安全漏洞,模拟入侵者的攻击…