index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. 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. myData: {},
  49. templates: 'hot',
  50. title: 'index中的title',
  51. jurisdictionFlag: true,
  52. hotInput: '12345',
  53. mineSettingInfo: '528',
  54. hide: true
  55. },
  56. jurisdiction: function () {
  57. //隐藏弹框
  58. this.setData({
  59. hide: !this.data.hide
  60. })
  61. //登录页信息
  62. this.onShow();
  63. },
  64. //tab点击
  65. switcher: function ({
  66. currentTarget
  67. }) {
  68. this.updateData(currentTarget.dataset.index);
  69. },
  70. // 根据index 更新template
  71. updateData: function (index) {
  72. let myIndex = index;
  73. let templates = this.data.tab[myIndex].templates;
  74. this.setData({
  75. myIndex,
  76. templates
  77. });
  78. if (myIndex == 0) {
  79. groupInit(this);
  80. }
  81. if (myIndex == 1) {
  82. hotInit(this);
  83. }
  84. if (myIndex == 2) {
  85. followInit(this);
  86. }
  87. if (myIndex == 3) {
  88. myInit(this);
  89. // getOpenidSessionKey( res => {
  90. // console.log(res);
  91. // }, (error) => {
  92. // this.setData({
  93. // hide: !this.data.hide
  94. // });
  95. // });
  96. }
  97. },
  98. aa: function () {
  99. let a = new Promise((resolve, reject) => {
  100. resolve(console.log('aa'))
  101. });
  102. return a;
  103. },
  104. bb: function () {
  105. let b = new Promise((resolve, reject) => {
  106. resolve(console.log('bb'))
  107. });
  108. return b
  109. },
  110. cc: function () {
  111. let c = new Promise((resolve, reject) => {
  112. console.log('cc')
  113. });
  114. return c
  115. },
  116. onLoad: function (options) {
  117. console.log(options)
  118. this.uid = wx.getStorageSync('uid');
  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. console.log(this.data.recommendPageNo)
  171. console.log('bottom')
  172. // 当前在推荐页面 加载推荐
  173. if (this.data.myIndex === 1) {
  174. this.setData({
  175. recommendPageNo: this.data.recommendPageNo + 1
  176. })
  177. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  178. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  179. } else {
  180. console.log('没有更多')
  181. }
  182. }
  183. if (this.data.myIndex === 2) {
  184. console.log(this.data.followPageTotalNo)
  185. this.setData({
  186. followPageNo: this.data.followPageNo + 1
  187. })
  188. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  189. this.getWorks(this.uid, this.data.followPageNo, 5);
  190. } else {
  191. console.log('没有更多')
  192. }
  193. }
  194. }
  195. })