index.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  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: 'my',
  34. }, {
  35. name: '推荐',
  36. templates: 'recommend',
  37. },
  38. {
  39. name: '关注',
  40. templates: 'follow',
  41. },
  42. {
  43. name: '资源',
  44. templates: 'courses',
  45. }
  46. ],
  47. winH: 568,
  48. statusBarHeight: getApp().globalData.statusBarHeight,
  49. myIndex: 0,
  50. followData: [],
  51. recommendPageNo: 1,
  52. recommendPageSize: 3,
  53. recommendTotalNo: 1,
  54. myData: {},
  55. templates: '',
  56. title: 'index中的title',
  57. jurisdictionFlag: true,
  58. hotInput: '12345',
  59. mineSettingInfo: '528',
  60. hide: true,
  61. isIOS: app.globalData.isIOS,
  62. ifHaveMore: true,
  63. indexSignDialog: false,
  64. indexMissionDialog: false,
  65. unfinishedCount: 0,
  66. videoList: [],
  67. nextMargin: '400rpx', // 视频下边距
  68. commentShow: false,
  69. commentList: [],
  70. commentNum: 0,
  71. followPageNo: 1,
  72. followPageSize: 6,
  73. coursePageNo: 1,
  74. coursesData: [],
  75. updateId: 0, // 刷新id
  76. statusbarobj: {
  77. isshowbtn: true, //是否显示按钮
  78. title: "小学语文朗读配音", //标题
  79. },
  80. grade: wx.getStorageSync('grade'),
  81. noMoreWork: false, // 没有更多作品 已经到底了
  82. },
  83. jurisdiction: function () {
  84. //隐藏弹框
  85. this.setData({
  86. hide: !this.data.hide
  87. })
  88. //登录页信息
  89. this.updateData(0)
  90. },
  91. //tab点击
  92. switcher: function ({
  93. currentTarget
  94. }) {
  95. if (currentTarget.dataset.index === this.data.myIndex) return;
  96. this.updateData(currentTarget.dataset.index);
  97. },
  98. // 根据index 更新template
  99. updateData: function (index) {
  100. let myIndex = parseInt(index);
  101. this.setData({
  102. myIndex,
  103. noMoreWork: false
  104. });
  105. // 获取推荐列表
  106. if (myIndex == 0) {
  107. this.setData({
  108. recommendPageNo: 1,
  109. videoList: [],
  110. isSwiper: false
  111. }, () => {
  112. this.getHotRecommend(this.uid);
  113. })
  114. return;
  115. }
  116. /* 关注和我的需要登陆后查看 */
  117. if (!this.data.isLogin) {
  118. wx.navigateTo({
  119. url: `../../pages/login/login?index=${myIndex}`
  120. });
  121. return;
  122. }
  123. console.log('继续')
  124. // 刷新关注列表
  125. if (myIndex == 1) {
  126. this.setData({
  127. videoList: [],
  128. isSwiper: false,
  129. followPageNo: 1
  130. }, () => {
  131. this.getFollowData()
  132. })
  133. return;
  134. }
  135. // 刷新资源
  136. if (myIndex == 2) {
  137. this.setData({
  138. videoList: [],
  139. coursesData: [],
  140. templates: 'courses',
  141. coursePageNo: 1
  142. }, () => {
  143. this.getCoursesList();
  144. })
  145. return;
  146. }
  147. // 刷新我的
  148. if (myIndex == 3) {
  149. this.setData({
  150. videoList: [],
  151. templates: 'my',
  152. isSwiper: false
  153. }, () => {
  154. myInit(this);
  155. })
  156. return;
  157. }
  158. },
  159. showPage: function () {
  160. let options = this.data.options;
  161. console.log('this.data.workId', this.data.workId)
  162. if (this.data.workId) {
  163. // 需要在推荐第一个上插入一条分享或者刚朗读完数据
  164. let id = this.data.workId;
  165. this.setData({
  166. workId: null,
  167. myIndex: 0,
  168. videoList: [],
  169. isSwiper: false,
  170. recommendTotalNo: 1
  171. })
  172. httpRequestApi.getClassDetail(id).success(res => {
  173. console.log('有一条数据', res)
  174. let tempList = [];
  175. tempList.push(res.data.data);
  176. this.setData({
  177. videoList: [],
  178. isSwiper: false,
  179. recommendTotalNo: 1
  180. }, () => {
  181. this.formatWorksList(tempList, true);
  182. console.log('插入数据')
  183. // this.getHotRecommend();
  184. // return;
  185. })
  186. // this.showPage()
  187. })
  188. }
  189. if (options && options.index) {
  190. this.updateData(options.index)
  191. } else {
  192. console.log('又加载一边')
  193. this.updateData(0)
  194. }
  195. setTimeout(() => {
  196. if (wx.getStorageSync('uid')) {
  197. httpRequestApi.userLoginRecord().success(res => {
  198. if (res.data.data && res.data.data.length !== 0) {
  199. // 有数据弹签到
  200. if (this.data.unfinishedCount > 0) {
  201. this.setData({
  202. indexSignDialog: true
  203. })
  204. }
  205. } else {
  206. // 没数据弹任务
  207. let oldDay = wx.getStorageSync('oldDay');
  208. let newDate = new Date();
  209. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  210. let timeStep = (newDate.getMonth() + 1).toString() + day
  211. if (oldDay) {
  212. let temp = parseInt(timeStep) - parseInt(oldDay)
  213. if (temp > 0) {
  214. wx.setStorageSync('oldDay', timeStep);
  215. this.setData({
  216. indexMissionDialog: true
  217. })
  218. }
  219. } else {
  220. wx.setStorageSync('oldDay', timeStep);
  221. this.setData({
  222. indexMissionDialog: true
  223. })
  224. }
  225. }
  226. })
  227. }
  228. }, 2800)
  229. },
  230. onLoad: function (options) {
  231. console.log('onload', options);
  232. if (options.scene) {
  233. this.setData({
  234. workId: options.scene
  235. })
  236. }
  237. if (options.readId) {
  238. this.setData({
  239. workId: options.readId
  240. })
  241. }
  242. getOpenidNoLogin((res) => {
  243. console.log('getOpenidNoLogin', res)
  244. if (!res.data.data.grade) {
  245. // 没有年级的老用户
  246. if (res.data.data.wechatName) {
  247. this.setData({
  248. isGradeShow: true,
  249. options,
  250. isLogin: true,
  251. oldUser: true
  252. })
  253. return;
  254. }
  255. this.setData({
  256. isGradeShow: true,
  257. options,
  258. isLogin: false,
  259. workId: options.scene ? options.scene : options.readId ? options.readId : undefined
  260. })
  261. return
  262. } else {
  263. if (res.data.data.wechatName) {
  264. this.setData({
  265. isLogin: true
  266. }, () => {
  267. this.showPage();
  268. })
  269. }
  270. }
  271. // 登录或注册完成 展示页面
  272. }, (error) => {
  273. console.log('获取失败', error)
  274. });
  275. this.uid = wx.getStorageSync('uid');
  276. let grade = wx.getStorageSync('grade');
  277. // if (!this.uid || !grade) {
  278. // this.setData({
  279. // isGradeShow: true,
  280. // options
  281. // })
  282. // console.log('没有uid 也不是游客,需要去授权')
  283. // return;
  284. // }
  285. wx.getSystemInfo({
  286. success: (res) => {
  287. console.log('系统', res)
  288. console.log('nextMargin', res.pixelRatio)
  289. console.log('windowHeight', res.windowHeight)
  290. console.log('windowWidth', res.windowWidth)
  291. // let ratio = res.pixelRatio;
  292. let ratio = (res.screenHeight / res.screenWidth) * 1.1;
  293. console.log('比例系数', ratio)
  294. let winH = res.windowHeight * ratio;
  295. let x1 = 465 * ratio;
  296. let x2 = 603 * ratio;
  297. let minusNumber = (winH * x1) / x2;
  298. let nextMargin = parseInt(winH - minusNumber);
  299. app.globalData.nextMargin = nextMargin;
  300. this.setData({
  301. winH: winH,
  302. devicePixelRatio: res.pixelRatio,
  303. nextMargin: nextMargin + 'rpx'
  304. });
  305. }
  306. });
  307. },
  308. onShow: function () {
  309. if (this.data.myIndex === 3) {
  310. this.getUserWorksInfo(1)
  311. }
  312. wx.setNavigationBarTitle({
  313. title: '小学语文朗读配音'
  314. })
  315. console.log('页面返回页面返回', this.data.fromLoginIndex)
  316. console.log('页面返回页面返回', this.data.myIndex)
  317. if (this.data.fromLoginIndex) {
  318. console.log('页面返回页面返回', this.data.fromLoginIndex)
  319. let index = this.data.fromLoginIndex;
  320. let userInfo = wx.getStorageSync('user');
  321. this.setData({
  322. fromLoginIndex: null,
  323. isLogin: userInfo.wechatName ? true : false
  324. }, () => {
  325. this.updateData(0)
  326. })
  327. }
  328. if (this.data.fromReading) {
  329. this.setData({
  330. fromReading: false
  331. })
  332. this.updateData(3)
  333. }
  334. // 刷新课程资源的收藏数等
  335. if (this.data.myIndex === 2) {
  336. console.log('去刷新')
  337. this.refreshCourseAmount()
  338. }
  339. // const userInfo = wx.getStorageSync('user')
  340. // console.log('userInfo',userInfo)
  341. // if (userInfo.wechatName) {
  342. // this.setData({
  343. // isLogin: true
  344. // })
  345. // } else {
  346. // this.setData({
  347. // isLogin: false
  348. // })
  349. // }
  350. },
  351. onHide: function () {
  352. const str = 'hotData.inputFocus'
  353. this.setData({
  354. [str]: false
  355. });
  356. },
  357. /* 两个接口维护同一个数组,手动的结束后添加算法的 */
  358. // 推荐页信息 获取消息和手动推荐内容
  359. // 获取热门作品 算法出来的
  360. getHotRecommend: function () {
  361. let grade = wx.getStorageSync('grade')
  362. let pageNo = this.data.recommendPageNo;
  363. let pageSize = this.data.recommendPageSize;
  364. httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
  365. console.log(res)
  366. const recommendRes = res.data.data.list;
  367. if (recommendRes.length === 0) {
  368. this.setData({
  369. noMoreWork: true
  370. })
  371. return
  372. };
  373. // const recommendWorks = [];
  374. this.formatWorksList(recommendRes);
  375. })
  376. },
  377. // 组装list
  378. formatWorksList(list, notSet) {
  379. // const tempList = [];
  380. console.log('列表长度列表长度', list.length)
  381. if (list.length < 6 || list.length === 0) {
  382. this.setData({
  383. noMoreWork: true
  384. })
  385. }
  386. list.forEach((item, index) => {
  387. /* if (index === list.length - 2 && list.length > 2) {
  388. console.log('设置当前id', item.id)
  389. this.setData({
  390. updateId: item.userRead.id
  391. })
  392. } */
  393. const temp = {};
  394. temp.title = item.userRead.title;
  395. temp.summary = item.userRead.summary;
  396. temp.img = item.userRead.iconImg;
  397. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  398. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  399. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  400. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  401. temp.time = formatDate(item.userRead.gmtCreated, 3);
  402. temp.avatar = item.user.avatar;
  403. temp.profession = item.user.profession;
  404. temp.uid = item.user.uid;
  405. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  406. temp.id = item.userRead.id;
  407. temp.type = item.userRead.type;
  408. temp.nickName = item.user.wechatName;
  409. temp.isLike = item.isLike;
  410. temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
  411. temp.isFavorite = item.isFavorites;
  412. temp.isEfun = item.user.profession === '官方' ? true : false;
  413. temp.hasTag = item.userRead.tag && item.userRead.tag !== 'EXAMPLE' ? true : false;
  414. temp.tagUrl = item.userRead.tag ? item.userRead.tag === 'HOT' ? '../../static/index/hot_tag.png' : '../../static/index/new_tag.png' : ''
  415. temp.status = item.userRead.status;
  416. temp.coverImg = item.userRead.coverImg;
  417. temp.shareImg = item.userRead.shareImg;
  418. temp.grade = item.userRead.grade;
  419. temp.videoShow = false;
  420. this.data.videoList.push(temp);
  421. // tempList.push(temp);
  422. });
  423. console.log('当前list', this.data.videoList)
  424. // if (!notSet) {
  425. this.setData({
  426. videoList: this.data.videoList
  427. })
  428. // }
  429. },
  430. // 获取用户信息
  431. getUserWorksInfo: function (flag) {
  432. if (flag) {
  433. httpRequestApi.getUserWorksInfo().success(res => {
  434. const userInfo = this.formatGrade(res.data.data.user);
  435. const str = 'myData.userInfo.wechatName';
  436. const avatarStr = 'myData.userInfo.avatar';
  437. const gradeTextStr = 'myData.userInfo.gradeText';
  438. this.setData({
  439. [str]: userInfo.wechatName,
  440. [avatarStr]: userInfo.avatar,
  441. [gradeTextStr]: userInfo.gradeText
  442. })
  443. })
  444. return;
  445. }
  446. httpRequestApi.getUserWorksInfo().success(res => {
  447. this.data.myData.user = res.data.data;
  448. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  449. if (res.data.data.myRead) {
  450. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  451. }
  452. res.data.data.user = this.formatGrade(res.data.data.user);
  453. this.setData({
  454. myData: res.data.data,
  455. ['myData.userInfo']: res.data.data.user
  456. }, () => {
  457. this.getMyRead()
  458. });
  459. }).fail(error => {
  460. console.log(error)
  461. })
  462. },
  463. formatGrade(userInfo) {
  464. switch (userInfo.grade) {
  465. case 'PRESCHOOL':
  466. userInfo.gradeText = '学前班'
  467. break;
  468. case 'PRIMARY_FIRST_GRADE':
  469. userInfo.gradeText = '一年级'
  470. break;
  471. case 'PRIMARY_SECOND_GRADE':
  472. userInfo.gradeText = '二年级'
  473. break;
  474. case 'PRIMARY_THREE_GRADE':
  475. userInfo.gradeText = '三年级'
  476. break;
  477. case 'PRIMARY_SENIOR_GRADE':
  478. userInfo.gradeText = '四年级';
  479. break;
  480. }
  481. return userInfo;
  482. },
  483. videoChange: function (e) {
  484. if (e.detail.activeId === this.data.updateId) {
  485. console.log('应该刷新')
  486. if (this.data.myIndex === 1) {
  487. this.setData({
  488. followPageNo: this.data.followPageNo + 1
  489. }, () => {
  490. this.getFollowData()
  491. })
  492. }
  493. if (this.data.myIndex === 0) {
  494. console.log('首页加载第二页')
  495. this.setData({
  496. recommendPageNo: this.data.recommendPageNo + 1
  497. }, () => {
  498. this.getHotRecommend()
  499. })
  500. }
  501. }
  502. },
  503. // 触底加载
  504. onReachBottom: function () {
  505. if (this.data.myIndex === 2) {
  506. this.setData({
  507. coursePageNo: this.data.coursePageNo + 1
  508. }, () => {
  509. this.getCoursesList()
  510. })
  511. }
  512. if (this.data.myIndex === 1) {
  513. this.setData({
  514. followPageNo: this.data.followPageNo + 1
  515. }, () => {
  516. this.getFollowData()
  517. })
  518. }
  519. if (this.data.myIndex === 0) {
  520. console.log('首页加载第二页')
  521. this.setData({
  522. recommendPageNo: this.data.recommendPageNo + 1
  523. }, () => {
  524. this.getHotRecommend()
  525. })
  526. }
  527. // // 当前在推荐页面 加载推荐
  528. // if (this.data.myIndex === 1) {
  529. // console.log(this.data.recommendPageNo)
  530. // console.log(this.data.recommendTotalNo)
  531. // this.setData({
  532. // recommendPageNo: this.data.recommendPageNo + 1
  533. // })
  534. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  535. // this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  536. // } else {
  537. // console.log('没有更多')
  538. // }
  539. // }
  540. },
  541. onPullDownRefresh: function () {
  542. //当前在团购页下拉加载
  543. this.updateData(this.data.myIndex)
  544. wx.showNavigationBarLoading() //在标题栏中显示加载
  545. //模拟加载
  546. setTimeout(function () {
  547. wx.hideNavigationBarLoading() //完成停止加载
  548. wx.stopPullDownRefresh() //停止下拉刷新
  549. }, 1000);
  550. },
  551. goToMessage: function () {
  552. wx.navigateTo({
  553. url: `../../pages/social/insideMessage/insideMessage`
  554. });
  555. const str = 'hotData.unReadMessageNum';
  556. this.setData({
  557. [str]: 0
  558. })
  559. },
  560. toMyCollage: function (e) {
  561. if (app.globalData.isIOS) {
  562. wx.navigateTo({
  563. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  564. });
  565. } else {
  566. wx.navigateTo({
  567. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  568. });
  569. }
  570. },
  571. toMyCourse: function () {
  572. wx.navigateTo({
  573. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  574. });
  575. },
  576. goToFlower: function () {
  577. wx.navigateTo({
  578. url: `../../pages/social/littleFlower/littleFlower`
  579. });
  580. },
  581. signInBtn: function (e) {
  582. this.setData({
  583. indexSignDialog: false
  584. })
  585. console.log(e.detail.formId)
  586. httpRequestApi.postFormId(e.detail.formId).success(res => {
  587. console.log(res)
  588. })
  589. this.goToFlower();
  590. },
  591. missionBtn: function () {
  592. this.setData({
  593. indexMissionDialog: false
  594. })
  595. this.goToFlower();
  596. },
  597. getUserAuth: function () {
  598. httpRequestApi.getUserAuth().success(res => {
  599. console.log(res)
  600. const str = 'myData.isVIP'
  601. if (res.data.data) {
  602. this.setData({
  603. [str]: true
  604. })
  605. } else {
  606. this.setData({
  607. [str]: false
  608. })
  609. }
  610. })
  611. },
  612. delHideMyWork: function () {
  613. this.getMyRead()
  614. },
  615. // 获取我的朗读
  616. getMyRead: function () {
  617. httpRequestApi.myRead().success(res => {
  618. console.log(123123, res)
  619. console.log('mydata', this.data.myData)
  620. const myList = res.data.data;
  621. if (myList.length === 0) {
  622. this.setData({
  623. videoList: []
  624. })
  625. return
  626. }
  627. // this.formatWorksList(myList)
  628. // const recommendWorks = [];
  629. const myWorks = [];
  630. myList.forEach(item => {
  631. const temp = {};
  632. temp.title = item.userRead.title;
  633. temp.summary = item.userRead.summary;
  634. temp.img = item.userRead.iconImg;
  635. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  636. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  637. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  638. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  639. temp.time = formatDate(item.userRead.gmtCreated, 3);
  640. temp.avatar = item.user.avatar;
  641. temp.profession = item.user.profession;
  642. temp.uid = item.user.uid;
  643. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  644. temp.id = item.userRead.id;
  645. temp.type = item.userRead.type;
  646. temp.nickName = item.user.wechatName;
  647. temp.isLike = item.isLike;
  648. temp.isFavorite = item.isFavorites;
  649. temp.showMyBtn = true;
  650. temp.nickName = this.data.myData.userInfo.wechatName;
  651. temp.status = item.userRead.status;
  652. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  653. temp.coverImg = item.userRead.coverImg;
  654. temp.grade = item.userRead.grade
  655. temp.isFans = true;
  656. temp.videoShow = false;
  657. temp.shareImg = item.userRead.shareImg;
  658. myWorks.push(temp);
  659. });
  660. console.log('myWorks', myWorks)
  661. if (this.data.myIndex === 3) {
  662. this.setData({
  663. videoList: myWorks,
  664. noMoreWork: true
  665. })
  666. }
  667. })
  668. },
  669. // 评论区点击
  670. commentTap: function (e) {
  671. console.log('点击评论区', e)
  672. if (e.target.dataset.type === 'blank') {
  673. this.setData({
  674. commentShow: false
  675. })
  676. }
  677. },
  678. touchMove: function (e) {
  679. return
  680. },
  681. // 打开评论
  682. openComment: function (e) {
  683. //
  684. console.log('id', e.detail.activeId)
  685. this.setData({
  686. commentShow: !this.data.commentShow,
  687. commentId: e.detail.activeId,
  688. // commentList: []
  689. });
  690. // this.getReply(e.detail.activeId);
  691. },
  692. // 获取评论信息
  693. getReply: function (columnId) {
  694. // let columnId = this.data.id;
  695. console.log(123123123, columnId)
  696. // let pageNo = this.data.pageNo;
  697. // let pageSize = this.data.pageSize;
  698. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  699. console.log('reply', res)
  700. const commentList = res.data.data.list;
  701. const commentNum = res.data.data.totalSize;
  702. console.log('评论数量', commentNum)
  703. commentList.forEach((item) => {
  704. const temp = {};
  705. temp.nickName = item.user.wechatName;
  706. temp.avatar = item.user.avatar;
  707. temp.uid = item.user.uid;
  708. temp.text = item.detailDesc;
  709. temp.id = item.id;
  710. temp.replyCount = item.replyCount;
  711. temp.time = formatDate(item.gmtCreated, 3);
  712. temp.likes = item.postsAttributeInfo.favors || 0;
  713. temp.isLike = item.isLike;
  714. temp.replyList = item.replyVOList;
  715. this.data.commentList.push(temp);
  716. });
  717. this.setData({
  718. commentList: this.data.commentList,
  719. commentNum: commentNum
  720. })
  721. });
  722. },
  723. // 发布回复
  724. sendReply: function (e) {
  725. console.log('triger', e.detail.content);
  726. let data = {
  727. columnId: this.data.commentId,
  728. colunmNames: 'what',
  729. detailDesc: e.detail.content,
  730. // productId: this.data.productId
  731. }
  732. httpRequestApi.postReply(this.uid, data).success(res => {
  733. console.log(res)
  734. this.setData({
  735. pageNo: 1,
  736. commentList: []
  737. }, () => {
  738. this.getReply(this.data.commentId);
  739. })
  740. });
  741. },
  742. gradeTap: function () {
  743. // console.log("组件回调,返回上一页");
  744. this.setData({
  745. isGradeShow: true
  746. })
  747. },
  748. onShareAppMessage: function (res) {
  749. if (res.from === 'button') {
  750. return {
  751. title: '请欣赏我的课文朗读作品,点赞+评论。',
  752. path: `/pages/index/index?readId=${this.data.shareId}`,
  753. imageUrl: this.data.shareImg
  754. }
  755. } else {
  756. return {
  757. title: '课文朗读,从未如此有趣。',
  758. path: '/pages/index/index',
  759. }
  760. }
  761. },
  762. openShare: function (e) {
  763. this.setData({
  764. shareTitle: e.detail.currentTarget.dataset.title,
  765. shareId: e.detail.currentTarget.dataset.id,
  766. shareImg: e.detail.currentTarget.dataset.shareimg
  767. })
  768. },
  769. // 修改年级
  770. changeGrade: function (e) {
  771. const grade = e.target.dataset.code;
  772. wx.setStorageSync('grade', grade)
  773. this.setData({
  774. isGradeShow: false,
  775. grade
  776. })
  777. if (this.data.oldUser) {
  778. let data = {
  779. grade: e.target.dataset.code
  780. };
  781. httpRequestApi.settingUserInfo(data).success(res => {
  782. })
  783. return;
  784. };
  785. getOpenidNoLogin((res) => {
  786. console.log('getOpenidNoLogin', res)
  787. // 登录或注册完成 展示页面
  788. if (res.data.data.wechatName) {
  789. this.setData({
  790. isLogin: true
  791. })
  792. } else {
  793. this.setData({
  794. isLogin: false
  795. })
  796. }
  797. this.showPage()
  798. }, (error) => {
  799. console.log('获取失败')
  800. wx.setStorageSync('userSourseType', 'normal')
  801. this.setData({
  802. hide: !this.data.hide
  803. })
  804. }, grade);
  805. },
  806. getFollowData: function () {
  807. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  808. if (res.data.data.totalSize === 0) {
  809. this.setData({
  810. videoList: [],
  811. noFollow: true
  812. })
  813. console.log('没有关注人或关注的人没有发过作品')
  814. return
  815. } else {
  816. this.setData({
  817. noFollow: false
  818. })
  819. }
  820. console.log('关注列表', res)
  821. const followData = res.data.data.list;
  822. // const videoList = [];
  823. this.formatWorksList(followData);
  824. });
  825. },
  826. // 点击用户头像区域
  827. headTapHandler: function (e) {
  828. console.log('点击头像', e)
  829. let tapId = e.detail.activeId;
  830. // 点击头像既关注 测试
  831. httpRequestApi.followUser(this.uid, tapId).success(res => {
  832. console.log(res)
  833. })
  834. },
  835. getCoursesList: function () {
  836. const grade = wx.getStorageSync('grade');
  837. const data = {
  838. pageNo: this.data.coursePageNo,
  839. pageSize: 6,
  840. grade,
  841. type: 'EXAMPLE'
  842. };
  843. console.log('资源', data)
  844. httpRequestApi.getClassRead(data).success(res => {
  845. console.log('资源', this.data.coursesData)
  846. this.setData({
  847. coursesData: this.data.coursesData.concat(res.data.data.list),
  848. noMoreWork: res.data.data.list <= 0 ? true : false
  849. }, () => {
  850. console.log(this.data.coursesData)
  851. })
  852. })
  853. },
  854. goToReading: function (e) {
  855. console.log('去朗读', e)
  856. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  857. const index = e.currentTarget.dataset.index;
  858. this.setData({
  859. goToCoursesId: id,
  860. goToCoursesIndex: index
  861. })
  862. wx.navigateTo({
  863. url: `../../pages/reading/reading?id=${id}`
  864. });
  865. },
  866. refreshCourseAmount() {
  867. console.log(this.data.goToCoursesId)
  868. console.log(this.data.goToCoursesIndex)
  869. if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
  870. httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
  871. console.log('刷新', res.data.data.userRead)
  872. let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
  873. let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
  874. let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
  875. let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
  876. let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
  877. console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
  878. console.log(2, res.data.data.userRead.likeAmount)
  879. this.setData({
  880. [likeStr]: res.data.data.userRead.likeAmount,
  881. [commentStr]: res.data.data.userRead.commentAmount,
  882. [playStr]: res.data.data.userRead.playAmount,
  883. [shareStr]: res.data.data.userRead.shareAmount,
  884. [collectStr]: res.data.data.userRead.collectAmount,
  885. }, () => {
  886. console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
  887. })
  888. })
  889. }
  890. },
  891. courseCollectTap: function collectClass(e) {
  892. console.log('收藏按钮', e);
  893. const data = {
  894. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  895. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  896. }
  897. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  898. let str = `coursesData[${index}].isFavorites`
  899. httpRequestApi.collectClass(data).success((res) => {
  900. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  901. this.setData({
  902. [str]: !this.data.coursesData[index].isFavorites
  903. })
  904. });
  905. },
  906. coursesOpenShare: function coursesOpenShare(e) {
  907. const obj = e.currentTarget.dataset
  908. console.log('分享', obj)
  909. console.log('分享', e)
  910. if (1) {
  911. this.shareDialog = this.selectComponent("#share-dialog");
  912. const data = {
  913. avatar: obj.avatar,
  914. author: obj.author,
  915. iconImg: obj.iconImg,
  916. title: obj.title,
  917. path: `pages/index/index`,
  918. scene: obj.id,
  919. productId: 1
  920. // tip: this.data.tip,
  921. }
  922. // console.log(data)
  923. this.setData({
  924. noScroll: 'noScroll',
  925. shareTitle: obj.title,
  926. shareId: obj.id,
  927. shareImg: obj.shareimg
  928. })
  929. this.shareDialog.share(data);
  930. }
  931. },
  932. collectTap: function (e) {
  933. console.log('点击收藏首页', e)
  934. const index = e.detail.index;
  935. let str = `videoList[${index}].isFavorite`
  936. this.setData({
  937. [str]: e.detail.isCollect
  938. })
  939. },
  940. likeTap: function (e) {
  941. console.log('点赞', e)
  942. const index = e.detail.index;
  943. let likeStr = `videoList[${index}].isLike`;
  944. let likeNumStr = `videoList[${index}].likes`;
  945. this.setData({
  946. [likeStr]: true,
  947. [likeNumStr]: this.data.videoList[index].likes + 1
  948. })
  949. // this.flowerAnimationHandler()
  950. },
  951. flowerAnimationHandler: function () {
  952. this.flowerBox = this.selectComponent("#flower-box");
  953. console.log('this.flower', this.flowerBox)
  954. this.flowerBox.comeOut();
  955. },
  956. })