index.js 26 KB

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