index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //获取应用实例
  2. const
  3. app = getApp(),
  4. Bmob = require('../../utils/Bmob-1.6.1.min.js'),
  5. Storage = require('../../utils/storage.js'),
  6. API = require('../../api/API.js'),
  7. utils = require('../../utils/util.js');
  8. let touchX = 0;//触摸时的原点
  9. let touchY = 0;//触摸时的原点
  10. let time = 0;// 时间记录,用于滑动时且时间小于1s则执行左右滑动
  11. let interval = "";// 记录/清理 时间记录
  12. let nth = 0;// 设置活动菜单的index
  13. let nthMax = 5;//活动菜单的最大个数
  14. let tmpFlag = true;// 判断左右华东超出菜单最大值时不再执行滑动事件
  15. // let pages = [
  16. // {
  17. // cover:'http://bmob-cdn-19734.b0.upaiyun.com/2018/06/07/dc1797d940ccb8cd80fc54c434c75883.png',
  18. // title:'一生所爱',
  19. // author:'卢冠延',
  20. // content:'开始终结总是',
  21. // encode:'http://bmob-cdn-19734.b0.upaiyun.com/2018/06/07/dc1797d940ccb8cd80fc54c434c75883.png'
  22. // },
  23. // {
  24. // cover:'http://bmob-cdn-19734.b0.upaiyun.com/2018/06/07/dc1797d940ccb8cd80fc54c434c75883.png',
  25. // title:'哈哈',
  26. // author:'林润茏',
  27. // content:'天天监管机构好几个监管机构监管机构监管机构天天监管机构好几个监管机构监管机构监管机构天天监管机构好几个监管机构监管机构监管机构天天监管机构好几个监管机构监管机构监管机构天天监管机构好几个监管机构监管机构监管机构',
  28. // encode:'http://bmob-cdn-19734.b0.upaiyun.com/2018/06/07/dc1797d940ccb8cd80fc54c434c75883.png'
  29. // },
  30. // ];
  31. Page({
  32. data: {
  33. pages:[],
  34. curPage:0,
  35. nextPage:0,
  36. lastPage:0,
  37. send:0,
  38. page:{},
  39. },
  40. onLoad: function () {
  41. let me =this;
  42. var animation = wx.createAnimation({
  43. duration: 100,
  44. timingFunction: 'ease-out',
  45. })
  46. this.animation = animation;
  47. API.getPosts(200,this.data.send).then(res=>{
  48. for (let i = 0;i<res.length;i++){
  49. res[i].post = JSON.parse( res[i].post);
  50. }
  51. console.error(res)
  52. if(res.length>0){
  53. me.data.pages = res;
  54. me.setData({
  55. page:me.data.pages[me.data.curPage]
  56. })
  57. }
  58. })
  59. },
  60. onReady:function () {
  61. //监听页面初次渲染完成
  62. },
  63. onShow:function () {
  64. //监听页面显示
  65. },
  66. onHide:function () {
  67. //监听页面隐藏
  68. },
  69. onPullDownRefresh: function() {
  70. console.log(1)
  71. },
  72. onReachBottom: function() {
  73. console.log(2)
  74. },
  75. pagemove: function (event) {
  76. },
  77. onShareAppMessage:function () {
  78. //用户点击右上角转发
  79. return {
  80. title: '回到你的幸福時光',
  81. path: '../main/index'
  82. }
  83. },
  84. pageend :function (e) {
  85. console.log(e);
  86. let me = this ;
  87. let curX = e.changedTouches[0].pageX;
  88. //下一页
  89. if(curX - touchX >= 60 && time <10){
  90. this.animationStart('left');
  91. this.data.curPage++;
  92. if(this.data.curPage<0||this.data.curPage>=this.data.pages.length){
  93. me.data.curPage = 0;
  94. // me.data.send +=10;
  95. // me._getPages(me.data.send);
  96. // return
  97. }
  98. let page = this.data.pages[this.data.curPage];
  99. setTimeout(function () {
  100. me.setData({
  101. page:page
  102. },function () {
  103. me.animationEnd('left');
  104. })
  105. },300)
  106. // 上一页
  107. }else if(curX - touchX <= -60 && time <10){
  108. this.animationStart('right');
  109. this.data.curPage--;
  110. if(this.data.curPage<0||this.data.curPage>=this.data.pages.length){
  111. this.data.curPage = this.data.pages.length-1;
  112. }
  113. let page = this.data.pages[this.data.curPage];
  114. setTimeout(function () {
  115. me.setData({
  116. page:page
  117. },function () {
  118. me.animationEnd('right');
  119. })
  120. },300)
  121. }
  122. clearInterval(interval); // 清除setInterval
  123. time = 0;
  124. },
  125. pagestart:function (e) {
  126. touchX = e.touches[0].pageX;
  127. touchY = e.touches[0].pageY;
  128. interval = setInterval(function(){
  129. time++;
  130. },100);
  131. },
  132. animationStart:function (e) {
  133. let systemInfo = app.globalData.systemInfo,
  134. width = app.globalData.systemInfo.windowWidth;
  135. if(e=='left'){
  136. this.animation.translateX(width).step();
  137. }else {
  138. this.animation.translateX(-width).step();
  139. }
  140. this.setData({
  141. animationData:this.animation.export()
  142. });
  143. },
  144. animationEnd:function (e) {
  145. let me = this;
  146. let systemInfo = app.globalData.systemInfo,
  147. width = app.globalData.systemInfo.windowWidth;
  148. setTimeout(function () {
  149. me.animation.translateX(0).step();
  150. me.setData({
  151. animationData:me.animation.export()
  152. });
  153. },200)
  154. },
  155. // _getPages :function () {
  156. // let me = this;
  157. // API.getPosts(10,me.data.send).then(res=>{
  158. // if(res.length ==0){
  159. // me.data.send=0;
  160. // return me._getPages(me.data.send);
  161. // }
  162. // for (let i = 0;i<res.length;i++){
  163. // res[i].post = JSON.parse( res[i].post);
  164. // }
  165. // console.error(res)
  166. // if(res.length>0){
  167. // me.data.pages = res;
  168. // me.setData({
  169. // page:me.data.pages[me.data.curPage]
  170. // })
  171. // }
  172. // })
  173. // },
  174. })