index.js 18 KB

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