signatureImg.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 '@/api/index.js'
  24. import ImageCropper from '@/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. //this.src = 'https://www.baidu.com/img/flexible/logo/pc/result@2.png';
  39. console.log(this.src)
  40. },
  41. onShow(){
  42. },
  43. methods:{
  44. /************************************************修改头像************************************************/
  45. beforeDraw(context, transform) {
  46. context.setFillStyle('yellow')
  47. transform.zoom = 2
  48. },
  49. afterDraw(ctx, info) {
  50. ctx.fillText('', 20, 20)
  51. console.log(`当前画布大小:${info.width}*${info.height}`)
  52. },
  53. async cropped(imagePath, imageInfo) {
  54. console.log("imagePath",imagePath)
  55. this.srcData = imagePath;
  56. console.log(imagePath)
  57. //小程序电子签名抠图生成图片
  58. uni.uploadFile({
  59. url: config.base_url+'/app/sysuser/api/genSign', //仅为示例,非真实的接口地址
  60. header:{'Authorization':uni.getStorageSync('token')},
  61. filePath: imagePath,
  62. name: 'file',
  63. formData: {
  64. 'user': 'test'
  65. },
  66. success: (response) => {
  67. console.log(typeof(response.data))
  68. let data=JSON.parse(response.data)
  69. if(data.code == 200){
  70. let text = data.data.replace(/[\r\n]/g,"");
  71. this.signatureData = 'data:image/png;base64,'+ text;
  72. } else {
  73. uni.showToast({
  74. title: response.msg,
  75. icon:"none",
  76. mask:true,
  77. duration: 2000
  78. });
  79. }
  80. },
  81. fail: err => {},
  82. complete: () => {
  83. uni.hideLoading()
  84. }
  85. });
  86. },
  87. /************************************************************************************************/
  88. upImg(){
  89. let self = this;
  90. console.log(this.signatureData)
  91. uni.setStorageSync('signatureData',this.signatureData)
  92. setTimeout(function(){
  93. uni.navigateBack();
  94. },200);
  95. /* uni.showModal({
  96. content: '确认提交吗?',
  97. cancelColor:"#999",
  98. confirmColor:"#0183FA",
  99. success: function (res) {
  100. if (res.confirm) {
  101. self.uploadImg(self.srcData);
  102. console.log('用户点击确定');
  103. } else if (res.cancel) {
  104. console.log('用户点击取消');
  105. }
  106. }
  107. }); */
  108. },
  109. backButton(){
  110. uni.navigateBack();
  111. },
  112. /* //小程序电子签名抠图生成图片
  113. async querygenSign(formData){
  114. const {data} = await querygenSign(formData);
  115. if(data.code == 200){
  116. console.log('程序电子签名抠图生成图片')
  117. }
  118. }, */
  119. }
  120. }
  121. </script>
  122. <style lang="stylus" scoped>
  123. .avatar-page{
  124. height:100%;
  125. width:100%
  126. .left-button{
  127. background #E0E0E0;
  128. color:#333;
  129. text-align center;
  130. font-size:26rpx;
  131. width:140rpx;
  132. height:60rpx;
  133. line-height:60rpx;
  134. position fixed;
  135. left:40rpx;
  136. bottom:40rpx;
  137. z-index:100;
  138. border-radius:10rpx;
  139. }
  140. .right-button{
  141. background #007AFF;
  142. color:#fff;
  143. text-align center;
  144. font-size:26rpx;
  145. width:140rpx;
  146. height:60rpx;
  147. line-height:60rpx;
  148. position fixed;
  149. right:40rpx;
  150. bottom:40rpx;
  151. z-index:100;
  152. border-radius:10rpx;
  153. }
  154. }
  155. </style>