signatureImg.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!-- 电子签名图片 -->
  2. <template>
  3. <view class="avatar-page">
  4. <view style="height:100%;width:100%;" v-if="src&&src!='null'">
  5. <image-cropper
  6. id="image-cropper"
  7. :zoom="1"
  8. :angle="0"
  9. :src="src"
  10. cutWidth='688rpx'
  11. cutHeight='250rpx'
  12. canvasBackground="red"
  13. @cropped="cropped"
  14. @afterDraw="afterDraw"
  15. @beforeDraw="beforeDraw"/>
  16. </view>
  17. <view class="left-button" @click="backButton">取消</view>
  18. <view class="right-button" @click="upImg">确定</view>
  19. </view>
  20. </template>
  21. <script>
  22. import { config } from '@/api/request/config.js'
  23. import { querygenSign} from '@/pages_basics/api/index.js'
  24. import ImageCropper from '@/pages_basics/component/cropper.vue'
  25. export default {
  26. components: {
  27. ImageCropper
  28. },
  29. data() {
  30. return {
  31. src:"",
  32. srcData:"",
  33. signatureData:'',
  34. }
  35. },
  36. onLoad(option){
  37. this.src = option.src;
  38. },
  39. onShow(){
  40. },
  41. methods:{
  42. /************************************************修改头像************************************************/
  43. beforeDraw(context, transform) {
  44. context.setFillStyle('yellow')
  45. transform.zoom = 2
  46. },
  47. afterDraw(ctx, info) {
  48. ctx.fillText('', 20, 20)
  49. },
  50. async cropped(imagePath, imageInfo) {
  51. this.srcData = imagePath;
  52. //小程序电子签名抠图生成图片
  53. uni.uploadFile({
  54. url: config.base_url+'/system/user/genSign', //仅为示例,非真实的接口地址
  55. header:{'Authorization':uni.getStorageSync('token')},
  56. filePath: imagePath,
  57. name: 'file',
  58. formData: {
  59. 'user': 'test'
  60. },
  61. success: (response) => {
  62. let data=JSON.parse(response.data)
  63. if(data.code == 200){
  64. let text = data.data.replace(/[\r\n]/g,"");
  65. this.signatureData = 'data:image/png;base64,'+ text;
  66. } else {
  67. uni.showToast({
  68. title: response.msg,
  69. icon:"none",
  70. mask:true,
  71. duration: 2000
  72. });
  73. }
  74. },
  75. fail: err => {},
  76. complete: () => {
  77. uni.hideLoading()
  78. }
  79. });
  80. },
  81. /************************************************************************************************/
  82. upImg(){
  83. let self = this;
  84. uni.setStorageSync('signatureData',this.signatureData)
  85. setTimeout(function(){
  86. uni.navigateBack();
  87. },200);
  88. },
  89. backButton(){
  90. uni.navigateBack();
  91. },
  92. }
  93. }
  94. </script>
  95. <style lang="stylus" scoped>
  96. .avatar-page{
  97. height:100%;
  98. width:100%
  99. .left-button{
  100. background #E0E0E0;
  101. color:#333;
  102. text-align center;
  103. font-size:26rpx;
  104. width:140rpx;
  105. height:60rpx;
  106. line-height:60rpx;
  107. position fixed;
  108. left:40rpx;
  109. bottom:40rpx;
  110. z-index:100;
  111. border-radius:10rpx;
  112. }
  113. .right-button{
  114. background #007AFF;
  115. color:#fff;
  116. text-align center;
  117. font-size:26rpx;
  118. width:140rpx;
  119. height:60rpx;
  120. line-height:60rpx;
  121. position fixed;
  122. right:40rpx;
  123. bottom:40rpx;
  124. z-index:100;
  125. border-radius:10rpx;
  126. }
  127. }
  128. </style>