index.js 19 KB

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