index.js 23 KB

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