index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. this.updateData(currentTarget.dataset.index);
  73. },
  74. // 根据index 更新template
  75. updateData: function (index) {
  76. let myIndex = index;
  77. let templates = this.data.tab[myIndex].templates;
  78. this.setData({
  79. myIndex,
  80. templates
  81. });
  82. if (myIndex == 0) {
  83. groupInit(this);
  84. }
  85. if (myIndex == 1) {
  86. this.setData({
  87. recommendPageNo: 1
  88. })
  89. hotInit(this);
  90. }
  91. if (myIndex == 2) {
  92. this.setData({
  93. followPageNo: 1
  94. })
  95. followInit(this);
  96. }
  97. if (myIndex == 3) {
  98. // console.log(this.data.isIOS)
  99. myInit(this);
  100. }
  101. },
  102. onLoad: function (options) {
  103. this.uid = wx.getStorageSync('uid');
  104. // const type = GetQueryString(decodeURIComponent(options.scene),"type");
  105. // const sceneId = GetQueryString( decodeURIComponent(options.scene),"id");
  106. // console.log(type,sceneId)
  107. // switch(type){
  108. // case "works":
  109. // wx.navigateTo({
  110. // url: `../social/works/works?id=${sceneId}&title="测试"`
  111. // })
  112. // break
  113. // };
  114. wx.getSystemInfo({
  115. success: (res) => {
  116. this.setData({
  117. winH: res.windowHeight
  118. });
  119. }
  120. });
  121. if (options.index) {
  122. this.updateData(options.index)
  123. }
  124. hotInit(this)
  125. // this.init();
  126. },
  127. onShow: function () {
  128. // this.init();
  129. getOpenidSessionKey((res) => {}, (error) => {
  130. // console.log(error)
  131. this.setData({
  132. hide: !this.data.hide
  133. })
  134. });
  135. if (this.data.myIndex === 3) {
  136. this.getUserWorksInfo();
  137. }
  138. },
  139. //初始化数据
  140. init: function () {
  141. httputil.getOpenidSessionKey((res) => {
  142. console.log('微信的用户信息', res)
  143. }, (error) => {
  144. console.log(error);
  145. this.jurisdiction()
  146. // this.setData({
  147. // jurisdictionFlag: false
  148. // })
  149. });
  150. },
  151. // 获取用户信息
  152. getUserWorksInfo: function () {
  153. httpRequestApi.getUserWorksInfo().success(res => {
  154. this.data.myData.user = res.data.data; //直接赋值 给 myData的user对象。
  155. this.setData({
  156. myData: this.data.myData,
  157. },() => {
  158. console.log(this.data.myData);
  159. });
  160. }).fail(error => {
  161. console.log(error)
  162. })
  163. },
  164. // 触底加载
  165. onReachBottom: function () {
  166. // 当前在推荐页面 加载推荐
  167. if (this.data.myIndex === 1) {
  168. console.log(this.data.recommendPageNo)
  169. this.setData({
  170. recommendPageNo: this.data.recommendPageNo + 1
  171. })
  172. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  173. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  174. } else {
  175. console.log('没有更多')
  176. }
  177. }
  178. if (this.data.myIndex === 2) {
  179. console.log(this.data.followPageTotalNo)
  180. this.setData({
  181. followPageNo: this.data.followPageNo + 1
  182. })
  183. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  184. this.getWorks(this.uid, this.data.followPageNo, 5);
  185. } else {
  186. console.log('没有更多')
  187. }
  188. }
  189. },
  190. onPullDownRefresh: function () {
  191. //当前在团购页下拉加载
  192. if (this.data.myIndex === 0) {
  193. groupInit(this);
  194. }
  195. wx.showNavigationBarLoading() //在标题栏中显示加载
  196. //模拟加载
  197. setTimeout(function()
  198. {
  199. // complete
  200. wx.hideNavigationBarLoading() //完成停止加载
  201. wx.stopPullDownRefresh() //停止下拉刷新
  202. },1500);
  203. }
  204. })