index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // pages/distribution-posters/index.js
  2. import { spreadBanner, userShare } from '../../api/user.js';
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. parameter: {
  10. 'navbar': '1',
  11. 'return': '1',
  12. 'title': '分销海报'
  13. },
  14. imgUrls: [],
  15. indicatorDots: false,
  16. circular: false,
  17. autoplay: false,
  18. interval: 3000,
  19. duration: 500,
  20. swiperIndex: 0,
  21. spreadList:[],
  22. userInfo:{},
  23. poster:'',
  24. },
  25. onLoadFun:function(e){
  26. this.setData({ userInfo: e.detail});
  27. this.userSpreadBannerList();
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. },
  34. bindchange(e) {
  35. var spreadList = this.data.spreadList;
  36. this.setData({
  37. swiperIndex: e.detail.current,
  38. poster: spreadList[e.detail.current].poster,
  39. })
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function () {
  50. this.data.isClone && this.userSpreadBannerList();
  51. },
  52. savePosterPath: function () {
  53. var that = this;
  54. wx.downloadFile({
  55. url: that.data.poster,
  56. success(resFile) {
  57. if (resFile.statusCode === 200) {
  58. wx.getSetting({
  59. success(res) {
  60. if (!res.authSetting['scope.writePhotosAlbum']) {
  61. wx.authorize({
  62. scope: 'scope.writePhotosAlbum',
  63. success() {
  64. wx.saveImageToPhotosAlbum({
  65. filePath: resFile.tempFilePath,
  66. success: function (res) {
  67. return app.Tips({ title: '保存成功' });
  68. },
  69. fail: function (res) {
  70. return app.Tips({ title: res.errMsg });
  71. },
  72. complete: function (res) { },
  73. })
  74. },
  75. fail(){
  76. wx.showModal({
  77. title: '您已拒绝获取相册权限',
  78. content: '是否进入权限管理,调整授权?',
  79. success(res) {
  80. if (res.confirm) {
  81. wx.openSetting({
  82. success: function (res) {
  83. console.log(res.authSetting)
  84. }
  85. });
  86. } else if (res.cancel) {
  87. return app.Tips({ title: '已取消!' });
  88. }
  89. }
  90. })
  91. }
  92. })
  93. } else {
  94. wx.saveImageToPhotosAlbum({
  95. filePath: resFile.tempFilePath,
  96. success: function (res) {
  97. return app.Tips({ title: '保存成功' });
  98. },
  99. fail: function (res) {
  100. return app.Tips({ title: res.errMsg });
  101. },
  102. complete: function (res) { },
  103. })
  104. }
  105. },
  106. fail(res){
  107. }
  108. })
  109. }else{
  110. return app.Tips({ title: resFile.errMsg});
  111. }
  112. },
  113. fail(res) {
  114. return app.Tips({ title: res.errMsg});
  115. }
  116. })
  117. },
  118. userSpreadBannerList: function () {
  119. var that = this;
  120. wx.showLoading({
  121. title: '获取中',
  122. mask: true,
  123. })
  124. spreadBanner().then(res=>{
  125. wx.hideLoading();
  126. that.setData({ spreadList: res.data, poster: res.data[0].poster });
  127. }).catch(err=>{
  128. wx.hideLoading();
  129. });
  130. },
  131. /**
  132. * 生命周期函数--监听页面隐藏
  133. */
  134. onHide: function () {
  135. this.setData({isClone:true});
  136. },
  137. /**
  138. * 生命周期函数--监听页面卸载
  139. */
  140. onUnload: function () {
  141. },
  142. /**
  143. * 页面相关事件处理函数--监听用户下拉动作
  144. */
  145. onPullDownRefresh: function () {
  146. },
  147. /**
  148. * 页面上拉触底事件的处理函数
  149. */
  150. onReachBottom: function () {
  151. },
  152. /**
  153. * 用户点击右上角分享
  154. */
  155. onShareAppMessage: function () {
  156. userShare();
  157. return {
  158. title: this.data.userInfo.nickname+'-分销海报',
  159. imageUrl: this.data.spreadList[0],
  160. path: '/pages/index/index?spid=' + this.data.userInfo.uid,
  161. };
  162. }
  163. })