index.js 6.2 KB

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