index.js 29 KB

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