index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. followData:[],
  44. recommendPageNo:1,
  45. recommendTotalNo:0,
  46. followPageNo:1,
  47. followPageTotalNo:0,
  48. templates: 'hot',
  49. title: 'index中的title',
  50. jurisdictionFlag: true,
  51. hotInput: '12345',
  52. mineSettingInfo: '528',
  53. hide: true
  54. },
  55. jurisdiction: function () {
  56. //隐藏弹框
  57. this.setData({
  58. hide: !this.data.hide
  59. })
  60. //登录页信息
  61. this.onShow();
  62. },
  63. //tab点击
  64. switcher: function ({
  65. currentTarget
  66. }) {
  67. this.updateData(currentTarget.dataset.index);
  68. },
  69. // 根据index 更新template
  70. updateData: function (index) {
  71. let myIndex = index;
  72. let templates = this.data.tab[myIndex].templates;
  73. this.setData({
  74. myIndex,
  75. templates
  76. });
  77. if (myIndex == 0) {
  78. groupInit(this);
  79. }
  80. if (myIndex == 1) {
  81. hotInit(this);
  82. }
  83. if (myIndex == 2) {
  84. followInit(this);
  85. }
  86. if (myIndex == 3) {
  87. myInit(this);
  88. // getOpenidSessionKey( res => {
  89. // console.log(res);
  90. // }, (error) => {
  91. // this.setData({
  92. // hide: !this.data.hide
  93. // });
  94. // });
  95. }
  96. },
  97. aa: function(){
  98. let a = new Promise((resolve, reject)=>{
  99. resolve(console.log('aa'))
  100. });
  101. return a;
  102. },
  103. bb: function(){
  104. let b = new Promise((resolve, reject)=>{
  105. resolve(console.log('bb'))
  106. });
  107. return b
  108. },
  109. cc: function(){
  110. let c = new Promise((resolve, reject)=>{
  111. console.log('cc')
  112. });
  113. return c
  114. },
  115. onLoad: function (options) {
  116. this.aa().then(()=>{
  117. console.log(1)
  118. return this.bb()
  119. }).then(()=>{
  120. console.log(2)
  121. return this.cc()
  122. })
  123. this.uid = wx.getStorageSync('uid');
  124. wx.getSystemInfo({
  125. success: (res) => {
  126. this.setData({
  127. winH: res.windowHeight
  128. });
  129. }
  130. });
  131. if (options.index) {
  132. this.updateData(options.index)
  133. }
  134. hotInit(this)
  135. // this.init();
  136. },
  137. onShow: function () {
  138. // this.init();
  139. getOpenidSessionKey((res) => {}, (error) => {
  140. // console.log(error)
  141. this.setData({
  142. hide: !this.data.hide
  143. })
  144. });
  145. },
  146. //初始化数据
  147. init: function () {
  148. httputil.getOpenidSessionKey((res) => {
  149. console.log('微信的用户信息', res);
  150. // this.setData({
  151. // jurisdictionFlag: true
  152. // })
  153. // lookInit(this);
  154. }, (error) => {
  155. console.log(error);
  156. this.jurisdiction()
  157. // this.setData({
  158. // jurisdictionFlag: false
  159. // })
  160. });
  161. },
  162. // 触底加载
  163. onReachBottom: function () {
  164. console.log(this.data.recommendPageNo)
  165. console.log('bottom')
  166. // 当前在推荐页面 加载推荐
  167. if (this.data.myIndex === 1) {
  168. this.setData({
  169. recommendPageNo: this.data.recommendPageNo+1
  170. })
  171. if(this.data.recommendPageNo <= this.data.recommendTotalNo ){
  172. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  173. } else {
  174. console.log('没有更多')
  175. }
  176. }
  177. if(this.data.myIndex === 2){
  178. console.log(this.data.followPageTotalNo)
  179. this.setData({
  180. followPageNo: this.data.followPageNo+1
  181. })
  182. if(this.data.followPageNo <= this.data.followPageTotalNo ){
  183. this.getWorks(this.uid, this.data.followPageNo, 5);
  184. } else {
  185. console.log('没有更多')
  186. }
  187. }
  188. }
  189. })