index.js 29 KB

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