index.js 4.8 KB

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