index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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({
  27. userInfo: e.detail
  28. })
  29. this.userSpreadBannerList()
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {},
  35. bindchange(e) {
  36. var spreadList = this.data.spreadList
  37. this.setData({
  38. swiperIndex: e.detail.current,
  39. poster: spreadList[e.detail.current].poster
  40. })
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady: function () {},
  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({
  68. title: '保存成功'
  69. })
  70. },
  71. fail: function (res) {
  72. return app.Tips({
  73. title: res.errMsg
  74. })
  75. },
  76. complete: function (res) {}
  77. })
  78. },
  79. fail() {
  80. wx.showModal({
  81. title: '您已拒绝获取相册权限',
  82. content: '是否进入权限管理,调整授权?',
  83. success(res) {
  84. if (res.confirm) {
  85. wx.openSetting({
  86. success: function (res) {
  87. console.log(res.authSetting)
  88. }
  89. })
  90. } else if (res.cancel) {
  91. return app.Tips({
  92. title: '已取消!'
  93. })
  94. }
  95. }
  96. })
  97. }
  98. })
  99. } else {
  100. wx.saveImageToPhotosAlbum({
  101. filePath: resFile.tempFilePath,
  102. success: function (res) {
  103. return app.Tips({
  104. title: '保存成功'
  105. })
  106. },
  107. fail: function (res) {
  108. return app.Tips({
  109. title: res.errMsg
  110. })
  111. },
  112. complete: function (res) {}
  113. })
  114. }
  115. },
  116. fail(res) {}
  117. })
  118. } else {
  119. return app.Tips({
  120. title: resFile.errMsg
  121. })
  122. }
  123. },
  124. fail(res) {
  125. return app.Tips({
  126. title: res.errMsg
  127. })
  128. }
  129. })
  130. },
  131. userSpreadBannerList: function () {
  132. var that = this
  133. wx.showLoading({
  134. title: '获取中',
  135. mask: true
  136. })
  137. spreadBanner()
  138. .then(res => {
  139. wx.hideLoading()
  140. that.setData({
  141. spreadList: res.data,
  142. poster: res.data[0].poster
  143. })
  144. })
  145. .catch(err => {
  146. wx.hideLoading()
  147. })
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. this.setData({
  154. isClone: true
  155. })
  156. },
  157. /**
  158. * 生命周期函数--监听页面卸载
  159. */
  160. onUnload: function () {},
  161. /**
  162. * 页面相关事件处理函数--监听用户下拉动作
  163. */
  164. onPullDownRefresh: function () {},
  165. /**
  166. * 页面上拉触底事件的处理函数
  167. */
  168. onReachBottom: function () {},
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function () {
  173. userShare()
  174. return {
  175. title: this.data.userInfo.nickname + '-分销海报',
  176. imageUrl: this.data.spreadList[0],
  177. path: '/pages/index/index?spid=' + this.data.userInfo.uid
  178. }
  179. }
  180. })