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.
huazhiyu/pages/home/sign.vue

125 lines
2.6 KiB

1 year ago
<template>
<view class="sign">
<view style="width: 100vw; height: 100vh;">
<l-signature disableScroll backgroundColor="#ddd"
ref="signatureRef"
:penColor="penColor"
:penSize="penSize"
:landscape="true"
:openSmooth="openSmooth" ></l-signature>
</view>
<view class="btn">
<button @click="onClick('clear')">清空</button>
<button @click="onClick('undo')">撤消</button>
<button @click="onClick('save')">保存</button>
</view>
</view>
</template>
<script>
import {getToken} from '@/common/auth.js'
import {updateUserInfo} from '@/common/api.js'
1 year ago
var base64Img = require('base64-img');
1 year ago
export default{
data(){
return{
title: 'Hello',
penColor: '#000000',
penSize: 5,
picurl: '',
landscape:true,
openSmooth: false
}
},
methods: {
1 year ago
base64toBlob(dataurl) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
1 year ago
1 year ago
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
1 year ago
return new Blob([u8arr], { type: mime });
1 year ago
},
1 year ago
onClick(type) {
if(type == 'openSmooth') {
this.openSmooth = !this.openSmooth
return
}
if (type == 'save') {
this.$refs.signatureRef.canvasToTempFilePath({
success: (res) => {
1 year ago
if(res.isEmpty){
uni.$u.toast("请签名")
return;
}
var path = URL.createObjectURL(this.base64toBlob(res.tempFilePath))
1 year ago
uni.uploadFile({
url: this.baseUrl+'api/common/upload',
filePath: path,
name: 'file',
header:{
token:getToken()
},
formData: {
},
success: (res) => {
1 year ago
console.log(JSON.parse(res.data),"00")
1 year ago
if(JSON.parse(res.data).code==1){
setTimeout(() => {
1 year ago
this.saveSignPic(JSON.parse(res.data).data.url)
1 year ago
}, 1000)
}else{
uni.$u.toast(JSON.parse(res.data).msg)
1 year ago
1 year ago
}
1 year ago
},
fail: (res) => {
console.log(res,"rrr")
}
});
1 year ago
}
})
return
}
if (this.$refs.signatureRef)
this.$refs.signatureRef[type]()
},
1 year ago
saveSignPic(picurl){
1 year ago
console.log(picurl)
1 year ago
updateUserInfo({sign_image:picurl}).then(res=>{
1 year ago
console.log(res,"ooooo")
1 year ago
if(res.code==1){
uni.switchTab({
url:"/pages/qianggou/qianggou"
})
}
1 year ago
})
1 year ago
}
1 year ago
}
}
</script>
<style lang="scss" scoped>
.sign{
height:calc(100vh);
overflow: hidden;
.btn{
// transform: rotate(90deg);
display: flex;
position: fixed;
bottom:10px;
width:100%;
button{
flex:1;
margin:0 10rpx;
background-color: $base;
color:#fff;
font-size: 28rpx;
}
}
}
</style>