index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //index.js
  2. //获取应用实例
  3. import {
  4. getOpenidSessionKey
  5. } from '../../utils/httpUtil';
  6. const app = getApp()
  7. import {
  8. hotInit
  9. } from '../../component/hot/hot';
  10. import {
  11. groupInit
  12. } from '../../component/group/group';
  13. import {
  14. myInit
  15. } from '../../component/my/my';
  16. import {
  17. followInit
  18. } from '../../component/follow/follow';
  19. // import '../../utils/hls';
  20. import httpRequestApi from '../../utils/APIClient';
  21. import httputil from '../../utils/httpUtil';
  22. import {
  23. GetQueryString
  24. } from '../../utils/util';
  25. Page({
  26. data: {
  27. tab: [{
  28. name: '热团',
  29. templates: 'group',
  30. },
  31. {
  32. name: '推荐',
  33. templates: 'hot',
  34. },
  35. {
  36. name: '关注',
  37. templates: 'follow',
  38. },
  39. {
  40. name: '我的',
  41. templates: 'my',
  42. }
  43. ],
  44. winH: 568,
  45. myIndex: 1,
  46. followData: [],
  47. recommendPageNo: 1,
  48. recommendTotalNo: 0,
  49. followPageNo: 1,
  50. followPageTotalNo: 0,
  51. myData: {},
  52. templates: 'hot',
  53. title: 'index中的title',
  54. jurisdictionFlag: true,
  55. hotInput: '12345',
  56. mineSettingInfo: '528',
  57. hide: true
  58. },
  59. jurisdiction: function () {
  60. //隐藏弹框
  61. this.setData({
  62. hide: !this.data.hide
  63. })
  64. //登录页信息
  65. this.onShow();
  66. },
  67. //tab点击
  68. switcher: function ({
  69. currentTarget
  70. }) {
  71. this.updateData(currentTarget.dataset.index);
  72. },
  73. // 根据index 更新template
  74. updateData: function (index) {
  75. let myIndex = index;
  76. let templates = this.data.tab[myIndex].templates;
  77. this.setData({
  78. myIndex,
  79. templates
  80. });
  81. if (myIndex == 0) {
  82. groupInit(this);
  83. }
  84. if (myIndex == 1) {
  85. this.setData({
  86. recommendPageNo: 1
  87. })
  88. hotInit(this);
  89. }
  90. if (myIndex == 2) {
  91. this.setData({
  92. followPageNo: 1
  93. })
  94. followInit(this);
  95. }
  96. if (myIndex == 3) {
  97. myInit(this);
  98. // getOpenidSessionKey( res => {
  99. // console.log(res);
  100. // }, (error) => {
  101. // this.setData({
  102. // hide: !this.data.hide
  103. // });
  104. // });
  105. }
  106. },
  107. onLoad: function (options) {
  108. this.uid = wx.getStorageSync('uid');
  109. // const type = GetQueryString(decodeURIComponent(options.scene),"type");
  110. // const sceneId = GetQueryString( decodeURIComponent(options.scene),"id");
  111. // console.log(type,sceneId)
  112. // switch(type){
  113. // case "works":
  114. // wx.navigateTo({
  115. // url: `../social/works/works?id=${sceneId}&title="测试"`
  116. // })
  117. // break
  118. // };
  119. wx.getSystemInfo({
  120. success: (res) => {
  121. this.setData({
  122. winH: res.windowHeight
  123. });
  124. }
  125. });
  126. if (options.index) {
  127. this.updateData(options.index)
  128. }
  129. hotInit(this)
  130. // this.init();
  131. },
  132. onShow: function () {
  133. // this.init();
  134. getOpenidSessionKey((res) => {}, (error) => {
  135. // console.log(error)
  136. this.setData({
  137. hide: !this.data.hide
  138. })
  139. });
  140. if (this.data.myIndex === 3) {
  141. this.getUserWorksInfo();
  142. }
  143. },
  144. //初始化数据
  145. init: function () {
  146. httputil.getOpenidSessionKey((res) => {
  147. console.log('微信的用户信息', res)
  148. }, (error) => {
  149. console.log(error);
  150. this.jurisdiction()
  151. // this.setData({
  152. // jurisdictionFlag: false
  153. // })
  154. });
  155. },
  156. // 获取用户信息
  157. getUserWorksInfo: function () {
  158. httpRequestApi.getUserWorksInfo().success(res => {
  159. console.log(res)
  160. this.data.myData.user = res.data.data; //直接赋值 给 myData的user对象。
  161. this.setData({
  162. myData: this.data.myData,
  163. });
  164. }).fail(error => {
  165. console.log(error)
  166. })
  167. },
  168. // 触底加载
  169. onReachBottom: function () {
  170. // 当前在推荐页面 加载推荐
  171. if (this.data.myIndex === 1) {
  172. console.log(this.data.recommendPageNo)
  173. this.setData({
  174. recommendPageNo: this.data.recommendPageNo + 1
  175. })
  176. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  177. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  178. } else {
  179. console.log('没有更多')
  180. }
  181. }
  182. if (this.data.myIndex === 2) {
  183. console.log(this.data.followPageTotalNo)
  184. this.setData({
  185. followPageNo: this.data.followPageNo + 1
  186. })
  187. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  188. this.getWorks(this.uid, this.data.followPageNo, 5);
  189. } else {
  190. console.log('没有更多')
  191. }
  192. }
  193. },
  194. onPullDownRefresh: function () {
  195. //当前在团购页下拉加载
  196. if (this.data.myIndex === 0) {
  197. groupInit(this);
  198. }
  199. wx.showNavigationBarLoading() //在标题栏中显示加载
  200. //模拟加载
  201. setTimeout(function()
  202. {
  203. // complete
  204. wx.hideNavigationBarLoading() //完成停止加载
  205. wx.stopPullDownRefresh() //停止下拉刷新
  206. },1500);
  207. }
  208. })