移动端
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.

162 lines
4.9 KiB

  1. <template>
  2. <div>
  3. <van-nav-bar
  4. title="电子签名"
  5. left-arrow
  6. @click-left="$router.back(-1)"
  7. />
  8. <van-cell-group style="width: 96%;margin:2%;border-radius: 6px;overflow: hidden;padding-top: 10px;padding-bottom: 10px;box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);">
  9. <div class="signature-box">
  10. <vue-esign
  11. ref="esign"
  12. class="mySign"
  13. :width="500"
  14. :height="225"
  15. :isCrop="signature.isCrop"
  16. :lineWidth="signature.lineWidth"
  17. :lineColor="signature.lineColor"
  18. :bgColor.sync="signature.bgColor"
  19. />
  20. </div>
  21. <div class="signature-footer">
  22. <signatureUploadSignature @signaImg = "signaImgFun"/>
  23. <van-button @click="handleGenerate" type="info" size="small"> 生成签字图片</van-button>
  24. <van-button @click="handleReset" class="clearBtn" type="info" plain size="small">清空画板</van-button>
  25. </div>
  26. <div class="esigh-result">
  27. <img :src="signatureImg" class="imgs" v-if="signatureImg!=''"/>
  28. </div>
  29. </van-cell-group>
  30. </div>
  31. </template>
  32. <script>
  33. import vueEsign from 'vue-esign'
  34. import {getToken} from "@/utils/auth";
  35. import axios from 'axios'
  36. import { getUserProfile } from "@/api/lawEnforcement/index";
  37. import signatureUploadSignature from './signatureUploadSignature';
  38. export default {
  39. name: "yinnongSignature",
  40. components:{vueEsign,signatureUploadSignature},
  41. data() {
  42. return {
  43. signatureImg:'',
  44. //上传图片
  45. uploadPictures:{
  46. action:process.env.VUE_APP_BASE_API+'/system/user/profile/electronicSignature',
  47. headers: { Authorization: "Bearer " + getToken() },
  48. },
  49. //电子签名
  50. signature:{
  51. lineWidth: 6, // 画笔的线条粗细
  52. lineColor: "#000000", // 画笔的颜色
  53. bgColor: "", // 画布的背景颜色
  54. resultImg: "", // 最终画布生成的base64图片
  55. isCrop: false, // 是否裁剪,在画布设定尺寸基础上裁掉四周空白部分
  56. }
  57. }
  58. },
  59. mounted(){
  60. this.getUser();
  61. },
  62. methods:{
  63. getUser(){
  64. getUserProfile().then(response => {
  65. const baseImgUrl = this.$store.getters.baseRoutingUrl;
  66. this.signatureImg = baseImgUrl+response.data.electronicSignature
  67. if(baseImgUrl==''){
  68. setTimeout(()=>{
  69. const baseImgUrl = this.$store.getters.baseRoutingUrl;
  70. this.signatureImg = baseImgUrl+response.data.electronicSignature
  71. },1000)
  72. }
  73. });
  74. },
  75. signaImgFun(url){
  76. this.signatureImg = url;
  77. // console.log(url)
  78. },
  79. // 清空画板
  80. handleReset() {
  81. this.$refs.esign.reset();
  82. },
  83. // 生成签字图
  84. handleGenerate() {
  85. this.$refs.esign
  86. .generate() // 使用生成器调用把签字的图片转换成为base64图片格式
  87. .then((res) => {
  88. console.log(res)
  89. this.signature.resultImg = res;
  90. let wj = this.dataURLtoBlob(res);
  91. let param = new FormData() // 创建form对象
  92. param.append('electronicSignaturefile', wj) // 通过append向form对象添加数据
  93. let config = {
  94. headers: this.uploadPictures.headers
  95. }
  96. // 添加请求头
  97. axios.post(this.uploadPictures.action, param, config)
  98. .then(res => {
  99. let content = res.data;
  100. if(content.code == 200){
  101. const baseImgUrl = this.$store.getters.baseRoutingUrl;
  102. this.signatureImg = baseImgUrl+content.esUrl;
  103. }
  104. })
  105. })
  106. .catch((err) => {
  107. // 画布没有签字时会执行这里提示一下
  108. this.$toast.fail('请签名后再生成签字图片');
  109. });
  110. },
  111. dataURLtoBlob(dataurl) {
  112. var arr = dataurl.split(',');
  113. //注意base64的最后面中括号和引号是不转译的
  114. var _arr = arr[1].substring(0,arr[1].length-2);
  115. var mime = arr[0].match(/:(.*?);/)[1],
  116. bstr =atob(_arr),
  117. n = bstr.length,
  118. u8arr = new Uint8Array(n);
  119. while (n--) {
  120. u8arr[n] = bstr.charCodeAt(n);
  121. }
  122. return new Blob([u8arr], {
  123. type: mime
  124. });
  125. },
  126. }
  127. }
  128. </script>
  129. <style scoped lang="scss">
  130. .signature-box{
  131. border:1px dashed #666;
  132. margin:2px 20px;
  133. }
  134. .signature-footer{
  135. margin:15px 20px 0;
  136. display: flex;
  137. .clearBtn{
  138. margin-left: 15px;
  139. }
  140. }
  141. .esigh-result{
  142. margin:15px 20px;
  143. // height: 110px;
  144. border:1px solid #666;
  145. font-size: 0;
  146. .imgs{
  147. width: 100%;
  148. }
  149. }
  150. </style>