|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<multi-color-background show-go-back="1">
|
|
|
<h1 class="title">手绘签名</h1>
|
|
|
- <div class="inner draw" >
|
|
|
+ <div class="inner draw">
|
|
|
<div class="canvas-container" @mousemove="beginPath($event)">
|
|
|
<canvas
|
|
|
id="canvas"
|
|
@@ -48,6 +48,8 @@
|
|
|
</multi-color-background>
|
|
|
</template>
|
|
|
<script>
|
|
|
+
|
|
|
+
|
|
|
import MultiColorBackground from "../components/multiColorBackground";
|
|
|
export default {
|
|
|
components: {MultiColorBackground},
|
|
@@ -76,6 +78,27 @@
|
|
|
created () {
|
|
|
},
|
|
|
mounted () {
|
|
|
+ var content = document.getElementById('canvas');
|
|
|
+ if(content){
|
|
|
+ content.addEventListener('touchstart', function (event) {
|
|
|
+ this.allowUp = (this.scrollTop > 0);
|
|
|
+ this.allowDown = (this.scrollTop < this.scrollHeight - this.clientHeight);
|
|
|
+ this.slideBeginY = event.pageY;
|
|
|
+ });
|
|
|
+
|
|
|
+ content.addEventListener('touchmove', function (event) {
|
|
|
+ var up = (event.pageY > this.slideBeginY);
|
|
|
+ var down = (event.pageY < this.slideBeginY);
|
|
|
+ this.slideBeginY = event.pageY;
|
|
|
+ if ((up && this.allowUp) || (down && this.allowDown)) {
|
|
|
+ event.stopPropagation();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ event.preventDefault();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // console.log('hellp')
|
|
|
const canvas = document.querySelector('#canvas')
|
|
|
this.canvasHeight=parseFloat(window.getComputedStyle(canvas).getPropertyValue('height'));
|
|
|
this.canvasWidth=parseFloat(window.getComputedStyle(canvas).getPropertyValue('width'));
|
|
@@ -107,6 +130,7 @@
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+
|
|
|
isPc () {
|
|
|
const userAgentInfo = navigator.userAgent
|
|
|
const Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod']
|
|
@@ -133,13 +157,9 @@
|
|
|
const t = e.target
|
|
|
let canvasX
|
|
|
let canvasY
|
|
|
- if (this.isPc()) {
|
|
|
- canvasX = e.clientX - t.parentNode.offsetLeft
|
|
|
- canvasY = e.clientY - t.parentNode.offsetTop
|
|
|
- } else {
|
|
|
- canvasX = e.changedTouches[0].clientX - t.parentNode.offsetLeft
|
|
|
- canvasY = e.changedTouches[0].clientY - t.parentNode.offsetTop
|
|
|
- }
|
|
|
+ canvasX = e.touches[0].clientX - t.parentNode.offsetLeft
|
|
|
+ canvasY = e.touches[0].clientY - t.parentNode.offsetTop
|
|
|
+
|
|
|
this.context.lineTo(canvasX, canvasY)
|
|
|
this.context.stroke()
|
|
|
}
|
|
@@ -172,8 +192,10 @@
|
|
|
this.canvasMoveUse = true
|
|
|
// client是基于整个页面的坐标
|
|
|
// offset是cavas距离顶部以及左边的距离
|
|
|
- const canvasX = e.clientX - e.target.parentNode.offsetLeft
|
|
|
- const canvasY = e.clientY - e.target.parentNode.offsetTop
|
|
|
+ console.log(e)
|
|
|
+ console.log('a',e.touches[0].clientX,e.touches[0].clientY,e.target.parentNode.offsetLeft,e.target.parentNode.offsetTop)
|
|
|
+ const canvasX = e.touches[0].clientX -e.target.parentNode.offsetLeft
|
|
|
+ const canvasY = e.touches[0].clientY - e.target.parentNode.offsetTop
|
|
|
this.setCanvasStyle()
|
|
|
// 清除子路径
|
|
|
this.context.beginPath()
|
|
@@ -234,11 +256,6 @@
|
|
|
}
|
|
|
</script>
|
|
|
<style >
|
|
|
- .title{
|
|
|
- color:white;
|
|
|
- font-size: 0.5rem;
|
|
|
- margin-top: 0.6rem;
|
|
|
- }
|
|
|
.control{
|
|
|
|
|
|
width: 100%;
|
|
@@ -291,6 +308,7 @@
|
|
|
text-align: right;
|
|
|
}
|
|
|
#canvas{
|
|
|
+ /*position: absolute;*/
|
|
|
width: 100%;
|
|
|
/*width: 100%;*/
|
|
|
height: 11.1rem;
|