index.js 27 KB

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