index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. //index.js
  2. //获取应用实例
  3. // 获取授权登录
  4. import {
  5. getOpenidSessionKey
  6. } from '../../utils/httpUtil';
  7. // 不用获取授权登录
  8. import {
  9. getOpenidNoLogin
  10. } from '../../utils/httpUtilNoLogin';
  11. import {
  12. formatDate
  13. } from '../../utils/util';
  14. const app = getApp()
  15. import {
  16. hotInit
  17. } from '../../component/hot/hot';
  18. import {
  19. groupInit
  20. } from '../../component/group/group';
  21. import {
  22. myInit
  23. } from '../../component/my/my';
  24. import httpRequestApi from '../../utils/APIClient';
  25. import httputil from '../../utils/httpUtil';
  26. import {
  27. GetQueryString
  28. } from '../../utils/util';
  29. Page({
  30. data: {
  31. tab: [{
  32. name: '推荐',
  33. templates: 'recommend',
  34. },
  35. {
  36. name: '关注',
  37. templates: 'follow',
  38. },
  39. {
  40. name: '资源',
  41. templates: 'courses',
  42. },
  43. {
  44. name: '我的',
  45. templates: 'my',
  46. }
  47. ],
  48. winH: 568,
  49. myIndex: 0,
  50. followData: [],
  51. recommendPageNo: 1,
  52. recommendPageSize: 6,
  53. recommendTotalNo: 1,
  54. myData: {},
  55. templates: '',
  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. videoList: [],
  67. nextMargin: '400rpx', // 视频下边距
  68. commentShow: false,
  69. commentList: [],
  70. commentNum: 0,
  71. followPageNo: 1,
  72. followPageSize: 6,
  73. coursePageNo: 1,
  74. coursesData: [],
  75. },
  76. jurisdiction: function () {
  77. //隐藏弹框
  78. this.setData({
  79. hide: !this.data.hide
  80. })
  81. //登录页信息
  82. this.updateData(0)
  83. },
  84. //tab点击
  85. switcher: function ({
  86. currentTarget
  87. }) {
  88. if (currentTarget.dataset.index === this.data.myIndex) return;
  89. this.updateData(currentTarget.dataset.index);
  90. },
  91. // 根据index 更新template
  92. updateData: function (index) {
  93. let myIndex = index;
  94. this.setData({
  95. myIndex,
  96. });
  97. // 获取推荐列表
  98. if (myIndex == 0) {
  99. this.setData({
  100. videoList: [],
  101. isSwiper: true
  102. }, () => {
  103. this.getHotRecommend(this.uid);
  104. })
  105. return;
  106. }
  107. /* 关注和我的需要登陆后查看 */
  108. if (!this.data.isLogin) {
  109. wx.navigateTo({
  110. url: `../../pages/login/login`
  111. });
  112. return;
  113. }
  114. console.log('继续')
  115. // 刷新关注列表
  116. if (myIndex == 1) {
  117. this.setData({
  118. videoList: [],
  119. isSwiper: true,
  120. followPageNo: 1
  121. }, () => {
  122. this.getFollowData()
  123. })
  124. return;
  125. }
  126. // 刷新资源
  127. if (myIndex == 2) {
  128. this.setData({
  129. videoList: [],
  130. coursesData: [],
  131. templates: 'courses',
  132. coursePageNo: 1
  133. }, () => {
  134. this.getCoursesList();
  135. })
  136. return;
  137. }
  138. // 刷新我的
  139. if (myIndex == 3) {
  140. this.setData({
  141. videoList: [],
  142. templates: 'my',
  143. isSwiper: false
  144. }, () => {
  145. myInit(this);
  146. })
  147. return;
  148. }
  149. },
  150. showPage: function () {
  151. let options = this.data.options;
  152. if (options && options.index) {
  153. this.updateData(options.index)
  154. } else {
  155. this.updateData(0)
  156. }
  157. setTimeout(() => {
  158. if (wx.getStorageSync('uid')) {
  159. httpRequestApi.userLoginRecord().success(res => {
  160. if (res.data.data && res.data.data.length !== 0) {
  161. // 有数据弹签到
  162. if (this.data.unfinishedCount > 0) {
  163. this.setData({
  164. indexSignDialog: true
  165. })
  166. }
  167. } else {
  168. // 没数据弹任务
  169. let oldDay = wx.getStorageSync('oldDay');
  170. let newDate = new Date();
  171. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  172. let timeStep = (newDate.getMonth() + 1).toString() + day
  173. if (oldDay) {
  174. let temp = parseInt(timeStep) - parseInt(oldDay)
  175. if (temp > 0) {
  176. wx.setStorageSync('oldDay', timeStep);
  177. this.setData({
  178. indexMissionDialog: true
  179. })
  180. }
  181. } else {
  182. wx.setStorageSync('oldDay', timeStep);
  183. this.setData({
  184. indexMissionDialog: true
  185. })
  186. }
  187. }
  188. })
  189. }
  190. }, 2800)
  191. },
  192. onLoad: function (options) {
  193. this.uid = wx.getStorageSync('uid');
  194. let grade = wx.getStorageSync('grade');
  195. let user = wx.getStorageSync('user');
  196. if (!this.uid || !grade) {
  197. this.setData({
  198. isGradeShow: true,
  199. options
  200. })
  201. console.log('没有uid 也不是游客,需要去授权')
  202. return;
  203. }
  204. this.showPage()
  205. if (this.uid && !user) {
  206. console.log('游客状态')
  207. }
  208. if (this.uid && user) {
  209. console.log('登陆状态')
  210. }
  211. wx.getSystemInfo({
  212. success: (res) => {
  213. console.log('系统', res)
  214. let winH = res.windowHeight * res.pixelRatio;
  215. let minusNumber = (winH * 920) / 1206;
  216. let nextMargin = parseInt(winH - minusNumber);
  217. app.globalData.nextMargin = nextMargin;
  218. this.setData({
  219. winH: winH,
  220. devicePixelRatio: res.pixelRatio,
  221. nextMargin: nextMargin + 'rpx'
  222. });
  223. }
  224. });
  225. },
  226. onShow: function (e) {
  227. console.log('this.data.workId', this.data.workId)
  228. if (this.data.workId) {
  229. // 需要在推荐第一个上插入一条分享或者刚朗读完数据
  230. this.setData({
  231. myIndex: 0,
  232. videoList: [],
  233. isSwiper: true,
  234. recommendTotalNo:1
  235. })
  236. httpRequestApi.getClassDetail(this.data.workId).success(res => {
  237. console.log('有一条数据', res)
  238. let tempList = [];
  239. tempList.push(res.data.data);
  240. this.formatWorksList(tempList, true);
  241. this.getHotRecommend()
  242. })
  243. }
  244. console.log('页面显示', e)
  245. if (this.data.myIndex === 3) {
  246. this.getUserWorksInfo(1)
  247. }
  248. wx.setNavigationBarTitle({
  249. title: '小学语文朗读配音'
  250. })
  251. const userInfo = wx.getStorageSync('user')
  252. if (userInfo.wechatName) {
  253. this.setData({
  254. isLogin: true
  255. })
  256. } else {
  257. this.setData({
  258. isLogin: false
  259. })
  260. }
  261. },
  262. onHide: function () {
  263. const str = 'hotData.inputFocus'
  264. this.setData({
  265. [str]: false
  266. });
  267. },
  268. /* 两个接口维护同一个数组,手动的结束后添加算法的 */
  269. // 推荐页信息 获取消息和手动推荐内容
  270. // 获取热门作品 算法出来的
  271. getHotRecommend: function () {
  272. let grade = wx.getStorageSync('grade')
  273. let pageNo = this.data.recommendPageNo;
  274. let pageSize = this.data.recommendPageSize;
  275. httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
  276. console.log(res)
  277. const recommendRes = res.data.data.list;
  278. if (recommendRes.length === 0) return;
  279. // const recommendWorks = [];
  280. this.formatWorksList(recommendRes);
  281. })
  282. },
  283. // 组装list
  284. formatWorksList(list, notSet) {
  285. list.forEach(item => {
  286. const temp = {};
  287. temp.title = item.userRead.title;
  288. temp.summary = item.userRead.summary;
  289. temp.img = item.userRead.iconImg;
  290. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  291. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  292. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  293. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  294. temp.time = formatDate(item.userRead.gmtCreated, 3);
  295. temp.avatar = item.user.avatar;
  296. temp.profession = item.user.profession;
  297. temp.uid = item.user.uid;
  298. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  299. temp.id = item.userRead.id;
  300. temp.type = item.userRead.type;
  301. temp.nickName = item.user.wechatName;
  302. temp.isLike = item.isLike;
  303. temp.isFavorite = item.isFavorites;
  304. this.data.videoList.push(temp);
  305. });
  306. if (!notSet) {
  307. this.setData({
  308. videoList: this.data.videoList
  309. })
  310. }
  311. },
  312. // 获取用户信息
  313. getUserWorksInfo: function (flag) {
  314. if (flag) {
  315. httpRequestApi.getUserWorksInfo().success(res => {
  316. const userInfo = this.formatGrade(res.data.data.user);
  317. const str = 'myData.userInfo.nickName';
  318. const avatarStr = 'myData.userInfo.avatar';
  319. const gradeTextStr = 'myData.userInfo.gradeText';
  320. this.setData({
  321. [str]: userInfo.nickName,
  322. [avatarStr]: userInfo.avatar,
  323. [gradeTextStr]: userInfo.gradeText
  324. })
  325. })
  326. return;
  327. }
  328. httpRequestApi.getUserWorksInfo().success(res => {
  329. this.data.myData.user = res.data.data;
  330. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  331. if (res.data.data.myRead) {
  332. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  333. }
  334. res.data.data.user = this.formatGrade(res.data.data.user);
  335. this.setData({
  336. myData: res.data.data,
  337. ['myData.userInfo']: res.data.data.user
  338. }, () => {
  339. this.getMyRead()
  340. });
  341. }).fail(error => {
  342. console.log(error)
  343. })
  344. },
  345. formatGrade(userInfo) {
  346. switch (userInfo.grade) {
  347. case 'PRESCHOOL':
  348. userInfo.gradeText = '学前班'
  349. break;
  350. case 'PRIMARY_FIRST_GRADE':
  351. userInfo.gradeText = '小学一年级'
  352. break;
  353. case 'PRIMARY_SECOND_GRADE':
  354. userInfo.gradeText = '小学二年级'
  355. break;
  356. case 'PRIMARY_THREE_GRADE':
  357. userInfo.gradeText = '小学三年级'
  358. break;
  359. }
  360. return userInfo;
  361. },
  362. videoChange: function (e) {
  363. console.log('到了底部到了底部', e.detail.index)
  364. console.log('到了底部到了底部', e.detail._last)
  365. console.log('到了底部到了底部', e.detail.nextQueue)
  366. if (e.detail.nextQueue.length === 1) {
  367. if (this.data.myIndex === 1) {
  368. this.setData({
  369. followPageNo: this.data.followPageNo + 1
  370. }, () => {
  371. this.getFollowData()
  372. })
  373. }
  374. }
  375. },
  376. // 触底加载
  377. onReachBottom: function () {
  378. console.log('到了底部到了底部', this.data.myIndex)
  379. if (this.data.myIndex === 2) {
  380. this.setData({
  381. coursePageNo: this.data.coursePageNo + 1
  382. }, () => {
  383. this.getCoursesList()
  384. })
  385. }
  386. if (this.data.myIndex === 0) {
  387. this.setData({
  388. recommendPageNo: this.data.recommendPageNo + 1
  389. }, () => {
  390. this.getHotRecommend()
  391. })
  392. }
  393. // // 当前在推荐页面 加载推荐
  394. // if (this.data.myIndex === 1) {
  395. // console.log(this.data.recommendPageNo)
  396. // console.log(this.data.recommendTotalNo)
  397. // this.setData({
  398. // recommendPageNo: this.data.recommendPageNo + 1
  399. // })
  400. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  401. // this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  402. // } else {
  403. // console.log('没有更多')
  404. // }
  405. // }
  406. },
  407. onPullDownRefresh: function () {
  408. //当前在团购页下拉加载
  409. if (this.data.myIndex === 0) {
  410. // groupInit(this);
  411. }
  412. wx.showNavigationBarLoading() //在标题栏中显示加载
  413. //模拟加载
  414. setTimeout(function () {
  415. wx.hideNavigationBarLoading() //完成停止加载
  416. wx.stopPullDownRefresh() //停止下拉刷新
  417. }, 1500);
  418. },
  419. goToMessage: function () {
  420. wx.navigateTo({
  421. url: `../../pages/social/insideMessage/insideMessage`
  422. });
  423. const str = 'hotData.unReadMessageNum';
  424. this.setData({
  425. [str]: 0
  426. })
  427. },
  428. toMyCollage: function (e) {
  429. if (app.globalData.isIOS) {
  430. wx.navigateTo({
  431. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  432. });
  433. } else {
  434. wx.navigateTo({
  435. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  436. });
  437. }
  438. },
  439. toMyCourse: function () {
  440. wx.navigateTo({
  441. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  442. });
  443. },
  444. goToFlower: function () {
  445. wx.navigateTo({
  446. url: `../../pages/social/littleFlower/littleFlower`
  447. });
  448. },
  449. signInBtn: function (e) {
  450. this.setData({
  451. indexSignDialog: false
  452. })
  453. console.log(e.detail.formId)
  454. httpRequestApi.postFormId(e.detail.formId).success(res => {
  455. console.log(res)
  456. })
  457. this.goToFlower();
  458. },
  459. missionBtn: function () {
  460. this.setData({
  461. indexMissionDialog: false
  462. })
  463. this.goToFlower();
  464. },
  465. getUserAuth: function () {
  466. httpRequestApi.getUserAuth().success(res => {
  467. console.log(res)
  468. const str = 'myData.isVIP'
  469. if (res.data.data) {
  470. this.setData({
  471. [str]: true
  472. })
  473. } else {
  474. this.setData({
  475. [str]: false
  476. })
  477. }
  478. })
  479. },
  480. delHideMyWork:function(){
  481. this.getMyRead()
  482. },
  483. // 获取我的朗读
  484. getMyRead: function () {
  485. httpRequestApi.myRead().success(res => {
  486. console.log(123123, res)
  487. console.log('mydata', this.data.myData)
  488. const myList = res.data.data;
  489. if (myList.length === 0) return;
  490. // const recommendWorks = [];
  491. const myWorks = [];
  492. myList.forEach(item => {
  493. const temp = {};
  494. temp.title = item.title;
  495. temp.summary = item.summary;
  496. temp.img = item.iconImg;
  497. temp.plays = item.playAmount;
  498. temp.likes = item.likeAmount;
  499. temp.commentAmount = item.commentAmount;
  500. temp.classId = item.exampleId ? item.exampleId : 1605097720036046;
  501. temp.time = formatDate(item.gmtCreated, 3);
  502. temp.avatar = this.data.myData.userInfo.avatar;
  503. temp.uid = this.uid;
  504. temp.url = item.videoPath;
  505. temp.id = item.id;
  506. temp.showMyBtn = true;
  507. temp.nickName = this.data.myData.userInfo.wechatName;
  508. temp.status = item.status
  509. myWorks.push(temp);
  510. });
  511. console.log('myWorks',myWorks)
  512. this.setData({
  513. videoList: myWorks
  514. })
  515. })
  516. },
  517. // 评论区点击
  518. commentTap: function (e) {
  519. console.log('点击评论区', e)
  520. if (e.target.dataset.type === 'blank') {
  521. this.setData({
  522. commentShow: false
  523. })
  524. }
  525. },
  526. // 打开评论
  527. openComment: function (e) {
  528. //
  529. console.log('id', e.detail.activeId)
  530. this.setData({
  531. commentShow: !this.data.commentShow,
  532. commentId: e.detail.activeId,
  533. // commentList: []
  534. });
  535. // this.getReply(e.detail.activeId);
  536. },
  537. // 获取评论信息
  538. getReply: function (columnId) {
  539. // let columnId = this.data.id;
  540. console.log(123123123, columnId)
  541. // let pageNo = this.data.pageNo;
  542. // let pageSize = this.data.pageSize;
  543. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  544. console.log('reply', res)
  545. const commentList = res.data.data.list;
  546. const commentNum = res.data.data.totalSize;
  547. console.log('评论数量', commentNum)
  548. commentList.forEach((item) => {
  549. const temp = {};
  550. temp.nickName = item.user.wechatName;
  551. temp.avatar = item.user.avatar;
  552. temp.uid = item.user.uid;
  553. temp.text = item.detailDesc;
  554. temp.id = item.id;
  555. temp.replyCount = item.replyCount;
  556. temp.time = formatDate(item.gmtCreated, 3);
  557. temp.likes = item.postsAttributeInfo.favors || 0;
  558. temp.isLike = item.isLike;
  559. temp.replyList = item.replyVOList;
  560. this.data.commentList.push(temp);
  561. });
  562. this.setData({
  563. commentList: this.data.commentList,
  564. commentNum: commentNum
  565. })
  566. });
  567. },
  568. // 发布回复
  569. sendReply: function (e) {
  570. console.log('triger', e.detail.content);
  571. let data = {
  572. columnId: this.data.commentId,
  573. colunmNames: 'what',
  574. detailDesc: e.detail.content,
  575. // productId: this.data.productId
  576. }
  577. httpRequestApi.postReply(this.uid, data).success(res => {
  578. console.log(res)
  579. this.setData({
  580. pageNo: 1,
  581. commentList: []
  582. }, () => {
  583. this.getReply(this.data.commentId);
  584. })
  585. });
  586. },
  587. gradeTap: function () {
  588. // console.log("组件回调,返回上一页");
  589. this.setData({
  590. isGradeShow: true
  591. })
  592. },
  593. // 修改年级
  594. changeGrade: function (e) {
  595. const grade = e.target.dataset.code;
  596. wx.setStorageSync('grade', grade)
  597. this.setData({
  598. isGradeShow: false,
  599. })
  600. getOpenidNoLogin((res) => {
  601. console.log('getOpenidNoLogin', res)
  602. // 登录或注册完成 展示页面
  603. this.showPage()
  604. }, (error) => {
  605. console.log('获取失败')
  606. wx.setStorageSync('userSourseType', 'normal')
  607. this.setData({
  608. hide: !this.data.hide
  609. })
  610. }, grade);
  611. },
  612. getFollowData: function () {
  613. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  614. if (res.data.data.totalSize === 0) {
  615. this.setData({
  616. videoList: []
  617. })
  618. console.log('没有关注人或关注的人没有发过作品')
  619. return
  620. }
  621. console.log('关注列表', res)
  622. const followData = res.data.data.list;
  623. // const videoList = [];
  624. this.formatWorksList(followData);
  625. });
  626. },
  627. // 点击用户头像区域
  628. headTapHandler: function (e) {
  629. console.log('点击头像', e)
  630. let tapId = e.detail.activeId;
  631. // 点击头像既关注 测试
  632. httpRequestApi.followUser(this.uid, tapId).success(res => {
  633. console.log(res)
  634. })
  635. },
  636. getCoursesList: function () {
  637. const grade = wx.getStorageSync('grade');
  638. const data = {
  639. pageNo: this.data.coursePageNo,
  640. pageSize: 6,
  641. grade,
  642. type: 'EXAMPLE'
  643. };
  644. console.log('资源', data)
  645. httpRequestApi.getClassRead(data).success(res => {
  646. console.log('资源', this.data.coursesData)
  647. this.setData({
  648. coursesData: this.data.coursesData.concat(res.data.data.list)
  649. }, () => {
  650. console.log(this.data.coursesData)
  651. })
  652. })
  653. },
  654. goToReading: function (e) {
  655. console.log('去朗读', e)
  656. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  657. wx.navigateTo({
  658. url: `../../pages/reading/reading?id=${id}`
  659. });
  660. },
  661. })