index.js 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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. console.log('插入数据')
  194. // this.getHotRecommend();
  195. // return;
  196. })
  197. // this.showPage()
  198. })
  199. }
  200. if (options && options.index) {
  201. this.updateData(options.index)
  202. } else {
  203. console.log('又加载一边')
  204. this.updateData(0)
  205. }
  206. setTimeout(() => {
  207. if (wx.getStorageSync('uid')) {
  208. httpRequestApi.userLoginRecord().success(res => {
  209. if (res.data.data && res.data.data.length !== 0) {
  210. // 有数据弹签到
  211. if (this.data.unfinishedCount > 0) {
  212. this.setData({
  213. indexSignDialog: true
  214. })
  215. }
  216. } else {
  217. // 没数据弹任务
  218. let oldDay = wx.getStorageSync('oldDay');
  219. let newDate = new Date();
  220. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  221. let timeStep = (newDate.getMonth() + 1).toString() + day
  222. if (oldDay) {
  223. let temp = parseInt(timeStep) - parseInt(oldDay)
  224. if (temp > 0) {
  225. wx.setStorageSync('oldDay', timeStep);
  226. this.setData({
  227. indexMissionDialog: true
  228. })
  229. }
  230. } else {
  231. wx.setStorageSync('oldDay', timeStep);
  232. this.setData({
  233. indexMissionDialog: true
  234. })
  235. }
  236. }
  237. })
  238. }
  239. }, 2800)
  240. },
  241. onLoad: function (options) {
  242. console.log('onload', options);
  243. if (options.scene) {
  244. this.setData({
  245. workId: options.scene
  246. })
  247. }
  248. if (options.readId) {
  249. this.setData({
  250. workId: options.readId
  251. })
  252. }
  253. /**
  254. * 活动统计
  255. */
  256. if (options.activity) {
  257. console.log('统计')
  258. httpRequestApi.shareAddHotAmount(options.readId).success(res => {
  259. console.log(res)
  260. })
  261. }
  262. getOpenidNoLogin((res) => {
  263. console.log('getOpenidNoLogin', res)
  264. if (!res.data.data.grade) {
  265. // 没有年级的老用户
  266. if (res.data.data.wechatName) {
  267. this.setData({
  268. isGradeShow: true,
  269. options,
  270. isLogin: true,
  271. oldUser: true
  272. })
  273. return;
  274. }
  275. this.setData({
  276. isGradeShow: true,
  277. options,
  278. isLogin: false,
  279. workId: options.scene ? options.scene : options.readId ? options.readId : undefined
  280. })
  281. return
  282. } else {
  283. if (res.data.data.wechatName) {
  284. this.setData({
  285. isLogin: true
  286. }, () => {
  287. this.showPage();
  288. })
  289. }
  290. }
  291. // 登录或注册完成 展示页面
  292. }, (error) => {
  293. console.log('获取失败', error)
  294. });
  295. this.uid = wx.getStorageSync('uid');
  296. // if (!this.uid || !grade) {
  297. // this.setData({
  298. // isGradeShow: true,
  299. // options
  300. // })
  301. // console.log('没有uid 也不是游客,需要去授权')
  302. // return;
  303. // }
  304. wx.getSystemInfo({
  305. success: (res) => {
  306. console.log('系统', res)
  307. console.log('nextMargin', res.pixelRatio)
  308. console.log('windowHeight', res.windowHeight)
  309. console.log('windowWidth', res.windowWidth)
  310. // let ratio = res.pixelRatio;
  311. let ratio = (res.screenHeight / res.screenWidth) * 1.1;
  312. console.log('比例系数', ratio)
  313. let winH = res.windowHeight * ratio;
  314. let x1 = 465 * ratio;
  315. let x2 = 603 * ratio;
  316. let minusNumber = (winH * x1) / x2;
  317. let nextMargin = parseInt(winH - minusNumber);
  318. app.globalData.nextMargin = nextMargin;
  319. this.setData({
  320. winH: winH,
  321. devicePixelRatio: res.pixelRatio,
  322. nextMargin: nextMargin + 'rpx'
  323. });
  324. }
  325. });
  326. },
  327. onShow: function () {
  328. let grade = wx.getStorageSync('grade');
  329. this.setData({
  330. gradeActivity: grade
  331. })
  332. if (this.data.myIndex === 3) {
  333. this.getUserWorksInfo(1)
  334. }
  335. wx.setNavigationBarTitle({
  336. title: '小学语文朗读配音'
  337. })
  338. if (this.data.fromLoginIndex) {
  339. console.log('页面返回页面返回', this.data.fromLoginIndex)
  340. let index = this.data.fromLoginIndex;
  341. let userInfo = wx.getStorageSync('user');
  342. this.setData({
  343. fromLoginIndex: null,
  344. isLogin: userInfo.wechatName ? true : false
  345. }, () => {
  346. this.updateData(0)
  347. })
  348. }
  349. if (this.data.fromReading) {
  350. this.setData({
  351. fromReading: false
  352. })
  353. this.updateData(3)
  354. }
  355. // 刷新课程资源的收藏数等
  356. if (this.data.myIndex === 2) {
  357. this.refreshCourseAmount()
  358. }
  359. this.setData({
  360. shareImg: '',
  361. shareId: ''
  362. })
  363. },
  364. onHide: function () {
  365. const str = 'hotData.inputFocus'
  366. this.setData({
  367. [str]: false
  368. });
  369. },
  370. /* 两个接口维护同一个数组,手动的结束后添加算法的 */
  371. // 推荐页信息 获取消息和手动推荐内容
  372. // 获取热门作品 算法出来的
  373. getHotRecommend: function () {
  374. let grade = wx.getStorageSync('grade')
  375. let pageNo = this.data.recommendPageNo;
  376. let pageSize = this.data.recommendPageSize;
  377. httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
  378. console.log(res)
  379. const recommendRes = res.data.data.list;
  380. if (recommendRes.length <= 0) {
  381. this.setData({
  382. noMoreWork: true
  383. })
  384. return
  385. };
  386. // const recommendWorks = [];
  387. this.formatWorksList(recommendRes);
  388. })
  389. },
  390. // 组装list
  391. formatWorksList(list, notSet) {
  392. // const tempList = [];
  393. console.log('列表长度列表长度', list.length)
  394. if (list.length < 3 || list.length === 0) {
  395. this.setData({
  396. noMoreWork: true
  397. })
  398. }
  399. list.forEach((item, index) => {
  400. /* if (index === list.length - 2 && list.length > 2) {
  401. console.log('设置当前id', item.id)
  402. this.setData({
  403. updateId: item.userRead.id
  404. })
  405. } */
  406. const temp = {};
  407. temp.title = item.userRead.title;
  408. temp.summary = item.userRead.summary;
  409. temp.img = item.userRead.iconImg;
  410. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  411. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  412. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  413. temp.shareAmount = item.userRead.shareAmount;
  414. temp.favoritesAmount = item.userRead.favoritesAmount;
  415. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  416. temp.time = formatDate(item.userRead.gmtCreated, 3);
  417. temp.avatar = item.user.avatar;
  418. temp.profession = item.user.profession;
  419. temp.uid = item.user.uid;
  420. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  421. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  422. temp.id = item.userRead.id;
  423. temp.type = item.userRead.type;
  424. temp.nickName = item.user.wechatName;
  425. temp.isLike = item.isLike;
  426. temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
  427. temp.isFavorite = item.isFavorites;
  428. temp.isEfun = item.user.profession === '官方' ? true : false;
  429. temp.hasTag = item.userRead.tag && item.userRead.tag !== 'EXAMPLE' ? true : false;
  430. temp.tagUrl = item.userRead.tag ? item.userRead.tag === 'HOT' ? '../../static/index/hot_tag.png' : '../../static/index/new_tag.png' : ''
  431. temp.status = item.userRead.status;
  432. temp.coverImg = item.userRead.coverImg;
  433. temp.shareImg = item.userRead.shareImg;
  434. temp.grade = item.userRead.grade;
  435. temp.videoShow = false;
  436. item.isActivity && (temp.activity = true);
  437. this.data.videoList.push(temp);
  438. // tempList.push(temp);
  439. });
  440. console.log('当前list', this.data.videoList)
  441. // if (!notSet) {
  442. this.setData({
  443. videoList: this.data.videoList
  444. })
  445. // }
  446. },
  447. // 获取用户信息
  448. getUserWorksInfo: function (flag) {
  449. if (flag) {
  450. httpRequestApi.getUserWorksInfo().success(res => {
  451. const userInfo = this.formatGrade(res.data.data.user);
  452. const str = 'myData.userInfo.wechatName';
  453. const avatarStr = 'myData.userInfo.avatar';
  454. const gradeTextStr = 'myData.userInfo.gradeText';
  455. this.setData({
  456. [str]: userInfo.wechatName,
  457. [avatarStr]: userInfo.avatar,
  458. [gradeTextStr]: userInfo.gradeText
  459. })
  460. })
  461. return;
  462. }
  463. httpRequestApi.getUserWorksInfo().success(res => {
  464. this.data.myData.user = res.data.data;
  465. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  466. if (res.data.data.myRead) {
  467. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  468. }
  469. res.data.data.user = this.formatGrade(res.data.data.user);
  470. this.setData({
  471. myData: res.data.data,
  472. ['myData.userInfo']: res.data.data.user
  473. }, () => {
  474. this.getMyRead()
  475. });
  476. }).fail(error => {
  477. console.log(error)
  478. })
  479. },
  480. formatGrade(userInfo) {
  481. switch (userInfo.grade) {
  482. case 'PRESCHOOL':
  483. userInfo.gradeText = '学前班'
  484. break;
  485. case 'PRIMARY_FIRST_GRADE':
  486. userInfo.gradeText = '一年级'
  487. break;
  488. case 'PRIMARY_SECOND_GRADE':
  489. userInfo.gradeText = '二年级'
  490. break;
  491. case 'PRIMARY_THREE_GRADE':
  492. userInfo.gradeText = '三年级'
  493. break;
  494. case 'PRIMARY_SENIOR_GRADE':
  495. userInfo.gradeText = '四年级';
  496. break;
  497. }
  498. return userInfo;
  499. },
  500. videoChange: function (e) {
  501. if (e.detail.activeId === this.data.updateId) {
  502. console.log('应该刷新')
  503. if (this.data.myIndex === 1) {
  504. this.setData({
  505. followPageNo: this.data.followPageNo + 1
  506. }, () => {
  507. this.getFollowData()
  508. })
  509. }
  510. if (this.data.myIndex === 0) {
  511. console.log('首页加载第二页')
  512. this.setData({
  513. recommendPageNo: this.data.recommendPageNo + 1
  514. }, () => {
  515. this.getHotRecommend()
  516. })
  517. }
  518. }
  519. },
  520. // 触底加载
  521. onReachBottom: function () {
  522. if (this.data.myIndex === 2) {
  523. this.setData({
  524. coursePageNo: this.data.coursePageNo + 1
  525. }, () => {
  526. this.getCoursesList()
  527. })
  528. }
  529. if (this.data.myIndex === 1) {
  530. this.setData({
  531. followPageNo: this.data.followPageNo + 1
  532. }, () => {
  533. this.getFollowData()
  534. })
  535. }
  536. if (this.data.myIndex === 0) {
  537. console.log('首页加载第二页')
  538. this.setData({
  539. recommendPageNo: this.data.recommendPageNo + 1
  540. }, () => {
  541. this.getHotRecommend()
  542. })
  543. }
  544. // // 当前在推荐页面 加载推荐
  545. // if (this.data.myIndex === 1) {
  546. // console.log(this.data.recommendPageNo)
  547. // console.log(this.data.recommendTotalNo)
  548. // this.setData({
  549. // recommendPageNo: this.data.recommendPageNo + 1
  550. // })
  551. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  552. // this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  553. // } else {
  554. // console.log('没有更多')
  555. // }
  556. // }
  557. },
  558. onPullDownRefresh: function () {
  559. //当前在团购页下拉加载
  560. this.updateData(this.data.myIndex)
  561. wx.showNavigationBarLoading() //在标题栏中显示加载
  562. //模拟加载
  563. setTimeout(function () {
  564. wx.hideNavigationBarLoading() //完成停止加载
  565. wx.stopPullDownRefresh() //停止下拉刷新
  566. }, 1000);
  567. },
  568. goToMessage: function () {
  569. wx.navigateTo({
  570. url: `../../pages/social/insideMessage/insideMessage`
  571. });
  572. const str = 'hotData.unReadMessageNum';
  573. this.setData({
  574. [str]: 0
  575. })
  576. },
  577. toMyCollage: function (e) {
  578. if (app.globalData.isIOS) {
  579. wx.navigateTo({
  580. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  581. });
  582. } else {
  583. wx.navigateTo({
  584. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  585. });
  586. }
  587. },
  588. toMyCourse: function () {
  589. wx.navigateTo({
  590. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  591. });
  592. },
  593. goToFlower: function () {
  594. wx.navigateTo({
  595. url: `../../pages/social/littleFlower/littleFlower`
  596. });
  597. },
  598. signInBtn: function (e) {
  599. this.setData({
  600. indexSignDialog: false
  601. })
  602. console.log(e.detail.formId)
  603. httpRequestApi.postFormId(e.detail.formId).success(res => {
  604. console.log(res)
  605. })
  606. this.goToFlower();
  607. },
  608. missionBtn: function () {
  609. this.setData({
  610. indexMissionDialog: false
  611. })
  612. this.goToFlower();
  613. },
  614. getUserAuth: function () {
  615. httpRequestApi.getUserAuth().success(res => {
  616. console.log(res)
  617. const str = 'myData.isVIP'
  618. if (res.data.data) {
  619. this.setData({
  620. [str]: true
  621. })
  622. } else {
  623. this.setData({
  624. [str]: false
  625. })
  626. }
  627. })
  628. },
  629. delHideMyWork: function () {
  630. this.getMyRead()
  631. },
  632. // 获取我的朗读
  633. getMyRead: function () {
  634. httpRequestApi.myRead().success(res => {
  635. console.log(123123, res)
  636. console.log('mydata', this.data.myData)
  637. const myList = res.data.data;
  638. if (myList.length === 0) {
  639. this.setData({
  640. videoList: []
  641. })
  642. return
  643. }
  644. // this.formatWorksList(myList)
  645. // const recommendWorks = [];
  646. const myWorks = [];
  647. myList.forEach(item => {
  648. const temp = {};
  649. temp.title = item.userRead.title;
  650. temp.summary = item.userRead.summary;
  651. temp.img = item.userRead.iconImg;
  652. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  653. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  654. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  655. temp.shareAmount = item.userRead.shareAmount;
  656. temp.favoritesAmount = item.userRead.favoritesAmount;
  657. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  658. temp.time = formatDate(item.userRead.gmtCreated, 3);
  659. temp.avatar = item.user.avatar;
  660. temp.profession = item.user.profession;
  661. temp.uid = item.user.uid;
  662. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  663. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  664. temp.id = item.userRead.id;
  665. temp.type = item.userRead.type;
  666. temp.nickName = item.user.wechatName;
  667. temp.isLike = item.isLike;
  668. temp.isFavorite = item.isFavorites;
  669. temp.showMyBtn = true;
  670. temp.nickName = this.data.myData.userInfo.wechatName;
  671. temp.status = item.userRead.status;
  672. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  673. temp.coverImg = item.userRead.coverImg;
  674. temp.grade = item.userRead.grade
  675. temp.isFans = true;
  676. temp.videoShow = false;
  677. temp.shareImg = item.userRead.shareImg;
  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. })