index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // pages/distribution-posters/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. 'navbar': '1',
  10. 'return': '1',
  11. 'title': '分销海报'
  12. },
  13. imgUrls: [],
  14. indicatorDots: false,
  15. circular: false,
  16. autoplay: false,
  17. interval: 3000,
  18. duration: 500,
  19. swiperIndex: 0,
  20. spreadList:[],
  21. userInfo:{},
  22. poster:'',
  23. },
  24. onLoadFun:function(){
  25. this.getUserInfo();
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. },
  32. bindchange(e) {
  33. var spreadList = this.data.spreadList;
  34. this.setData({
  35. swiperIndex: e.detail.current,
  36. poster: spreadList[e.detail.current].poster,
  37. })
  38. },
  39. /**
  40. * 生命周期函数--监听页面初次渲染完成
  41. */
  42. onReady: function () {
  43. },
  44. getUserInfo:function(){
  45. var that=this;
  46. app.baseGet(app.U({ c: 'user_api', a:'get_my_user_info'}),function(res){
  47. that.setData({userInfo:res.data});
  48. });
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. this.userSpreadBannerList();
  55. },
  56. savePosterPath: function () {
  57. var that = this;
  58. wx.downloadFile({
  59. url: that.data.poster,
  60. success(resFile) {
  61. console.log(resFile.tempFilePath)
  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. wx.showToast({
  73. title: '保存成功',
  74. icon: 'success',
  75. duration: 1500,
  76. })
  77. },
  78. fail: function (res) {
  79. wx.showToast({
  80. title: res.errMsg,
  81. icon: 'none',
  82. duration: 1500,
  83. })
  84. },
  85. complete: function (res) { },
  86. })
  87. }
  88. })
  89. } else {
  90. wx.saveImageToPhotosAlbum({
  91. filePath: resFile.tempFilePath,
  92. success: function (res) {
  93. wx.showToast({
  94. title: '保存成功',
  95. icon: 'success',
  96. duration: 1500,
  97. })
  98. },
  99. fail: function (res) {
  100. wx.showToast({
  101. title: res.errMsg,
  102. icon: 'none',
  103. duration: 1500,
  104. })
  105. },
  106. complete: function (res) { },
  107. })
  108. }
  109. }
  110. })
  111. }else{
  112. wx.showToast({
  113. title: resFile.errMsg,
  114. icon: 'none',
  115. duration: 1000,
  116. mask: true,
  117. })
  118. }
  119. },
  120. fail(res) {
  121. wx.showToast({
  122. title: res.errMsg,
  123. icon: 'none',
  124. duration: 1000,
  125. mask: true,
  126. })
  127. }
  128. })
  129. },
  130. userSpreadBannerList: function () {
  131. var that = this;
  132. wx.showLoading({
  133. title: '获取中',
  134. mask: true,
  135. })
  136. app.baseGet(app.U({ c: 'user_api', a: 'user_spread_banner_list' }), function (res) {
  137. wx.hideLoading();
  138. that.setData({ spreadList: res.data ,poster: res.data[0].poster});
  139. }, function (res) { wx.hideLoading(); });
  140. },
  141. /**
  142. * 生命周期函数--监听页面隐藏
  143. */
  144. onHide: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面卸载
  148. */
  149. onUnload: function () {
  150. },
  151. /**
  152. * 页面相关事件处理函数--监听用户下拉动作
  153. */
  154. onPullDownRefresh: function () {
  155. },
  156. /**
  157. * 页面上拉触底事件的处理函数
  158. */
  159. onReachBottom: function () {
  160. },
  161. set_user_share: function () {
  162. app.baseGet(app.U({ c: 'public_api', a: 'set_user_share' }), null, null, true);
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage: function () {
  168. this.set_user_share();
  169. return {
  170. title: this.data.userInfo.nickname+'-分销海报',
  171. imageUrl: this.data.spreadList[0],
  172. path: '/pages/index/index?spid=' + this.data.userInfo.uid,
  173. };
  174. }
  175. })