index.js 17 KB

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