index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  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: 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. recommendPageNo: 1,
  102. videoList: [],
  103. isSwiper: false
  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: false,
  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: false,
  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: false,
  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. if (this.data.fromReading) {
  319. this.setData({
  320. fromReading: false
  321. })
  322. this.updateData(3)
  323. }
  324. // const userInfo = wx.getStorageSync('user')
  325. // console.log('userInfo',userInfo)
  326. // if (userInfo.wechatName) {
  327. // this.setData({
  328. // isLogin: true
  329. // })
  330. // } else {
  331. // this.setData({
  332. // isLogin: false
  333. // })
  334. // }
  335. },
  336. onHide: function () {
  337. const str = 'hotData.inputFocus'
  338. this.setData({
  339. [str]: false
  340. });
  341. },
  342. /* 两个接口维护同一个数组,手动的结束后添加算法的 */
  343. // 推荐页信息 获取消息和手动推荐内容
  344. // 获取热门作品 算法出来的
  345. getHotRecommend: function () {
  346. let grade = wx.getStorageSync('grade')
  347. let pageNo = this.data.recommendPageNo;
  348. let pageSize = this.data.recommendPageSize;
  349. httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
  350. console.log(res)
  351. const recommendRes = res.data.data.list;
  352. if (recommendRes.length === 0) return;
  353. // const recommendWorks = [];
  354. this.formatWorksList(recommendRes);
  355. })
  356. },
  357. // 组装list
  358. formatWorksList(list, notSet) {
  359. // const tempList = [];
  360. list.forEach((item, index) => {
  361. /* if (index === list.length - 2 && list.length > 2) {
  362. console.log('设置当前id', item.id)
  363. this.setData({
  364. updateId: item.userRead.id
  365. })
  366. } */
  367. const temp = {};
  368. temp.title = item.userRead.title;
  369. temp.summary = item.userRead.summary;
  370. temp.img = item.userRead.iconImg;
  371. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  372. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  373. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  374. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  375. temp.time = formatDate(item.userRead.gmtCreated, 3);
  376. temp.avatar = item.user.avatar;
  377. temp.profession = item.user.profession;
  378. temp.uid = item.user.uid;
  379. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  380. temp.id = item.userRead.id;
  381. temp.type = item.userRead.type;
  382. temp.nickName = item.user.wechatName;
  383. temp.isLike = item.isLike;
  384. temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
  385. temp.isFavorite = item.isFavorites;
  386. temp.isEfun = item.user.profession === '官方' ? true : false;
  387. temp.hasTag = item.userRead.tag && item.userRead.tag !== 'EXAMPLE' ? true : false;
  388. temp.tagUrl = item.userRead.tag ? item.userRead.tag === 'HOT' ? '../../static/index/hot_tag.png' : '../../static/index/new_tag.png' : ''
  389. temp.status = item.userRead.status;
  390. temp.coverImg = item.userRead.coverImg;
  391. temp.videoShow = false;
  392. this.data.videoList.push(temp);
  393. // tempList.push(temp);
  394. });
  395. console.log('当前list', this.data.videoList)
  396. // if (!notSet) {
  397. this.setData({
  398. videoList: this.data.videoList
  399. })
  400. // }
  401. },
  402. // 获取用户信息
  403. getUserWorksInfo: function (flag) {
  404. if (flag) {
  405. httpRequestApi.getUserWorksInfo().success(res => {
  406. const userInfo = this.formatGrade(res.data.data.user);
  407. const str = 'myData.userInfo.nickName';
  408. const avatarStr = 'myData.userInfo.avatar';
  409. const gradeTextStr = 'myData.userInfo.gradeText';
  410. this.setData({
  411. [str]: userInfo.nickName,
  412. [avatarStr]: userInfo.avatar,
  413. [gradeTextStr]: userInfo.gradeText
  414. })
  415. })
  416. return;
  417. }
  418. httpRequestApi.getUserWorksInfo().success(res => {
  419. this.data.myData.user = res.data.data;
  420. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  421. if (res.data.data.myRead) {
  422. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  423. }
  424. res.data.data.user = this.formatGrade(res.data.data.user);
  425. this.setData({
  426. myData: res.data.data,
  427. ['myData.userInfo']: res.data.data.user
  428. }, () => {
  429. this.getMyRead()
  430. });
  431. }).fail(error => {
  432. console.log(error)
  433. })
  434. },
  435. formatGrade(userInfo) {
  436. switch (userInfo.grade) {
  437. case 'PRESCHOOL':
  438. userInfo.gradeText = '学前班'
  439. break;
  440. case 'PRIMARY_FIRST_GRADE':
  441. userInfo.gradeText = '一年级'
  442. break;
  443. case 'PRIMARY_SECOND_GRADE':
  444. userInfo.gradeText = '二年级'
  445. break;
  446. case 'PRIMARY_THREE_GRADE':
  447. userInfo.gradeText = '三年级'
  448. break;
  449. }
  450. return userInfo;
  451. },
  452. videoChange: function (e) {
  453. if (e.detail.activeId === this.data.updateId) {
  454. console.log('应该刷新')
  455. if (this.data.myIndex === 1) {
  456. this.setData({
  457. followPageNo: this.data.followPageNo + 1
  458. }, () => {
  459. this.getFollowData()
  460. })
  461. }
  462. if (this.data.myIndex === 0) {
  463. console.log('首页加载第二页')
  464. this.setData({
  465. recommendPageNo: this.data.recommendPageNo + 1
  466. }, () => {
  467. this.getHotRecommend()
  468. })
  469. }
  470. }
  471. },
  472. // 触底加载
  473. onReachBottom: function () {
  474. if (this.data.myIndex === 2) {
  475. this.setData({
  476. coursePageNo: this.data.coursePageNo + 1
  477. }, () => {
  478. this.getCoursesList()
  479. })
  480. }
  481. if (this.data.myIndex === 1) {
  482. this.setData({
  483. followPageNo: this.data.followPageNo + 1
  484. }, () => {
  485. this.getFollowData()
  486. })
  487. }
  488. if (this.data.myIndex === 0) {
  489. console.log('首页加载第二页')
  490. this.setData({
  491. recommendPageNo: this.data.recommendPageNo + 1
  492. }, () => {
  493. this.getHotRecommend()
  494. })
  495. }
  496. // // 当前在推荐页面 加载推荐
  497. // if (this.data.myIndex === 1) {
  498. // console.log(this.data.recommendPageNo)
  499. // console.log(this.data.recommendTotalNo)
  500. // this.setData({
  501. // recommendPageNo: this.data.recommendPageNo + 1
  502. // })
  503. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  504. // this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  505. // } else {
  506. // console.log('没有更多')
  507. // }
  508. // }
  509. },
  510. onPullDownRefresh: function () {
  511. //当前在团购页下拉加载
  512. this.updateData(this.data.myIndex)
  513. wx.showNavigationBarLoading() //在标题栏中显示加载
  514. //模拟加载
  515. setTimeout(function () {
  516. wx.hideNavigationBarLoading() //完成停止加载
  517. wx.stopPullDownRefresh() //停止下拉刷新
  518. }, 1000);
  519. },
  520. goToMessage: function () {
  521. wx.navigateTo({
  522. url: `../../pages/social/insideMessage/insideMessage`
  523. });
  524. const str = 'hotData.unReadMessageNum';
  525. this.setData({
  526. [str]: 0
  527. })
  528. },
  529. toMyCollage: function (e) {
  530. if (app.globalData.isIOS) {
  531. wx.navigateTo({
  532. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  533. });
  534. } else {
  535. wx.navigateTo({
  536. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  537. });
  538. }
  539. },
  540. toMyCourse: function () {
  541. wx.navigateTo({
  542. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  543. });
  544. },
  545. goToFlower: function () {
  546. wx.navigateTo({
  547. url: `../../pages/social/littleFlower/littleFlower`
  548. });
  549. },
  550. signInBtn: function (e) {
  551. this.setData({
  552. indexSignDialog: false
  553. })
  554. console.log(e.detail.formId)
  555. httpRequestApi.postFormId(e.detail.formId).success(res => {
  556. console.log(res)
  557. })
  558. this.goToFlower();
  559. },
  560. missionBtn: function () {
  561. this.setData({
  562. indexMissionDialog: false
  563. })
  564. this.goToFlower();
  565. },
  566. getUserAuth: function () {
  567. httpRequestApi.getUserAuth().success(res => {
  568. console.log(res)
  569. const str = 'myData.isVIP'
  570. if (res.data.data) {
  571. this.setData({
  572. [str]: true
  573. })
  574. } else {
  575. this.setData({
  576. [str]: false
  577. })
  578. }
  579. })
  580. },
  581. delHideMyWork: function () {
  582. this.getMyRead()
  583. },
  584. // 获取我的朗读
  585. getMyRead: function () {
  586. httpRequestApi.myRead().success(res => {
  587. console.log(123123, res)
  588. console.log('mydata', this.data.myData)
  589. const myList = res.data.data;
  590. if (myList.length === 0) return;
  591. // this.formatWorksList(myList)
  592. // const recommendWorks = [];
  593. const myWorks = [];
  594. myList.forEach(item => {
  595. const temp = {};
  596. temp.title = item.userRead.title;
  597. temp.summary = item.userRead.summary;
  598. temp.img = item.userRead.iconImg;
  599. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  600. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  601. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  602. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  603. temp.time = formatDate(item.userRead.gmtCreated, 3);
  604. temp.avatar = item.user.avatar;
  605. temp.profession = item.user.profession;
  606. temp.uid = item.user.uid;
  607. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  608. temp.id = item.userRead.id;
  609. temp.type = item.userRead.type;
  610. temp.nickName = item.user.wechatName;
  611. temp.isLike = item.isLike;
  612. temp.isFavorite = item.isFavorites;
  613. temp.showMyBtn = true;
  614. temp.nickName = this.data.myData.userInfo.wechatName;
  615. temp.status = item.userRead.status;
  616. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  617. temp.coverImg = item.userRead.coverImg;
  618. temp.isFans = true;
  619. temp.videoShow = false;
  620. myWorks.push(temp);
  621. });
  622. console.log('myWorks', myWorks)
  623. if (this.data.myIndex === 3) {
  624. this.setData({
  625. videoList: myWorks
  626. })
  627. }
  628. })
  629. },
  630. // 评论区点击
  631. commentTap: function (e) {
  632. console.log('点击评论区', e)
  633. if (e.target.dataset.type === 'blank') {
  634. this.setData({
  635. commentShow: false
  636. })
  637. }
  638. },
  639. touchMove: function (e) {
  640. return
  641. },
  642. // 打开评论
  643. openComment: function (e) {
  644. //
  645. console.log('id', e.detail.activeId)
  646. this.setData({
  647. commentShow: !this.data.commentShow,
  648. commentId: e.detail.activeId,
  649. // commentList: []
  650. });
  651. // this.getReply(e.detail.activeId);
  652. },
  653. // 获取评论信息
  654. getReply: function (columnId) {
  655. // let columnId = this.data.id;
  656. console.log(123123123, columnId)
  657. // let pageNo = this.data.pageNo;
  658. // let pageSize = this.data.pageSize;
  659. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  660. console.log('reply', res)
  661. const commentList = res.data.data.list;
  662. const commentNum = res.data.data.totalSize;
  663. console.log('评论数量', commentNum)
  664. commentList.forEach((item) => {
  665. const temp = {};
  666. temp.nickName = item.user.wechatName;
  667. temp.avatar = item.user.avatar;
  668. temp.uid = item.user.uid;
  669. temp.text = item.detailDesc;
  670. temp.id = item.id;
  671. temp.replyCount = item.replyCount;
  672. temp.time = formatDate(item.gmtCreated, 3);
  673. temp.likes = item.postsAttributeInfo.favors || 0;
  674. temp.isLike = item.isLike;
  675. temp.replyList = item.replyVOList;
  676. this.data.commentList.push(temp);
  677. });
  678. this.setData({
  679. commentList: this.data.commentList,
  680. commentNum: commentNum
  681. })
  682. });
  683. },
  684. // 发布回复
  685. sendReply: function (e) {
  686. console.log('triger', e.detail.content);
  687. let data = {
  688. columnId: this.data.commentId,
  689. colunmNames: 'what',
  690. detailDesc: e.detail.content,
  691. // productId: this.data.productId
  692. }
  693. httpRequestApi.postReply(this.uid, data).success(res => {
  694. console.log(res)
  695. this.setData({
  696. pageNo: 1,
  697. commentList: []
  698. }, () => {
  699. this.getReply(this.data.commentId);
  700. })
  701. });
  702. },
  703. gradeTap: function () {
  704. // console.log("组件回调,返回上一页");
  705. this.setData({
  706. isGradeShow: true
  707. })
  708. },
  709. onShareAppMessage: function (res) {
  710. console.log('点击分享按钮', res)
  711. console.log('点击分享按钮', this.data.shareTitle)
  712. console.log('点击分享按钮', this.data.shareId)
  713. console.log('点击分享按钮', this.data.shareImg)
  714. if (res.from === 'button') {
  715. return {
  716. title: this.data.shareTitle,
  717. path: `/pages/index/index?readId=${this.data.shareId}`,
  718. imageUrl: '../../static/index/share_icon.png'
  719. }
  720. } else {
  721. return {
  722. title: '快来听我的朗读作品吧',
  723. path: '/pages/index/index'
  724. }
  725. }
  726. },
  727. openShare: function (e) {
  728. console.log('用户点击分享按钮', e)
  729. this.setData({
  730. shareTitle: e.detail.currentTarget.dataset.title,
  731. shareId: e.detail.currentTarget.dataset.id,
  732. shareImg: e.detail.currentTarget.dataset.img
  733. })
  734. },
  735. // 修改年级
  736. changeGrade: function (e) {
  737. const grade = e.target.dataset.code;
  738. wx.setStorageSync('grade', grade)
  739. this.setData({
  740. isGradeShow: false,
  741. })
  742. if (this.data.oldUser) {
  743. let data = {
  744. grade: e.target.dataset.code
  745. };
  746. httpRequestApi.settingUserInfo(data).success(res => {
  747. })
  748. };
  749. getOpenidNoLogin((res) => {
  750. console.log('getOpenidNoLogin', res)
  751. // 登录或注册完成 展示页面
  752. if (res.data.data.wechatName) {
  753. this.setData({
  754. isLogin: true
  755. })
  756. } else {
  757. this.setData({
  758. isLogin: false
  759. })
  760. }
  761. this.showPage()
  762. }, (error) => {
  763. console.log('获取失败')
  764. wx.setStorageSync('userSourseType', 'normal')
  765. this.setData({
  766. hide: !this.data.hide
  767. })
  768. }, grade);
  769. },
  770. getFollowData: function () {
  771. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  772. if (res.data.data.totalSize === 0) {
  773. this.setData({
  774. videoList: []
  775. })
  776. console.log('没有关注人或关注的人没有发过作品')
  777. return
  778. }
  779. console.log('关注列表', res)
  780. const followData = res.data.data.list;
  781. // const videoList = [];
  782. this.formatWorksList(followData);
  783. });
  784. },
  785. // 点击用户头像区域
  786. headTapHandler: function (e) {
  787. console.log('点击头像', e)
  788. let tapId = e.detail.activeId;
  789. // 点击头像既关注 测试
  790. httpRequestApi.followUser(this.uid, tapId).success(res => {
  791. console.log(res)
  792. })
  793. },
  794. getCoursesList: function () {
  795. const grade = wx.getStorageSync('grade');
  796. const data = {
  797. pageNo: this.data.coursePageNo,
  798. pageSize: 6,
  799. grade,
  800. type: 'EXAMPLE'
  801. };
  802. console.log('资源', data)
  803. httpRequestApi.getClassRead(data).success(res => {
  804. console.log('资源', this.data.coursesData)
  805. this.setData({
  806. coursesData: this.data.coursesData.concat(res.data.data.list)
  807. }, () => {
  808. console.log(this.data.coursesData)
  809. })
  810. })
  811. },
  812. goToReading: function (e) {
  813. console.log('去朗读', e)
  814. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  815. wx.navigateTo({
  816. url: `../../pages/reading/reading?id=${id}`
  817. });
  818. },
  819. courseCollectTap: function collectClass(e) {
  820. console.log('收藏按钮', e);
  821. const data = {
  822. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  823. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  824. }
  825. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  826. let str = `coursesData[${index}].isFavorites`
  827. httpRequestApi.collectClass(data).success((res) => {
  828. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  829. this.setData({
  830. [str]: !this.data.coursesData[index].isFavorites
  831. })
  832. });
  833. },
  834. coursesOpenShare: function coursesOpenShare(e) {
  835. const obj = e.currentTarget.dataset
  836. console.log('分享', obj)
  837. console.log('分享', e)
  838. if (1) {
  839. this.shareDialog = this.selectComponent("#share-dialog");
  840. const data = {
  841. avatar: obj.avatar,
  842. author: obj.author,
  843. iconImg: obj.iconImg,
  844. title: obj.title,
  845. path: `pages/index/index`,
  846. scene: obj.id,
  847. productId: 1
  848. // tip: this.data.tip,
  849. }
  850. // console.log(data)
  851. this.setData({
  852. noScroll: 'noScroll'
  853. })
  854. this.shareDialog.share(data);
  855. }
  856. }
  857. })