index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class="ht-qm-box">
  3. <view class="qm-tip-box">
  4. <view>手写签名</view>
  5. <jp-signature ref="signatureRef"></jp-signature>
  6. <view class="qm-tip-text">
  7. 注意事项:<br/>
  8. 1.请仔细阅读全文,确认完全理解条款后签名。<br/>
  9. 2.需本人手写签名,签字即视为认可合同内容。<br/>
  10. 3.签名具有法律效力,签署后须履行约定义务,纠纷以签名数据为法律凭据。
  11. </view>
  12. </view>
  13. </view>
  14. <image v-show="false" :src="url" alt="" />
  15. <view class="ht-btn-box">
  16. <button @click="save" type="default" class="phone-green-btn">保存</button>
  17. <button @click="clear" type="default" class="phone-white-btn">清空</button>
  18. <!-- <button @click="undo">撤消</button> -->
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. url: '',
  26. }
  27. },
  28. methods: {
  29. save() {
  30. this.$refs.signatureRef.canvasToTempFilePath({
  31. success: (res) => {
  32. // 是否为空画板 无签名
  33. console.log(res.isEmpty)
  34. console.log(res)
  35. this.base64(res.tempFilePath)
  36. }
  37. })
  38. },
  39. base64(tempFilePath) {
  40. uni.getFileSystemManager().readFile({
  41. filePath: tempFilePath,
  42. encoding: 'base64',
  43. success: (res) => {
  44. console.log('res111',res);
  45. let base64 = 'data:image/png;base64,' + res.data
  46. console.log('小程序base64转换成功,长度:', base64.length)
  47. this.url = base64
  48. this.$emit("getBase64",this.url)
  49. },
  50. fail: (err) => {
  51. console.error('小程序转换失败:', err)
  52. // 转换失败时保持使用临时路径
  53. uni.showToast({
  54. title: '转换失败,使用原图',
  55. icon: 'none'
  56. })
  57. }
  58. })
  59. },
  60. clear() {
  61. this.$refs.signatureRef.clear()
  62. },
  63. undo() {
  64. this.$refs.signatureRef.undo()
  65. },
  66. }
  67. }
  68. </script>