index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. name: '我的',
  32. templates: 'my',
  33. },
  34. {
  35. name: '发现',
  36. templates: 'hot',
  37. },
  38. {
  39. name: '热团',
  40. templates: 'group',
  41. },
  42. // {
  43. // name: '动态',
  44. // templates: 'follow',
  45. // },
  46. ],
  47. winH: 568,
  48. myIndex: 1,
  49. followData: [],
  50. recommendPageNo: 0,
  51. recommendTotalNo: 1,
  52. followPageNo: 1,
  53. followPageTotalNo: 1,
  54. myData: {},
  55. templates: 'hot',
  56. title: 'index中的title',
  57. jurisdictionFlag: true,
  58. hotInput: '12345',
  59. mineSettingInfo: '528',
  60. hide: true,
  61. isIOS: app.globalData.isIOS,
  62. ifHaveMore: true,
  63. indexSignDialog: false,
  64. indexMissionDialog: false,
  65. unfinishedCount: 0
  66. },
  67. jurisdiction: function () {
  68. //隐藏弹框
  69. this.setData({
  70. hide: !this.data.hide
  71. })
  72. //登录页信息
  73. this.onShow();
  74. },
  75. //tab点击
  76. switcher: function ({
  77. currentTarget
  78. }) {
  79. if (currentTarget.dataset.index === this.data.myIndex) return;
  80. this.updateData(currentTarget.dataset.index);
  81. },
  82. // 根据index 更新template
  83. updateData: function (index) {
  84. let myIndex = index;
  85. let templates = this.data.tab[myIndex].templates;
  86. this.setData({
  87. myIndex,
  88. templates
  89. });
  90. if (myIndex == 0) {
  91. // groupInit(this);
  92. this.setData({
  93. followPageNo: 1,
  94. })
  95. myInit(this);
  96. }
  97. if (myIndex == 1) {
  98. // this.setData({
  99. // recommendPageNo: 0
  100. // })
  101. hotInit(this);
  102. }
  103. if (myIndex == 2) {
  104. groupInit(this);
  105. }
  106. },
  107. onLoad: function (options) {
  108. this.uid = wx.getStorageSync('uid');
  109. wx.getSystemInfo({
  110. success: (res) => {
  111. this.setData({
  112. winH: res.windowHeight
  113. });
  114. }
  115. });
  116. if (options.index) {
  117. this.updateData(options.index)
  118. }
  119. setTimeout(() => {
  120. if (wx.getStorageSync('uid')) {
  121. httpRequestApi.userLoginRecord().success(res => {
  122. if (res.data.data) {
  123. // 有数据弹任务窗口
  124. if (this.data.unfinishedCount > 0) {
  125. this.setData({
  126. indexSignDialog: true
  127. })
  128. }
  129. } else {
  130. // 没数据弹签到
  131. let oldDay = wx.getStorageSync('oldDay');
  132. let newDate = new Date();
  133. let timeStep =(newDate.getMonth() + 1).toString() + newDate.getDate().toString()
  134. if (oldDay) {
  135. let temp = parseInt(timeStep) - parseInt(oldDay)
  136. if (temp > 0) {
  137. wx.setStorageSync('oldDay', timeStep);
  138. this.setData({
  139. indexMissionDialog: true
  140. })
  141. }
  142. } else {
  143. wx.setStorageSync('oldDay', timeStep);
  144. this.setData({
  145. indexMissionDialog: true
  146. })
  147. }
  148. }
  149. })
  150. }
  151. }, 2800)
  152. // hotInit(this)
  153. // this.init();
  154. },
  155. onShow: function () {
  156. wx.setNavigationBarTitle({
  157. title: '小学课文朗读配音'
  158. })
  159. // this.init();
  160. getOpenidSessionKey((res) => {
  161. hotInit(this)
  162. }, (error) => {
  163. // console.log(error)
  164. wx.setStorageSync('userSourseType','normal')
  165. this.setData({
  166. hide: !this.data.hide
  167. })
  168. return;
  169. });
  170. if (this.data.myIndex === 0) {
  171. // 从修改信息页面退回
  172. this.getUserWorksInfo(true);
  173. }
  174. },
  175. onHide: function(){
  176. const str = 'hotData.inputFocus'
  177. this.setData({
  178. [str]: false
  179. });
  180. },
  181. //初始化数据
  182. // init: function () {
  183. // httputil.getOpenidSessionKey((res) => {
  184. // console.log('微信的用户信息', res)
  185. // }, (error) => {
  186. // console.log(1111111111111111)
  187. // // this.jurisdiction()
  188. // wx.navigateTo({
  189. // url: '../../loginPage/loginPage'
  190. // })
  191. // });
  192. // },
  193. // 获取用户信息
  194. getUserWorksInfo: function (flag) {
  195. console.log(flag)
  196. if (flag) {
  197. httpRequestApi.getUserWorksInfo().success(res => {
  198. const str = 'myData.user.user.nickName';
  199. this.setData({
  200. [str]: res.data.data.user.nickName
  201. })
  202. })
  203. return;
  204. }
  205. const userLocal = wx.getStorageSync('user')
  206. console.log(userLocal)
  207. const str = 'myData.user';
  208. this.setData({
  209. [str]: userLocal
  210. })
  211. httpRequestApi.getUserWorksInfo().success(res => {
  212. this.data.myData.user = res.data.data;
  213. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  214. if (this.data.myData.user.myRead) {
  215. this.data.myData.user.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  216. }
  217. this.setData({
  218. myData: this.data.myData,
  219. });
  220. }).fail(error => {
  221. console.log(error)
  222. })
  223. },
  224. // 触底加载
  225. onReachBottom: function () {
  226. console.log(this.data.myIndex )
  227. if (this.data.myIndex === 0) {
  228. this.setData({
  229. followPageNo: this.data.followPageNo + 1
  230. })
  231. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  232. this.getFollowWorks(this.data.followPageNo, 3);
  233. } else {
  234. console.log('没有更多')
  235. this.setData({
  236. ifHaveMore: false
  237. })
  238. }
  239. }
  240. // 当前在推荐页面 加载推荐
  241. if (this.data.myIndex === 1) {
  242. console.log(this.data.recommendPageNo)
  243. console.log(this.data.recommendTotalNo)
  244. this.setData({
  245. recommendPageNo: this.data.recommendPageNo + 1
  246. })
  247. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  248. this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  249. } else {
  250. console.log('没有更多')
  251. }
  252. }
  253. },
  254. onPullDownRefresh: function () {
  255. //当前在团购页下拉加载
  256. if (this.data.myIndex === 0) {
  257. // groupInit(this);
  258. }
  259. wx.showNavigationBarLoading() //在标题栏中显示加载
  260. //模拟加载
  261. setTimeout(function () {
  262. wx.hideNavigationBarLoading() //完成停止加载
  263. wx.stopPullDownRefresh() //停止下拉刷新
  264. }, 1500);
  265. },
  266. // 获取全部课本
  267. // getBookList: function () {
  268. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  269. // this.data.bookList = res.data.data.list;
  270. // res.data.data.list.forEach(element => {
  271. // this.data.selectFlag.push(true);
  272. // });
  273. // this.setData({
  274. // bookList: this.data.bookList
  275. // })
  276. // }).fail((error) => {
  277. // console.log('错误', error)
  278. // })
  279. // },
  280. goToMessage: function () {
  281. wx.navigateTo({
  282. url: `../../pages/social/insideMessage/insideMessage`
  283. });
  284. const str = 'hotData.unReadMessageNum';
  285. this.setData({
  286. [str]: 0
  287. })
  288. },
  289. toMyCollage: function (e) {
  290. if (app.globalData.isIOS) {
  291. wx.navigateTo({
  292. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  293. });
  294. } else {
  295. wx.navigateTo({
  296. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  297. });
  298. }
  299. },
  300. toMyCourse: function () {
  301. wx.navigateTo({
  302. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  303. });
  304. },
  305. goToFlower: function () {
  306. wx.navigateTo({
  307. url: `../../pages/social/littleFlower/littleFlower`
  308. });
  309. },
  310. signInBtn: function (e) {
  311. this.setData({
  312. indexSignDialog: false
  313. })
  314. console.log(e.detail.formId)
  315. httpRequestApi.postFormId(e.detail.formId).success(res => {
  316. console.log(res)
  317. })
  318. this.goToFlower();
  319. },
  320. missionBtn: function () {
  321. this.setData({
  322. indexMissionDialog: false
  323. })
  324. this.goToFlower();
  325. }
  326. })