index.js 6.3 KB

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