HomeLease/pages/signature/signature.vue

67 lines
1.8 KiB
Vue
Raw Normal View History

2025-09-11 15:49:16 +08:00
<template>
<view style="width: 100vw; height: 80vh; background-color: #8f939c">
<l-signature
ref="signatureRef"
:openSmooth="openSmooth"
:penColor="penColor"
:penSize="penSize"
disableScroll
></l-signature>
2025-09-11 15:49:16 +08:00
</view>
<view style="width: 100vw; height: 20vh; background-color: #ffffff">
2025-09-11 15:49:16 +08:00
<button @click="onClick('clear')">清空</button>
<button @click="onClick('undo')">撤消</button>
<button @click="onClick('save')">提交</button>
2025-09-11 15:49:16 +08:00
</view>
</template>
2025-09-11 15:49:16 +08:00
<script>
import { tempUrlToRealUrl } from '../../utils/tempUrl-to-realUrl'
2025-09-11 15:49:16 +08:00
export default {
data() {
return {
title: 'Hello',
penColor: 'white',
2025-09-11 15:49:16 +08:00
penSize: 5,
url: '',
openSmooth: true,
signatureUrl: '',
2025-09-11 15:49:16 +08:00
}
},
methods: {
async onClick(type) {
2025-09-11 15:49:16 +08:00
if (type === 'openSmooth') {
this.openSmooth = !this.openSmooth
return
}
if (type === 'save') {
await this.$refs.signatureRef.canvasToTempFilePath({
success: async res => {
2025-09-11 15:49:16 +08:00
// 是否为空画板 无签名
console.log('签名返回是否为空', res.isEmpty)
if (res.isEmpty) {
this.signatureUrl = ''
return
}
2025-09-11 15:49:16 +08:00
// 生成图片的临时路径
// H5 生成的是base64
this.tempUrl = res.tempFilePath
console.log('临时路径', res.tempFilePath)
this.signatureUrl = await tempUrlToRealUrl(res.tempFilePath)
console.log('签名路径', this.signatureUrl)
console.log('签名上传成功')
uni.showToast({ title: '签名上传成功', icon: 'success' })
2025-09-11 15:49:16 +08:00
},
})
return
}
if (this.$refs.signatureRef) this.$refs.signatureRef[type]()
},
},
}
</script>
<style lang="scss"></style>