index.js 26 KB

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