index.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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.grade=item.userRead.grade
  400. temp.videoShow = false;
  401. this.data.videoList.push(temp);
  402. // tempList.push(temp);
  403. });
  404. console.log('当前list', this.data.videoList)
  405. // if (!notSet) {
  406. this.setData({
  407. videoList: this.data.videoList
  408. })
  409. // }
  410. },
  411. // 获取用户信息
  412. getUserWorksInfo: function (flag) {
  413. if (flag) {
  414. httpRequestApi.getUserWorksInfo().success(res => {
  415. const userInfo = this.formatGrade(res.data.data.user);
  416. const str = 'myData.userInfo.wechatName';
  417. const avatarStr = 'myData.userInfo.avatar';
  418. const gradeTextStr = 'myData.userInfo.gradeText';
  419. this.setData({
  420. [str]: userInfo.wechatName,
  421. [avatarStr]: userInfo.avatar,
  422. [gradeTextStr]: userInfo.gradeText
  423. })
  424. })
  425. return;
  426. }
  427. httpRequestApi.getUserWorksInfo().success(res => {
  428. this.data.myData.user = res.data.data;
  429. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  430. if (res.data.data.myRead) {
  431. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  432. }
  433. res.data.data.user = this.formatGrade(res.data.data.user);
  434. this.setData({
  435. myData: res.data.data,
  436. ['myData.userInfo']: res.data.data.user
  437. }, () => {
  438. this.getMyRead()
  439. });
  440. }).fail(error => {
  441. console.log(error)
  442. })
  443. },
  444. formatGrade(userInfo) {
  445. switch (userInfo.grade) {
  446. case 'PRESCHOOL':
  447. userInfo.gradeText = '学前班'
  448. break;
  449. case 'PRIMARY_FIRST_GRADE':
  450. userInfo.gradeText = '一年级'
  451. break;
  452. case 'PRIMARY_SECOND_GRADE':
  453. userInfo.gradeText = '二年级'
  454. break;
  455. case 'PRIMARY_THREE_GRADE':
  456. userInfo.gradeText = '三年级'
  457. break;
  458. case 'PRIMARY_SENIOR_GRADE':
  459. userInfo.gradeText = '四年级';
  460. break;
  461. }
  462. return userInfo;
  463. },
  464. videoChange: function (e) {
  465. if (e.detail.activeId === this.data.updateId) {
  466. console.log('应该刷新')
  467. if (this.data.myIndex === 1) {
  468. this.setData({
  469. followPageNo: this.data.followPageNo + 1
  470. }, () => {
  471. this.getFollowData()
  472. })
  473. }
  474. if (this.data.myIndex === 0) {
  475. console.log('首页加载第二页')
  476. this.setData({
  477. recommendPageNo: this.data.recommendPageNo + 1
  478. }, () => {
  479. this.getHotRecommend()
  480. })
  481. }
  482. }
  483. },
  484. // 触底加载
  485. onReachBottom: function () {
  486. if (this.data.myIndex === 2) {
  487. this.setData({
  488. coursePageNo: this.data.coursePageNo + 1
  489. }, () => {
  490. this.getCoursesList()
  491. })
  492. }
  493. if (this.data.myIndex === 1) {
  494. this.setData({
  495. followPageNo: this.data.followPageNo + 1
  496. }, () => {
  497. this.getFollowData()
  498. })
  499. }
  500. if (this.data.myIndex === 0) {
  501. console.log('首页加载第二页')
  502. this.setData({
  503. recommendPageNo: this.data.recommendPageNo + 1
  504. }, () => {
  505. this.getHotRecommend()
  506. })
  507. }
  508. // // 当前在推荐页面 加载推荐
  509. // if (this.data.myIndex === 1) {
  510. // console.log(this.data.recommendPageNo)
  511. // console.log(this.data.recommendTotalNo)
  512. // this.setData({
  513. // recommendPageNo: this.data.recommendPageNo + 1
  514. // })
  515. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  516. // this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  517. // } else {
  518. // console.log('没有更多')
  519. // }
  520. // }
  521. },
  522. onPullDownRefresh: function () {
  523. //当前在团购页下拉加载
  524. this.updateData(this.data.myIndex)
  525. wx.showNavigationBarLoading() //在标题栏中显示加载
  526. //模拟加载
  527. setTimeout(function () {
  528. wx.hideNavigationBarLoading() //完成停止加载
  529. wx.stopPullDownRefresh() //停止下拉刷新
  530. }, 1000);
  531. },
  532. goToMessage: function () {
  533. wx.navigateTo({
  534. url: `../../pages/social/insideMessage/insideMessage`
  535. });
  536. const str = 'hotData.unReadMessageNum';
  537. this.setData({
  538. [str]: 0
  539. })
  540. },
  541. toMyCollage: function (e) {
  542. if (app.globalData.isIOS) {
  543. wx.navigateTo({
  544. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  545. });
  546. } else {
  547. wx.navigateTo({
  548. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  549. });
  550. }
  551. },
  552. toMyCourse: function () {
  553. wx.navigateTo({
  554. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  555. });
  556. },
  557. goToFlower: function () {
  558. wx.navigateTo({
  559. url: `../../pages/social/littleFlower/littleFlower`
  560. });
  561. },
  562. signInBtn: function (e) {
  563. this.setData({
  564. indexSignDialog: false
  565. })
  566. console.log(e.detail.formId)
  567. httpRequestApi.postFormId(e.detail.formId).success(res => {
  568. console.log(res)
  569. })
  570. this.goToFlower();
  571. },
  572. missionBtn: function () {
  573. this.setData({
  574. indexMissionDialog: false
  575. })
  576. this.goToFlower();
  577. },
  578. getUserAuth: function () {
  579. httpRequestApi.getUserAuth().success(res => {
  580. console.log(res)
  581. const str = 'myData.isVIP'
  582. if (res.data.data) {
  583. this.setData({
  584. [str]: true
  585. })
  586. } else {
  587. this.setData({
  588. [str]: false
  589. })
  590. }
  591. })
  592. },
  593. delHideMyWork: function () {
  594. this.getMyRead()
  595. },
  596. // 获取我的朗读
  597. getMyRead: function () {
  598. httpRequestApi.myRead().success(res => {
  599. console.log(123123, res)
  600. console.log('mydata', this.data.myData)
  601. const myList = res.data.data;
  602. if (myList.length === 0) {
  603. this.setData({
  604. videoList:[]
  605. })
  606. return
  607. }
  608. // this.formatWorksList(myList)
  609. // const recommendWorks = [];
  610. const myWorks = [];
  611. myList.forEach(item => {
  612. const temp = {};
  613. temp.title = item.userRead.title;
  614. temp.summary = item.userRead.summary;
  615. temp.img = item.userRead.iconImg;
  616. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  617. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  618. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  619. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  620. temp.time = formatDate(item.userRead.gmtCreated, 3);
  621. temp.avatar = item.user.avatar;
  622. temp.profession = item.user.profession;
  623. temp.uid = item.user.uid;
  624. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  625. temp.id = item.userRead.id;
  626. temp.type = item.userRead.type;
  627. temp.nickName = item.user.wechatName;
  628. temp.isLike = item.isLike;
  629. temp.isFavorite = item.isFavorites;
  630. temp.showMyBtn = true;
  631. temp.nickName = this.data.myData.userInfo.wechatName;
  632. temp.status = item.userRead.status;
  633. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  634. temp.coverImg = item.userRead.coverImg;
  635. temp.grade=item.userRead.grade
  636. temp.isFans = true;
  637. temp.videoShow = false;
  638. myWorks.push(temp);
  639. });
  640. console.log('myWorks', myWorks)
  641. if (this.data.myIndex === 3) {
  642. this.setData({
  643. videoList: myWorks
  644. })
  645. }
  646. })
  647. },
  648. // 评论区点击
  649. commentTap: function (e) {
  650. console.log('点击评论区', e)
  651. if (e.target.dataset.type === 'blank') {
  652. this.setData({
  653. commentShow: false
  654. })
  655. }
  656. },
  657. touchMove: function (e) {
  658. return
  659. },
  660. // 打开评论
  661. openComment: function (e) {
  662. //
  663. console.log('id', e.detail.activeId)
  664. this.setData({
  665. commentShow: !this.data.commentShow,
  666. commentId: e.detail.activeId,
  667. // commentList: []
  668. });
  669. // this.getReply(e.detail.activeId);
  670. },
  671. // 获取评论信息
  672. getReply: function (columnId) {
  673. // let columnId = this.data.id;
  674. console.log(123123123, columnId)
  675. // let pageNo = this.data.pageNo;
  676. // let pageSize = this.data.pageSize;
  677. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  678. console.log('reply', res)
  679. const commentList = res.data.data.list;
  680. const commentNum = res.data.data.totalSize;
  681. console.log('评论数量', commentNum)
  682. commentList.forEach((item) => {
  683. const temp = {};
  684. temp.nickName = item.user.wechatName;
  685. temp.avatar = item.user.avatar;
  686. temp.uid = item.user.uid;
  687. temp.text = item.detailDesc;
  688. temp.id = item.id;
  689. temp.replyCount = item.replyCount;
  690. temp.time = formatDate(item.gmtCreated, 3);
  691. temp.likes = item.postsAttributeInfo.favors || 0;
  692. temp.isLike = item.isLike;
  693. temp.replyList = item.replyVOList;
  694. this.data.commentList.push(temp);
  695. });
  696. this.setData({
  697. commentList: this.data.commentList,
  698. commentNum: commentNum
  699. })
  700. });
  701. },
  702. // 发布回复
  703. sendReply: function (e) {
  704. console.log('triger', e.detail.content);
  705. let data = {
  706. columnId: this.data.commentId,
  707. colunmNames: 'what',
  708. detailDesc: e.detail.content,
  709. // productId: this.data.productId
  710. }
  711. httpRequestApi.postReply(this.uid, data).success(res => {
  712. console.log(res)
  713. this.setData({
  714. pageNo: 1,
  715. commentList: []
  716. }, () => {
  717. this.getReply(this.data.commentId);
  718. })
  719. });
  720. },
  721. gradeTap: function () {
  722. // console.log("组件回调,返回上一页");
  723. this.setData({
  724. isGradeShow: true
  725. })
  726. },
  727. onShareAppMessage: function (res) {
  728. console.log('点击分享按钮', res)
  729. console.log('点击分享按钮', this.data.shareTitle)
  730. console.log('点击分享按钮', this.data.shareId)
  731. console.log('点击分享按钮', this.data.shareImg)
  732. if (res.from === 'button') {
  733. return {
  734. title: '请欣赏我的课文朗读作品,点赞+评论。',
  735. path: `/pages/index/index?readId=${this.data.shareId}`,
  736. imageUrl: '../../static/index/share_icon.png'
  737. }
  738. } else {
  739. return {
  740. title: '课文朗读,从未如此有趣。',
  741. path: '/pages/index/index',
  742. }
  743. }
  744. },
  745. openShare: function (e) {
  746. console.log('用户点击分享按钮', e)
  747. this.setData({
  748. shareTitle: e.detail.currentTarget.dataset.title,
  749. shareId: e.detail.currentTarget.dataset.id,
  750. shareImg: e.detail.currentTarget.dataset.img
  751. })
  752. },
  753. // 修改年级
  754. changeGrade: function (e) {
  755. const grade = e.target.dataset.code;
  756. wx.setStorageSync('grade', grade)
  757. this.setData({
  758. isGradeShow: false,
  759. grade
  760. })
  761. if (this.data.oldUser) {
  762. let data = {
  763. grade: e.target.dataset.code
  764. };
  765. httpRequestApi.settingUserInfo(data).success(res => {
  766. })
  767. return;
  768. };
  769. getOpenidNoLogin((res) => {
  770. console.log('getOpenidNoLogin', res)
  771. // 登录或注册完成 展示页面
  772. if (res.data.data.wechatName) {
  773. this.setData({
  774. isLogin: true
  775. })
  776. } else {
  777. this.setData({
  778. isLogin: false
  779. })
  780. }
  781. this.showPage()
  782. }, (error) => {
  783. console.log('获取失败')
  784. wx.setStorageSync('userSourseType', 'normal')
  785. this.setData({
  786. hide: !this.data.hide
  787. })
  788. }, grade);
  789. },
  790. getFollowData: function () {
  791. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  792. if (res.data.data.totalSize === 0) {
  793. this.setData({
  794. videoList: [],
  795. noFollow: true
  796. })
  797. console.log('没有关注人或关注的人没有发过作品')
  798. return
  799. } else {
  800. this.setData({
  801. noFollow: false
  802. })
  803. }
  804. console.log('关注列表', res)
  805. const followData = res.data.data.list;
  806. // const videoList = [];
  807. this.formatWorksList(followData);
  808. });
  809. },
  810. // 点击用户头像区域
  811. headTapHandler: function (e) {
  812. console.log('点击头像', e)
  813. let tapId = e.detail.activeId;
  814. // 点击头像既关注 测试
  815. httpRequestApi.followUser(this.uid, tapId).success(res => {
  816. console.log(res)
  817. })
  818. },
  819. getCoursesList: function () {
  820. const grade = wx.getStorageSync('grade');
  821. const data = {
  822. pageNo: this.data.coursePageNo,
  823. pageSize: 6,
  824. grade,
  825. type: 'EXAMPLE'
  826. };
  827. console.log('资源', data)
  828. httpRequestApi.getClassRead(data).success(res => {
  829. console.log('资源', this.data.coursesData)
  830. this.setData({
  831. coursesData: this.data.coursesData.concat(res.data.data.list)
  832. }, () => {
  833. console.log(this.data.coursesData)
  834. })
  835. })
  836. },
  837. goToReading: function (e) {
  838. console.log('去朗读', e)
  839. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  840. wx.navigateTo({
  841. url: `../../pages/reading/reading?id=${id}`
  842. });
  843. },
  844. courseCollectTap: function collectClass(e) {
  845. console.log('收藏按钮', e);
  846. const data = {
  847. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  848. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  849. }
  850. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  851. let str = `coursesData[${index}].isFavorites`
  852. httpRequestApi.collectClass(data).success((res) => {
  853. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  854. this.setData({
  855. [str]: !this.data.coursesData[index].isFavorites
  856. })
  857. });
  858. },
  859. coursesOpenShare: function coursesOpenShare(e) {
  860. const obj = e.currentTarget.dataset
  861. console.log('分享', obj)
  862. console.log('分享', e)
  863. if (1) {
  864. this.shareDialog = this.selectComponent("#share-dialog");
  865. const data = {
  866. avatar: obj.avatar,
  867. author: obj.author,
  868. iconImg: obj.iconImg,
  869. title: obj.title,
  870. path: `pages/index/index`,
  871. scene: obj.id,
  872. productId: 1
  873. // tip: this.data.tip,
  874. }
  875. // console.log(data)
  876. this.setData({
  877. noScroll: 'noScroll'
  878. })
  879. this.shareDialog.share(data);
  880. }
  881. },
  882. collectTap: function(e){
  883. console.log('点击收藏首页',e)
  884. const index = e.detail.index;
  885. let str = `videoList[${index}].isFavorite`
  886. this.setData({
  887. [str]: e.detail.isCollect
  888. })
  889. },
  890. likeTap:function(e){
  891. console.log('点赞',e)
  892. const index = e.detail.index;
  893. let likeStr = `videoList[${index}].isLike`;
  894. let likeNumStr = `videoList[${index}].likes`;
  895. this.setData({
  896. [likeStr]: true,
  897. [likeNumStr]: this.data.videoList[index].likes + 1
  898. })
  899. },
  900. })