index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <view>
  3. <view id="box">
  4. <view class='distribution-posters'>
  5. <swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :circular="circular" :interval="interval"
  6. :duration="duration" @change="bindchange" previous-margin="40px" next-margin="40px">
  7. <block v-for="(item,index) in spreadList" :key="index">
  8. <swiper-item>
  9. <view class="fx-h fx-bc fx-ac" style="height: 100%;">
  10. <image v-if="item.qrcode_img != ''" :src="item.qrcode_img" class="slide-image"
  11. :class="swiperIndex == index ? 'active' : 'quiet'" mode="widthFix" />
  12. <image v-else :src="item.poster_img" class="slide-image"
  13. :class="swiperIndex == index ? 'active' : 'quiet'" mode="widthFix" />
  14. </view>
  15. </swiper-item>
  16. </block>
  17. </swiper>
  18. </view>
  19. <view class="foot-view fx-r">
  20. <view class="save fx-h fx-bc fx-ac" @tap="tapScheng">
  21. <image src="/static/img/foot-save.png" mode="widthFix"></image>
  22. <view class="text">重新生成</view>
  23. </view>
  24. <view class="save fx-h fx-bc fx-ac" @tap="savePosterPath">
  25. <image src="/static/img/foot-down.png" mode="widthFix"></image>
  26. <view class="text">保存海报</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. mapState,
  35. mapMutations
  36. } from 'vuex';
  37. export default {
  38. data() {
  39. return {
  40. indicatorDots: false,
  41. circular: false,
  42. autoplay: false,
  43. interval: 3000,
  44. duration: 500,
  45. swiperIndex: 0,
  46. spreadList: [],
  47. userInfo: {},
  48. poster: '',
  49. navIndex: 0
  50. };
  51. },
  52. computed: mapState(['user']),
  53. onLoad() {
  54. this.userSpreadBannerList();
  55. },
  56. methods: {
  57. ...mapMutations(['checkUserLogin']),
  58. onLoadFun: function(e) {
  59. this.$set(this, 'userInfo', e);
  60. this.userSpreadBannerList();
  61. },
  62. bindchange(e) {
  63. this.navIndex = e.detail.current;
  64. this.changeImg(e.detail.current);
  65. },
  66. tapScheng: function() {
  67. let spreadList = this.spreadList;
  68. uni.showLoading({
  69. title: '获取推广码中..',
  70. mask: true
  71. });
  72. this
  73. .request
  74. .post("userSpreadQrcode", {
  75. id: spreadList[this.navIndex].id,
  76. type: 1
  77. })
  78. .then(res => {
  79. uni.hideLoading();
  80. if (res.code == 200) {
  81. this.spreadList[this.navIndex].qrcode_img = res.data.img;
  82. } else {
  83. this.utils.Tip(res.msg);
  84. }
  85. })
  86. .catch(err => {
  87. console.log(err);
  88. uni.hideLoading();
  89. this.utils.Tip("加载失败,返回在尝试!");
  90. });
  91. },
  92. changeImg: function(index) {
  93. let spreadList = this.spreadList;
  94. this.swiperIndex = index;
  95. this.$set(this, 'poster', spreadList[index].poster);
  96. if (!this.utils.isDefine(spreadList[index].qrcode_img)) {
  97. uni.showLoading({
  98. title: '获取推广码中..',
  99. mask: true
  100. });
  101. this
  102. .request
  103. .post("userSpreadQrcode", {
  104. id: spreadList[index].id
  105. })
  106. .then(res => {
  107. uni.hideLoading();
  108. if (res.code == 200) {
  109. this.spreadList[index].qrcode_img = res.data.img;
  110. } else {
  111. this.utils.Tip(res.msg);
  112. }
  113. })
  114. .catch(err => {
  115. console.log(err);
  116. uni.hideLoading();
  117. this.utils.Tip("加载失败,返回在尝试!");
  118. });
  119. }
  120. },
  121. savePosterPath: function() {
  122. var img = this.spreadList[this.swiperIndex].qrcode_img;
  123. if (img == '') {
  124. return this.utils.Tip("海报在生成中!");
  125. }
  126. let that = this;
  127. // #ifdef APP
  128. let p = uni.getSystemInfoSync().platform;
  129. if (p === "ios") {
  130. that.domImage(img);
  131. } else {
  132. that.$store.dispatch('permission/requestPermissions', 'WRITE_EXTERNAL_STORAGE').then(res => {
  133. that.domImage(img);
  134. });
  135. }
  136. // #endif
  137. // #ifndef APP
  138. that.domImage(img);
  139. // #endif
  140. },
  141. domImage(img) {
  142. const that = this;
  143. uni.downloadFile({
  144. url: img,
  145. success(resFile) {
  146. if (resFile.statusCode === 200) {
  147. uni.saveImageToPhotosAlbum({
  148. filePath: resFile.tempFilePath,
  149. success: function(res) {
  150. return that.utils.Tip("保存成功");
  151. },
  152. fail: function(res) {
  153. return that.utils.Tip(res.errMsg);
  154. },
  155. complete: function(res) {},
  156. })
  157. } else {
  158. return that.utils.Tip(resFile.errMsg);
  159. }
  160. },
  161. fail(res) {
  162. return that.utils.Tip(res.errMsg);
  163. }
  164. })
  165. },
  166. userSpreadBannerList: function() {
  167. let that = this;
  168. uni.showLoading({
  169. title: '获取中',
  170. mask: true
  171. });
  172. this
  173. .request
  174. .post("userSpreadBanner")
  175. .then(res => {
  176. uni.hideLoading();
  177. if (res.code == 200) {
  178. that.$set(that, 'spreadList', res.data);
  179. that.changeImg(0);
  180. } else {
  181. this.utils.showAlert({
  182. title: res.msg,
  183. icon: "none",
  184. mask: true
  185. });
  186. }
  187. })
  188. .catch(err => {
  189. uni.hideLoading();
  190. uni.showModal({
  191. title: '系统提示',
  192. content: '加载失败,返回在尝试',
  193. showCancel: false
  194. });
  195. });
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss">
  201. .about {
  202. width: 100%;
  203. height: 100%;
  204. background: #303033;
  205. ;
  206. }
  207. .distribution-posters {
  208. padding-top: 40rpx;
  209. }
  210. .distribution-posters swiper {
  211. width: 100%;
  212. height: calc(100vh - 120rpx - 40rpx);
  213. position: relative;
  214. }
  215. /* #ifdef H5 */
  216. .distribution-posters swiper {
  217. height: calc(100vh - 120rpx - 40rpx - 50px);
  218. }
  219. /* #endif */
  220. .distribution-posters .slide-image {
  221. width: calc(54 - 86rpx);
  222. height: calc(100vh - 160rpx);
  223. margin: 0 auto;
  224. border-radius: 15rpx;
  225. }
  226. .distribution-posters .slide-image.active {
  227. transform: none;
  228. transition: all 0.2s ease-in 0s;
  229. }
  230. .distribution-posters .slide-image.quiet {
  231. transform: scale(0.8333333);
  232. transition: all 0.2s ease-in 0s;
  233. }
  234. .distribution-posters .keep {
  235. font-size: 30rpx;
  236. color: #fff;
  237. width: 600rpx;
  238. height: 80rpx;
  239. border-radius: 50rpx;
  240. text-align: center;
  241. line-height: 80rpx;
  242. margin: 38rpx auto;
  243. }
  244. .distribution-posters .preserve {
  245. color: #fff;
  246. text-align: center;
  247. margin-top: 38rpx;
  248. }
  249. .distribution-posters .preserve .line {
  250. width: 100rpx;
  251. height: 1px;
  252. background-color: #fff;
  253. }
  254. .distribution-posters .preserve .tip {
  255. margin: 0 30rpx;
  256. }
  257. .bg-color {
  258. background: #844bff;
  259. }
  260. .row-between-wrapper {
  261. -webkit-box-align: center;
  262. -moz-box-align: center;
  263. -o-box-align: center;
  264. -ms-flex-align: center;
  265. -webkit-align-items: center;
  266. align-items: center;
  267. -webkit-box-pack: justify;
  268. -moz-box-pack: justify;
  269. -o-box-pack: justify;
  270. -ms-flex-pack: justify;
  271. -webkit-justify-content: space-between;
  272. justify-content: space-between
  273. }
  274. .row-middle {
  275. -webkit-box-align: center;
  276. -moz-box-align: center;
  277. -o-box-align: center;
  278. -ms-flex-align: center;
  279. -webkit-align-items: center;
  280. align-items: center
  281. }
  282. .row-around {
  283. justify-content: space-around;
  284. -webkit-justify-content: space-around
  285. }
  286. .foot-view {
  287. height: 120rpx;
  288. }
  289. .foot-view .save {
  290. width: 50%;
  291. }
  292. .foot-view .save image {
  293. width: 60rpx;
  294. height: 60rpx;
  295. }
  296. .foot-view .save .text {
  297. color: #999999;
  298. text-align: center;
  299. font-size: 14px;
  300. margin-top: 6px;
  301. }
  302. </style>