<template>
<div class="share" style="background:#fff">
<div class="zk-title">
请工整的书写 <span style="color:#06F;">独孤求败</span> 的签字
</div>
<!-- <div style="width:100px;height:100px"><img src="" width="40px" height="40px" id="test"/>88</div> -->
<div class="canvasBox" ref="canvasHW">
<canvas @touchstart='touchStart'
@touchmove='touchMove'
@touchend='touchEnd'
@mousedown="mouseDown"
@mousemove="mouseMove"
@mouseup="mouseUp"
ref="canvasF">
</canvas>
</div>
<div class="btnBox">
<button class="clear" @click="overwrite">清除</button>
<button class="confirm" @click="commit">确认</button>
<button class="cancel" @click="cancel">取消</button>
</div>
</div>
</template>
<script>
export default {
name: 'signature',
data () {
return {
points: [],
startX: 0,
startY: 0,
moveY: 0,
moveX: 0,
endY: 0,
endX: 0,
w: null,
h: null,
imgData: '',
isDown: false,
canvasBoard: null,
canvasContext: null
}
},
mounted () {
this.canvasBoard = this.$refs.canvasF;
this.canvasBoard.height = this.$refs.canvasHW.offsetHeight;
this.canvasBoard.width = this.$refs.canvasHW.offsetWidth;
var ctx = this.canvasBoard.getContext('2d');
this.canvasContext = ctx;
ctx.lineWidth=3;
ctx.font = "Arial";
}, methods: {
back(){ },
// Computer event -- Mouse down
mouseDown (ev) {
ev = ev || event
ev.preventDefault()
console.log(ev) let obj = {
x: ev.offsetX,
y: ev.offsetY
} console.log(obj)
this.startX = obj.x
this.startY = obj.y
this.canvasContext.beginPath()
this.canvasContext.moveTo(this.startX, this.startY)
this.canvasContext.lineTo(obj.x, obj.y)
this.canvasContext.stroke()
this.canvasContext.closePath()
this.points.push(obj)
this.isDown = true
}, // Mobile event -- Touch start
touchStart (ev) {
ev = ev || event
ev.preventDefault()
if (ev.touches.length === 1) {
let obj = {
x: ev.targetTouches[0].clientX,
y: ev.targetTouches[0].clientY - 0//0为y轴的偏移量
} this.startX = obj.x
this.startY = obj.y
this.canvasContext.beginPath()
this.canvasContext.moveTo(this.startX, this.startY)
this.canvasContext.lineTo(obj.x, obj.y)
this.canvasContext.stroke()
this.canvasContext.closePath()
this.points.push(obj)
}
}, // Mobile -- Mouse move
mouseMove (ev) {
ev = ev || event
ev.preventDefault()
if (this.isDown) {
let obj = {
x: ev.offsetX,
y: ev.offsetY
} this.moveY = obj.y
this.moveX = obj.x
this.canvasContext.beginPath()
this.canvasContext.moveTo(this.startX, this.startY)
this.canvasContext.lineTo(obj.x, obj.y)
this.canvasContext.stroke()
this.canvasContext.closePath()
this.startY = obj.y
this.startX = obj.x
this.points.push(obj)
}
}, // Mobile event -- Touch move
touchMove (ev) {
ev = ev || event
ev.preventDefault()
if (ev.touches.length === 1) {
let obj = {
x: ev.targetTouches[0].clientX,
y: ev.targetTouches[0].clientY - 0
} this.moveY = obj.y
this.moveX = obj.x
this.canvasContext.beginPath()
this.canvasContext.moveTo(this.startX, this.startY)
this.canvasContext.lineTo(obj.x, obj.y)
this.canvasContext.stroke()
this.canvasContext.closePath()
this.startY = obj.y
this.startX = obj.x
this.points.push(obj)
}
}, // Computer event -- Mouse up
mouseUp (ev) {
ev = ev || event
ev.preventDefault() let obj = {
x: ev.offsetX,
y: ev.offsetY
} this.canvasContext.beginPath()
this.canvasContext.moveTo(this.startX, this.startY)
this.canvasContext.lineTo(obj.x, obj.y)
this.canvasContext.stroke()
this.canvasContext.closePath()
this.points.push(obj)
this.points.push({x: -1, y: -1})
this.isDown = false
}, // Mobile event TouchEnd
touchEnd (ev) {
ev = ev || event
ev.preventDefault()
console.log(ev)
if (ev.touches.length === 1) {
let obj = {
x: ev.targetTouches[0].clientX,
y: ev.targetTouches[0].clientY - 0
} this.canvasContext.beginPath()
this.canvasContext.moveTo(this.startX, this.startY)
this.canvasContext.lineTo(obj.x, obj.y)
this.canvasContext.stroke()
this.canvasContext.closePath()
this.points.push(obj)
this.points.push({x: -1, y: -1})
}
}, // Over write
overwrite () {
// this.canvasBoard.height
// this.canvasBoard.width
this.canvasContext.clearRect(0, 0, this.$refs.canvasF.width, this.$refs.canvasF.height);
this.points = [];
}, // Commit
commit () {
// this.$refs.mySignature.src = this.$refs.canvasF.toDataURL('image/png')
//this.$store.state.currentSignatureData = this.$refs.canvasF.toDataURL('image/png');
var imgdata = this.$refs.canvasF.toDataURL('image/png');
// var vertical = true;
// var imgdata = signaturePad.toDataURL(); // base64
//alert(Vertical);
// this.upload(imgdata, Vertical);
// 当Vertical为true的时候,后台需要转90度;
// 当Vertical为false的时候,后台不需要转;
document.getElementById('test').src=imgdata;
this.$router.back();
},
upload(imgdata, vertical) {
// $("#clearButton,#backBtn,#subBtn").hide();
//alert("v:"+vertical);
$.ajax({
type : 'POST',
dataType : 'json',
url : $("#url").val(),
data : {
media : imgdata,
v : vertical,
res_code:$("#resCode").val(),
clientId:$("#clientId").val() },
success : function(data) { if (data['error'] != null) {
alert(data['error']);
$("#clearButton,#backBtn,#subBtn").show();
$("#msg").hide();
} else { if (data.url!=null)
location.href = data.url;
else
{
$("#msg").hide();
alert("签署成功");
}
} },
error : function() {
alert("错误:" + error);
$("#clearButton,#backBtn,#subBtn").show();
$("#msg").hide();
}
});
},
cancel(){
this.$router.back();
}
}
}
</script>
<style lang="stylus" scoped>
.share
position absolute
top 0
bottom 0
left 0
right 0
z-index 15
background #fff </style> <style scoped>
.signatureBox{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
overflow: hidden;
background: #fff;
z-index: 100;
display: flex;
flex-direction: column;
} .visaDetailTop p{
margin: 0;
text-align: center;
color: #000;
font-size: 1em;
position: relative;
} .visaDetailTop p span{
color: #fff;
font-size: 1.2em;
} .visaDetailTop p:first-of-type{
float: left;
} .visaDetailTop p:nth-of-type(2){
float: right;
} .canvasBox{
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
box-sizing: border-box;
flex: 1;
font-family: 'Helvetica, Sans-Serif';
font-size: 16px;
} .btnBox{
height: 30px;
padding: 5px;
text-align: right;
line-height: 30px;
}
.btnBox button{
border: 1px solid lightgray;
color: #fff;
border-radius: 4px;
padding: 5px 10px;
width: 60px;
outline:none;
}
.zk-title {
position: absolute;
right: -85px;
top: 85px;
font-size: 16px;
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
canvas {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border-radius: 4px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.02) inset;
} .btnBox {
position: absolute;
left: -68px;
bottom: 90px;
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
.btnBox .clear{
background: #808080;
}
.btnBox .confirm{
background: #04BE02;
}
.btnBox .cancel{
background: #39F;
}
@media only screen and (min-width: 750px){
.signatureBox{
position: absolute;
top: 0;
left: 0;
width: 100%;
min-height: 100%;
box-sizing: border-box;
overflow: visible;
}
}
</style>

  

canvas签名的更多相关文章

  1. vue H5页面手机端 利用canvas 签名

    签名首先用一个canvas标签,上面加三个代码,分别是点击,移动,离开.这里点击是开始画笔的地方,如果不加@touchstart 笔头会发生偏移,可以试试. @toucheend也是如此.尾巴也会出现 ...

  2. 画布canvas签名

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  3. HTML5 中canvas支持触摸屏的签名面板

    1.前言 最近实在是太忙了,从国庆之后的辞职,在慢慢的找工作,到今天在现在的这家公司上班大半个月了,太多的心酸泪无以言表,面试过程中,见到的坑货公司是一家又一家,好几家公司自己都只是上一天班就走了,其 ...

  4. canvas画布实现手写签名效果

    最近项目中涉及到移动端手写签名的功能需求,将实现代码记录于此,供小伙伴们参考指摘哦~ HTML代码: <!--手写区--> <div class="mSign_signMa ...

  5. pc端结合canvas实现简单签名功能

    需求:业务员做提交时要签名... 代码不多简单易懂,直接看代码 <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  6. canvas 实现签名效果

    效果图 概述 在线签名,现在在很多场景下都能看到,而且在移动端见的比较多. 用canvas和svg都可以实现,而且跨平台能力也很好. canvas基于像素,提供 2D 绘制函数,提供的功能更原始,适合 ...

  7. VUE中使用canvas做签名功能,兼容IE

    <template>         <div>           <div class="msgInput">             &l ...

  8. uni-app通过canvas实现手写签名

    分享一个uni-app实现手写签名的方法 具体代码如下: <template> <view > <view class="title">请在下面 ...

  9. 【微信小程序canvas】实现小程序手写板用户签名(附代码)

    工作中公司业务需要的微信小程序用户签字功能 先看效果图: wxml: <view class="wrapper"> <view class="handB ...

随机推荐

  1. 终端less命令执行完之后怎样退出

    Linux中的less命令主要用来浏览文件内容,与more命令的用法相似,不同于more命令的是,less命令可往回卷动浏览以看过的部分,less 的用法比起 more 更加的有弹性.如果想退出les ...

  2. 手写web框架之实现依赖注入功能

    我们在Controller中定义了Service成员变量,然后在Controller的Action方法中调用Service成员变量的方法,那么如果实现Service的成员变量? 之前定义了@Injec ...

  3. 线程池小结(JDK8)

    1.线程池的好处 降低资源消耗(重复利用已创建的线程减少创建和销毁线程的开销) 提高响应速度(无须创建线程) 提高线程的可管理性 2.相关类图 JDK5以后将工作单元和执行机制分离开来,工作单元包括R ...

  4. CentOS7安装openjdk8+环境变量配置

    CentOS7安装openjdk8+环境变量配置 步骤: 使用yum命令安装openjdk yum clean yum install -y java-1.8.0-openjdk-1.8.0.212. ...

  5. 双系统删除Linux系统

    1.首先解决Linux的grub引导问题.电脑先安装了Windows10,然后又安装了Linux,grub直接覆盖了Windows的引导, 所以每次开机都是进入了Linux的grub引导,现在我们需要 ...

  6. 【VS开发】组播(多播)的C程序实战

    每个人都有不同的认知规律和习惯, 有的人喜欢搞一套严密的大理论, 论述起来滔滔不绝, 不管自己懂不懂, 反正读者/听者是没搞懂. 有的人喜欢从实践出发, 没看到代码, 不运行一下, 不看到结果, 就不 ...

  7. e4a 记录

    自动点击 浏览框.跳转("javascript:document.getElementById('按钮的ID').clcik();")

  8. Jenkins学习指南

    jenkinshttps://www.cnblogs.com/jimmy-xuli/p/9020825.htmlhttps://www.cnblogs.com/along21/p/10172855.h ...

  9. Less学习(1)

    写在开头的话: 月余前被问起会不会Less,当时就有想学这个css框架的念头,而在昨天,在前端乱炖上看到一篇LessCss的开篇介绍,忽然就有了一股立马去学的冲动,回到家后找了几篇文章看了下,初感觉比 ...

  10. Springmvc使用注解实现执行定时任务(定时器)

    1.在Spring配置文件中添加 <task:annotation-driven/> 2.在需要调用执行定时任务的类中使用注解 @Service @Lazy(false) //避免spri ...