2023-11-01 18:40:05 +08:00
|
|
|
|
<template>
|
|
|
|
|
<view class="sign">
|
2023-11-13 10:11:34 +08:00
|
|
|
|
<head-view title="绘制质损图"></head-view>
|
2023-11-01 18:40:05 +08:00
|
|
|
|
<view class="containe contentFixedr">
|
|
|
|
|
<view class="sign-box">
|
2024-01-08 15:16:29 +08:00
|
|
|
|
|
2023-11-16 18:04:18 +08:00
|
|
|
|
<canvas class="mycanvas" canvas-id="mycanvas" @touchstart="touchstart" @touchmove="touchmove"
|
|
|
|
|
@touchend="touchend" disable-scroll="true"></canvas>
|
2023-11-13 10:11:34 +08:00
|
|
|
|
<view class="canvasBg">
|
2023-11-28 17:52:09 +08:00
|
|
|
|
<image :src="imgUrl" mode=""></image>
|
2023-11-13 10:11:34 +08:00
|
|
|
|
</view>
|
2023-11-01 18:40:05 +08:00
|
|
|
|
</view>
|
|
|
|
|
<view class="sigh-btns">
|
2023-12-22 17:48:52 +08:00
|
|
|
|
<view class="btn qx" @click="handleCancel">取消</view>
|
|
|
|
|
<view class="btn qc" @click="handleReset">清除</view>
|
|
|
|
|
<view class="btn bc" @click="handleConfirm">保存</view>
|
2023-11-01 18:40:05 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
import {
|
|
|
|
|
pathToBase64,
|
|
|
|
|
base64ToPath
|
|
|
|
|
} from '../../js_sdk/mmmm-image-tools/index.js'
|
|
|
|
|
import utils from '@/common/util.js';
|
|
|
|
|
var x = 20;
|
|
|
|
|
var y = 20;
|
|
|
|
|
var tempPoint = []; //用来存放当前画纸上的轨迹点
|
|
|
|
|
var id = 0;
|
|
|
|
|
var type = '';
|
|
|
|
|
let that;
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
ctx: '', //绘图图像
|
|
|
|
|
points: [], //路径点集合,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
|
|
|
|
loginObj: {},
|
|
|
|
|
signImg: "",
|
2023-11-13 10:11:34 +08:00
|
|
|
|
url: "",
|
2023-11-28 17:52:09 +08:00
|
|
|
|
imgUrl: "",
|
2024-01-08 15:16:29 +08:00
|
|
|
|
ytImg: "",
|
|
|
|
|
isSign: false,
|
2023-11-01 18:40:05 +08:00
|
|
|
|
};
|
|
|
|
|
},
|
2023-11-28 17:52:09 +08:00
|
|
|
|
onLoad(options) {
|
|
|
|
|
if ('params' in options) {
|
|
|
|
|
// 获取传递的对象参数,使用decodeURIComponent解码,并转为对象
|
|
|
|
|
this.imgUrl = JSON.parse(decodeURIComponent(options.params)).imgUrl
|
|
|
|
|
}
|
2023-11-01 18:40:05 +08:00
|
|
|
|
this.loginObj = uni.getStorageSync('loginObj')
|
2023-12-08 17:42:10 +08:00
|
|
|
|
if (this.imgUrl == "") {
|
|
|
|
|
this.handleReset()
|
|
|
|
|
} else {
|
|
|
|
|
this.initImg(this.imgUrl)
|
|
|
|
|
}
|
2023-11-01 18:40:05 +08:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
2023-12-08 17:42:10 +08:00
|
|
|
|
initImg(name) {
|
|
|
|
|
uni.request({
|
|
|
|
|
url: `${this.$local}/api/file/url/?fileName=${name}`,
|
|
|
|
|
header: {
|
|
|
|
|
'Content-Type': 'application/json', //自定义请求头信息
|
|
|
|
|
'Authorization': `Bearer ${this.loginObj.access_token}`
|
|
|
|
|
},
|
|
|
|
|
method: 'GET', //请求方式,必须为大写
|
|
|
|
|
success: (res) => {
|
|
|
|
|
if (res.statusCode == 200) {
|
|
|
|
|
this.imgUrl = res.data
|
2023-12-22 17:48:52 +08:00
|
|
|
|
this.init()
|
2023-12-08 17:42:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2023-11-13 10:11:34 +08:00
|
|
|
|
init() {
|
2023-11-28 17:52:09 +08:00
|
|
|
|
let that = this
|
|
|
|
|
that.ctx = uni.createCanvasContext('mycanvas', that); //创建绘图对象
|
2023-11-13 10:11:34 +08:00
|
|
|
|
//设置画笔样式
|
2023-11-28 17:52:09 +08:00
|
|
|
|
that.ctx.lineWidth = 4;
|
|
|
|
|
that.ctx.lineCap = 'round';
|
|
|
|
|
that.ctx.lineJoin = 'round';
|
2023-11-21 17:43:02 +08:00
|
|
|
|
uni.getImageInfo({
|
2023-11-28 17:52:09 +08:00
|
|
|
|
src: that.imgUrl,
|
2023-11-21 17:43:02 +08:00
|
|
|
|
success(res1) {
|
|
|
|
|
//填充白色背景图片
|
2023-11-28 17:52:09 +08:00
|
|
|
|
that.ctx.drawImage(that.imgUrl, 0, 0, 624, 224);
|
2023-11-13 18:02:20 +08:00
|
|
|
|
},
|
2023-11-28 17:52:09 +08:00
|
|
|
|
fail(res) {
|
|
|
|
|
console.log(res);
|
2023-11-21 17:43:02 +08:00
|
|
|
|
}
|
2023-11-13 10:11:34 +08:00
|
|
|
|
});
|
|
|
|
|
},
|
2023-11-01 18:40:05 +08:00
|
|
|
|
//触摸开始,获取到起点
|
|
|
|
|
touchstart: function(e) {
|
|
|
|
|
let startX = e.changedTouches[0].x;
|
|
|
|
|
let startY = e.changedTouches[0].y;
|
|
|
|
|
let startPoint = {
|
2023-11-21 17:43:02 +08:00
|
|
|
|
X: startX / 1.75,
|
|
|
|
|
Y: startY / 1.75
|
2023-11-01 18:40:05 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* **************************************************
|
|
|
|
|
#由于uni对canvas的实现有所不同,这里需要把起点存起来
|
|
|
|
|
* **************************************************/
|
|
|
|
|
this.points.push(startPoint);
|
2024-01-08 15:16:29 +08:00
|
|
|
|
this.isSign = true
|
2023-11-01 18:40:05 +08:00
|
|
|
|
|
|
|
|
|
//每次触摸开始,开启新的路径
|
|
|
|
|
this.ctx.beginPath();
|
|
|
|
|
},
|
|
|
|
|
//触摸移动,获取到路径点
|
|
|
|
|
touchmove: function(e) {
|
|
|
|
|
let moveX = e.changedTouches[0].x;
|
|
|
|
|
let moveY = e.changedTouches[0].y;
|
|
|
|
|
let movePoint = {
|
2023-11-21 17:43:02 +08:00
|
|
|
|
X: moveX / 1.75,
|
|
|
|
|
Y: moveY / 1.75
|
2023-11-01 18:40:05 +08:00
|
|
|
|
};
|
|
|
|
|
this.points.push(movePoint); //存点
|
|
|
|
|
let len = this.points.length;
|
|
|
|
|
if (len >= 2) {
|
|
|
|
|
this.draw(); //绘制路径
|
|
|
|
|
}
|
|
|
|
|
tempPoint.push(movePoint);
|
|
|
|
|
},
|
|
|
|
|
// 触摸结束,将未绘制的点清空防止对后续路径产生干扰
|
|
|
|
|
touchend: function() {
|
|
|
|
|
this.points = [];
|
|
|
|
|
},
|
|
|
|
|
/* ***********************************************
|
|
|
|
|
# 绘制笔迹
|
|
|
|
|
# 1.为保证笔迹实时显示,必须在移动的同时绘制笔迹
|
2024-01-08 15:16:29 +08:00
|
|
|
|
# 2.为保证笔迹连续,每次从路径集合中区两个点作为起点(moveTo)和终点(lineTo)
|
2023-11-01 18:40:05 +08:00
|
|
|
|
# 3.将上一次的终点作为下一次绘制的起点(即清除第一个点)
|
|
|
|
|
************************************************ */
|
|
|
|
|
draw: function() {
|
|
|
|
|
let point1 = this.points[0];
|
|
|
|
|
let point2 = this.points[1];
|
|
|
|
|
this.points.shift();
|
2023-11-21 17:43:02 +08:00
|
|
|
|
this.ctx.strokeStyle = 'red';
|
|
|
|
|
this.ctx.lineWidth = 2;
|
2023-11-01 18:40:05 +08:00
|
|
|
|
this.ctx.moveTo(point1.X, point1.Y);
|
|
|
|
|
this.ctx.lineTo(point2.X, point2.Y);
|
|
|
|
|
this.ctx.stroke();
|
|
|
|
|
this.ctx.draw(true);
|
|
|
|
|
},
|
|
|
|
|
handleCancel() {
|
|
|
|
|
uni.navigateBack({
|
|
|
|
|
delta: 1
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
//清空画布
|
|
|
|
|
handleReset: function() {
|
2023-11-13 18:02:20 +08:00
|
|
|
|
var that = this
|
2023-12-22 17:48:52 +08:00
|
|
|
|
that.points = []
|
2023-11-28 17:52:09 +08:00
|
|
|
|
uni.request({
|
|
|
|
|
url: `${that.$local}/api/miniapp/typeRef/domain/REFERENCE_DIAGRAM`,
|
|
|
|
|
header: {
|
|
|
|
|
'Content-Type': 'application/json', //自定义请求头信息
|
|
|
|
|
'Authorization': `Bearer ${that.loginObj.access_token}`
|
|
|
|
|
},
|
|
|
|
|
method: 'GET', //请求方式,必须为大写
|
|
|
|
|
success: (res) => {
|
|
|
|
|
if (res.statusCode == 200) {
|
2023-12-08 17:42:10 +08:00
|
|
|
|
that.initImg(res.data.data[0].ptrDesc)
|
2024-01-08 15:16:29 +08:00
|
|
|
|
this.ytImg = res.data.data[0].ptrDesc
|
|
|
|
|
this.isSign = false
|
2023-11-28 17:52:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// that.ctx.clearRect(0, 0, 624, 224);
|
|
|
|
|
// that.ctx.draw(true);
|
|
|
|
|
// tempPoint = [];
|
2023-11-01 18:40:05 +08:00
|
|
|
|
},
|
|
|
|
|
//将签名笔迹上传到服务器,并将返回来的地址存到本地
|
|
|
|
|
handleConfirm: function() {
|
|
|
|
|
let that = this
|
2023-11-13 10:11:34 +08:00
|
|
|
|
uni.canvasToTempFilePath({
|
|
|
|
|
canvasId: 'mycanvas',
|
|
|
|
|
success: function(e) {
|
|
|
|
|
const myPromise = new Promise((resolve, reject) => {
|
|
|
|
|
// 执行异步操作
|
|
|
|
|
// 当操作完成时调用resolve()或reject()
|
|
|
|
|
pathToBase64(e.tempFilePath).then(path => {
|
|
|
|
|
that.url = path
|
2024-01-08 15:16:29 +08:00
|
|
|
|
if (that.isSign) {
|
|
|
|
|
uni.setStorageSync('hzzsImg', that.url)
|
|
|
|
|
} else {
|
|
|
|
|
uni.setStorageSync('hzzsImg', that.ytImg)
|
|
|
|
|
}
|
|
|
|
|
uni.setStorageSync('isSign', that.isSign)
|
2023-11-16 18:04:18 +08:00
|
|
|
|
uni.navigateBack({
|
|
|
|
|
delta: 1
|
|
|
|
|
});
|
2023-11-13 10:11:34 +08:00
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error(error)
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-12-22 17:48:52 +08:00
|
|
|
|
}
|
2023-11-01 18:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.container {
|
|
|
|
|
height: calc(100vh - 68px);
|
|
|
|
|
padding-bottom: 30px;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sign-box {
|
|
|
|
|
display: flex;
|
2023-11-13 10:11:34 +08:00
|
|
|
|
justify-content: center;
|
|
|
|
|
position: relative;
|
2023-11-21 17:43:02 +08:00
|
|
|
|
margin-top: 48px;
|
2023-11-01 18:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sign-view {
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sigh-btns {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
2023-12-22 17:48:52 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
height: 80px;
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
box-shadow: 0 -3px 7px 0 rgba(0, 0, 0, 0.10);
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 0;
|
2023-11-01 18:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn {
|
2023-12-22 17:48:52 +08:00
|
|
|
|
margin: 15.5px 17px;
|
|
|
|
|
width: 200px;
|
|
|
|
|
height: 49px;
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
line-height: 49px;
|
2023-11-01 18:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-22 17:48:52 +08:00
|
|
|
|
.qx {
|
|
|
|
|
background-color: #eee;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.qc {
|
|
|
|
|
color: #0067CF;
|
|
|
|
|
background-color: rgba(0, 103, 207, 0.10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.bc {
|
|
|
|
|
color: #fff;
|
|
|
|
|
background: #0067CF;
|
2023-11-01 18:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.mycanvas {
|
|
|
|
|
margin: auto 0rpx;
|
2024-01-08 15:16:29 +08:00
|
|
|
|
background-color: transparent;
|
|
|
|
|
margin-top: 130px;
|
|
|
|
|
width: 624px;
|
|
|
|
|
height: 224px;
|
|
|
|
|
z-index: 999;
|
|
|
|
|
transform: scale(1.75)
|
2023-11-13 10:11:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.canvasBg {
|
2023-11-21 17:43:02 +08:00
|
|
|
|
width: 624px;
|
|
|
|
|
height: 224px;
|
2023-11-13 10:11:34 +08:00
|
|
|
|
position: absolute;
|
2023-11-21 17:43:02 +08:00
|
|
|
|
top: 130px;
|
|
|
|
|
transform: scale(1.75)
|
2023-11-01 18:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.canvsborder {
|
|
|
|
|
border: 1rpx solid #333;
|
|
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 10000rpx;
|
|
|
|
|
}
|
|
|
|
|
</style>
|