• 代码如下:
<template><view class="content"><button type="primary" @tap="doss">点击签名1</button><button type="primary" @tap="doss2">点击签名2</button><view class="imgs"><image class="img" :src="img1" mode="widthFix"></image><image class="img" :src="img2" mode="widthFix"></image></view><catSignature canvasId="canvas1"  @close="close" @save="save" :visible="isShow" /><catSignature canvasId="canvas2" @close="close2" @save="save2" :visible="isShow2" /></view>
</template><script>import catSignature from "@/components/cat-signature/cat-signature.vue"export default {components:{catSignature},data() {return {img1:'',img2:'',isShow:false,isShow2:false,}},onLoad() {},methods: {doss(){this.isShow = true;},close(){this.isShow = false;},save(val){this.isShow = false;this.img1 = val},doss2(){this.isShow2 = true;},close2(){this.isShow2 = false;},save2(val){this.isShow2 = false;this.img2 = val},}}
</script><style>.imgs{width: 500upx;height: 500upx;display: flex;margin: 0 auto;flex-wrap: wrap;}.imgs img{width: 100%; height: 100%;}
</style>
  • 插件代码:

<template><view v-if="visibleSync" class="cat-signature" :class="{'visible':show}" @touchmove.stop.prevent="moveHandle"><view class="mask" @tap="close" /><view class="content"><canvas class='firstCanvas' :canvas-id="canvasId" @touchmove='move' @touchstart='start($event)' @touchend='end'@touchcancel='cancel' @longtap='tap' disable-scroll='true' @error='error' /><view class="btns"><view class="btn" @tap="clear">清除</view><view class="btn" @tap="save">保存</view></view></view></view>
</template><script>var content = null;var touchs = [];var canvasw = 0;var canvash = 0;//获取系统信息uni.getSystemInfo({success: function(res) {canvasw = res.windowWidth;canvash = canvasw * 9 / 16;},})export default{name:'cat-signature',props:{visible: {type: Boolean,default: false},canvasId:{type: String,default: 'firstCanvas'}},data(){return{show:false,visibleSync: false,signImage:'',hasDh:false,}},watch:{visible(val) {this.visibleSync = val;this.show = val;this.getInfo()}},created(options) {this.visibleSync = this.visiblethis.getInfo()setTimeout(() => {this.show = this.visible;}, 100)},methods:{getInfo(){//获得Canvas的上下文content = uni.createCanvasContext(this.canvasId,this)//设置线的颜色content.setStrokeStyle("#000")//设置线的宽度content.setLineWidth(5)//设置线两端端点样式更加圆润content.setLineCap('round')//设置两条线连接处更加圆润content.setLineJoin('round')},// close() {this.show = false;this.hasDh = false;this.$emit('close')},moveHandle(){},// 画布的触摸移动开始手势响应start(e){let point = {x: e.touches[0].x,y: e.touches[0].y,}touchs.push(point);this.hasDh = true},// 画布的触摸移动手势响应move: function(e) {let point = {x: e.touches[0].x,y: e.touches[0].y}touchs.push(point)if (touchs.length >= 2) {this.draw(touchs)}},// 画布的触摸移动结束手势响应end: function(e) {//清空轨迹数组for (let i = 0; i < touchs.length; i++) {touchs.pop()}},// 画布的触摸取消响应cancel: function(e) {// console.log("触摸取消" + e)},// 画布的长按手势响应tap: function(e) {// console.log("长按手势" + e)},error: function(e) {// console.log("画布触摸错误" + e)},//绘制draw: function(touchs) {let point1 = touchs[0]let point2 = touchs[1]// console.log(JSON.stringify(touchs))content.moveTo(point1.x, point1.y)content.lineTo(point2.x, point2.y)content.stroke()content.draw(true);touchs.shift()},//清除操作clear: function() {//清除画布content.clearRect(0, 0, canvasw, canvash)content.draw(true)// this.close()this.hasDh = false;this.$emit('clear')},save(){var that = this;if(!this.hasDh){uni.showToast({title:'请先签字',icon:'none'})return;}uni.showLoading({title:'生成中...',mask:true})setTimeout(()=>{uni.canvasToTempFilePath({canvasId: this.canvasId,success: function(res) {that.signImage = res.tempFilePath;that.$emit('save',res.tempFilePath);uni.hideLoading()that.hasDh = false;that.show = false;},fail:function(err){console.log(err)uni.hideLoading()}},this)},100)}}}
</script><style lang="scss">.cat-signature.visible {visibility: visible}.cat-signature{display: block;position: fixed;top: 0;left: 0;right: 0;bottom: 0;overflow: hidden;z-index: 11;height: 100vh;visibility: hidden;.mask{display: block;opacity: 0;position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: rgba(0, 0, 0, .4);transition: opacity .3s;}.content{display: block;position: absolute;top: 0;left: 0;bottom:0;right: 0;margin: auto; width:94%;height: 500upx;background: #fff;border-radius: 8upx;box-shadow: 0px 3px 3px #333;// canvas.firstCanvas {background-color: #fff;width: 100%;height: 400upx;}// canvas.btns{padding: 0 15px;height: 100upx;overflow: hidden; position: absolute;bottom: 10upx;left: 0;right: 0;margin: auto;display: flex;justify-content: space-between;.btn{width: 40%;text-align: center;font-size: 28upx;height:60upx;line-height: 60upx;background-color: #999;color: #fff;border-radius: 6upx;}}}}.visible .mask {display: block;opacity: 1}
</style>

转载于:https://www.cnblogs.com/neo-java/p/11535899.html

【uniapp 开发】手绘签名组件相关推荐

  1. uniapp手写_【uniapp 开发】手绘签名组件

    代码如下: 点击签名1 点击签名2 import catSignature from "@/components/cat-signature/cat-signature.vue" ...

  2. uniapp 手写签名组件

    组件地址: 手写签名组件,弹框签名,可配置签名,签名返回base64,签名专用 - DCloud 插件市场 # 欢迎使用 手写签名组件 **手写签名组件,签名后可以获取到base64编码,同时内置了弹 ...

  3. 记录一下小程序的手写签名组件

    文章目录 前言 一..js文件的内容 二..json文件的内容 三..wxml文件的内容 四..wxss文件的内容 五.要引用的.wxml文件的内容 六.要引用的.js文件的内容 七.总结 前言 由于 ...

  4. 这是你从未见过的组件库 -- Android 上的手绘风格组件

    之前看到一位作者开源了一款手绘风格的图表库 Chart.xkcd,感觉很是喜欢. 当然仅仅图表是满足不了我滴,于是想看看 Android 上是否有类似的开源库,一番搜索之后,颗粒无收. 想想原理可能不 ...

  5. uni-app 实现手写签名

    代码主要是参考: 实现 uniapp 手写签名功能 - 简书 本示例主要包含三个功能: 1.绘制签名笔迹 2.判断当前是否已经签名 (食之无味,弃之可惜的功能,聊胜于无吧哈哈哈哈) 3.根据实际需求旋 ...

  6. vue canvas手绘签名

    需求 公司业务想要在手机端h5搞个签名需求.签名好像在哪里见到过:好像钉钉上请假时有个签名可以仿照写一个 思路想法 既然是绘制 那想到的是用 canvas 或者svg 应该都可以 既然canvas 或 ...

  7. uniapp的手写签名,当签名时,页面会滑动

    这两天在开发一款手机端,涉及到了手写签名的功能,,当测试的时候,手指在页面上写名字的时候,页面总会跟着滑动,找了很久,在微信开发者工具的官方文档中找到了答案,关闭页面的回弹效果即可,再次测试,页面就不 ...

  8. 安卓开发-手绘板自定义绘画的保存,清空与恢复

    写这篇文章是因为代码中刚实现过这些功能,害怕自己之后会忘记,所以把整个方法写出来,方便自己日后复习用. 还是老样子,先上图: 1.首页 2.点击手绘板图片后跳出的窗口 3.用手指进行绘制 4.点击保存 ...

  9. uniapp实现手写签名

    1.主要功能有横屏展示签名.清空.撤销.保存.判断是否有签 上代码!!! 撤销操作的核心代码 // 每次触摸开始,调用uniapp内置的uni.canvasGetImageData将当前画布进行保存u ...

最新文章

  1. LFCS 系列第二讲:如何安装和使用纯文本编辑器 vi/vim
  2. Scribe日志收集工具
  3. python的窗口处理模块_Python tkinter模块弹出窗口及传值回到主窗口操作详解
  4. Java黑皮书课后题第6章:6.12(显示字符)使用下面的方法头,编写一个打印字符的方法。编写一个测试程序、打印从‘1‘到‘Z‘的字符,每行打印10个,字符之间使用一个空格字符隔开
  5. 【Redis学习】Redis数据类型及存储结构
  6. java有any类型吗_Java开发网 - 一个关于CORBA中any类型的问题
  7. .NET Core 从 Github到 Nuget 持续集成、部署
  8. linux 移动硬盘 大于4g,Linux下挂大于2G的NTFS格式移动硬盘方法
  9. webdriver原理_(最新版)如何正确移除 Pyppeteer 中的window.navigator.webdriver
  10. Hadoop_28_MapReduce_自定义 inputFormat
  11. C语言中的`sprintf`和`sscanf`两个函数介绍
  12. Anaconda 最新版本的下载和安装
  13. 搜索引擎算法研究(一)
  14. 如何把图片的文字转换成word
  15. 【无代码爬虫】web scraper 之 采集单个内容
  16. 数据分析专题报告范文6篇_数据分析系列篇(6):如何写好一个专题的分析报告...
  17. 【Python 基础教程】Python语言中的数据类型(二)
  18. 生成树协议(RTP、RSTP、MSTP)
  19. P,MTHBGWB 水题
  20. 牛客网错题集系列(三)

热门文章

  1. 医疗大数据分析的几个重点方向
  2. 北京电信校招面试准备
  3. 测试工程师职业生涯规划
  4. 一文搞懂数据转换之摘要、编码、加密、签名
  5. 选择决定命运,不如说是选择自己的命运
  6. 2020-12-17 Scopus文献检索 TargetDetection|Dim|Infrared Image
  7. 计算机网络原理(21)——信道与信道容量、基带传输、频带传输、物理层接口
  8. springcontext.xml 中方言是红色的_影评:陆河方言电影我的村,我的家值得一看
  9. 加密王座游戏攻略——GoDapp
  10. 我又进入天堂2的深渊了