index.js 19 KB

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