index.js 19 KB

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