qrcode.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <app-layout>
  3. <view class="bg">
  4. <view class="dir-top-wrap cross-center">
  5. <image mode="aspectFill" class='qrcode' @click='look' :src='img'></image>
  6. <view @click="saveImg" :class="[`share-btn main-center cross-center`,`${theme}-background`]">保存图片分享赚钱</view>
  7. </view>
  8. </view>
  9. </app-layout>
  10. </template>
  11. <script>
  12. import { mapState } from "vuex";
  13. export default {
  14. data() {
  15. return {
  16. img: ''
  17. }
  18. },
  19. computed: {
  20. ...mapState({
  21. theme: state => state.mallConfig.theme,
  22. mall: state => state.mallConfig.mall,
  23. custom_setting: state => state.mallConfig.share_setting_custom,
  24. share_img: state => state.mallConfig.__wxapp_img.share
  25. })
  26. },
  27. methods: {
  28. look() {
  29. let that = this;
  30. uni.previewImage({
  31. current: that.img,
  32. urls: [that.img]
  33. })
  34. },
  35. saveImg() {
  36. let that = this;
  37. // #ifndef MP-ALIPAY
  38. uni.authorize({
  39. scope: 'scope.writePhotosAlbum',
  40. success(res) {
  41. if (res.errMsg == "authorize:ok") {
  42. uni.downloadFile({
  43. url: that.img,
  44. success(res) {
  45. uni.saveImageToPhotosAlbum({
  46. filePath: res.tempFilePath,
  47. success(res) {
  48. uni.showToast({
  49. title: '保存成功',
  50. icon: 'success',
  51. duration: 1000
  52. })
  53. },
  54. fail(res) {
  55. uni.showToast({
  56. title: '保存失败',
  57. icon: 'none',
  58. duration: 1000
  59. })
  60. }
  61. })
  62. }
  63. })
  64. }
  65. },
  66. fail(res) {
  67. uni.showModal({
  68. title: '提示',
  69. content: '保存到相册失败,需要授权保存到相册权限',
  70. showCancel: false,
  71. confirmText: '打开授权',
  72. success(e) {
  73. if (e.confirm) {
  74. uni.openSetting({});
  75. }
  76. }
  77. });
  78. }
  79. })
  80. // #endif
  81. // #ifdef MP-ALIPAY
  82. my.showLoading({
  83. content: '图片保存中'
  84. });
  85. my.saveImage({
  86. url: that.img,
  87. showActionSheet: true,
  88. success: (res) => {
  89. uni.showToast({
  90. title: '保存成功',
  91. icon: 'success',
  92. duration: 1000
  93. })
  94. },
  95. fail() {
  96. uni.showToast({
  97. title: '保存失败',
  98. icon: 'none',
  99. duration: 1000
  100. })
  101. },
  102. complete() {
  103. my.hideLoading();
  104. }
  105. });
  106. // #endif
  107. },
  108. getList() {
  109. let that = this;
  110. that.$request({
  111. url: that.$api.share.poster,
  112. method: 'get',
  113. }).then(response=>{
  114. that.$hideLoading();
  115. if(response.code == 0) {
  116. that.img = response.data.pic_url;
  117. }else {
  118. uni.showToast({
  119. title: response.msg,
  120. icon: 'none',
  121. duration: 1000
  122. });
  123. }
  124. }).catch(response => {
  125. that.$hideLoading();
  126. that.$event.on(that.$const.EVENT_USER_LOGIN).then(()=>{
  127. that.getList();
  128. });
  129. });
  130. },
  131. },
  132. onLoad(options) {
  133. let that = this;
  134. uni.setNavigationBarTitle({
  135. title: that.custom_setting.menus.qrcode.name
  136. });
  137. that.$showLoading({
  138. type: 'global',
  139. text: '加载中...'
  140. });
  141. that.getList();
  142. }
  143. }
  144. </script>
  145. <style scoped lang="scss">
  146. .bg {
  147. position: absolute;
  148. width: 100%;
  149. background-color: #fff;
  150. height: 100%;
  151. }
  152. .qrcode {
  153. height: #{1030rpx};
  154. width: #{580rpx};
  155. margin-top: #{32rpx};
  156. }
  157. .load {
  158. width: #{400rpx};
  159. height: #{400rpx};
  160. margin: 0 auto;
  161. padding-top: #{280rpx};
  162. }
  163. .share-btn {
  164. margin-top: #{24rpx};
  165. width: #{480rpx};
  166. height: #{80rpx};
  167. font-size: #{32rpx};
  168. color: #fff;
  169. border-radius: #{40rpx};
  170. }
  171. </style>