index.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 size="mini" @click="save" type="default" class="phone-green-btn">保存</button>
  17. <button size="mini" @click="clear" type="default" class="phone-white-btn">清空</button>
  18. <!-- <button size="mini" @click="undo" type="default" class="phone-white-btn">撤消</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. // H5 生成的是base64
  38. // this.url = res.tempFilePath
  39. }
  40. })
  41. },
  42. // 转换 app
  43. base64(tempFilePath) {
  44. let base64Code;
  45. let path = plus.io.convertLocalFileSystemURL(tempFilePath);
  46. // console.log('tempFilePath',tempFilePath);
  47. // console.log('path',path);
  48. let fileReader = new plus.io.FileReader();
  49. fileReader.readAsDataURL(path);
  50. fileReader.onloadend = res => {
  51. // console.log('res',res);
  52. base64Code = res.target.result;
  53. this.url = res.target.result
  54. this.$emit('getBase64',this.url)
  55. // console.log('base64Code',base64Code);
  56. }
  57. },
  58. // miniProgramConvertToBase64(tempFilePath) {
  59. // uni.getFileSystemManager().readFile({
  60. // filePath: tempFilePath,
  61. // encoding: 'base64',
  62. // success: (res) => {
  63. // let base64 = 'data:image/png;base64,' + res.data
  64. // console.log('小程序base64转换成功,长度:', base64.length)
  65. // this.url = base64
  66. // },
  67. // fail: (err) => {
  68. // console.error('小程序转换失败:', err)
  69. // // 转换失败时保持使用临时路径
  70. // uni.showToast({
  71. // title: '转换失败,使用原图',
  72. // icon: 'none'
  73. // })
  74. // }
  75. // })
  76. // },
  77. clear() {
  78. this.$refs.signatureRef.clear()
  79. },
  80. undo() {
  81. this.$refs.signatureRef.undo()
  82. },
  83. }
  84. }
  85. </script>