shareQrCode.vue 6.5 KB

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