index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="andr-shQ-padL30 andr-shQ-padR30 andr-shQ-Flex andr-shQ-FlexDirC">
  3. <view class="andr-shQ-w100B andr-shQ-Flex andr-shQ-JusCC">
  4. <swiper class="imgw750h375 matop" :indicator-dots="false" :current="current" @change="currentChange" >
  5. <swiper-item v-for="(item, index) in rwmListArr" :key="index"><image :src="item.poster" mode="aspectFit" class="imgw750h375" /></swiper-item>
  6. </swiper>
  7. </view>
  8. <!-- #ifdef H5 -->
  9. <view class="baocun">长按二维码保存图片</view>
  10. <!-- #endif -->
  11. <!-- #ifdef MP-WEIXIN -->
  12. <view class="baocun" @click="seav">保存图片并转发</view>
  13. <!-- <button open-type="share" class="baocun btn" v-if="scLoading == 2">分享到微信</button> -->
  14. <!-- #endif -->
  15. </view>
  16. </template>
  17. <script>
  18. import { mapState } from 'vuex';
  19. import { spreadBanner } from '@/api/shareQrCode.js';
  20. import { interceptor, saveUrl } from '@/utils/loginUtils';
  21. // #ifdef H5
  22. import { weixindata } from '@/utils/wxAuthorized';
  23. // #endif
  24. export default {
  25. data() {
  26. return {
  27. rwmListArr: [],
  28. current: 0,
  29. imgSrc: ''
  30. };
  31. },
  32. onLoad(option) {
  33. uni.showLoading({
  34. title: '邀请图生成中',
  35. mask: true
  36. });
  37. // 判断是否强制登录
  38. this.loadCodeList();
  39. // #ifdef MP-WEIXIN
  40. uni.authorize({
  41. scope: 'scope.writePhotosAlbum',
  42. complete() {}
  43. });
  44. // #endif
  45. },
  46. onShow() {
  47. if (this.loginInterceptor && !this.hasLogin) {
  48. saveUrl();
  49. // 登录拦截
  50. interceptor();
  51. }
  52. },
  53. //下拉刷新
  54. onPullDownRefresh() {
  55. let obj = this;
  56. //监听下拉刷新动作的执行方法,每次手动下拉刷新都会执行一次
  57. setTimeout(function() {
  58. obj.loadCodeList();
  59. uni.stopPullDownRefresh(); //停止下拉刷新动画
  60. }, 1000);
  61. },
  62. computed: {
  63. ...mapState(['weichatObj', 'baseURL', 'urlFile']),
  64. },
  65. methods: {
  66. loadCodeList() {
  67. let self = this;
  68. // 加载二维码信息
  69. // let andrUid = uni.getStorageSync('andrUid')||'';
  70. spreadBanner({
  71. // #ifdef H5
  72. type: 2,
  73. // #endif
  74. // #ifdef MP
  75. type: 1,
  76. // #endif
  77. }).then(e => {
  78. if (e.status == 200) {
  79. self.rwmListArr = e.data;
  80. // #ifdef H5
  81. self.imgSrc = self.rwmListArr[0].wap_poster;
  82. // #endif
  83. // #ifdef MP-WEIXIN
  84. self.imgSrc = self.rwmListArr[0].poster;
  85. // #endif
  86. }
  87. uni.hideLoading();
  88. });
  89. },
  90. currentChange(e) {
  91. this.current = e.detail.current;
  92. },
  93. // onShareAppMessage(options){
  94. // console.log(options,'options')
  95. // let userInfo = uni.getStorageSync('userInfo');
  96. // console.log(userInfo)
  97. //   let obj = this;
  98. //   // 设置菜单中的转发按钮触发转发事件时的转发内容
  99. //   let shareObj = {
  100. //     title: "邀请好友领券", // 默认是小程序的名称(可以写slogan等)
  101. //     path: '/pages/index/index?spread='+userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  102. //     imageUrl: obj.imgSrc,
  103. //     success: function(res){
  104. //       // 转发成功之后的回调
  105. //       if(res.errMsg == 'shareAppMessage:ok'){
  106. //       }
  107. //     },
  108. //     fail: function(){
  109. //       // 转发失败之后的回调
  110. //       if(res.errMsg == 'shareAppMessage:fail cancel'){
  111. //         // 用户取消转发
  112. //       }else if(res.errMsg == 'shareAppMessage:fail'){
  113. //         // 转发失败,其中 detail message 为详细失败信息
  114. //       }
  115. //     }
  116. //   };
  117. //   // 来自页面内的按钮的转发
  118. //   if( options.from == 'button' ){
  119. //     // 此处可以修改 shareObj 中的内容
  120. //     shareObj.path = '/pages/index/index?spread='+userInfo.uid;
  121. // console.log(shareObj.path,'shareObj.path')
  122. //   }
  123. //   // 返回shareObj
  124. //   return shareObj;
  125. // },
  126. // scClick() {
  127. // let self = this;
  128. // // #ifdef H5
  129. // self.imgSrc = self.rwmListArr[self.current].wap_poster;
  130. // // #endif
  131. // // #ifdef MP-WEIXIN
  132. // self.imgSrc = self.rwmListArr[self.current].poster;
  133. // // #endif
  134. // },
  135. // #ifdef MP-WEIXIN
  136. seav() {
  137. uni.getImageInfo({
  138. src: this.imgSrc,
  139. complete: function (result) {
  140. let path = result.path;
  141. uni.getSetting({
  142. success(res) {
  143. console.log(res)
  144. if (!res.authSetting['scope.writePhotosAlbum']) {
  145. uni.authorize({
  146. scope:'scope.writePhotosAlbum',
  147. success(res) {
  148. uni.saveImageToPhotosAlbum({
  149. filePath:path,
  150. complete(result) {
  151. }
  152. });
  153. },
  154. complete(result) {
  155. uni.showToast({
  156. title: '请先授权保存图片',
  157. duration: 2000,
  158. icon:'none'
  159. });
  160. obj.seav();
  161. }
  162. })
  163. }else{
  164. uni.saveImageToPhotosAlbum({
  165. filePath:path,
  166. complete(result) {
  167. uni.showToast({
  168. title: '保存图片成功!',
  169. duration: 2000,
  170. icon:'none'
  171. });
  172. }
  173. });
  174. }
  175. }
  176. });
  177. }
  178. });
  179. }
  180. // #endif
  181. }
  182. };
  183. </script>
  184. <style lang="scss">
  185. .imgw750h375 {
  186. width: 700rpx;
  187. height: 958rpx;
  188. }
  189. .matop{
  190. margin-top: 40rpx;
  191. }
  192. .andr-shQ-padL30 {
  193. padding-left: 30rpx;
  194. }
  195. .andr-shQ-padR30 {
  196. padding-right: 30rpx;
  197. }
  198. .andr-shQ-Flex {
  199. display: flex;
  200. }
  201. .andr-shQ-FlexDirC {
  202. flex-direction: column;
  203. }
  204. .andr-shQ-w100B {
  205. width: 100%;
  206. }
  207. .andr-shQ-JusCC {
  208. justify-content: center;
  209. }
  210. .andr-shQ-marginT30 {
  211. margin-top: 30rpx;
  212. }
  213. .andr-shQ-bgc06B163 {
  214. background-color: $base-color;
  215. }
  216. .andr-shQ-cFFF {
  217. color: #ffffff;
  218. }
  219. .andr-shQ-bdR50 {
  220. border-radius: 50rpx;
  221. }
  222. .andr-shQ-h86 {
  223. height: 86rpx;
  224. }
  225. .andr-shQ-AIC {
  226. align-items: center;
  227. }
  228. .baocun {
  229. color: #ffffff;
  230. background: $base-color;
  231. text-align: center;
  232. width: 80%;
  233. margin: 50rpx auto;
  234. font-size: 28rpx;
  235. padding: 25rpx 0rpx;
  236. border-radius: 50rpx;
  237. }
  238. .btn{
  239. padding: 0rpx 0rpx !important;
  240. margin: 0rpx auto;
  241. margin-bottom: 100rpx;
  242. }
  243. /* #ifdef H5 */
  244. .cbnagan {
  245. width: 80%;
  246. background: $base-color;
  247. margin: 50rpx auto;
  248. font-size: 28rpx;
  249. text-align: center;
  250. }
  251. /* #endif */
  252. </style>