index.js 28 KB

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