index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view>
  3. <z-navbar title="二维码分享" back></z-navbar>
  4. <canvas :style="{width:canvasWidth+'px',height:canvasHeight+'px'}" canvas-id="firstCanvas"></canvas>
  5. <view class="area2" @click="saveToPhone">
  6. <image class="share_img2" mode="widthFix" src="../../../static/share_btn.png"></image>
  7. <view class="share_area_content2" >
  8. <view class="share_content2_text">
  9. 保存到手机
  10. </view>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. info: {},
  20. image: '',
  21. canvasWidth: 0,
  22. canvasHeight: 0,
  23. img1: '',
  24. img2: '',
  25. img3: '',
  26. img4: '',
  27. img5: '',
  28. saveimg:''
  29. };
  30. },
  31. mounted() {
  32. uni.showLoading({
  33. title:'加载中',
  34. mask:true
  35. })
  36. uni.getStorage({
  37. key: 'shareInfo',
  38. success: (res) => {
  39. console.log(res.data)
  40. this.info = res.data;
  41. this.$axios.post('qrcode/orderDetialQRCode', {
  42. url: 'http://117.ci2.cn:8080/bookinfo?id=' + res.data.id
  43. }).then(info => {
  44. console.log(info)
  45. this.image = info.data.url;
  46. this.makeImage();
  47. var rpx = uni.getSystemInfoSync().windowWidth / 750;
  48. this.canvasWidth = uni.getSystemInfoSync().windowWidth;
  49. this.canvasHeight = uni.getSystemInfoSync().windowHeight - 84 * rpx - uni.getSystemInfoSync().statusBarHeight;
  50. }).catch(err => {
  51. console.log(err)
  52. })
  53. }
  54. })
  55. },
  56. methods: {
  57. makeImage() {
  58. uni.getImageInfo({
  59. src: '../../../static/bg.png',
  60. success: (res) => {
  61. console.log(res.path)
  62. this.img1 = res.path;
  63. uni.getImageInfo({
  64. src: '../../../static/share_card.png',
  65. success: (res) => {
  66. console.log(res.path)
  67. this.img2 = res.path;
  68. uni.getImageInfo({
  69. src: '../../../static/shijian.png',
  70. success: (res) => {
  71. console.log(res.path)
  72. this.img3 = res.path;
  73. uni.getImageInfo({
  74. src: '../../../static/rili.png',
  75. success: (res) => {
  76. console.log(res.path)
  77. this.img4 = res.path;
  78. // uni.downloadFile({
  79. // url:this.image
  80. // })
  81. uni.getImageInfo({
  82. src: this.image,
  83. success: (res) => {
  84. console.log(res.path)
  85. this.img5 = res.path;
  86. this.drawImage();
  87. }
  88. })
  89. // this.drawImage();
  90. }
  91. })
  92. }
  93. })
  94. }
  95. })
  96. }
  97. })
  98. },
  99. drawImage() {
  100. var rpx = uni.getSystemInfoSync().windowWidth / 750;
  101. var context = uni.createCanvasContext('firstCanvas')
  102. context.drawImage(this.img1, 0, 0, this.canvasWidth, this.canvasHeight);
  103. console.log(this.img5)
  104. context.drawImage(this.img2, 30 * rpx, 87 * rpx, 689 * rpx, 744 * rpx);
  105. context.drawImage(this.img5, 188 * rpx, 178 * rpx, 374 * rpx, 374 * rpx);
  106. context.setStrokeStyle("#C2C2C2");
  107. context.setLineDash([5]);
  108. context.beginPath();
  109. context.moveTo(97 * rpx, 603 * rpx);
  110. context.lineTo(645 * rpx, 603 * rpx);
  111. context.stroke();
  112. context.drawImage(this.img4, 137 * rpx, 659 * rpx, 32 * rpx, 32 * rpx);
  113. context.drawImage(this.img3, 137 * rpx, 720 * rpx, 32 * rpx, 32 * rpx);
  114. context.fillStyle = "#666";
  115. context.font = "13px Arial";
  116. context.fillText(this.info.customName + ' ' + this.info.houseName, 187 * rpx, 685 * rpx);
  117. context.fillText(this.info.orderDate + ' ' + this.info.activityBeginTime + '-' + this.info.activityEndTime, 187 *
  118. rpx, 748 * rpx);
  119. context.draw();
  120. setTimeout(()=>{
  121. uni.canvasToTempFilePath({
  122. x: 0,
  123. y: 0,
  124. width: this.canvasWidth,
  125. height: this.canvasHeight,
  126. canvasId: 'firstCanvas',
  127. success:(res)=> {
  128. console.log(res.tempFilePath)
  129. this.saveimg=res.tempFilePath;
  130. }
  131. })
  132. uni.hideLoading();
  133. },500)
  134. },
  135. saveToPhone() {
  136. uni.saveImageToPhotosAlbum({
  137. filePath: this.saveimg,
  138. success: function() {
  139. console.log('save success');
  140. uni.showToast({
  141. title: '图片已存到手机',
  142. duration: 2000
  143. });
  144. }
  145. });
  146. }
  147. },
  148. beforeDestroy() {
  149. // uni.removeStorage({
  150. // key: 'shareInfo'
  151. // })
  152. }
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .area2 {
  157. text-align: center;
  158. position: absolute;
  159. top: 964rpx;
  160. z-index: 999;
  161. left: 55rpx;
  162. .share_img2 {
  163. width: 662rpx;
  164. height: 195rpx;
  165. }
  166. .share_area_content2 {
  167. position: absolute;
  168. top: 0;
  169. left: 0;
  170. text-align: center;
  171. width: 640rpx;
  172. .share_content2_text {
  173. font-size: 40rpx;
  174. padding-top: 40rpx;
  175. height:100rpx;
  176. left:0;
  177. width: 100%;
  178. text-align: center;
  179. color: #FF8400;
  180. font-weight: bold;
  181. }
  182. }
  183. }
  184. </style>