favorites.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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">{{$t('huiyuan.b1')}}</div>
  37. <div class="line"></div>
  38. </div>
  39. <!-- #endif -->
  40. <!-- #ifdef MP -->
  41. <view
  42. class="keep"
  43. @click="savePosterPath"
  44. >{{$t('huiyuan.b2')}}</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 + this.$t("huiyuan.b3"),
  61. };
  62. return data;
  63. },
  64. // #endif
  65. data() {
  66. return {
  67. shareList: [],
  68. swiperIndex: 0,
  69. poster: "", // 当前海报
  70. };
  71. },
  72. onLoad(option) {
  73. uni.setNavigationBarTitle({
  74. title: this.$t("tab.b2"),
  75. });
  76. this.loadData();
  77. },
  78. computed: {
  79. ...mapState("user", ["userInfo"]),
  80. },
  81. methods: {
  82. bindchange(e) {
  83. let shareList = this.shareList;
  84. this.swiperIndex = e.detail.current;
  85. // #ifdef MP
  86. this.poster = shareList[this.swiperIndex].poster;
  87. // #endif
  88. console.log(this.poster);
  89. },
  90. // 保存海报
  91. savePosterPath: function () {
  92. let that = this;
  93. if (that.poster == "") {
  94. that.poster = that.shareList[0].poster;
  95. }
  96. uni.downloadFile({
  97. url: that.poster,
  98. success(resFile) {
  99. if (resFile.statusCode === 200) {
  100. uni.getSetting({
  101. success(res) {
  102. if (
  103. !res.authSetting[
  104. "scope.writePhotosAlbum"
  105. ]
  106. ) {
  107. uni.authorize({
  108. scope: "scope.writePhotosAlbum",
  109. success() {
  110. uni.saveImageToPhotosAlbum({
  111. filePath:
  112. resFile.tempFilePath,
  113. success: function (res) {
  114. return that.$api.msg(
  115. this.$t("huiyuan.b4")
  116. );
  117. },
  118. fail: function (res) {
  119. return that.$api.msg(
  120. res.errMsg
  121. );
  122. },
  123. complete: function (res) {},
  124. });
  125. },
  126. fail() {
  127. uni.showModal({
  128. title: this.$t("huiyuan.b5"),
  129. content:
  130. this.$t("huiyuan.b6"),
  131. success(res) {
  132. if (res.confirm) {
  133. uni.openSetting({
  134. success:
  135. function (
  136. res
  137. ) {
  138. console.log(
  139. res.authSetting
  140. );
  141. },
  142. });
  143. } else if (res.cancel) {
  144. return that.$api.msg(
  145. this.$t("huiyuan.b7")
  146. );
  147. }
  148. },
  149. });
  150. },
  151. });
  152. } else {
  153. uni.saveImageToPhotosAlbum({
  154. filePath: resFile.tempFilePath,
  155. success: function (res) {
  156. return that.$api.msg(
  157. this.$t("huiyuan.b8")
  158. );
  159. },
  160. fail: function (res) {
  161. return that.$api.msg(
  162. res.errMsg
  163. );
  164. },
  165. complete: function (res) {},
  166. });
  167. }
  168. },
  169. fail(res) {},
  170. });
  171. } else {
  172. return that.$api.msg(resFile.errMsg);
  173. }
  174. },
  175. fail(res) {
  176. return that.$api.msg(res.errMsg);
  177. },
  178. });
  179. },
  180. // #ifdef MP-WEIXIN
  181. // 保存画图图片到本地
  182. seav(url) {
  183. uni.showLoading({
  184. title: this.$t("huiyuan.b9"),
  185. mask: true,
  186. });
  187. uni.saveImageToPhotosAlbum({
  188. filePath: this.poster,
  189. complete(result) {
  190. uni.hideLoading();
  191. console.log(result);
  192. uni.showToast({
  193. title: this.$t("huiyuan.b0"),
  194. duration: 2000,
  195. icon: "none",
  196. });
  197. },
  198. });
  199. },
  200. // #endif
  201. // 获取海报
  202. loadData() {
  203. let obj = this;
  204. uni.showLoading({
  205. title: "获取中",
  206. mask: true,
  207. });
  208. spreadBanner({
  209. // #ifdef H5
  210. type: 2,
  211. // #endif
  212. // #ifdef MP
  213. type: 1,
  214. // #endif
  215. })
  216. .then(res => {
  217. uni.hideLoading();
  218. obj.shareList = res.data;
  219. console.log("obj.shareList", obj.shareList);
  220. })
  221. .catch(err => {
  222. uni.hideLoading();
  223. });
  224. },
  225. },
  226. };
  227. </script>
  228. <style lang="scss">
  229. page {
  230. background: #a3a3a3;
  231. height: 100%;
  232. }
  233. .container {
  234. width: 100%;
  235. .posters-box {
  236. width: 100%;
  237. height: 1000rpx;
  238. margin-top: 40rpx;
  239. .slide-image {
  240. width: 100%;
  241. height: 100%;
  242. border-radius: 15rpx;
  243. }
  244. }
  245. .posters-box .slide-image.active {
  246. transform: none;
  247. transition: all 0.2s ease-in 0s;
  248. }
  249. .posters-box .slide-image.quiet {
  250. transform: scale(0.8333333);
  251. transition: all 0.2s ease-in 0s;
  252. }
  253. .keep {
  254. font-size: 30rpx;
  255. background: $base-color;
  256. color: #fff;
  257. width: 600rpx;
  258. height: 80rpx;
  259. border-radius: 50rpx;
  260. text-align: center;
  261. line-height: 80rpx;
  262. margin: 38rpx auto;
  263. }
  264. }
  265. .preserve {
  266. color: #fff;
  267. text-align: center;
  268. margin-top: 38rpx;
  269. display: flex;
  270. align-items: center;
  271. justify-content: center;
  272. .line {
  273. width: 100rpx;
  274. height: 1px;
  275. background-color: #fff;
  276. }
  277. .tip {
  278. margin: 0 20rpx;
  279. font-size: 28rpx;
  280. }
  281. }
  282. </style>