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