index.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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: 'recommend',
  34. },
  35. {
  36. name: '关注',
  37. templates: 'follow',
  38. },
  39. {
  40. name: '资源',
  41. templates: 'courses',
  42. },
  43. {
  44. name: '我的',
  45. templates: 'my',
  46. }
  47. ],
  48. winH: 568,
  49. myIndex: 0,
  50. followData: [],
  51. recommendPageNo: 1,
  52. recommendPageSize: 12,
  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: 6,
  73. coursePageNo: 1,
  74. coursesData: [],
  75. updateId: 0 // 刷新id
  76. },
  77. jurisdiction: function () {
  78. //隐藏弹框
  79. this.setData({
  80. hide: !this.data.hide
  81. })
  82. //登录页信息
  83. this.updateData(0)
  84. },
  85. //tab点击
  86. switcher: function ({
  87. currentTarget
  88. }) {
  89. if (currentTarget.dataset.index === this.data.myIndex) return;
  90. this.updateData(currentTarget.dataset.index);
  91. },
  92. // 根据index 更新template
  93. updateData: function (index) {
  94. let myIndex = index;
  95. this.setData({
  96. myIndex,
  97. });
  98. // 获取推荐列表
  99. if (myIndex == 0) {
  100. this.setData({
  101. videoList: [],
  102. isSwiper: true
  103. }, () => {
  104. this.getHotRecommend(this.uid);
  105. })
  106. return;
  107. }
  108. /* 关注和我的需要登陆后查看 */
  109. if (!this.data.isLogin) {
  110. wx.navigateTo({
  111. url: `../../pages/login/login?index=${myIndex}`
  112. });
  113. return;
  114. }
  115. console.log('继续')
  116. // 刷新关注列表
  117. if (myIndex == 1) {
  118. this.setData({
  119. videoList: [],
  120. isSwiper: true,
  121. followPageNo: 1
  122. }, () => {
  123. this.getFollowData()
  124. })
  125. return;
  126. }
  127. // 刷新资源
  128. if (myIndex == 2) {
  129. this.setData({
  130. videoList: [],
  131. coursesData: [],
  132. templates: 'courses',
  133. coursePageNo: 1
  134. }, () => {
  135. this.getCoursesList();
  136. })
  137. return;
  138. }
  139. // 刷新我的
  140. if (myIndex == 3) {
  141. this.setData({
  142. videoList: [],
  143. templates: 'my',
  144. isSwiper: false
  145. }, () => {
  146. myInit(this);
  147. })
  148. return;
  149. }
  150. },
  151. showPage: function () {
  152. let options = this.data.options;
  153. if (options && options.index) {
  154. this.updateData(options.index)
  155. } else {
  156. this.updateData(0)
  157. }
  158. setTimeout(() => {
  159. if (wx.getStorageSync('uid')) {
  160. httpRequestApi.userLoginRecord().success(res => {
  161. if (res.data.data && res.data.data.length !== 0) {
  162. // 有数据弹签到
  163. if (this.data.unfinishedCount > 0) {
  164. this.setData({
  165. indexSignDialog: true
  166. })
  167. }
  168. } else {
  169. // 没数据弹任务
  170. let oldDay = wx.getStorageSync('oldDay');
  171. let newDate = new Date();
  172. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  173. let timeStep = (newDate.getMonth() + 1).toString() + day
  174. if (oldDay) {
  175. let temp = parseInt(timeStep) - parseInt(oldDay)
  176. if (temp > 0) {
  177. wx.setStorageSync('oldDay', timeStep);
  178. this.setData({
  179. indexMissionDialog: true
  180. })
  181. }
  182. } else {
  183. wx.setStorageSync('oldDay', timeStep);
  184. this.setData({
  185. indexMissionDialog: true
  186. })
  187. }
  188. }
  189. })
  190. }
  191. }, 2800)
  192. },
  193. onLoad: function (options) {
  194. console.log('onload', options);
  195. getOpenidNoLogin((res) => {
  196. console.log('getOpenidNoLogin', res)
  197. if (!res.data.data.grade) {
  198. // 没有年级的老用户
  199. if (res.data.data.wechatName) {
  200. this.setData({
  201. isGradeShow: true,
  202. options,
  203. isLogin: true,
  204. oldUser: true
  205. })
  206. return;
  207. }
  208. this.setData({
  209. isGradeShow: true,
  210. options,
  211. isLogin: false,
  212. workId: options.scene ? options.scene : options.readId ? options.readId : undefined
  213. })
  214. return
  215. } else {
  216. if (res.data.data.wechatName) {
  217. this.setData({
  218. isLogin: true
  219. }, () => {
  220. this.showPage();
  221. })
  222. }
  223. }
  224. // 登录或注册完成 展示页面
  225. }, (error) => {
  226. console.log('获取失败', error)
  227. });
  228. if (options.scene) {
  229. this.setData({
  230. workId: options.scene
  231. })
  232. }
  233. if (options.readId) {
  234. this.setData({
  235. workId: options.readId
  236. })
  237. }
  238. this.uid = wx.getStorageSync('uid');
  239. let grade = wx.getStorageSync('grade');
  240. // if (!this.uid || !grade) {
  241. // this.setData({
  242. // isGradeShow: true,
  243. // options
  244. // })
  245. // console.log('没有uid 也不是游客,需要去授权')
  246. // return;
  247. // }
  248. wx.getSystemInfo({
  249. success: (res) => {
  250. console.log('系统', res)
  251. let winH = res.windowHeight * res.pixelRatio;
  252. let minusNumber = (winH * 920) / 1206;
  253. let nextMargin = parseInt(winH - minusNumber);
  254. app.globalData.nextMargin = nextMargin;
  255. this.setData({
  256. winH: winH,
  257. devicePixelRatio: res.pixelRatio,
  258. nextMargin: nextMargin + 'rpx'
  259. });
  260. }
  261. });
  262. },
  263. onShow: function () {
  264. console.log('this.data.workId', this.data.workId)
  265. if (this.data.workId) {
  266. // 需要在推荐第一个上插入一条分享或者刚朗读完数据
  267. let id = this.data.workId;
  268. this.setData({
  269. workId: null,
  270. myIndex: 0,
  271. videoList: [],
  272. isSwiper: true,
  273. recommendTotalNo: 1
  274. })
  275. httpRequestApi.getClassDetail(id).success(res => {
  276. console.log('有一条数据', res)
  277. let tempList = [];
  278. tempList.push(res.data.data);
  279. this.setData({
  280. videoList: [],
  281. isSwiper: true,
  282. recommendTotalNo: 1
  283. }, () => {
  284. this.formatWorksList(tempList, true);
  285. this.getHotRecommend()
  286. })
  287. // this.showPage()
  288. })
  289. }
  290. if (this.data.myIndex === 3) {
  291. this.getUserWorksInfo(1)
  292. }
  293. wx.setNavigationBarTitle({
  294. title: '小学语文朗读配音'
  295. })
  296. console.log('页面返回页面返回', this.data.fromLoginIndex)
  297. if (this.data.fromLoginIndex) {
  298. console.log('页面返回页面返回', this.data.fromLoginIndex)
  299. let index = this.data.fromLoginIndex;
  300. let userInfo = wx.getStorageSync('user');
  301. this.setData({
  302. fromLoginIndex: null,
  303. isLogin: userInfo.wechatName ? true : false
  304. }, () => {
  305. this.updateData(0)
  306. })
  307. }
  308. // const userInfo = wx.getStorageSync('user')
  309. // console.log('userInfo',userInfo)
  310. // if (userInfo.wechatName) {
  311. // this.setData({
  312. // isLogin: true
  313. // })
  314. // } else {
  315. // this.setData({
  316. // isLogin: false
  317. // })
  318. // }
  319. },
  320. onHide: function () {
  321. const str = 'hotData.inputFocus'
  322. this.setData({
  323. [str]: false
  324. });
  325. },
  326. /* 两个接口维护同一个数组,手动的结束后添加算法的 */
  327. // 推荐页信息 获取消息和手动推荐内容
  328. // 获取热门作品 算法出来的
  329. getHotRecommend: function () {
  330. let grade = wx.getStorageSync('grade')
  331. let pageNo = this.data.recommendPageNo;
  332. let pageSize = this.data.recommendPageSize;
  333. httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
  334. console.log(res)
  335. const recommendRes = res.data.data.list;
  336. if (recommendRes.length === 0) return;
  337. // const recommendWorks = [];
  338. this.formatWorksList(recommendRes);
  339. })
  340. },
  341. // 组装list
  342. formatWorksList(list, notSet) {
  343. const tempList = [];
  344. list.forEach((item,index) => {
  345. if(index === 1){
  346. console.log('设置当前id',item.id)
  347. this.setData({
  348. updateId: item.userRead.id
  349. })
  350. }
  351. const temp = {};
  352. temp.title = item.userRead.title;
  353. temp.summary = item.userRead.summary;
  354. temp.img = item.userRead.iconImg;
  355. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  356. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  357. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  358. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  359. temp.time = formatDate(item.userRead.gmtCreated, 3);
  360. temp.avatar = item.user.avatar;
  361. temp.profession = item.user.profession;
  362. temp.uid = item.user.uid;
  363. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  364. temp.id = item.userRead.id;
  365. temp.type = item.userRead.type;
  366. temp.nickName = item.user.wechatName;
  367. temp.isLike = item.isLike;
  368. temp.isFavorite = item.isFavorites;
  369. // this.data.videoList.push(temp);
  370. tempList.push(temp);
  371. });
  372. if (!notSet) {
  373. this.setData({
  374. videoList: tempList
  375. })
  376. }
  377. },
  378. // 获取用户信息
  379. getUserWorksInfo: function (flag) {
  380. if (flag) {
  381. httpRequestApi.getUserWorksInfo().success(res => {
  382. const userInfo = this.formatGrade(res.data.data.user);
  383. const str = 'myData.userInfo.nickName';
  384. const avatarStr = 'myData.userInfo.avatar';
  385. const gradeTextStr = 'myData.userInfo.gradeText';
  386. this.setData({
  387. [str]: userInfo.nickName,
  388. [avatarStr]: userInfo.avatar,
  389. [gradeTextStr]: userInfo.gradeText
  390. })
  391. })
  392. return;
  393. }
  394. httpRequestApi.getUserWorksInfo().success(res => {
  395. this.data.myData.user = res.data.data;
  396. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  397. if (res.data.data.myRead) {
  398. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  399. }
  400. res.data.data.user = this.formatGrade(res.data.data.user);
  401. this.setData({
  402. myData: res.data.data,
  403. ['myData.userInfo']: res.data.data.user
  404. }, () => {
  405. this.getMyRead()
  406. });
  407. }).fail(error => {
  408. console.log(error)
  409. })
  410. },
  411. formatGrade(userInfo) {
  412. switch (userInfo.grade) {
  413. case 'PRESCHOOL':
  414. userInfo.gradeText = '学前班'
  415. break;
  416. case 'PRIMARY_FIRST_GRADE':
  417. userInfo.gradeText = '小学一年级'
  418. break;
  419. case 'PRIMARY_SECOND_GRADE':
  420. userInfo.gradeText = '小学二年级'
  421. break;
  422. case 'PRIMARY_THREE_GRADE':
  423. userInfo.gradeText = '小学三年级'
  424. break;
  425. }
  426. return userInfo;
  427. },
  428. videoChange: function (e) {
  429. console.log('到了底部到了底部', e)
  430. console.log('到了底部到了底部', e.detail.index)
  431. console.log('到了底部到了底部', e.detail._last)
  432. console.log('到了底部到了底部', e.detail.direction)
  433. // if (e.detail.nextQueue.length === 1) {
  434. console.log('当前ID',e.detail.activeId);
  435. console.log('目标ID',this.data.updateId);
  436. if (e.detail.activeId === this.data.updateId) {
  437. console.log('应该刷新')
  438. if (this.data.myIndex === 1) {
  439. this.setData({
  440. followPageNo: this.data.followPageNo + 1
  441. }, () => {
  442. this.getFollowData()
  443. })
  444. }
  445. if (this.data.myIndex === 0) {
  446. console.log('首页加载第二页')
  447. this.setData({
  448. recommendPageNo: this.data.recommendPageNo + 1
  449. }, () => {
  450. this.getHotRecommend()
  451. })
  452. }
  453. }
  454. },
  455. // 触底加载
  456. onReachBottom: function () {
  457. if (this.data.myIndex === 2) {
  458. this.setData({
  459. coursePageNo: this.data.coursePageNo + 1
  460. }, () => {
  461. this.getCoursesList()
  462. })
  463. }
  464. // // 当前在推荐页面 加载推荐
  465. // if (this.data.myIndex === 1) {
  466. // console.log(this.data.recommendPageNo)
  467. // console.log(this.data.recommendTotalNo)
  468. // this.setData({
  469. // recommendPageNo: this.data.recommendPageNo + 1
  470. // })
  471. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  472. // this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  473. // } else {
  474. // console.log('没有更多')
  475. // }
  476. // }
  477. },
  478. onPullDownRefresh: function () {
  479. //当前在团购页下拉加载
  480. if (this.data.myIndex === 0) {
  481. // groupInit(this);
  482. }
  483. wx.showNavigationBarLoading() //在标题栏中显示加载
  484. //模拟加载
  485. setTimeout(function () {
  486. wx.hideNavigationBarLoading() //完成停止加载
  487. wx.stopPullDownRefresh() //停止下拉刷新
  488. }, 1500);
  489. },
  490. goToMessage: function () {
  491. wx.navigateTo({
  492. url: `../../pages/social/insideMessage/insideMessage`
  493. });
  494. const str = 'hotData.unReadMessageNum';
  495. this.setData({
  496. [str]: 0
  497. })
  498. },
  499. toMyCollage: function (e) {
  500. if (app.globalData.isIOS) {
  501. wx.navigateTo({
  502. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  503. });
  504. } else {
  505. wx.navigateTo({
  506. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  507. });
  508. }
  509. },
  510. toMyCourse: function () {
  511. wx.navigateTo({
  512. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  513. });
  514. },
  515. goToFlower: function () {
  516. wx.navigateTo({
  517. url: `../../pages/social/littleFlower/littleFlower`
  518. });
  519. },
  520. signInBtn: function (e) {
  521. this.setData({
  522. indexSignDialog: false
  523. })
  524. console.log(e.detail.formId)
  525. httpRequestApi.postFormId(e.detail.formId).success(res => {
  526. console.log(res)
  527. })
  528. this.goToFlower();
  529. },
  530. missionBtn: function () {
  531. this.setData({
  532. indexMissionDialog: false
  533. })
  534. this.goToFlower();
  535. },
  536. getUserAuth: function () {
  537. httpRequestApi.getUserAuth().success(res => {
  538. console.log(res)
  539. const str = 'myData.isVIP'
  540. if (res.data.data) {
  541. this.setData({
  542. [str]: true
  543. })
  544. } else {
  545. this.setData({
  546. [str]: false
  547. })
  548. }
  549. })
  550. },
  551. delHideMyWork: function () {
  552. this.getMyRead()
  553. },
  554. // 获取我的朗读
  555. getMyRead: function () {
  556. httpRequestApi.myRead().success(res => {
  557. console.log(123123, res)
  558. console.log('mydata', this.data.myData)
  559. const myList = res.data.data;
  560. if (myList.length === 0) return;
  561. // this.formatWorksList(myList)
  562. // const recommendWorks = [];
  563. const myWorks = [];
  564. myList.forEach(item => {
  565. const temp = {};
  566. temp.title = item.userRead.title;
  567. temp.summary = item.userRead.summary;
  568. temp.img = item.userRead.iconImg;
  569. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  570. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  571. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  572. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  573. temp.time = formatDate(item.userRead.gmtCreated, 3);
  574. temp.avatar = item.user.avatar;
  575. temp.profession = item.user.profession;
  576. temp.uid = item.user.uid;
  577. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  578. temp.id = item.userRead.id;
  579. temp.type = item.userRead.type;
  580. temp.nickName = item.user.wechatName;
  581. temp.isLike = item.isLike;
  582. temp.isFavorite = item.isFavorites;
  583. temp.showMyBtn = true;
  584. temp.nickName = this.data.myData.userInfo.wechatName;
  585. temp.status = item.userRead.status
  586. myWorks.push(temp);
  587. });
  588. console.log('myWorks', myWorks)
  589. this.setData({
  590. videoList: myWorks
  591. })
  592. })
  593. },
  594. // 评论区点击
  595. commentTap: function (e) {
  596. console.log('点击评论区', e)
  597. if (e.target.dataset.type === 'blank') {
  598. this.setData({
  599. commentShow: false
  600. })
  601. }
  602. },
  603. touchMove: function (e) {
  604. return
  605. },
  606. // 打开评论
  607. openComment: function (e) {
  608. //
  609. console.log('id', e.detail.activeId)
  610. this.setData({
  611. commentShow: !this.data.commentShow,
  612. commentId: e.detail.activeId,
  613. // commentList: []
  614. });
  615. // this.getReply(e.detail.activeId);
  616. },
  617. // 获取评论信息
  618. getReply: function (columnId) {
  619. // let columnId = this.data.id;
  620. console.log(123123123, columnId)
  621. // let pageNo = this.data.pageNo;
  622. // let pageSize = this.data.pageSize;
  623. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  624. console.log('reply', res)
  625. const commentList = res.data.data.list;
  626. const commentNum = res.data.data.totalSize;
  627. console.log('评论数量', commentNum)
  628. commentList.forEach((item) => {
  629. const temp = {};
  630. temp.nickName = item.user.wechatName;
  631. temp.avatar = item.user.avatar;
  632. temp.uid = item.user.uid;
  633. temp.text = item.detailDesc;
  634. temp.id = item.id;
  635. temp.replyCount = item.replyCount;
  636. temp.time = formatDate(item.gmtCreated, 3);
  637. temp.likes = item.postsAttributeInfo.favors || 0;
  638. temp.isLike = item.isLike;
  639. temp.replyList = item.replyVOList;
  640. this.data.commentList.push(temp);
  641. });
  642. this.setData({
  643. commentList: this.data.commentList,
  644. commentNum: commentNum
  645. })
  646. });
  647. },
  648. // 发布回复
  649. sendReply: function (e) {
  650. console.log('triger', e.detail.content);
  651. let data = {
  652. columnId: this.data.commentId,
  653. colunmNames: 'what',
  654. detailDesc: e.detail.content,
  655. // productId: this.data.productId
  656. }
  657. httpRequestApi.postReply(this.uid, data).success(res => {
  658. console.log(res)
  659. this.setData({
  660. pageNo: 1,
  661. commentList: []
  662. }, () => {
  663. this.getReply(this.data.commentId);
  664. })
  665. });
  666. },
  667. gradeTap: function () {
  668. // console.log("组件回调,返回上一页");
  669. this.setData({
  670. isGradeShow: true
  671. })
  672. },
  673. onShareAppMessage: function (res) {
  674. console.log('点击分享按钮', res)
  675. console.log('点击分享按钮', this.data.shareTitle)
  676. console.log('点击分享按钮', this.data.shareId)
  677. console.log('点击分享按钮', this.data.shareImg)
  678. if (res.from === 'button') {
  679. return {
  680. title: this.data.shareTitle,
  681. path: `/pages/index/index?readId=${this.data.shareId}`,
  682. imageUrl: this.data.shareImg
  683. }
  684. } else {
  685. return {
  686. title: '快来听我的朗读作品吧',
  687. path: '/pages/index/index'
  688. }
  689. }
  690. },
  691. openShare: function (e) {
  692. console.log('用户点击分享按钮', e)
  693. this.setData({
  694. shareTitle: e.detail.currentTarget.dataset.title,
  695. shareId: e.detail.currentTarget.dataset.id,
  696. shareImg: e.detail.currentTarget.dataset.img
  697. })
  698. },
  699. // 修改年级
  700. changeGrade: function (e) {
  701. const grade = e.target.dataset.code;
  702. wx.setStorageSync('grade', grade)
  703. this.setData({
  704. isGradeShow: false,
  705. })
  706. if (this.data.oldUser) {
  707. let data = {
  708. grade: e.target.dataset.code
  709. };
  710. httpRequestApi.settingUserInfo(data).success(res => {
  711. })
  712. };
  713. getOpenidNoLogin((res) => {
  714. console.log('getOpenidNoLogin', res)
  715. // 登录或注册完成 展示页面
  716. if (res.data.data.wechatName) {
  717. this.setData({
  718. isLogin: true
  719. })
  720. } else {
  721. this.setData({
  722. isLogin: false
  723. })
  724. }
  725. this.showPage()
  726. }, (error) => {
  727. console.log('获取失败')
  728. wx.setStorageSync('userSourseType', 'normal')
  729. this.setData({
  730. hide: !this.data.hide
  731. })
  732. }, grade);
  733. },
  734. getFollowData: function () {
  735. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  736. if (res.data.data.totalSize === 0) {
  737. this.setData({
  738. videoList: []
  739. })
  740. console.log('没有关注人或关注的人没有发过作品')
  741. return
  742. }
  743. console.log('关注列表', res)
  744. const followData = res.data.data.list;
  745. // const videoList = [];
  746. this.formatWorksList(followData);
  747. });
  748. },
  749. // 点击用户头像区域
  750. headTapHandler: function (e) {
  751. console.log('点击头像', e)
  752. let tapId = e.detail.activeId;
  753. // 点击头像既关注 测试
  754. httpRequestApi.followUser(this.uid, tapId).success(res => {
  755. console.log(res)
  756. })
  757. },
  758. getCoursesList: function () {
  759. const grade = wx.getStorageSync('grade');
  760. const data = {
  761. pageNo: this.data.coursePageNo,
  762. pageSize: 6,
  763. grade,
  764. type: 'EXAMPLE'
  765. };
  766. console.log('资源', data)
  767. httpRequestApi.getClassRead(data).success(res => {
  768. console.log('资源', this.data.coursesData)
  769. this.setData({
  770. coursesData: this.data.coursesData.concat(res.data.data.list)
  771. }, () => {
  772. console.log(this.data.coursesData)
  773. })
  774. })
  775. },
  776. goToReading: function (e) {
  777. console.log('去朗读', e)
  778. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  779. wx.navigateTo({
  780. url: `../../pages/reading/reading?id=${id}`
  781. });
  782. },
  783. courseCollectTap: function collectClass(e) {
  784. console.log('收藏按钮', e);
  785. const data = {
  786. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  787. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  788. }
  789. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  790. let str = `coursesData[${index}].isFavorites`
  791. httpRequestApi.collectClass(data).success((res) => {
  792. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  793. this.setData({
  794. [str]: !this.data.coursesData[index].isFavorites
  795. })
  796. });
  797. },
  798. coursesOpenShare: function coursesOpenShare(e) {
  799. const obj = e.currentTarget.dataset
  800. console.log('分享', obj)
  801. console.log('分享', e)
  802. if (1) {
  803. this.shareDialog = this.selectComponent("#share-dialog");
  804. const data = {
  805. avatar: obj.avatar,
  806. author: obj.author,
  807. iconImg: obj.iconImg,
  808. title: obj.title,
  809. path: `pages/index/index`,
  810. scene: obj.id,
  811. productId: 1
  812. // tip: this.data.tip,
  813. }
  814. // console.log(data)
  815. this.setData({
  816. noScroll: 'noScroll'
  817. })
  818. this.shareDialog.share(data);
  819. }
  820. }
  821. })