index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/APIRequest';
  21. import httputil from '../../utils/httpUtil';
  22. Page({
  23. data: {
  24. tab: [{
  25. name: '热团',
  26. templates: 'group',
  27. },
  28. {
  29. name: '推荐',
  30. templates: 'hot',
  31. },
  32. {
  33. name: '关注',
  34. templates: 'follow',
  35. },
  36. {
  37. name: '我的',
  38. templates: 'my',
  39. }
  40. ],
  41. winH: 568,
  42. myIndex: 1,
  43. recommendPageNo:1,
  44. recommendTotalNo:0,
  45. followPageNo:1,
  46. followPageSize:0,
  47. templates: 'hot',
  48. title: 'index中的title',
  49. jurisdictionFlag: true,
  50. hotInput: '12345',
  51. mineSettingInfo: '528',
  52. hide: true
  53. },
  54. jurisdiction: function () {
  55. //隐藏弹框
  56. this.setData({
  57. hide: !this.data.hide
  58. })
  59. //登录页信息
  60. this.onShow();
  61. },
  62. //tab点击
  63. switcher: function ({
  64. currentTarget
  65. }) {
  66. this.updateData(currentTarget.dataset.index);
  67. },
  68. // 根据index 更新template
  69. updateData: function (index) {
  70. let myIndex = index;
  71. let templates = this.data.tab[myIndex].templates;
  72. this.setData({
  73. myIndex,
  74. templates
  75. });
  76. if (myIndex == 0) {
  77. groupInit(this);
  78. }
  79. if (myIndex == 1) {
  80. hotInit(this);
  81. }
  82. if (myIndex == 2) {
  83. followInit(this);
  84. }
  85. if (myIndex == 3) {
  86. myInit(this);
  87. getOpenidSessionKey( res => {
  88. console.log(res);
  89. }, (error) => {
  90. this.setData({
  91. hide: !this.data.hide
  92. });
  93. });
  94. }
  95. },
  96. onLoad: function (options) {
  97. this.uid = wx.getStorageSync('uid');
  98. wx.getSystemInfo({
  99. success: (res) => {
  100. this.setData({
  101. winH: res.windowHeight
  102. });
  103. }
  104. });
  105. if (options.index) {
  106. this.updateData(options.index)
  107. }
  108. hotInit(this)
  109. // this.init();
  110. },
  111. onShow: function () {
  112. // this.init();
  113. getOpenidSessionKey((res) => {}, (error) => {
  114. // console.log(error)
  115. this.setData({
  116. hide: !this.data.hide
  117. })
  118. });
  119. },
  120. //初始化数据
  121. init: function () {
  122. httputil.getOpenidSessionKey((res) => {
  123. console.log('微信的用户信息', res);
  124. // this.setData({
  125. // jurisdictionFlag: true
  126. // })
  127. // lookInit(this);
  128. }, (error) => {
  129. console.log(error);
  130. this.jurisdiction()
  131. // this.setData({
  132. // jurisdictionFlag: false
  133. // })
  134. });
  135. },
  136. // 触底加载
  137. onReachBottom: function () {
  138. console.log(this.data.recommendPageNo)
  139. console.log('bottom')
  140. // 当前在推荐页面 加载推荐
  141. if (this.data.myIndex === 1) {
  142. this.setData({
  143. recommendPageNo: this.data.recommendPageNo+1
  144. })
  145. if(this.data.recommendPageNo <= this.data.recommendTotalNo ){
  146. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  147. } else {
  148. console.log('没有更多')
  149. }
  150. }
  151. }
  152. })