index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. console.log('aaaaaaa')
  142. this.getUserWorksInfo();
  143. }
  144. },
  145. //初始化数据
  146. init: function () {
  147. httputil.getOpenidSessionKey((res) => {
  148. console.log('微信的用户信息', res)
  149. }, (error) => {
  150. console.log(error);
  151. this.jurisdiction()
  152. // this.setData({
  153. // jurisdictionFlag: false
  154. // })
  155. });
  156. },
  157. // 获取用户信息
  158. getUserWorksInfo: function () {
  159. httpRequestApi.getUserWorksInfo().success(res => {
  160. console.log(res)
  161. this.data.myData.user = res.data.data; //直接赋值 给 myData的user对象。
  162. this.setData({
  163. myData: this.data.myData,
  164. });
  165. }).fail(error => {
  166. console.log(error)
  167. })
  168. },
  169. // 触底加载
  170. onReachBottom: function () {
  171. console.log(this.data.recommendPageNo)
  172. console.log('bottom')
  173. // 当前在推荐页面 加载推荐
  174. if (this.data.myIndex === 1) {
  175. this.setData({
  176. recommendPageNo: this.data.recommendPageNo + 1
  177. })
  178. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  179. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  180. } else {
  181. console.log('没有更多')
  182. }
  183. }
  184. if (this.data.myIndex === 2) {
  185. console.log(this.data.followPageTotalNo)
  186. this.setData({
  187. followPageNo: this.data.followPageNo + 1
  188. })
  189. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  190. this.getWorks(this.uid, this.data.followPageNo, 5);
  191. } else {
  192. console.log('没有更多')
  193. }
  194. }
  195. }
  196. })