index.js 4.7 KB

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