index.js 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  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. console.log('this.data', this.data)
  783. if (res.from === 'button') {
  784. return {
  785. title: '请欣赏我的课文朗读作品,点赞+评论。',
  786. path: `/pages/index/index?readId=${this.data.shareId}&activity=${this.data.ifTapActivity}`,
  787. imageUrl: this.data.shareImg
  788. }
  789. } else {
  790. return {
  791. title: '课文朗读,从未如此有趣。',
  792. path: '/pages/index/index',
  793. }
  794. }
  795. },
  796. openShare: function (e) {
  797. console.log('点击分享', e)
  798. this.setData({
  799. shareTitle: e.detail.currentTarget.dataset.title,
  800. shareId: e.detail.currentTarget.dataset.id,
  801. shareImg: e.detail.currentTarget.dataset.shareimg,
  802. goToShare: true,
  803. ifTapActivity: e.detail.currentTarget.dataset.activity
  804. })
  805. },
  806. // 修改年级
  807. changeGrade: function (e) {
  808. const grade = e.target.dataset.code;
  809. wx.setStorageSync('grade', grade)
  810. this.setData({
  811. isGradeShow: false,
  812. grade
  813. })
  814. if (this.data.oldUser) {
  815. let data = {
  816. grade: e.target.dataset.code
  817. };
  818. httpRequestApi.settingUserInfo(data).success(res => {
  819. })
  820. return;
  821. };
  822. getOpenidNoLogin((res) => {
  823. console.log('getOpenidNoLogin', res)
  824. // 登录或注册完成 展示页面
  825. if (res.data.data.wechatName) {
  826. this.setData({
  827. isLogin: true
  828. })
  829. } else {
  830. this.setData({
  831. isLogin: false
  832. })
  833. }
  834. this.showPage()
  835. }, (error) => {
  836. console.log('获取失败')
  837. wx.setStorageSync('userSourseType', 'normal')
  838. this.setData({
  839. hide: !this.data.hide
  840. })
  841. }, grade);
  842. },
  843. getFollowData: function () {
  844. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  845. if (res.data.data.totalSize === 0) {
  846. this.setData({
  847. videoList: [],
  848. noFollow: true
  849. })
  850. console.log('没有关注人或关注的人没有发过作品')
  851. return
  852. } else {
  853. this.setData({
  854. noFollow: false
  855. })
  856. }
  857. console.log('关注列表', res)
  858. const followData = res.data.data.list;
  859. // const videoList = [];
  860. this.formatWorksList(followData);
  861. });
  862. },
  863. // 点击用户头像区域
  864. headTapHandler: function (e) {
  865. console.log('点击头像', e)
  866. let tapId = e.detail.activeId;
  867. // 点击头像既关注 测试
  868. httpRequestApi.followUser(this.uid, tapId).success(res => {
  869. console.log(res)
  870. })
  871. },
  872. getCoursesList: function () {
  873. const grade = wx.getStorageSync('grade');
  874. const data = {
  875. pageNo: this.data.coursePageNo,
  876. pageSize: 6,
  877. grade,
  878. type: 'EXAMPLE'
  879. };
  880. console.log('资源', data)
  881. httpRequestApi.getClassRead(data).success(res => {
  882. console.log('资源', this.data.coursesData)
  883. this.setData({
  884. coursesData: this.data.coursesData.concat(res.data.data.list),
  885. noMoreWork: res.data.data.list.length <= 0 ? true : false
  886. }, () => {
  887. console.log(this.data.coursesData)
  888. })
  889. })
  890. },
  891. goToReading: function (e) {
  892. console.log('去朗读', e)
  893. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  894. const index = e.currentTarget.dataset.index;
  895. this.setData({
  896. goToCoursesId: id,
  897. goToCoursesIndex: index
  898. })
  899. wx.navigateTo({
  900. url: `../../pages/reading/reading?id=${id}`
  901. });
  902. },
  903. refreshCourseAmount() {
  904. console.log(this.data.goToCoursesId)
  905. console.log(this.data.goToCoursesIndex)
  906. if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
  907. httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
  908. console.log('刷新', res.data.data.userRead)
  909. let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
  910. let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
  911. let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
  912. let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
  913. let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
  914. console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
  915. console.log(2, res.data.data.userRead.likeAmount)
  916. this.setData({
  917. [likeStr]: res.data.data.userRead.likeAmount,
  918. [commentStr]: res.data.data.userRead.commentAmount,
  919. [playStr]: res.data.data.userRead.playAmount,
  920. [shareStr]: res.data.data.userRead.shareAmount,
  921. [collectStr]: res.data.data.userRead.collectAmount,
  922. }, () => {
  923. console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
  924. })
  925. })
  926. }
  927. },
  928. courseCollectTap: function collectClass(e) {
  929. console.log('收藏按钮', e);
  930. const data = {
  931. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  932. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  933. }
  934. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  935. let str = `coursesData[${index}].isFavorites`
  936. httpRequestApi.collectClass(data).success((res) => {
  937. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  938. this.setData({
  939. [str]: !this.data.coursesData[index].isFavorites
  940. })
  941. });
  942. },
  943. coursesOpenShare: function coursesOpenShare(e) {
  944. const obj = e.currentTarget.dataset
  945. console.log('分享', obj)
  946. console.log('分享', e)
  947. if (1) {
  948. this.shareDialog = this.selectComponent("#share-dialog");
  949. const data = {
  950. avatar: obj.avatar,
  951. author: obj.author,
  952. iconImg: obj.iconImg,
  953. title: obj.title,
  954. path: `pages/index/index`,
  955. scene: obj.id,
  956. productId: 1
  957. // tip: this.data.tip,
  958. }
  959. // console.log(data)
  960. this.setData({
  961. noScroll: 'noScroll',
  962. shareTitle: obj.title,
  963. shareId: obj.id,
  964. shareImg: obj.shareimg
  965. })
  966. this.shareDialog.share(data);
  967. }
  968. },
  969. collectTap: function (e) {
  970. const index = e.detail.index;
  971. let str = `videoList[${index}].isFavorite`;
  972. let str2 = `videoList[${index}].favoritesAmount`;
  973. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  974. this.setData({
  975. [str]: e.detail.isCollect,
  976. [str2]: favoritesAmount
  977. })
  978. },
  979. likeTap: function (e) {
  980. console.log('点赞', e)
  981. const index = e.detail.index;
  982. let likeStr = `videoList[${index}].isLike`;
  983. let likeNumStr = `videoList[${index}].likes`;
  984. this.setData({
  985. [likeStr]: true,
  986. [likeNumStr]: this.data.videoList[index].likes + 1
  987. })
  988. // this.flowerAnimationHandler()
  989. },
  990. flowerAnimationHandler: function () {
  991. this.flowerBox = this.selectComponent("#flower-box");
  992. console.log('this.flower', this.flowerBox)
  993. this.flowerBox.comeOut();
  994. },
  995. addShareAmount: function (e) {
  996. console.log('+++++1', e)
  997. let str = `videoList[${e.detail.index}].shareAmount`;
  998. this.setData({
  999. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  1000. })
  1001. },
  1002. /**
  1003. * 跳转到活动页
  1004. */
  1005. goToActivity() {
  1006. wx.navigateTo({
  1007. url: `../activity/index/index`
  1008. });
  1009. }
  1010. })