index.js 30 KB

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