index.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  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. upgradeHide: false
  83. },
  84. jurisdiction: function () {
  85. //隐藏弹框
  86. this.setData({
  87. hide: !this.data.hide
  88. })
  89. //登录页信息
  90. this.updateData(0)
  91. },
  92. // 隐藏升级弹窗
  93. hideUpgrade() {
  94. this.setData({
  95. upgradeHide: true
  96. })
  97. },
  98. //tab点击
  99. switcher: function ({
  100. currentTarget
  101. }) {
  102. if (currentTarget.dataset.index === this.data.myIndex) return;
  103. this.updateData(currentTarget.dataset.index);
  104. },
  105. // 根据index 更新template
  106. updateData: function (index) {
  107. let myIndex = index;
  108. this.setData({
  109. myIndex,
  110. });
  111. // 获取推荐列表
  112. if (myIndex == 0) {
  113. this.setData({
  114. recommendPageNo: 1,
  115. videoList: [],
  116. isSwiper: false
  117. }, () => {
  118. this.getHotRecommend(this.uid);
  119. })
  120. return;
  121. }
  122. /* 关注和我的需要登陆后查看 */
  123. if (!this.data.isLogin) {
  124. wx.navigateTo({
  125. url: `../../pages/login/login?index=${myIndex}`
  126. });
  127. return;
  128. }
  129. console.log('继续')
  130. // 刷新关注列表
  131. if (myIndex == 1) {
  132. this.setData({
  133. videoList: [],
  134. isSwiper: false,
  135. followPageNo: 1
  136. }, () => {
  137. this.getFollowData()
  138. })
  139. return;
  140. }
  141. // 刷新资源
  142. if (myIndex == 2) {
  143. this.setData({
  144. videoList: [],
  145. coursesData: [],
  146. templates: 'courses',
  147. coursePageNo: 1
  148. }, () => {
  149. this.getCoursesList();
  150. })
  151. return;
  152. }
  153. // 刷新我的
  154. if (myIndex == 3) {
  155. this.setData({
  156. videoList: [],
  157. templates: 'my',
  158. isSwiper: false
  159. }, () => {
  160. myInit(this);
  161. })
  162. return;
  163. }
  164. },
  165. showPage: function () {
  166. let options = this.data.options;
  167. console.log('this.data.workId', this.data.workId)
  168. if (this.data.workId) {
  169. // 需要在推荐第一个上插入一条分享或者刚朗读完数据
  170. let id = this.data.workId;
  171. this.setData({
  172. workId: null,
  173. myIndex: 0,
  174. videoList: [],
  175. isSwiper: false,
  176. recommendTotalNo: 1
  177. })
  178. httpRequestApi.getClassDetail(id).success(res => {
  179. console.log('有一条数据', res)
  180. let tempList = [];
  181. tempList.push(res.data.data);
  182. this.setData({
  183. videoList: [],
  184. isSwiper: false,
  185. recommendTotalNo: 1
  186. }, () => {
  187. this.formatWorksList(tempList, true);
  188. console.log('插入数据')
  189. // this.getHotRecommend();
  190. // return;
  191. })
  192. // this.showPage()
  193. })
  194. }
  195. if (options && options.index) {
  196. this.updateData(options.index)
  197. } else {
  198. console.log('又加载一边')
  199. this.updateData(0)
  200. }
  201. setTimeout(() => {
  202. if (wx.getStorageSync('uid')) {
  203. httpRequestApi.userLoginRecord().success(res => {
  204. if (res.data.data && res.data.data.length !== 0) {
  205. // 有数据弹签到
  206. if (this.data.unfinishedCount > 0) {
  207. this.setData({
  208. indexSignDialog: true
  209. })
  210. }
  211. } else {
  212. // 没数据弹任务
  213. let oldDay = wx.getStorageSync('oldDay');
  214. let newDate = new Date();
  215. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  216. let timeStep = (newDate.getMonth() + 1).toString() + day
  217. if (oldDay) {
  218. let temp = parseInt(timeStep) - parseInt(oldDay)
  219. if (temp > 0) {
  220. wx.setStorageSync('oldDay', timeStep);
  221. this.setData({
  222. indexMissionDialog: true
  223. })
  224. }
  225. } else {
  226. wx.setStorageSync('oldDay', timeStep);
  227. this.setData({
  228. indexMissionDialog: true
  229. })
  230. }
  231. }
  232. })
  233. }
  234. }, 2800)
  235. },
  236. onLoad: function (options) {
  237. console.log('onload', options);
  238. if (options.scene) {
  239. this.setData({
  240. workId: options.scene
  241. })
  242. }
  243. if (options.readId) {
  244. this.setData({
  245. workId: options.readId
  246. })
  247. }
  248. getOpenidNoLogin((res) => {
  249. console.log('getOpenidNoLogin', res)
  250. if (!res.data.data.grade) {
  251. // 没有年级的老用户
  252. if (res.data.data.wechatName) {
  253. this.setData({
  254. isGradeShow: true,
  255. options,
  256. isLogin: true,
  257. oldUser: true
  258. })
  259. return;
  260. }
  261. this.setData({
  262. isGradeShow: true,
  263. options,
  264. isLogin: false,
  265. workId: options.scene ? options.scene : options.readId ? options.readId : undefined
  266. })
  267. return
  268. } else {
  269. if (res.data.data.wechatName) {
  270. this.setData({
  271. isLogin: true
  272. }, () => {
  273. this.showPage();
  274. })
  275. }
  276. }
  277. // 登录或注册完成 展示页面
  278. }, (error) => {
  279. console.log('获取失败', error)
  280. });
  281. this.uid = wx.getStorageSync('uid');
  282. let grade = wx.getStorageSync('grade');
  283. // if (!this.uid || !grade) {
  284. // this.setData({
  285. // isGradeShow: true,
  286. // options
  287. // })
  288. // console.log('没有uid 也不是游客,需要去授权')
  289. // return;
  290. // }
  291. wx.getSystemInfo({
  292. success: (res) => {
  293. console.log('系统', res)
  294. console.log('nextMargin', res.pixelRatio)
  295. console.log('windowHeight', res.windowHeight)
  296. console.log('windowWidth', res.windowWidth)
  297. // let ratio = res.pixelRatio;
  298. let ratio = (res.screenHeight / res.screenWidth) * 1.1;
  299. console.log('比例系数', ratio)
  300. let winH = res.windowHeight * ratio;
  301. let x1 = 465 * ratio;
  302. let x2 = 603 * ratio;
  303. let minusNumber = (winH * x1) / x2;
  304. let nextMargin = parseInt(winH - minusNumber);
  305. app.globalData.nextMargin = nextMargin;
  306. this.setData({
  307. winH: winH,
  308. devicePixelRatio: res.pixelRatio,
  309. nextMargin: nextMargin + 'rpx'
  310. });
  311. }
  312. });
  313. },
  314. onShow: function () {
  315. if (this.data.myIndex === 3) {
  316. this.getUserWorksInfo(1)
  317. }
  318. wx.setNavigationBarTitle({
  319. title: '小学语文朗读配音'
  320. })
  321. console.log('页面返回页面返回', this.data.fromLoginIndex)
  322. if (this.data.fromLoginIndex) {
  323. console.log('页面返回页面返回', this.data.fromLoginIndex)
  324. let index = this.data.fromLoginIndex;
  325. let userInfo = wx.getStorageSync('user');
  326. this.setData({
  327. fromLoginIndex: null,
  328. isLogin: userInfo.wechatName ? true : false
  329. }, () => {
  330. this.updateData(0)
  331. })
  332. }
  333. if (this.data.fromReading) {
  334. this.setData({
  335. fromReading: false
  336. })
  337. this.updateData(3)
  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) return;
  368. // const recommendWorks = [];
  369. this.formatWorksList(recommendRes);
  370. })
  371. },
  372. // 组装list
  373. formatWorksList(list, notSet) {
  374. // const tempList = [];
  375. list.forEach((item, index) => {
  376. /* if (index === list.length - 2 && list.length > 2) {
  377. console.log('设置当前id', item.id)
  378. this.setData({
  379. updateId: item.userRead.id
  380. })
  381. } */
  382. const temp = {};
  383. temp.title = item.userRead.title;
  384. temp.summary = item.userRead.summary;
  385. temp.img = item.userRead.iconImg;
  386. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  387. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  388. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  389. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  390. temp.time = formatDate(item.userRead.gmtCreated, 3);
  391. temp.avatar = item.user.avatar;
  392. temp.profession = item.user.profession;
  393. temp.uid = item.user.uid;
  394. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  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.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  634. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  635. temp.id = item.userRead.id;
  636. temp.type = item.userRead.type;
  637. temp.nickName = item.user.wechatName;
  638. temp.isLike = item.isLike;
  639. temp.isFavorite = item.isFavorites;
  640. temp.showMyBtn = true;
  641. temp.nickName = this.data.myData.userInfo.wechatName;
  642. temp.status = item.userRead.status;
  643. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  644. temp.coverImg = item.userRead.coverImg;
  645. temp.grade = item.userRead.grade
  646. temp.isFans = true;
  647. temp.videoShow = false;
  648. temp.shareImg = item.userRead.shareImg;
  649. myWorks.push(temp);
  650. });
  651. console.log('myWorks', myWorks)
  652. if (this.data.myIndex === 3) {
  653. this.setData({
  654. videoList: myWorks
  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('点击分享按钮', res)
  740. console.log('点击分享按钮', this.data.shareTitle)
  741. console.log('点击分享按钮', this.data.shareId)
  742. console.log('点击分享按钮', this.data.shareImg)
  743. if (res.from === 'button') {
  744. return {
  745. title: '请欣赏我的课文朗读作品,点赞+评论。',
  746. path: `/pages/index/index?readId=${this.data.shareId}`,
  747. imageUrl: this.data.shareImg
  748. }
  749. } else {
  750. return {
  751. title: '课文朗读,从未如此有趣。',
  752. path: '/pages/index/index',
  753. }
  754. }
  755. },
  756. openShare: function (e) {
  757. console.log('用户点击分享按钮123', e)
  758. this.setData({
  759. shareTitle: e.detail.currentTarget.dataset.title,
  760. shareId: e.detail.currentTarget.dataset.id,
  761. shareImg: e.detail.currentTarget.dataset.shareimg
  762. })
  763. },
  764. // 修改年级
  765. changeGrade: function (e) {
  766. const grade = e.target.dataset.code;
  767. wx.setStorageSync('grade', grade)
  768. this.setData({
  769. isGradeShow: false,
  770. grade
  771. })
  772. if (this.data.oldUser) {
  773. let data = {
  774. grade: e.target.dataset.code
  775. };
  776. httpRequestApi.settingUserInfo(data).success(res => {
  777. })
  778. return;
  779. };
  780. getOpenidNoLogin((res) => {
  781. console.log('getOpenidNoLogin', res)
  782. // 登录或注册完成 展示页面
  783. if (res.data.data.wechatName) {
  784. this.setData({
  785. isLogin: true
  786. })
  787. } else {
  788. this.setData({
  789. isLogin: false
  790. })
  791. }
  792. this.showPage()
  793. }, (error) => {
  794. console.log('获取失败')
  795. wx.setStorageSync('userSourseType', 'normal')
  796. this.setData({
  797. hide: !this.data.hide
  798. })
  799. }, grade);
  800. },
  801. getFollowData: function () {
  802. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  803. if (res.data.data.totalSize === 0) {
  804. this.setData({
  805. videoList: [],
  806. noFollow: true
  807. })
  808. console.log('没有关注人或关注的人没有发过作品')
  809. return
  810. } else {
  811. this.setData({
  812. noFollow: false
  813. })
  814. }
  815. console.log('关注列表', res)
  816. const followData = res.data.data.list;
  817. // const videoList = [];
  818. this.formatWorksList(followData);
  819. });
  820. },
  821. // 点击用户头像区域
  822. headTapHandler: function (e) {
  823. console.log('点击头像', e)
  824. let tapId = e.detail.activeId;
  825. // 点击头像既关注 测试
  826. httpRequestApi.followUser(this.uid, tapId).success(res => {
  827. console.log(res)
  828. })
  829. },
  830. getCoursesList: function () {
  831. const grade = wx.getStorageSync('grade');
  832. const data = {
  833. pageNo: this.data.coursePageNo,
  834. pageSize: 6,
  835. grade,
  836. type: 'EXAMPLE'
  837. };
  838. console.log('资源', data)
  839. httpRequestApi.getClassRead(data).success(res => {
  840. console.log('资源', this.data.coursesData)
  841. this.setData({
  842. coursesData: this.data.coursesData.concat(res.data.data.list)
  843. }, () => {
  844. console.log(this.data.coursesData)
  845. })
  846. })
  847. },
  848. goToReading: function (e) {
  849. console.log('去朗读', e)
  850. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  851. wx.navigateTo({
  852. url: `../../pages/reading/reading?id=${id}`
  853. });
  854. },
  855. courseCollectTap: function collectClass(e) {
  856. console.log('收藏按钮', e);
  857. const data = {
  858. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  859. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  860. }
  861. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  862. let str = `coursesData[${index}].isFavorites`
  863. httpRequestApi.collectClass(data).success((res) => {
  864. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  865. this.setData({
  866. [str]: !this.data.coursesData[index].isFavorites
  867. })
  868. });
  869. },
  870. coursesOpenShare: function coursesOpenShare(e) {
  871. const obj = e.currentTarget.dataset
  872. console.log('分享', obj)
  873. console.log('分享', e)
  874. if (1) {
  875. this.shareDialog = this.selectComponent("#share-dialog");
  876. const data = {
  877. avatar: obj.avatar,
  878. author: obj.author,
  879. iconImg: obj.iconImg,
  880. title: obj.title,
  881. path: `pages/index/index`,
  882. scene: obj.id,
  883. productId: 1
  884. // tip: this.data.tip,
  885. }
  886. // console.log(data)
  887. this.setData({
  888. noScroll: 'noScroll',
  889. shareTitle: obj.title,
  890. shareId: obj.id,
  891. shareImg: obj.shareimg
  892. })
  893. this.shareDialog.share(data);
  894. }
  895. },
  896. collectTap: function (e) {
  897. console.log('点击收藏首页', e)
  898. const index = e.detail.index;
  899. let str = `videoList[${index}].isFavorite`
  900. this.setData({
  901. [str]: e.detail.isCollect
  902. })
  903. },
  904. likeTap: function (e) {
  905. console.log('点赞', e)
  906. const index = e.detail.index;
  907. let likeStr = `videoList[${index}].isLike`;
  908. let likeNumStr = `videoList[${index}].likes`;
  909. this.setData({
  910. [likeStr]: true,
  911. [likeNumStr]: this.data.videoList[index].likes + 1
  912. })
  913. },
  914. })