index.js 18 KB

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