index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. {
  32. name: '我的',
  33. templates: 'my',
  34. },
  35. {
  36. name: '发现',
  37. templates: 'hot',
  38. },
  39. {
  40. name: '热团',
  41. templates: 'group',
  42. },
  43. // {
  44. // name: '动态',
  45. // templates: 'follow',
  46. // },
  47. ],
  48. winH: 568,
  49. myIndex: 1,
  50. followData: [],
  51. recommendPageNo: 1,
  52. recommendTotalNo: 0,
  53. followPageNo: 0,
  54. followPageTotalNo: 1,
  55. myData: {},
  56. templates: 'hot',
  57. title: 'index中的title',
  58. jurisdictionFlag: true,
  59. hotInput: '12345',
  60. mineSettingInfo: '528',
  61. hide: true,
  62. isIOS:app.globalData.isIOS,
  63. ifHaveMore: true
  64. },
  65. jurisdiction: function () {
  66. //隐藏弹框
  67. this.setData({
  68. hide: !this.data.hide
  69. })
  70. //登录页信息
  71. this.onShow();
  72. },
  73. //tab点击
  74. switcher: function ({
  75. currentTarget
  76. }) {
  77. if (currentTarget.dataset.index === this.data.myIndex) return;
  78. this.updateData(currentTarget.dataset.index);
  79. },
  80. // 根据index 更新template
  81. updateData: function (index) {
  82. let myIndex = index;
  83. let templates = this.data.tab[myIndex].templates;
  84. this.setData({
  85. myIndex,
  86. templates
  87. });
  88. if (myIndex == 0) {
  89. // groupInit(this);
  90. this.setData({
  91. followPageNo: 0,
  92. })
  93. myInit(this);
  94. }
  95. if (myIndex == 1) {
  96. this.setData({
  97. recommendPageNo: 1
  98. })
  99. hotInit(this);
  100. }
  101. if (myIndex == 2) {
  102. // this.setData({
  103. // followPageNo: 1
  104. // })
  105. // followInit(this);
  106. groupInit(this);
  107. }
  108. if (myIndex == 3) {
  109. // console.log(this.data.isIOS)
  110. myInit(this);
  111. }
  112. },
  113. onLoad: function (options) {
  114. this.uid = wx.getStorageSync('uid');
  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. wx.setNavigationBarTitle({
  130. title: '小学课文朗读配音'
  131. })
  132. // this.init();
  133. // getOpenidSessionKey((res) => {}, (error) => {
  134. // // console.log(error)
  135. // wx.navigateTo({
  136. // url: '../../pages/loginPage/loginPage'
  137. // })
  138. // });
  139. if (this.data.myIndex === 3) {
  140. this.getUserWorksInfo();
  141. }
  142. },
  143. //初始化数据
  144. // init: function () {
  145. // httputil.getOpenidSessionKey((res) => {
  146. // console.log('微信的用户信息', res)
  147. // }, (error) => {
  148. // console.log(1111111111111111)
  149. // // this.jurisdiction()
  150. // wx.navigateTo({
  151. // url: '../../loginPage/loginPage'
  152. // })
  153. // });
  154. // },
  155. // 获取用户信息
  156. getUserWorksInfo: function () {
  157. console.log(wx.getStorageSync('user'));
  158. httpRequestApi.getUserWorksInfo().success(res => {
  159. this.data.myData.user = res.data.data;
  160. this.data.myData.user.user.birthday = this.data.myData.user.user.birthday ? formatDate(res.data.data.user.birthday,3) : '2018年1月1日';
  161. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  162. if(this.data.myData.user.myRead){
  163. this.data.myData.user.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated,4)
  164. }
  165. this.setData({
  166. myData: this.data.myData,
  167. });
  168. }).fail(error => {
  169. console.log(error)
  170. })
  171. },
  172. // 触底加载
  173. onReachBottom: function () {
  174. if (this.data.myIndex === 0) {
  175. console.log(this.data.followPageTotalNo)
  176. console.log(this.data.followPageNo)
  177. this.setData({
  178. followPageNo: this.data.followPageNo + 1
  179. })
  180. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  181. this.getFollowWorks(this.data.followPageNo, 3);
  182. } else {
  183. console.log('没有更多')
  184. this.setData({
  185. ifHaveMore: false
  186. })
  187. }
  188. }
  189. // 当前在推荐页面 加载推荐
  190. if (this.data.myIndex === 1) {
  191. console.log(this.data.recommendPageNo)
  192. this.setData({
  193. recommendPageNo: this.data.recommendPageNo + 1
  194. })
  195. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  196. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  197. } else {
  198. console.log('没有更多')
  199. }
  200. }
  201. },
  202. onPullDownRefresh: function () {
  203. //当前在团购页下拉加载
  204. if (this.data.myIndex === 0) {
  205. groupInit(this);
  206. }
  207. wx.showNavigationBarLoading() //在标题栏中显示加载
  208. //模拟加载
  209. setTimeout(function () {
  210. wx.hideNavigationBarLoading() //完成停止加载
  211. wx.stopPullDownRefresh() //停止下拉刷新
  212. },1500);
  213. },
  214. // 获取全部课本
  215. // getBookList: function () {
  216. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  217. // this.data.bookList = res.data.data.list;
  218. // res.data.data.list.forEach(element => {
  219. // this.data.selectFlag.push(true);
  220. // });
  221. // this.setData({
  222. // bookList: this.data.bookList
  223. // })
  224. // }).fail((error) => {
  225. // console.log('错误', error)
  226. // })
  227. // },
  228. goToMessage: function(){
  229. wx.navigateTo({
  230. url: `../../pages/social/insideMessage/insideMessage`
  231. });
  232. const str = 'hotData.unReadMessageNum';
  233. this.setData({
  234. [str]: 0
  235. })
  236. },
  237. toMyCollage: function(e){
  238. if(app.globalData.isIOS){
  239. wx.navigateTo({
  240. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  241. });
  242. }else {
  243. wx.navigateTo({
  244. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  245. });
  246. }
  247. },
  248. goToFlower: function(){
  249. wx.navigateTo({
  250. url: `../../pages/social/littleFlower/littleFlower`
  251. });
  252. }
  253. })