index.js 4.8 KB

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