You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

384 lines
8.6 KiB

<template>
<view class="sign">
1 year ago
<canvas canvas-id="sign-cnv" :style="{ height: cnv.height + 'px', width: cnv.width + 'px' }"></canvas>
1 year ago
<image class="hide-img" ref="resultImg" :src="src" alt="" @load="resultImgLoad"></image>
<view class="sign-bkg">
<view class="sign-bkg__word">
<span></span>
<span></span>
</view>
</view>
<!-- <view class="sign-pic">-->
<!-- <image src="/static/cloud.png" class="sign-pic__cloud" mode="widthFix"></image>-->
<!-- <image class="sign-pic__city" src="/static/home-city.png" mode="widthFix" />-->
<!-- </view>-->
<view class="sign-cnv">
<l-signature disableScroll backgroundColor="#ddd" ref="signatureRef" :penColor="options.penColor"
:backgroundColor="options.backgroundColor" :penSize="options.penSize" :openSmooth="options.openSmooth">
</l-signature>
</view>
<view class="sign-btn">
1 year ago
<view class="sign-btn__back" @click="$u.throttle(pageBack())"></view>
<view class="sign-btn__reset" @click="$u.throttle(onClick('clear'))"></view>
<view class="sign-btn__confirm" @click="$u.throttle(onClick('save'))"></view>
</view>
</view>
</template>
<script>
import {
1 year ago
base64ToFile, writeFile
} from '@/common/util.js'
import {
ROOTPATH
} from '@/common/config.js'
export default {
data() {
return {
1 year ago
src: '',
Img: {},
cnv: {
width: 300,
height: 225
},
saveKey: '',
url: '',
options: {
penColor: '#000',
penSize: 16,
openSmooth: true,
backgroundColor: 'rgba(0,0,0,0)'
},
}
},
methods: {
1 year ago
resultImgLoad (e) {
1 year ago
// this.Img = e.detail;
// let rate = this.Img.width / this.Img.height;
// this.cnv.width = this.Img.height;
// this.cnv.height = this.Img.width ;
// this.rotateImage(this.src, 270)
1 year ago
},
pageBack () {
uni.navigateBack()
},
//src - 图片路径deg旋转角度
1 year ago
rotateImage(src, degree) {
const ctx = uni.createCanvasContext('sign-cnv',this);
ctx.translate(this.cnv.width / 2, 0);
ctx.rotate(degree * Math.PI / 180);
ctx.drawImage(src, 0, 0,-this.cnv.width / 2, -this.cnv.height / 2, this.cnv.width, this.cnv.height);
ctx.draw(false, () => {
// 将canvas转换为图片
uni.canvasToTempFilePath({
canvasId: 'sign-cnv',
success: (res) => {
// res.tempFilePath是旋转后的图片路径
console.log(this.saveKey, res.tempFilePath)
this.$u.vuex(this.saveKey, res.tempFilePath)
setTimeout(() => {
this.pageBack()
}, 500)
},
fail: (err) => {
console.error(err);
}
1 year ago
});
});
},
onClick(type) {
if (type == 'openSmooth') {
this.openSmooth = !this.openSmooth
return
}
if (type == 'save') {
this.$refs.signatureRef.canvasToTempFilePath({
success: (res) => {
// 是否为空画板 无签名
if (res.isEmpty) {
uni.showToast({
title: '请签名',
icon: 'none'
})
return
}
// 生成图片的临时路径
// app | H5 | 微信小程序 生成的是base64
if (res.tempFilePath) {
//this.$u.vuex('vuex_sign_base64', res.tempFilePath)
1 year ago
writeFile(res.tempFilePath).then(url => {
// console.log(url)
// this.src = url
this.$u.vuex(this.saveKey, url)
setTimeout(() => {
this.pageBack()
}, 500)
})
1 year ago
// this.rotateBase64Img(res.tempFilePath, -90).then(res => {
// this.$u.vuex(this.saveKey, res)
// this.pageBack()
// })
}
}
})
return
}
if (this.$refs.signatureRef)
this.$refs.signatureRef[type]()
},
},
1 year ago
onLoad (option) {
console.log(option)
this.saveKey = option.key;
}
}
</script>
<style scoped lang="scss">
1 year ago
.hide-img {
position: fixed;
width: 200px;
object-fit: contain;
top: 0;
left: 0;
z-index: 999999999;
}
@media screen and (orientation: portrait) {
.sign {
height: 100vh;
width: 100vw;
&-pic {
width: 100vh;
display: flex;
align-items: flex-end;
transform: rotate(90deg) translateX(0%) translateY(-100%);
transform-origin: 0 0;
position: absolute;
&__cloud {
flex: 1;
}
&__city {
flex: 1;
}
}
&-bkg {
background-color: #FEFAEE;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
&__word {
width: 390rpx;
font-size: 128rpx;
//font-family: CloudHeiTiGBK;
font-weight: 400;
color: #BBB6B2;
opacity: 0.3;
display: flex;
justify-content: space-between;
transform: rotate(90deg) translateX(-50%) translateY(calc(-100% - 426rpx));
transform-origin: 0 0;
position: absolute;
top: 50%;
}
}
&-cnv {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
&-btn {
display: flex;
transform: rotate(90deg) translateX(-50%) translateY(-100%);
transform-origin: 0% 0%;
margin-left: 112rpx;
z-index: 99999;
position: fixed;
top: 50%;
1 year ago
&__back {
width: 200rpx;
height: 66rpx;
background: #FEFAEE;
border: 4rpx solid #CA3F32;
border-radius: 34rpx;
font-size: 26rpx;
font-weight: 400;
color: #B61F2E;
line-height: 58rpx;
text-align: center;
margin-right: 52rpx;
}
&__reset {
width: 200rpx;
height: 66rpx;
background: #FEFAEE;
border: 4rpx solid #CA3F32;
border-radius: 34rpx;
font-size: 26rpx;
//font-family: FZXiaoBiaoSong-B05S;
font-weight: 400;
color: #B61F2E;
line-height: 58rpx;
text-align: center;
margin-right: 52rpx;
}
&__confirm {
font-size: 26rpx;
//font-family: FZXiaoBiaoSong-B05S;
font-weight: 400;
color: #FFFFFF;
width: 200rpx;
height: 66rpx;
background: linear-gradient(0deg, #E16055, #C54439);
border-radius: 34rpx;
line-height: 66rpx;
text-align: center;
}
}
}
}
@media screen and (orientation: landscape) {
.sign {
height: 100vh;
width: 100vw;
&-pic {
width: 100vw;
display: flex;
align-items: flex-end;
position: absolute;
bottom: 0;
&__cloud {
flex: 1;
}
&__city {
flex: 1;
}
}
&-bkg {
background-color: #FEFAEE;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
&__word {
width: 18vw;
font-size: 6vw;
//font-family: CloudHeiTiGBK;
font-weight: 400;
color: #BBB6B2;
opacity: 0.3;
display: flex;
justify-content: space-between;
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
}
}
&-cnv {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
&-btn {
display: flex;
transform: translateX(-50%);
z-index: 99999;
position: fixed;
bottom: 8vh;
left: 50%;
1 year ago
&__back {
width: 16.6vw;
height: 5.2vw;
background: #FEFAEE;
border: 0.4vw solid #CA3F32;
border-radius: 34rpx;
font-size: 2.6vw;
font-weight: 400;
color: #B61F2E;
text-align: center;
line-height: 5.2vw;
box-sizing: content-box;
margin-right: 48rpx;
}
&__reset {
width: 16.6vw;
height: 5.2vw;
background: #FEFAEE;
border: 0.4vw solid #CA3F32;
border-radius: 34rpx;
font-size: 2.6vw;
//font-family: FZXiaoBiaoSong-B05S;
font-weight: 400;
color: #B61F2E;
text-align: center;
line-height: 5.2vw;
box-sizing: content-box;
margin-right: 48rpx;
}
&__confirm {
font-size: 2.6vw;
//font-family: FZXiaoBiaoSong-B05S;
font-weight: 400;
color: #FFFFFF;
width: 17.4vw;
height: 6vw;
background: linear-gradient(0deg, #E16055, #C54439);
border-radius: 34rpx;
text-align: center;
line-height: 6vw;
}
}
}
}
</style>