2023-08-01 17:28:15 +08:00
< template >
2023-08-24 16:22:29 +08:00
< view class = "sign" >
2023-09-23 20:16:54 +08:00
< head -view title = "单证签名" :url ="backUrl" > < / h e a d - v i e w >
2023-11-01 18:40:05 +08:00
< view class = "container contentFixed" >
2023-08-24 16:22:29 +08:00
< view class = "sign-box" >
< canvas class = "mycanvas" : style = "{width:width +'px',height:height +'px'}" canvas -id = " mycanvas "
@ touchstart = "touchstart" @ touchmove = "touchmove" @ touchend = "touchend" > < / canvas >
< canvas canvas -id = " camCacnvs " : style = "{width:height +'px',height:width +'px'}"
class = "canvsborder" > < / canvas >
< / view >
< view class = "sigh-btns" >
< van -button class = "btn" type = "default" @tap ="handleCancel" > 取 消 < / van -button >
< van -button class = "btn" type = "default" @tap ="handleReset" > 重 写 < / van -button >
< van -button class = "btn" type = "default" @tap ="handleConfirm" > 确 认 < / van -button >
< / view >
2023-08-01 17:28:15 +08:00
< / view >
< / view >
< / template >
< script >
2023-09-23 20:16:54 +08:00
import {
pathToBase64 ,
base64ToPath
} from '../../js_sdk/mmmm-image-tools/index.js'
import {
compressImgBySize
} from '@/common/compressImg'
import sqlite from "../../common/sqlite.js"
import api from "../../common/api.js"
import {
v4 as uuidv4
} from 'uuid' ;
2023-08-01 17:28:15 +08:00
var x = 20 ;
var y = 20 ;
var tempPoint = [ ] ; //用来存放当前画纸上的轨迹点
var id = 0 ;
var type = '' ;
let that ;
let canvasw ;
let canvash ;
export default {
data ( ) {
return {
ctx : '' , //绘图图像
points : [ ] , //路径点集合,
width : 0 ,
2023-08-23 17:42:44 +08:00
height : 0 ,
2023-09-23 20:16:54 +08:00
sginId : "" ,
signImgUrl : "" ,
shipInfo : { } ,
nextUrl : "" ,
signType : "" ,
signTable : "" ,
backUrl : "" ,
2023-11-01 18:40:05 +08:00
tabsValue : 0 ,
vvyId : "" ,
2023-08-01 17:28:15 +08:00
} ;
} ,
2023-09-23 20:16:54 +08:00
mounted ( ) {
this . executeSql1 ( 'shipInfoTable' )
} ,
2023-08-01 17:28:15 +08:00
onLoad ( option ) {
2023-09-23 20:16:54 +08:00
this . sginId = JSON . parse ( decodeURIComponent ( option . params ) ) . id
this . nextUrl = JSON . parse ( decodeURIComponent ( option . params ) ) . url
this . signType = JSON . parse ( decodeURIComponent ( option . params ) ) . signType
this . signTable = JSON . parse ( decodeURIComponent ( option . params ) ) . signTable
this . tabsValue = JSON . parse ( decodeURIComponent ( option . params ) ) . tabsValue
2023-11-01 18:40:05 +08:00
this . vvyId = JSON . parse ( decodeURIComponent ( option . params ) ) . vvyId
2023-11-13 10:11:34 +08:00
console . log ( this . vvyId )
2023-09-23 20:16:54 +08:00
this . backUrl = ` /pages/shipWork/ ${ this . nextUrl } `
2023-08-01 17:28:15 +08:00
that = this ;
id = option . id ;
type = option . type ;
this . ctx = uni . createCanvasContext ( 'mycanvas' , this ) ; //创建绘图对象
//设置画笔样式
this . ctx . lineWidth = 4 ;
this . ctx . lineCap = 'round' ;
this . ctx . lineJoin = 'round' ;
uni . getSystemInfo ( {
success : function ( res ) {
that . width = res . windowWidth * 0.8 ;
that . height = res . windowHeight * 0.85 ;
}
} ) ;
} ,
methods : {
//触摸开始,获取到起点
touchstart : function ( e ) {
let startX = e . changedTouches [ 0 ] . x ;
let startY = e . changedTouches [ 0 ] . y ;
let startPoint = {
X : startX ,
Y : startY
} ;
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# 由于uni对canvas的实现有所不同 , 这里需要把起点存起来
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
this . points . push ( startPoint ) ;
//每次触摸开始,开启新的路径
this . ctx . beginPath ( ) ;
} ,
//触摸移动,获取到路径点
touchmove : function ( e ) {
let moveX = e . changedTouches [ 0 ] . x ;
let moveY = e . changedTouches [ 0 ] . y ;
let movePoint = {
X : moveX ,
Y : moveY
} ;
this . points . push ( movePoint ) ; //存点
let len = this . points . length ;
if ( len >= 2 ) {
this . draw ( ) ; //绘制路径
}
tempPoint . push ( movePoint ) ;
} ,
// 触摸结束,将未绘制的点清空防止对后续路径产生干扰
touchend : function ( ) {
this . points = [ ] ;
} ,
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# 绘制笔迹
# 1. 为保证笔迹实时显示 , 必须在移动的同时绘制笔迹
# 2. 为保证笔迹连续 , 每次从路径集合中区两个点作为起点 ( moveTo ) 和终点 ( lineTo )
# 3. 将上一次的终点作为下一次绘制的起点 ( 即清除第一个点 )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
draw : function ( ) {
let point1 = this . points [ 0 ] ;
let point2 = this . points [ 1 ] ;
this . points . shift ( ) ;
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 ( ) {
that . ctx . clearRect ( 0 , 0 , that . width , that . height ) ;
that . ctx . draw ( true ) ;
tempPoint = [ ] ;
} ,
//将签名笔迹上传到服务器,并将返回来的地址存到本地
handleConfirm : function ( ) {
2023-09-23 20:16:54 +08:00
that = this
2023-08-01 17:28:15 +08:00
if ( tempPoint . length == 0 ) {
uni . showToast ( {
title : '请先签名' ,
icon : 'none' ,
duration : 2000
} ) ;
return ;
2023-09-23 20:16:54 +08:00
} else {
2023-11-01 18:40:05 +08:00
let signId = that . sginId
2023-09-23 20:16:54 +08:00
uni . canvasToTempFilePath ( {
canvasId : 'mycanvas' ,
success : function ( res ) {
setTimeout ( function ( ) {
pathToBase64 ( res . tempFilePath )
. then ( base64 => {
compressImgBySize ( base64 , 1200 ) . then ( baseImg => {
// 输出图片base64
that . signImgUrl = baseImg
let date = new Date ( ) . getTime ( )
let webId = uuidv4 ( )
let webDate = api . getDate ( date )
let sql =
2023-11-13 10:11:34 +08:00
` insert into workSignTable values(' ${ webId } ',' ${ that . shipInfo . vtpId } ',' ${ signId } ',' ${ that . signImgUrl } ',' ${ that . signTable } ',' ${ that . signType } ',' ${ that . vvyId } ',' ${ webDate } ') `
console . log ( sql )
2023-09-23 20:16:54 +08:00
sqlite . executeSqlCeshi ( sql ) . then ( (
value ) => {
// 在resolve时执行的回调函数
let obj = {
tabsValue : that
2023-11-01 18:40:05 +08:00
. tabsValue ,
2023-09-23 20:16:54 +08:00
}
const params =
encodeURIComponent ( JSON
. stringify ( obj ) ) ;
uni . navigateTo ( {
url : ` /pages/shipWork/ ${ that . nextUrl } ?params= ${ params } `
} )
} ) . catch ( ( error ) => {
// 在reject时执行的回调函数
console . error ( error ) ;
} ) ;
} )
} )
. catch ( error => {
console . error ( error )
} )
} , 1000 )
}
} ) ;
2023-08-01 17:28:15 +08:00
}
2023-09-23 20:16:54 +08:00
} ,
// 查船舶信息
executeSql1 ( tableName ) {
let sql = ` select * from ${ tableName } `
sqlite . executeSqlCeshi ( sql ) . then ( ( value ) => {
// 在resolve时执行的回调函数
if ( tableName == 'shipInfoTable' ) {
this . shipInfo = value [ 0 ]
2023-11-13 10:11:34 +08:00
console . log ( this . shipInfo )
2023-08-01 17:28:15 +08:00
}
2023-09-23 20:16:54 +08:00
} ) . catch ( ( error ) => {
// 在reject时执行的回调函数
console . error ( error ) ;
2023-08-01 17:28:15 +08:00
} ) ;
} ,
}
} ;
< / script >
< style lang = "scss" scoped >
. container {
2023-08-24 16:22:29 +08:00
height : calc ( 100 vh - 68 px ) ;
2023-08-01 17:28:15 +08:00
padding - bottom : 30 px ;
background - color : # fff ;
}
. sign - box {
2023-08-24 16:22:29 +08:00
width : 100 % ;
2023-08-01 17:28:15 +08:00
height : 90 % ;
2023-08-24 16:22:29 +08:00
margin - left : 10 % ;
2023-08-01 17:28:15 +08:00
display : flex ;
flex - direction : column ;
text - align : center ;
}
. sign - view {
height : 100 % ;
}
. sigh - btns {
display : flex ;
justify - content : center ;
}
. btn {
2023-08-24 16:22:29 +08:00
margin : 10 px 10 px 0 ;
2023-08-01 17:28:15 +08:00
}
/deep/ . van - button {
width : 100 px ;
height : 50 px ;
background - color : # fff ;
}
. mycanvas {
margin : auto 0 rpx ;
background - color : # ececec ;
}
. canvsborder {
border : 1 rpx solid # 333 ;
position : fixed ;
top : 0 ;
left : 10000 rpx ;
}
2023-07-24 16:56:46 +08:00
< / style >