shareQrCode.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view class="container">
  3. <image class="backImg" :src="backImg" @click="bc_code(backImg)"></image>
  4. <!-- <view class="" @longtap="bc_code">
  5. 保存分享海报
  6. </view> -->
  7. <!-- <view class="tki-qrcode"><canvas @longtap="bc_code" canvas-id="qrcode" /></view> -->
  8. </view>
  9. </template>
  10. <script>
  11. import {
  12. spreadBanner
  13. } from '@/api/user.js';
  14. export default {
  15. // components: { tkiQrcode },
  16. data() {
  17. return {
  18. url: '',
  19. backImg: '',
  20. userInfo: ''
  21. };
  22. },
  23. onLoad() {
  24. this.spread();
  25. },
  26. computed: {
  27. cpSize() {
  28. if (this.unit == 'upx') {
  29. return uni.upx2px(this.size);
  30. } else {
  31. return this.size;
  32. }
  33. }
  34. },
  35. methods: {
  36. spread() {
  37. uni.showLoading({
  38. title: '加载中'
  39. });
  40. let obj = this;
  41. spreadBanner({
  42. //#ifdef H5
  43. type: 2,
  44. //#endif
  45. //#ifdef MP
  46. type: 1,
  47. //#endif
  48. //#ifdef APP-PLUS
  49. type: 2,
  50. //#endif
  51. }).then(({
  52. data
  53. }) => {
  54. console.log(data);
  55. //#ifdef MP
  56. obj.backImg = data[0].poster;
  57. //#endif
  58. //#ifdef H5
  59. obj.backImg = data[0].wap_poster;
  60. //#endif
  61. //#ifdef APP-PLUS
  62. obj.backImg = data[0].wap_poster;
  63. //#endif
  64. uni.hideLoading();
  65. });
  66. },
  67. bc_code(imgUrl) {
  68. let that = this;
  69. console.log('保存二维码', this.backImg);
  70. uni.downloadFile({
  71. //获得二维码的临时地址
  72. url: this.backImg,
  73. success: res => {
  74. //console.log('获取url',res)
  75. if (res.statusCode == 200) {
  76. uni.saveImageToPhotosAlbum({
  77. filePath: res.tempFilePath, //传入临时地址
  78. success() {
  79. that.$api.msg('保存成功'); //封装的提示
  80. },
  81. fail() {
  82. that.$api.msg('保存失败');
  83. }
  84. });
  85. }
  86. }
  87. });
  88. // let imageUrl = 'http://yg.hqgjsmc.com' + imgUrl
  89. // window.URL = window.URL || window.webkitURL;
  90. // var xhr = new XMLHttpRequest();
  91. // console.log(xhr,imgUrl)
  92. // xhr.open("get", imgUrl, true);
  93. // xhr.responseType = "blob";
  94. // xhr.onload = function() {
  95. // if (this.status == 200) {
  96. // //得到一个blob对象
  97. // var blob = this.response;
  98. // console.log("blob", blob)
  99. // // 至关重要
  100. // let oFileReader = new FileReader();
  101. // oFileReader.onloadend = function(e) {
  102. // // 此处拿到的已经是base64的图片了,可以赋值做相应的处理
  103. // console.log(e.target.result)
  104. // }
  105. // oFileReader.readAsDataURL(blob);
  106. // }
  107. // }
  108. // xhr.send();
  109. // alert(xhr.send())
  110. // console.log(xhr.send(),'ddddddddddddddd')
  111. }
  112. }
  113. };
  114. </script>
  115. <style lang="scss">
  116. page {
  117. width: 100%;
  118. min-height: 100%;
  119. .container {
  120. width: 100%;
  121. height: 100%;
  122. }
  123. }
  124. .backImg {
  125. position: absolute;
  126. width: 100%;
  127. // width: 750rpx;
  128. height: 100%;
  129. }
  130. .portrait {
  131. width: 100%;
  132. text-align: center;
  133. padding-top: 80rpx;
  134. padding-bottom: 30rpx;
  135. image {
  136. width: 250rpx;
  137. height: 250rpx;
  138. }
  139. }
  140. .text {
  141. text-align: center;
  142. width: 100%;
  143. color: #ffffff;
  144. font-size: 55rpx;
  145. letter-spacing: 15rpx;
  146. }
  147. .uid-name {
  148. padding: 50rpx 0rpx;
  149. text-align: center;
  150. width: 100%;
  151. color: #ffffff;
  152. }
  153. .copy-btn {
  154. color: #ffffff;
  155. background-color: #4ba6ed;
  156. border-radius: 50rpx;
  157. width: 170rpx;
  158. line-height: 70rpx;
  159. margin: 0rpx auto;
  160. text-align: center;
  161. }
  162. .tki-qrcode {
  163. position: fixed;
  164. bottom: 10%;
  165. left: 30%;
  166. }
  167. canvas {
  168. width: 150px;
  169. height: 150px;
  170. margin: auto;
  171. }
  172. </style>