<template>
<section class="signature">
<div class="signatureBox">
<div class="canvasBox" ref="canvasHW">
<canvas ref="canvasF"
@touchstart='touchStart'
@touchmove='touchMove'
@touchend='touchEnd'
@mousedown="mouseDown"
@mousemove="mouseMove"
@mouseup="mouseUp"
>
</canvas>
<div class="btnBox">
<button @click="overwrite">重新签名</button>
<button @click="commit">提交签名</button>
</div>
</div>
</div>
<img class="imgCanvas" :src="imgUrl">
</section>
</template> <script>
export default {
data() {
return {
stageInfo:'',
imgUrl:'',
client: {},
points: [],
canvasTxt: null,
startX: 0,
startY: 0,
moveY: 0,
moveX: 0,
endY: 0,
endX: 0,
w: null,
h: null,
isDown: false,
// isViewAutograph: this.$route.query.isViews > 0,
// contractSuccess: this.$route.query.contractSuccess
}
},
mounted() {
let canvas = this.$refs.canvasF
canvas.height = this.$refs.canvasHW.offsetHeight - 500
canvas.width = this.$refs.canvasHW.offsetWidth - 2
this.canvasTxt = canvas.getContext('2d')
this.stageInfo = canvas.getBoundingClientRect()
this.canvasTxt.lineWidth = 3; // 线条宽度
},
methods: {
//mobile
touchStart(ev) {
ev = ev || event
ev.preventDefault()
if (ev.touches.length == 1) {
let obj = {
x: ev.targetTouches[0].clientX,
y: ev.targetTouches[0].clientY,
}
this.startX = obj.x
this.startY = obj.y
this.canvasTxt.beginPath()
this.canvasTxt.moveTo(this.startX, this.startY)
this.canvasTxt.lineTo(obj.x, obj.y)
this.canvasTxt.stroke()
this.canvasTxt.closePath()
this.points.push(obj)
}
},
touchMove(ev) {
ev = ev || event
ev.preventDefault()
if (ev.touches.length == 1) {
let obj = {
x: ev.targetTouches[0].clientX - this.stageInfo.left,
y: ev.targetTouches[0].clientY - this.stageInfo.top
}
this.moveY = obj.y
this.moveX = obj.x
this.canvasTxt.beginPath()
// strokeStyle = 'blue';
this.canvasTxt.moveTo(this.startX, this.startY)
this.canvasTxt.lineTo(obj.x, obj.y)
this.canvasTxt.stroke()
this.canvasTxt.closePath()
this.startY = obj.y
this.startX = obj.x
this.points.push(obj)
}
},
touchEnd(ev) {
ev = ev || event
ev.preventDefault()
if (ev.touches.length == 1) {
let obj = {
x: ev.targetTouches[0].clientX - this.stageInfo.left,
y: ev.targetTouches[0].clientY - this.stageInfo.top
}
this.canvasTxt.beginPath()
this.canvasTxt.moveTo(this.startX, this.startY)
this.canvasTxt.lineTo(obj.x, obj.y)
this.canvasTxt.stroke()
this.canvasTxt.closePath()
this.points.push(obj)
}
},
//pc
mouseDown(ev) {
ev = ev || event
ev.preventDefault()
if (1) {
let obj = {
x: ev.offsetX,
y: ev.offsetY
}
this.startX = obj.x
this.startY = obj.y
this.canvasTxt.beginPath()
this.canvasTxt.moveTo(this.startX, this.startY)
this.canvasTxt.lineTo(obj.x, obj.y)
this.canvasTxt.stroke()
this.canvasTxt.closePath()
this.points.push(obj)
this.isDown = true
}
},
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.canvasTxt.beginPath()
this.canvasTxt.moveTo(this.startX, this.startY)
this.canvasTxt.lineTo(obj.x, obj.y)
this.canvasTxt.stroke()
this.canvasTxt.closePath()
this.startY = obj.y
this.startX = obj.x
this.points.push(obj)
}
},
mouseUp(ev) {
ev = ev || event
ev.preventDefault()
if (1) {
let obj = {
x: ev.offsetX,
y: ev.offsetY
}
this.canvasTxt.beginPath()
this.canvasTxt.moveTo(this.startX, this.startY)
this.canvasTxt.lineTo(obj.x, obj.y)
this.canvasTxt.stroke()
this.canvasTxt.closePath()
this.points.push(obj)
this.points.push({x: -1, y: -1})
this.isDown = false
}
},
//重写
overwrite() {
this.canvasTxt.clearRect(0, 0, this.$refs.canvasF.width, this.$refs.canvasF.height)
this.points = []
},
//提交签名
commit() {
this.imgUrl=this.$refs.canvasF.toDataURL();
console.log(this.$refs.canvasF.toDataURL()) //签名img回传后台
}
}
}
</script> <style scoped>
.signatureBox {
width: 100%;
height: calc(100% - 50px);
box-sizing: border-box;
overflow: hidden;
background: #fff;
z-index: 100;
display: flex;
flex-direction: column;
}
.canvasBox {
box-sizing: border-box;
flex: 1;
}
.canvasBox canvas {
border: 1px solid #7d7d7d;
}
.btnBox {
padding: 10px;
text-align: center;
}
.btnBox button:first-of-type {
background: transparent;
border-radius: 4px;
height: 34px;
width: 80px;
font-size: 14px;
color: #71b900;
border: 1px solid #71b900;
}
.btnBox button:last-of-type {
background: #71b900;
color: #fff;
border-radius: 4px;
height: 34px;
width: 80px;
border: none;
font-size: 14px;
}
</style>

vue移动端在线签名的更多相关文章

  1. Egg + Vue 服务端渲染工程化实现

    在实现 egg + vue 服务端渲染工程化实现之前,我们先来看看前面两篇关于Webpack构建和Egg的文章: 在 Webpack工程化解决方案easywebpack 文章中我们提到了基于 Vue ...

  2. Vue PC端框架

    Vue PC端框架 1. Element 中文文档:http://element-cn.eleme.io/#/zh-CN github地址:https://github.com/ElemeFE/ele ...

  3. Odoo : 门店订货及在线签名免费开源方案

    引言 Odoo是欧洲开发的,世界排名第一的开源免费ERP系统.该系统从2002开始研发,经过十几年的发展,去年下半年发布了12.0版.该软件因为免费下载,源代码开放,吸引了世界范围很多人参与使用及开发 ...

  4. Vue移动端项目模板

    一个集成移动端开发插件的Vue移动端模板包含1.css: 使用stylus开发css 集成reset样式文件 修改UI组件文件 统一样式处理(如主题色等)2.UI组件 使用热门的vant与mint-u ...

  5. 用pdf.js实现在移动端在线预览pdf文件

    用pdf.js实现在移动端在线预览pdf文件1.下载pdf.js    官网地址:https://mozilla.github.io/pdf.js/ 2.配置    下载下来的文件包,就是一个demo ...

  6. 创建您的 ActiveReports Web端在线报表设计器

    概述 ActiveReports Web端在线报表设计器已经正式上线!看到它这么帅气.实用,你是不是也想自己动手创建一个? 现在我们就来教您,如何创建一个简单的 ActiveReports Web端在 ...

  7. vue移动端金融UI组件库滴滴MandMobile面向金融场景设计附功能思维导图

    vue移动端金融UI组件库滴滴MandMobile面向金融场景设计附功能思维导图 Mand Mobile是面向金融场景设计的移动端组件库,基于Vue.js实现.目前已实际应用于滴滴四大金融业务板块的1 ...

  8. vue移动端h5页面根据屏幕适配的四种方案

    最近做了两个关于h5页面对接公众号的项目,不得不提打开微信浏览器内置地图导航的功能确实有点恶心.下次想起来了的话,进行总结分享一下如何处理.在vue移动端h5页面当中,其中适配是经常会遇到的问题,这块 ...

  9. 阿里云OSS-web直传---在服务端c#签名,浏览器直传

    OSS web直传---在服务端php签名,浏览器直传 本文:OSS web直传---在服务端c#签名,浏览器直传 其他语言的范例地址:https://help.aliyun.com/document ...

  10. vue服务端渲染axios预取数据

    首先是要参考vue服务端渲染教程:https://ssr.vuejs.org/zh/data.html. 本文主要代码均参考教程得来.基本原理如下,拷贝的原文教程. 为了解决这个问题,获取的数据需要位 ...

随机推荐

  1. 基于注解的AOP

    1.引入依赖 <!--spring aop依赖--> <dependency> <groupId>org.springframework</groupId&g ...

  2. go - 泛型

    为什么要用泛型 在 go 1.18 前的版本中,如果对传入参数的值不确定时,就要使用空接口的方法传参,然后通过对参数进行断言的方式,取出原结构体. 对泛型切片进行遍历 func printSlice[ ...

  3. 解决504 GATEWAY TIMEOUT Nginx网关超时

    最近遇到一个问题504 GATEWAY TIMEOUT的问题,在浏览器的NetWork里面看是这个效果.时间大概是60s. 修改nginx配置 目前后端技术架构主要是nginx和php-fpm,前端主 ...

  4. python逐行读取替换文件中的字符串

    用列表中的值逐行替换文件中符合条件的字符串,并保存为新的文件, open("file").readlines 方案1: 逐行替换并保存为新的文件 import re def rep ...

  5. css设置背景图(背景图太大导致图片显示不全)

    .bg{background:url('/back.png');filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(sizi ...

  6. jquery获取单选按钮选中的值

    jQuery 取选中的radio的值方法 var val=$('input:radio[name="sex"]:checked').val(); 附三种方法都可以: $('inpu ...

  7. dart extends 覆盖规则

    1,不覆写super的变量,child会自动继承super的变量.即使是在child里给super赋值,child里也是可以访问到的,可能是因为引用的关系. 2,只要覆写了super的变量,只给sup ...

  8. idea 导入项目之后,只显示项目文件,不显示项目结构

    导入项目之后,只显示项目文件,不显示项目结构 解决方法 1.点击file->project structure..->Modules 点击右上角+加号 ->import Module ...

  9. iOS SDK开发

    一款好用且设计充分的 SDK 必须要遵循以下 4 条基本原则,即: 1.SDK 安全,稳定2.统一的开发规范3.Library 小而精4.不依赖第三方 SDK安全,稳定:考虑到 SDK 是需要嵌入到 ...

  10. node_modules/canvas npm ERR! command failed

    Installing packages. This might take a couple of minutes.Installing react, react-dom, and react-scri ...