代码如下:

点击签名1

点击签名2

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

},

}

}

.imgs{width: 500upx;height: 500upx;display: flex;margin: 0 auto;flex-wrap: wrap;}

.imgs img{width: 100%; height: 100%;}

插件代码:

@touchcancel='cancel' @longtap='tap' disable-scroll='true' @error='error' />

清除

保存

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.visible

this.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)

}

}

}

.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

}

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

  1. 如何为MNIST手写数字分类开发CNN

    导言 MNIST手写数字分类问题是计算机视觉和深度学习中使用的标准数据集. 虽然数据集得到了有效的解决,但它可以作为学习和实践如何开发,评估和使用卷积深度学习神经网络从头开始进行图像分类的基础.这包括 ...

  2. 【手写系列】纯手写实现一个高可用的RPC

    前言 在实际后台服务开发中,比如订单服务(开发者A负责)需要调用商品服务(开发者B负责),那么开发者B会和A约定调用API,以接口的形式提供给A.通常都是B把API上传到Maven私服,然后B开始写A ...

  3. 手写篇:如何手写RPC框架?

    手写篇:如何手写RPC框架? 首先我们讲下什么是RPC? RPC(Remote Procedure Call)远程过程调用协议,他是一种通过网络从远程计算机程序请求服务.简单的来说,就是通过网络进行远 ...

  4. 【手写系列】纯手写实现JDK动态代理

    前言 在Java领域,动态代理应用非常广泛,特别是流行的Spring/MyBatis等框架.JDK本身是有实现动态代理技术的,不过要求被代理的类必须实现接口,不过cglib对这一不足进行了有效补充.本 ...

  5. 手写键盘计算机,手写键盘怎么用 手写键盘使用技巧【详解】

    [电脑手写板输入法]手写键盘用户使用指导 手写键盘使用技巧 手写键盘用户使用指导 手写键盘巧妙的将 手写板 和键盘.鼠标结合到一起,备受用户青睐,需要文字录入时可以用手写板写字,平时可以用键盘进行一些 ...

  6. uniapp手写_【转】uni-app框架纯手写微信小程序开发左侧滑动菜单

    本帖最后由 fengrui99 于 2020-7-22 14:38 编辑 原文来自:在学习的uni-app的微信小程序开发路上慢慢开始不一直依赖插件(但是使用插件是真的香,一直用一直香) 在大佬的指引 ...

  7. uniapp手写_uni-app框架纯手写微信小程序开发左侧滑动菜单

    原来到最后才发现有些东西,没有就真的没有.不行,就真的不行 唠叨一会 在学习的uni-app的微信小程序开发路上慢慢开始不一直依赖插件(但是使用插件是真的香,一直用一直香),在大佬的指引下学会自己去写 ...

  8. uniapp手写_手写签名

    前言: 简单的手写签名 参考 https://www.auiaa.com/fron/uni/2019-03-17/103.html 的例子,进行了修改 主要代码 @touchcancel='cance ...

  9. python乘法符号手写_利用Python自动生成小学生加减乘除口算考试题卷,不再为手写算术题烦恼!...

    还在为给孩子抄各种各样的口算题而烦恼?孩子上小学一年级之后,加减乘除的口算就要开始练习了,老师肯定会让家长出题.所以我们当家长的,要提前准备一下,就利用Python开发了一套自动生成小学生口算题的小应 ...

  10. ios手写_如何在iOS 10中发送手写和数字触摸消息

    ios手写 We live in a very high-tech world. We walk around with our heads bowed down to our phones tapp ...

最新文章

  1. 三、概念数据模型CDM(Conceptual Database Model )
  2. 数据结构Queue:poll、offer、element、peek
  3. C# WinForm 技巧十: 开发工具
  4. python字典里可以放列表吗_学习python之列表及字典
  5. Nginx 代理服务的配置说明
  6. 锁屏界面显示某些设置已隐藏_iOS 14 隐藏功能,只要轻点手机背面就能截屏
  7. 索尼Xperia 5 II官方高清渲染图曝光:还是那个熟悉的小屏旗舰
  8. 苹果x与苹果xs的区别_卡通与苹果Xs手机壳的完美邂逅,可爱气质萦绕指尖
  9. 伪标记是一种简单的半监督学习方法
  10. Ubuntu英语环境下完全显示文泉驿微米黑字体的字体配置文件
  11. android Intent调用地图应用客户端
  12. IEC60870-5-101基本远动任务通信协议测试方法
  13. 分享几个PPT模板免费下载的网站
  14. 不看公式自己复原魔方
  15. 本科毕业论文的引言怎么写?
  16. ISPRS2020/遥感云检测:Transferring deep learning models for cloud detection between Landsat-8 and Proba-V
  17. [量化学院]使用cvxopt包实现马科维茨投资组合优化:以一个股票策略为例
  18. Simple-fasterrcnn源码学习笔记(4)
  19. 输出下三角数字阵列C语言
  20. Shell脚本编程案例集(持续更新)

热门文章

  1. DevExpress GridView 自定义实现底部汇总
  2. 【基于STM32F407IGT6】STemWin5.20d + uCOS-III + FatFS程序下载
  3. 【转贴】使用和制作patch文件
  4. 在场景中添加光线——在反光表面添加镜面高光
  5. 趣味思考--苹果剩余最大量
  6. C#小游戏-------猜数字(转载)
  7. 三种前端手机开发(uni-app、vant、mui)
  8. Android7.1 audio 播放流程(三十五)
  9. Pulseaudio之meson编译(十二)
  10. FFmpeg之yuv镜像(十八)