shareQrCode.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view class="container">
  3. <swiper
  4. class="posters-box"
  5. :autoplay="false"
  6. :circular="false"
  7. :interval="3000"
  8. :duration="500"
  9. @change="bindchange"
  10. previous-margin="40px"
  11. next-margin="40px">
  12. <block
  13. v-for="(item, index) in shareList"
  14. :key="index">
  15. <swiper-item>
  16. <!-- #ifndef MP -->
  17. <image
  18. class="slide-image"
  19. :class="swiperIndex == index ? 'active' : 'quiet'"
  20. mode="aspectFill"
  21. :src="item.wap_poster"></image>
  22. <!-- #endif -->
  23. <!-- #ifdef MP -->
  24. <image
  25. class="slide-image"
  26. :class="swiperIndex == index ? 'active' : 'quiet'"
  27. mode="aspectFill"
  28. :src="item.poster"></image>
  29. <!-- #endif -->
  30. </swiper-item>
  31. </block>
  32. </swiper>
  33. <!-- #ifndef MP -->
  34. <div class="preserve">
  35. <div class="line"></div>
  36. <div class="tip">长按保存图片</div>
  37. <div class="line"></div>
  38. </div>
  39. <!-- #endif -->
  40. <!-- #ifdef MP -->
  41. <view
  42. class="keep"
  43. @click="savePosterPath"
  44. >长按保存图片</view
  45. >
  46. <!-- #endif -->
  47. </view>
  48. </template>
  49. <script>
  50. import { spreadBanner } from "@/api/user.js";
  51. import { mapState } from "vuex";
  52. export default {
  53. // #ifdef MP
  54. onShareAppMessage: function (res) {
  55. // 保存邀请人
  56. let path = "/pages/index/index?" + "spread=" + this.userInfo.uid;
  57. let data = {
  58. path: path,
  59. imageUrl: this.poster,
  60. title: this.userInfo.nickname +'邀请您加入',
  61. };
  62. return data;
  63. },
  64. // #endif
  65. data() {
  66. return {
  67. shareList: [],
  68. swiperIndex: 0,
  69. poster: "", // 当前海报
  70. };
  71. },
  72. onLoad(option) {
  73. this.loadData();
  74. },
  75. computed: {
  76. ...mapState("user", ["userInfo"]),
  77. },
  78. methods: {
  79. bindchange(e) {
  80. let shareList = this.shareList;
  81. this.swiperIndex = e.detail.current;
  82. // #ifdef MP
  83. this.poster = shareList[this.swiperIndex].poster;
  84. // #endif
  85. console.log(this.poster);
  86. },
  87. // 保存海报
  88. savePosterPath: function () {
  89. let that = this;
  90. if (that.poster == "") {
  91. that.poster = that.shareList[0].poster;
  92. }
  93. uni.downloadFile({
  94. url: that.poster,
  95. success(resFile) {
  96. if (resFile.statusCode === 200) {
  97. uni.getSetting({
  98. success(res) {
  99. if (
  100. !res.authSetting[
  101. "scope.writePhotosAlbum"
  102. ]
  103. ) {
  104. uni.authorize({
  105. scope: "scope.writePhotosAlbum",
  106. success() {
  107. uni.saveImageToPhotosAlbum({
  108. filePath:
  109. resFile.tempFilePath,
  110. success: function (res) {
  111. return that.$api.msg(
  112. this.$t("huiyuan.b4")
  113. );
  114. },
  115. fail: function (res) {
  116. return that.$api.msg(
  117. res.errMsg
  118. );
  119. },
  120. complete: function (res) {},
  121. });
  122. },
  123. fail() {
  124. uni.showModal({
  125. title: this.$t("huiyuan.b5"),
  126. content:
  127. this.$t("huiyuan.b6"),
  128. success(res) {
  129. if (res.confirm) {
  130. uni.openSetting({
  131. success:
  132. function (
  133. res
  134. ) {
  135. console.log(
  136. res.authSetting
  137. );
  138. },
  139. });
  140. } else if (res.cancel) {
  141. return that.$api.msg(
  142. this.$t("huiyuan.b7")
  143. );
  144. }
  145. },
  146. });
  147. },
  148. });
  149. } else {
  150. uni.saveImageToPhotosAlbum({
  151. filePath: resFile.tempFilePath,
  152. success: function (res) {
  153. return that.$api.msg(
  154. this.$t("huiyuan.b8")
  155. );
  156. },
  157. fail: function (res) {
  158. return that.$api.msg(
  159. res.errMsg
  160. );
  161. },
  162. complete: function (res) {},
  163. });
  164. }
  165. },
  166. fail(res) {},
  167. });
  168. } else {
  169. return that.$api.msg(resFile.errMsg);
  170. }
  171. },
  172. fail(res) {
  173. return that.$api.msg(res.errMsg);
  174. },
  175. });
  176. },
  177. // #ifdef MP-WEIXIN
  178. // 保存画图图片到本地
  179. seav(url) {
  180. uni.showLoading({
  181. title: '保存中',
  182. mask: true,
  183. });
  184. uni.saveImageToPhotosAlbum({
  185. filePath: this.poster,
  186. complete(result) {
  187. uni.hideLoading();
  188. console.log(result);
  189. uni.showToast({
  190. title: '保存成功',
  191. duration: 2000,
  192. icon: "none",
  193. });
  194. },
  195. });
  196. },
  197. // #endif
  198. // 获取海报
  199. loadData() {
  200. let obj = this;
  201. uni.showLoading({
  202. title: "获取中",
  203. mask: true,
  204. });
  205. spreadBanner({
  206. // #ifdef H5
  207. type: 2,
  208. // #endif
  209. // #ifdef MP
  210. type: 1,
  211. // #endif
  212. })
  213. .then(res => {
  214. uni.hideLoading();
  215. obj.shareList = res.data;
  216. console.log("obj.shareList", obj.shareList);
  217. })
  218. .catch(err => {
  219. uni.hideLoading();
  220. });
  221. },
  222. },
  223. };
  224. </script>
  225. <style lang="scss">
  226. page {
  227. background: #a3a3a3;
  228. height: 100%;
  229. }
  230. .container {
  231. width: 100%;
  232. .posters-box {
  233. width: 100%;
  234. height: 1000rpx;
  235. margin-top: 40rpx;
  236. .slide-image {
  237. width: 100%;
  238. height: 100%;
  239. border-radius: 15rpx;
  240. }
  241. }
  242. .posters-box .slide-image.active {
  243. transform: none;
  244. transition: all 0.2s ease-in 0s;
  245. }
  246. .posters-box .slide-image.quiet {
  247. transform: scale(0.8333333);
  248. transition: all 0.2s ease-in 0s;
  249. }
  250. .keep {
  251. font-size: 30rpx;
  252. background: $base-color;
  253. color: #fff;
  254. width: 600rpx;
  255. height: 80rpx;
  256. border-radius: 50rpx;
  257. text-align: center;
  258. line-height: 80rpx;
  259. margin: 38rpx auto;
  260. }
  261. }
  262. .preserve {
  263. color: #fff;
  264. text-align: center;
  265. margin-top: 38rpx;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. .line {
  270. width: 100rpx;
  271. height: 1px;
  272. background-color: #fff;
  273. }
  274. .tip {
  275. margin: 0 20rpx;
  276. font-size: 28rpx;
  277. }
  278. }
  279. </style>