index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. {
  30. name: '我的',
  31. templates: 'my',
  32. },
  33. {
  34. name: '发现',
  35. templates: 'hot',
  36. },
  37. {
  38. name: '热团',
  39. templates: 'group',
  40. },
  41. // {
  42. // name: '动态',
  43. // templates: 'follow',
  44. // },
  45. ],
  46. winH: 568,
  47. myIndex: 1,
  48. followData: [],
  49. recommendPageNo: 1,
  50. recommendTotalNo: 0,
  51. followPageNo: 0,
  52. followPageTotalNo: 1,
  53. myData: {},
  54. templates: 'hot',
  55. title: 'index中的title',
  56. jurisdictionFlag: true,
  57. hotInput: '12345',
  58. mineSettingInfo: '528',
  59. hide: true,
  60. isIOS:app.globalData.isIOS,
  61. ifHaveMore: true
  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. this.setData({
  89. followPageNo: 0,
  90. })
  91. myInit(this);
  92. }
  93. if (myIndex == 1) {
  94. this.setData({
  95. recommendPageNo: 1
  96. })
  97. hotInit(this);
  98. }
  99. if (myIndex == 2) {
  100. // this.setData({
  101. // followPageNo: 1
  102. // })
  103. // followInit(this);
  104. groupInit(this);
  105. }
  106. if (myIndex == 3) {
  107. // console.log(this.data.isIOS)
  108. myInit(this);
  109. }
  110. },
  111. onLoad: function (options) {
  112. this.uid = wx.getStorageSync('uid');
  113. wx.getSystemInfo({
  114. success: (res) => {
  115. this.setData({
  116. winH: res.windowHeight
  117. });
  118. }
  119. });
  120. if (options.index) {
  121. this.updateData(options.index)
  122. }
  123. hotInit(this)
  124. // this.init();
  125. },
  126. onShow: function () {
  127. wx.setNavigationBarTitle({
  128. title: '小学课文朗读配音'
  129. })
  130. // this.init();
  131. getOpenidSessionKey((res) => {}, (error) => {
  132. // console.log(error)
  133. this.setData({
  134. hide: !this.data.hide
  135. })
  136. });
  137. if (this.data.myIndex === 3) {
  138. this.getUserWorksInfo();
  139. }
  140. },
  141. //初始化数据
  142. init: function () {
  143. httputil.getOpenidSessionKey((res) => {
  144. console.log('微信的用户信息', res)
  145. }, (error) => {
  146. console.log(error);
  147. this.jurisdiction()
  148. // this.setData({
  149. // jurisdictionFlag: false
  150. // })
  151. });
  152. },
  153. // 获取用户信息
  154. getUserWorksInfo: function () {
  155. console.log(wx.getStorageSync('user'));
  156. httpRequestApi.getUserWorksInfo().success(res => {
  157. this.data.myData.user = res.data.data;
  158. this.data.myData.user.user.birthday = this.data.myData.user.user.birthday ? formatDate(res.data.data.user.birthday,3) : '2018年1月1日';
  159. if(this.data.myData.user.myRead){
  160. this.data.myData.user.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated,4)
  161. }
  162. this.setData({
  163. myData: this.data.myData,
  164. });
  165. }).fail(error => {
  166. console.log(error)
  167. })
  168. },
  169. // 触底加载
  170. onReachBottom: function () {
  171. if (this.data.myIndex === 0) {
  172. console.log(this.data.followPageTotalNo)
  173. console.log(this.data.followPageNo)
  174. this.setData({
  175. followPageNo: this.data.followPageNo + 1
  176. })
  177. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  178. this.getFollowWorks(this.data.followPageNo, 3);
  179. } else {
  180. console.log('没有更多')
  181. this.setData({
  182. ifHaveMore: false
  183. })
  184. }
  185. }
  186. // 当前在推荐页面 加载推荐
  187. if (this.data.myIndex === 1) {
  188. console.log(this.data.recommendPageNo)
  189. this.setData({
  190. recommendPageNo: this.data.recommendPageNo + 1
  191. })
  192. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  193. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  194. } else {
  195. console.log('没有更多')
  196. }
  197. }
  198. },
  199. onPullDownRefresh: function () {
  200. //当前在团购页下拉加载
  201. if (this.data.myIndex === 0) {
  202. groupInit(this);
  203. }
  204. wx.showNavigationBarLoading() //在标题栏中显示加载
  205. //模拟加载
  206. setTimeout(function(){
  207. wx.hideNavigationBarLoading() //完成停止加载
  208. wx.stopPullDownRefresh() //停止下拉刷新
  209. },1500);
  210. }
  211. })