index.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  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. winH: 568,
  45. statusBarHeight: getApp().globalData.statusBarHeight,
  46. myIndex: 0,
  47. followData: [],
  48. recommendPageNo: 1,
  49. recommendPageSize: 3,
  50. recommendTotalNo: 1,
  51. myData: {},
  52. templates: '',
  53. title: 'index中的title',
  54. jurisdictionFlag: true,
  55. hotInput: '12345',
  56. mineSettingInfo: '528',
  57. hide: true,
  58. ifHaveMore: true,
  59. indexSignDialog: false,
  60. indexMissionDialog: false,
  61. unfinishedCount: 0,
  62. videoList: [],
  63. nextMargin: '400rpx', // 视频下边距
  64. commentShow: false,
  65. commentList: [],
  66. commentNum: 0,
  67. followPageNo: 1,
  68. followPageSize: 3,
  69. coursePageNo: 1,
  70. coursesData: [],
  71. updateId: 0, // 刷新id
  72. statusbarobj: {
  73. isshowbtn: true, //是否显示按钮
  74. title: "小学语文朗读配音", //标题
  75. },
  76. grade: wx.getStorageSync('grade'),
  77. noMoreWork: false, // 没有更多作品 已经到底了
  78. upgradeHide: true,
  79. gradeActivity: '',
  80. helpPayHide: true,
  81. tipsType: '',
  82. helpPayImg: '',
  83. tipsImg: '',
  84. payPrice: '',
  85. iphoneType: '',
  86. isVip: null,
  87. isIos: null,
  88. temporaryGrade: null
  89. },
  90. jurisdiction: function() {
  91. //隐藏弹框
  92. this.setData({
  93. hide: !this.data.hide
  94. })
  95. //登录页信息
  96. this.updateData(0)
  97. },
  98. // 隐藏升级弹窗
  99. hideUpgrade() {
  100. this.setData({
  101. upgradeHide: true
  102. })
  103. },
  104. jumpMy() {
  105. wx.redirectTo({
  106. url: '/pages/my/index'
  107. });
  108. },
  109. //tab点击
  110. switcher: function({
  111. currentTarget
  112. }) {
  113. if (currentTarget.dataset.index === this.data.myIndex) return;
  114. this.updateData(currentTarget.dataset.index);
  115. },
  116. // 根据index 更新template
  117. updateData: function(index) {
  118. let myIndex = parseInt(index);
  119. this.setData({
  120. myIndex,
  121. noMoreWork: false
  122. });
  123. // 获取推荐列表
  124. if (myIndex == 0) {
  125. this.setData({
  126. recommendPageNo: 1,
  127. videoList: [],
  128. isSwiper: false
  129. }, () => {
  130. // 转为异步
  131. setTimeout(() => {
  132. this.getHotRecommend(this.uid);
  133. }, 0)
  134. })
  135. return;
  136. }
  137. /* 关注和我的需要登陆后查看 */
  138. if (!this.data.isLogin) {
  139. wx.navigateTo({
  140. url: `../../pages/login/login?index=${myIndex}`
  141. });
  142. return;
  143. }
  144. // 刷新关注列表
  145. if (myIndex == 1) {
  146. this.setData({
  147. videoList: [],
  148. isSwiper: false,
  149. followPageNo: 1
  150. }, () => {
  151. this.getFollowData()
  152. })
  153. return;
  154. }
  155. // 刷新资源
  156. if (myIndex == 2) {
  157. this.setData({
  158. videoList: [],
  159. coursesData: [],
  160. templates: 'courses',
  161. coursePageNo: 1
  162. }, () => {
  163. this.getCoursesList();
  164. })
  165. return;
  166. }
  167. // 刷新我的
  168. /* if (myIndex == 3) {
  169. this.setData({
  170. videoList: [],
  171. templates: 'my',
  172. isSwiper: false
  173. }, () => {
  174. myInit(this);
  175. httpRequestApi.userEvent('MY');
  176. })
  177. return;
  178. } */
  179. },
  180. showPage: function() {
  181. let options = this.data.options;
  182. if (this.data.workId) {
  183. // 需要在推荐第一个上插入一条分享或者刚朗读完数据
  184. let id = this.data.workId;
  185. this.setData({
  186. workId: null,
  187. myIndex: 0,
  188. videoList: [],
  189. isSwiper: false,
  190. recommendTotalNo: 1
  191. })
  192. httpRequestApi.getClassDetail(id).success(res => {
  193. let tempList = [];
  194. tempList.push(res.data.data);
  195. this.setData({
  196. videoList: [],
  197. isSwiper: false,
  198. recommendTotalNo: 1
  199. }, () => {
  200. this.formatWorksList(tempList, true);
  201. this.getHotRecommend(this.uid);
  202. })
  203. })
  204. } else {
  205. console.log('没有分享')
  206. if (options && options.index) {
  207. this.updateData(options.index)
  208. } else {
  209. console.log('又加载一边')
  210. this.updateData(0)
  211. }
  212. }
  213. setTimeout(() => {
  214. if (wx.getStorageSync('uid')) {
  215. httpRequestApi.userLoginRecord().success(res => {
  216. if (res.data.data && res.data.data.length !== 0) {
  217. // 有数据弹签到
  218. if (this.data.unfinishedCount > 0) {
  219. this.setData({
  220. indexSignDialog: true
  221. })
  222. }
  223. } else {
  224. // 没数据弹任务
  225. let oldDay = wx.getStorageSync('oldDay');
  226. let newDate = new Date();
  227. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  228. let timeStep = (newDate.getMonth() + 1).toString() + day
  229. if (oldDay) {
  230. let temp = parseInt(timeStep) - parseInt(oldDay)
  231. if (temp > 0) {
  232. wx.setStorageSync('oldDay', timeStep);
  233. this.setData({
  234. indexMissionDialog: true
  235. })
  236. }
  237. } else {
  238. wx.setStorageSync('oldDay', timeStep);
  239. this.setData({
  240. indexMissionDialog: true
  241. })
  242. }
  243. }
  244. })
  245. }
  246. }, 2800)
  247. },
  248. onLoad: function(options) {
  249. if (wx.getStorageSync('uid')) {
  250. this.setData({
  251. isLogin: true
  252. })
  253. }
  254. //网络原因,还没有拿到登陆数据,这里调用全局的callback
  255. getApp().callBack = (res) => {
  256. /**获取权限和订单信息 */
  257. // 获取商品信息
  258. httpRequestApi.getProductActivity().success(res => {
  259. wx.setStorageSync('price', res.data.data.price / 100)
  260. wx.setStorageSync('productId', res.data.data.id)
  261. if (options.type && options.type === 'iphone') {
  262. this.setData({
  263. payPrice: res.data.data.price / 100
  264. })
  265. }
  266. }).fail(error => {
  267. console.log(error)
  268. })
  269. // 获取用户权限
  270. this.getHelpAuth()
  271. if (!res.data.data.grade) {
  272. this.setData({
  273. isGradeShow: true,
  274. options,
  275. isLogin: true,
  276. workId: options.scene ? options.scene : options.readId ? options.readId : undefined
  277. })
  278. return
  279. } else {
  280. this.setData({
  281. isLogin: true
  282. }, () => {
  283. this.showPage();
  284. })
  285. }
  286. // 获取商品信息
  287. httpRequestApi.getProductActivity().success(res => {
  288. wx.setStorageSync('price', res.data.data.price / 100)
  289. wx.setStorageSync('productId', res.data.data.id)
  290. if (options.type && options.type === 'iphone') {
  291. this.setData({
  292. payPrice: res.data.data.price / 100
  293. })
  294. }
  295. }).fail(error => {
  296. console.log(error)
  297. })
  298. // 获取用户权限
  299. this.getHelpAuth()
  300. }
  301. this.setData({
  302. isIos: app.globalData.isIOS
  303. })
  304. if (options.scene) {
  305. let optionsStr = decodeURIComponent(options.scene);
  306. let optionsArr = optionsStr.split('&');
  307. // 暂时这样写
  308. if (optionsArr[0].split("=")[0] === "type") {
  309. console.log('我是团购分享')
  310. options.type = optionsArr[0].split("=")[1];
  311. options.sid = optionsArr[1].split("=")[1];
  312. } else {
  313. options.readId = optionsArr[0];
  314. options.activity = optionsArr[1];
  315. }
  316. }
  317. if (options.readId) {
  318. this.setData({
  319. workId: options.readId
  320. })
  321. }
  322. /**
  323. * 活动统计
  324. */
  325. if (options.activity) {
  326. httpRequestApi.shareAddHotAmount(options.readId).success(res => {
  327. console.log(res)
  328. })
  329. }
  330. /**团购弹窗时间紧逻辑越写越乱功能越加越多 */
  331. this.setData({
  332. iphoneType: options.type || ''
  333. })
  334. console.log('onload', options);
  335. if (options.tabbarIndx) {
  336. this.updateData(options.tabbarIndx);
  337. }
  338. this.uid = wx.getStorageSync('uid');
  339. if (options.sid) {
  340. httpRequestApi.getUserRec(options.sid).success(res => {
  341. options.uid = res.data.data;
  342. this.shareGetPage(options)
  343. })
  344. } else {
  345. this.shareGetPage(options)
  346. }
  347. wx.getSystemInfo({
  348. success: (res) => {
  349. let ratio = (res.screenHeight / res.screenWidth) * 1.1;
  350. let winH = res.windowHeight * ratio;
  351. let x1 = 465 * ratio;
  352. let x2 = 603 * ratio;
  353. let minusNumber = (winH * x1) / x2;
  354. let nextMargin = parseInt(winH - minusNumber);
  355. app.globalData.nextMargin = nextMargin;
  356. this.setData({
  357. winH: winH,
  358. devicePixelRatio: res.pixelRatio,
  359. nextMargin: nextMargin + 'rpx'
  360. });
  361. }
  362. });
  363. },
  364. // 封装分享方法之后跳到页面方法
  365. shareGetPage(options) {
  366. console.log(this.uid, options.uid, this.uid !== options.uid)
  367. if (options.type && options.type === 'iphone' && !app.globalData.isIOS && this.uid !== options.uid) {
  368. this.setData({
  369. helpPayHide: false,
  370. tipsType: 'helpPay',
  371. helpPayImg: 'http://reader-wx.ai160.com/images/reader/pay/buy.png',
  372. })
  373. }
  374. if (options.type && options.type === 'ios' && this.uid !== options.uid) {
  375. this.setData({
  376. helpPayHide: false,
  377. tipsType: 'helpPay',
  378. helpPayImg: 'http://reader-wx.ai160.com/images/reader/pay/help.png',
  379. })
  380. console.log(options.uid)
  381. }
  382. const recOsType = options.type === 'iphone' ? 'ANDROID' : (options.type === 'ios' && 'IOS');
  383. if (options.type && options.uid) {
  384. httpRequestApi.settingUserInfo({
  385. rec_uid: options.uid,
  386. recOsType,
  387. }).success(res => {
  388. console.log(res)
  389. })
  390. }
  391. },
  392. onShow: function() {
  393. let grade = wx.getStorageSync('grade');
  394. this.setData({
  395. gradeActivity: grade
  396. })
  397. if (this.data.myIndex === 3) {
  398. this.getUserWorksInfo(1)
  399. this.getHelpAuth()
  400. }
  401. wx.setNavigationBarTitle({
  402. title: '小学语文朗读配音'
  403. })
  404. console.log('页面返回页面返回', this.data.fromLoginIndex)
  405. if (this.data.fromLoginIndex || this.data.fromLoginIndex == 0) {
  406. console.log('页面返回页面返回', this.data.fromLoginIndex)
  407. let index = this.data.fromLoginIndex;
  408. let userInfo = wx.getStorageSync('user');
  409. this.setData({
  410. fromLoginIndex: null,
  411. isLogin: userInfo.nickName ? true : false
  412. }, () => {
  413. this.updateData(index)
  414. })
  415. }
  416. if (this.data.fromReading) {
  417. this.setData({
  418. fromReading: false
  419. })
  420. this.updateData('0')
  421. }
  422. // 刷新课程资源的收藏数等
  423. if (this.data.myIndex === 2) {
  424. this.refreshCourseAmount()
  425. }
  426. this.setData({
  427. shareImg: '',
  428. shareId: ''
  429. })
  430. },
  431. onHide: function() {
  432. const str = 'hotData.inputFocus'
  433. this.setData({
  434. [str]: false
  435. });
  436. },
  437. /* 两个接口维护同一个数组,手动的结束后添加算法的 */
  438. // 推荐页信息 获取消息和手动推荐内容
  439. // 获取热门作品 算法出来的
  440. getHotRecommend: function() {
  441. let grade = wx.getStorageSync('grade')
  442. let pageNo = this.data.recommendPageNo;
  443. let pageSize = this.data.recommendPageSize;
  444. httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
  445. console.log(res)
  446. const recommendRes = res.data.data.list;
  447. if (recommendRes.length <= 0) {
  448. this.setData({
  449. noMoreWork: true
  450. })
  451. return
  452. };
  453. // const recommendWorks = [];
  454. this.formatWorksList(recommendRes);
  455. });
  456. httpRequestApi.userEvent('RECOMMEND');
  457. },
  458. // 组装list
  459. formatWorksList(list, notSet) {
  460. // const tempList = [];
  461. console.log('列表长度列表长度', list.length)
  462. if (list.length < 3 || list.length === 0) {
  463. this.setData({
  464. noMoreWork: true
  465. })
  466. }
  467. list.forEach((item, index) => {
  468. /* if (index === list.length - 2 && list.length > 2) {
  469. console.log('设置当前id', item.id)
  470. this.setData({
  471. updateId: item.userRead.id
  472. })
  473. } */
  474. const temp = {};
  475. temp.title = item.userRead.title;
  476. temp.summary = item.userRead.summary;
  477. temp.img = item.userRead.iconImg;
  478. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  479. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  480. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  481. temp.shareAmount = item.userRead.shareAmount;
  482. temp.favoritesAmount = item.userRead.favoritesAmount;
  483. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  484. temp.time = formatDate(item.userRead.gmtCreated, 3);
  485. temp.avatar = item.user.avatar;
  486. temp.profession = item.user.profession;
  487. temp.uid = item.user.uid;
  488. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  489. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  490. temp.id = item.userRead.id;
  491. temp.type = item.userRead.type;
  492. temp.nickName = item.user.nickName || item.user.eid;
  493. temp.isLike = item.isLike;
  494. temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
  495. temp.isFavorite = item.isFavorites;
  496. temp.isEfun = item.user.profession === '官方' ? true : false;
  497. temp.hasTag = item.userRead.tag && item.userRead.tag !== 'EXAMPLE' ? true : false;
  498. temp.tagUrl = item.userRead.tag ? item.userRead.tag === 'HOT' ? '../../static/index/hot_tag.png' : '../../static/index/new_tag.png' : ''
  499. temp.status = item.userRead.status;
  500. temp.coverImg = item.userRead.coverImg;
  501. temp.shareImg = item.userRead.shareImg;
  502. temp.grade = item.userRead.grade;
  503. temp.videoShow = false;
  504. item.isActivity && (temp.activity = true);
  505. this.data.videoList.push(temp);
  506. // tempList.push(temp);
  507. });
  508. console.log('当前list', this.data.videoList)
  509. // if (!notSet) {
  510. this.setData({
  511. videoList: this.data.videoList
  512. })
  513. // }
  514. },
  515. // 获取用户信息
  516. getUserWorksInfo: function(flag) {
  517. if (flag) {
  518. httpRequestApi.getUserWorksInfo().success(res => {
  519. const userInfo = this.formatGrade(res.data.data.user);
  520. const str = 'myData.userInfo.nickName';
  521. const avatarStr = 'myData.userInfo.avatar';
  522. const gradeTextStr = 'myData.userInfo.gradeText';
  523. this.setData({
  524. [str]: userInfo.nickName,
  525. [avatarStr]: userInfo.avatar,
  526. [gradeTextStr]: userInfo.gradeText
  527. })
  528. })
  529. return;
  530. }
  531. httpRequestApi.getUserWorksInfo().success(res => {
  532. this.data.myData.user = res.data.data;
  533. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  534. if (res.data.data.myRead) {
  535. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  536. }
  537. res.data.data.user = this.formatGrade(res.data.data.user);
  538. this.setData({
  539. // myData: res.data.data,
  540. ['myData.user']: res.data.data,
  541. ['myData.userInfo']: res.data.data.user,
  542. ['myData.isIOS']: app.globalData.isIOS
  543. }, () => {
  544. this.getMyRead()
  545. });
  546. }).fail(error => {
  547. console.log(error)
  548. })
  549. },
  550. formatGrade(userInfo) {
  551. switch (userInfo.grade) {
  552. case 'PRESCHOOL':
  553. userInfo.gradeText = '学前班'
  554. break;
  555. case 'PRIMARY_FIRST_GRADE':
  556. userInfo.gradeText = '一年级'
  557. break;
  558. case 'PRIMARY_SECOND_GRADE':
  559. userInfo.gradeText = '二年级'
  560. break;
  561. case 'PRIMARY_THREE_GRADE':
  562. userInfo.gradeText = '三年级'
  563. break;
  564. case 'PRIMARY_SENIOR_GRADE':
  565. userInfo.gradeText = '四年级';
  566. break;
  567. }
  568. return userInfo;
  569. },
  570. videoChange: function(e) {
  571. if (e.detail.activeId === this.data.updateId) {
  572. console.log('应该刷新')
  573. if (this.data.myIndex === 1) {
  574. this.setData({
  575. followPageNo: this.data.followPageNo + 1
  576. }, () => {
  577. this.getFollowData()
  578. })
  579. }
  580. if (this.data.myIndex === 0) {
  581. console.log('首页加载第二页')
  582. this.setData({
  583. recommendPageNo: this.data.recommendPageNo + 1
  584. }, () => {
  585. this.getHotRecommend()
  586. })
  587. }
  588. }
  589. },
  590. // 触底加载
  591. onReachBottom: function() {
  592. if (this.data.myIndex === 2) {
  593. this.setData({
  594. coursePageNo: this.data.coursePageNo + 1
  595. }, () => {
  596. this.getCoursesList()
  597. })
  598. }
  599. if (this.data.myIndex === 1) {
  600. this.setData({
  601. followPageNo: this.data.followPageNo + 1
  602. }, () => {
  603. this.getFollowData()
  604. })
  605. }
  606. if (this.data.myIndex === 0) {
  607. console.log('首页加载第二页')
  608. this.setData({
  609. recommendPageNo: this.data.recommendPageNo + 1
  610. }, () => {
  611. this.getHotRecommend()
  612. })
  613. }
  614. },
  615. onPullDownRefresh: function() {
  616. //当前在团购页下拉加载
  617. this.updateData(this.data.myIndex)
  618. wx.showNavigationBarLoading() //在标题栏中显示加载
  619. //模拟加载
  620. setTimeout(function() {
  621. wx.hideNavigationBarLoading() //完成停止加载
  622. wx.stopPullDownRefresh() //停止下拉刷新
  623. }, 1000);
  624. },
  625. goToMessage: function() {
  626. wx.navigateTo({
  627. url: `../../pages/social/insideMessage/insideMessage`
  628. });
  629. const str = 'hotData.unReadMessageNum';
  630. httpRequestApi.userEvent('MESSAGE');
  631. this.setData({
  632. [str]: 0
  633. })
  634. },
  635. goToService: function() {
  636. httpRequestApi.userEvent('SERVICE');
  637. },
  638. toMyCollage: function(e) {
  639. if (app.globalData.isIOS) {
  640. wx.navigateTo({
  641. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  642. });
  643. } else {
  644. wx.navigateTo({
  645. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  646. });
  647. }
  648. },
  649. toMyCourse: function() {
  650. wx.navigateTo({
  651. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  652. });
  653. },
  654. goToFlower: function() {
  655. wx.navigateTo({
  656. url: `../../pages/social/littleFlower/littleFlower`
  657. });
  658. httpRequestApi.userEvent('INTEGRAL');
  659. },
  660. signInBtn: function(e) {
  661. this.setData({
  662. indexSignDialog: false
  663. })
  664. console.log(e.detail.formId)
  665. httpRequestApi.postFormId(e.detail.formId).success(res => {
  666. console.log(res)
  667. })
  668. this.goToFlower();
  669. },
  670. missionBtn: function() {
  671. this.setData({
  672. indexMissionDialog: false
  673. })
  674. this.goToFlower();
  675. },
  676. getUserAuth: function() {
  677. httpRequestApi.getUserAuth().success(res => {
  678. console.log(res)
  679. const str = 'myData.isVIP'
  680. if (res.data.data) {
  681. this.setData({
  682. [str]: true
  683. })
  684. } else {
  685. this.setData({
  686. [str]: false
  687. })
  688. }
  689. })
  690. },
  691. delHideMyWork: function() {
  692. this.getMyRead()
  693. },
  694. // 获取我的朗读
  695. getMyRead: function() {
  696. httpRequestApi.myRead().success(res => {
  697. console.log(123123, res)
  698. console.log('mydata', this.data.myData)
  699. const myList = res.data.data;
  700. if (myList.length === 0) {
  701. this.setData({
  702. videoList: []
  703. })
  704. return
  705. }
  706. // this.formatWorksList(myList)
  707. // const recommendWorks = [];
  708. const myWorks = [];
  709. myList.forEach(item => {
  710. const temp = {};
  711. temp.title = item.userRead.title;
  712. temp.summary = item.userRead.summary;
  713. temp.img = item.userRead.iconImg;
  714. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  715. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  716. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  717. temp.shareAmount = item.userRead.shareAmount;
  718. temp.favoritesAmount = item.userRead.favoritesAmount;
  719. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  720. temp.time = formatDate(item.userRead.gmtCreated, 3);
  721. temp.avatar = item.user.avatar;
  722. temp.profession = item.user.profession;
  723. temp.uid = item.user.uid;
  724. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  725. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  726. temp.id = item.userRead.id;
  727. temp.type = item.userRead.type;
  728. temp.nickName = item.user.nickName;
  729. temp.isLike = item.isLike;
  730. temp.isFavorite = item.isFavorites;
  731. temp.showMyBtn = true;
  732. temp.nickName = this.data.myData.userInfo.nickName;
  733. temp.status = item.userRead.status;
  734. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  735. temp.coverImg = item.userRead.coverImg;
  736. temp.grade = item.userRead.grade
  737. temp.isFans = true;
  738. temp.videoShow = false;
  739. temp.shareImg = item.userRead.shareImg;
  740. item.isActivity && (temp.activity = true);
  741. myWorks.push(temp);
  742. });
  743. if (this.data.myIndex === 3) {
  744. this.setData({
  745. videoList: myWorks,
  746. noMoreWork: true
  747. })
  748. }
  749. })
  750. },
  751. // 评论区点击
  752. commentTap: function(e) {
  753. console.log('点击评论区', e)
  754. if (e.target.dataset.type === 'blank') {
  755. if (this.data.commentShow && this.data.commentId) {
  756. httpRequestApi.getClassDetail(this.data.commentId).success(res => {
  757. console.log('评论回显', res.data.data.userRead.commentAmount)
  758. let str = `videoList[${this.data.commentIndex}].commentAmount`;
  759. this.setData({
  760. [str]: res.data.data.userRead.commentAmount
  761. })
  762. })
  763. }
  764. this.setData({
  765. commentShow: false
  766. })
  767. }
  768. },
  769. touchMove: function(e) {
  770. return
  771. },
  772. // 打开评论
  773. openComment: function(e) {
  774. //
  775. console.log('id', e.detail.activeId)
  776. console.log('id', e)
  777. this.setData({
  778. commentShow: !this.data.commentShow,
  779. commentId: e.detail.activeId,
  780. commentIndex: e.detail.activeIndex
  781. // commentList: []
  782. });
  783. // this.getReply(e.detail.activeId);
  784. },
  785. // 获取评论信息
  786. getReply: function(columnId) {
  787. debugger
  788. // let columnId = this.data.id;
  789. console.log(123123123, columnId)
  790. // let pageNo = this.data.pageNo;
  791. // let pageSize = this.data.pageSize;
  792. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  793. console.log('reply', res)
  794. const commentList = res.data.data.list;
  795. const commentNum = res.data.data.totalSize;
  796. console.log('评论数量', commentNum)
  797. commentList.forEach((item) => {
  798. const temp = {};
  799. temp.nickName = item.user.nickName;
  800. temp.avatar = item.user.avatar;
  801. temp.uid = item.user.uid;
  802. temp.text = item.detailDesc;
  803. temp.id = item.id;
  804. temp.replyCount = item.replyCount;
  805. temp.time = formatDate(item.gmtCreated, 3);
  806. temp.likes = item.postsAttributeInfo.favors || 0;
  807. temp.isLike = item.isLike;
  808. temp.replyList = item.replyVOList;
  809. this.data.commentList.push(temp);
  810. });
  811. this.setData({
  812. commentList: this.data.commentList,
  813. commentNum: commentNum
  814. })
  815. });
  816. },
  817. // 发布回复
  818. sendReply: function(e) {
  819. console.log('triger', e.detail.content);
  820. let data = {
  821. columnId: this.data.commentId,
  822. colunmNames: 'what',
  823. detailDesc: e.detail.content,
  824. // productId: this.data.productId
  825. }
  826. httpRequestApi.postReply(this.uid, data).success(res => {
  827. console.log(res)
  828. this.setData({
  829. pageNo: 1,
  830. commentList: []
  831. }, () => {
  832. this.getReply(this.data.commentId);
  833. })
  834. });
  835. },
  836. gradeTap: function() {
  837. // console.log("组件回调,返回上一页");
  838. this.setData({
  839. isGradeShow: true
  840. })
  841. },
  842. onShareAppMessage: function(res) {
  843. if (res.from === 'button') {
  844. return {
  845. title: '请欣赏我的课文朗读作品,点赞+评论。',
  846. path: `/pages/index/index?readId=${this.data.shareId}&activity=${this.data.ifTapActivity}`,
  847. imageUrl: this.data.shareImg
  848. }
  849. } else {
  850. return {
  851. title: '课文朗读,从未如此有趣。',
  852. path: '/pages/index/index',
  853. }
  854. }
  855. },
  856. openShare: function(e) {
  857. console.log('点击分享', e)
  858. /* this.setData({
  859. shareTitle: e.detail.currentTarget.dataset.title,
  860. shareId: e.detail.currentTarget.dataset.id,
  861. shareImg: e.detail.currentTarget.dataset.shareimg,
  862. goToShare: true,
  863. ifTapActivity: e.detail.currentTarget.dataset.activity
  864. }) */
  865. },
  866. // 选择年纪
  867. selectGrade({
  868. target
  869. }) {
  870. let code = target.dataset.code
  871. if (!code) {
  872. return
  873. }
  874. this.setData({
  875. temporaryGrade: code
  876. })
  877. console.log(code);
  878. },
  879. // 修改年级
  880. changeGrade: function(e) {
  881. const grade = this.data.temporaryGrade
  882. if (!grade) {
  883. return wx.showToast({
  884. title: '请选择年级',
  885. icon: 'none',
  886. duration: 2000
  887. })
  888. }
  889. wx.setStorageSync('grade', grade)
  890. this.setData({
  891. isGradeShow: false,
  892. grade
  893. })
  894. let data = {
  895. grade
  896. };
  897. httpRequestApi.settingUserInfo(data).success(res => {
  898. this.showPage()
  899. })
  900. return;
  901. },
  902. getFollowData: function() {
  903. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  904. if (res.data.data.totalSize === 0) {
  905. this.setData({
  906. videoList: [],
  907. noFollow: true
  908. })
  909. console.log('没有关注人或关注的人没有发过作品')
  910. return
  911. } else {
  912. this.setData({
  913. noFollow: false
  914. })
  915. }
  916. console.log('关注列表', res)
  917. const followData = res.data.data.list;
  918. // const videoList = [];
  919. this.formatWorksList(followData);
  920. });
  921. httpRequestApi.userEvent('SUBSCRIBE');
  922. },
  923. // 点击用户头像区域
  924. headTapHandler: function(e) {
  925. console.log('点击头像', e)
  926. let tapId = e.detail.activeId;
  927. // 点击头像既关注 测试
  928. httpRequestApi.followUser(this.uid, tapId).success(res => {
  929. console.log(res)
  930. })
  931. },
  932. getCoursesList: function() {
  933. const grade = wx.getStorageSync('grade');
  934. const data = {
  935. pageNo: this.data.coursePageNo,
  936. pageSize: 6,
  937. grade,
  938. type: 'EXAMPLE'
  939. };
  940. console.log('资源', data)
  941. httpRequestApi.getClassRead(data).success(res => {
  942. console.log('资源', this.data.coursesData)
  943. this.setData({
  944. coursesData: this.data.coursesData.concat(res.data.data.list),
  945. noMoreWork: res.data.data.list.length <= 0 ? true : false
  946. }, () => {
  947. console.log(this.data.coursesData)
  948. })
  949. })
  950. httpRequestApi.userEvent('RESOURCES');
  951. },
  952. goToReading: function(e) {
  953. console.log('去朗读', e)
  954. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  955. const index = e.currentTarget.dataset.index;
  956. this.setData({
  957. goToCoursesId: id,
  958. goToCoursesIndex: index
  959. })
  960. wx.navigateTo({
  961. url: `../../pages/reading/reading?id=${id}`
  962. });
  963. httpRequestApi.userEvent('REC_READ');
  964. },
  965. refreshCourseAmount() {
  966. console.log(this.data.goToCoursesId)
  967. console.log(this.data.goToCoursesIndex)
  968. if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
  969. httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
  970. console.log('刷新', res.data.data.userRead)
  971. let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
  972. let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
  973. let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
  974. let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
  975. let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
  976. console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
  977. console.log(2, res.data.data.userRead.likeAmount)
  978. this.setData({
  979. [likeStr]: res.data.data.userRead.likeAmount,
  980. [commentStr]: res.data.data.userRead.commentAmount,
  981. [playStr]: res.data.data.userRead.playAmount,
  982. [shareStr]: res.data.data.userRead.shareAmount,
  983. [collectStr]: res.data.data.userRead.collectAmount,
  984. }, () => {
  985. console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
  986. })
  987. })
  988. }
  989. },
  990. courseCollectTap: function collectClass(e) {
  991. console.log('收藏按钮', e);
  992. const data = {
  993. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  994. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  995. }
  996. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  997. let str = `coursesData[${index}].isFavorites`
  998. httpRequestApi.collectClass(data).success((res) => {
  999. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  1000. this.setData({
  1001. [str]: !this.data.coursesData[index].isFavorites
  1002. })
  1003. });
  1004. },
  1005. coursesOpenShare: function coursesOpenShare(e) {
  1006. const obj = e.currentTarget.dataset
  1007. console.log('分享', obj)
  1008. console.log('分享', e)
  1009. if (1) {
  1010. this.shareDialog = this.selectComponent("#share-dialog");
  1011. const data = {
  1012. avatar: obj.avatar,
  1013. author: obj.author,
  1014. iconImg: obj.iconImg,
  1015. title: obj.title,
  1016. path: `pages/index/index`,
  1017. scene: obj.id,
  1018. productId: 1
  1019. // tip: this.data.tip,
  1020. }
  1021. // console.log(data)
  1022. this.setData({
  1023. noScroll: 'noScroll',
  1024. shareTitle: obj.title,
  1025. shareId: obj.id,
  1026. shareImg: obj.shareimg
  1027. })
  1028. this.shareDialog.share(data);
  1029. }
  1030. },
  1031. collectTap: function(e) {
  1032. const index = e.detail.index;
  1033. let str = `videoList[${index}].isFavorite`;
  1034. let str2 = `videoList[${index}].favoritesAmount`;
  1035. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  1036. this.setData({
  1037. [str]: e.detail.isCollect,
  1038. [str2]: favoritesAmount
  1039. })
  1040. },
  1041. likeTap: function(e) {
  1042. console.log('点赞', e)
  1043. const index = e.detail.index;
  1044. let likeStr = `videoList[${index}].isLike`;
  1045. let likeNumStr = `videoList[${index}].likes`;
  1046. this.setData({
  1047. [likeStr]: true,
  1048. [likeNumStr]: this.data.videoList[index].likes + 1
  1049. })
  1050. },
  1051. addShareAmount: function(e) {
  1052. let str = `videoList[${e.detail.index}].shareAmount`;
  1053. this.setData({
  1054. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  1055. })
  1056. },
  1057. /**
  1058. * 跳转到活动页
  1059. */
  1060. goToActivity() {
  1061. httpRequestApi.postActEvent('BANNER').success(res => {
  1062. console.log('活动banner', res)
  1063. })
  1064. // wx.navigateTo({
  1065. // url: `../activity/index/index`
  1066. // // url: `../activity/rule/rule`
  1067. // });
  1068. wx.navigateTo({
  1069. url: `../activity/goodList/goodList`
  1070. });
  1071. },
  1072. /**
  1073. * banner点击
  1074. */
  1075. bannerTap() {
  1076. if (!this.data.isLogin) {
  1077. wx.navigateTo({
  1078. url: `../../pages/login/login?index=0`
  1079. });
  1080. return;
  1081. }
  1082. if (this.data.isIos || this.data.isVip) {
  1083. this.myPlase();
  1084. } else {
  1085. this.messageAuth();
  1086. }
  1087. },
  1088. /**活动改版 */
  1089. // myPlase() {
  1090. // if (!wx.getStorageSync('message')) {
  1091. // wx.requestSubscribeMessage({
  1092. // tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1093. // '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1094. // ],
  1095. // success: (res) => {
  1096. // console.log(res)
  1097. // if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1098. // console.log('用户不同意订阅')
  1099. // // 用户不同意订阅
  1100. // wx.setStorageSync('message', false)
  1101. // } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1102. // console.log('订阅成功')
  1103. // // 用户点击统一订阅
  1104. // wx.setStorageSync('message', true)
  1105. // }
  1106. // wx.navigateTo({
  1107. // url: `../vipActivity/vipActivity`
  1108. // });
  1109. // },
  1110. // fail: () => {
  1111. // wx.navigateTo({
  1112. // url: `../vipActivity/vipActivity`
  1113. // });
  1114. // }
  1115. // })
  1116. // } else {
  1117. // wx.navigateTo({
  1118. // url: `../vipActivity/vipActivity`
  1119. // });
  1120. // }
  1121. // },
  1122. // 弹窗提示
  1123. helpPayHideEvent() {
  1124. this.setData({
  1125. helpPayHide: !this.data.helpPayHide
  1126. })
  1127. },
  1128. // 支付或者助力
  1129. payAndHelp() {
  1130. if (!this.data.isLogin) {
  1131. wx.navigateTo({
  1132. url: `../../pages/login/login?index=0`
  1133. });
  1134. return;
  1135. }
  1136. if (this.data.iphoneType === 'ios') {
  1137. httpRequestApi.postUserHelp().success(res => {
  1138. console.log(res)
  1139. if (res.data.data) {
  1140. this.setData({
  1141. tipsType: 'tips',
  1142. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/help_success.png'
  1143. })
  1144. } else {
  1145. this.setData({
  1146. tipsType: 'tips',
  1147. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/helped.png'
  1148. })
  1149. }
  1150. })
  1151. } else {
  1152. // 去支付需要获取权限
  1153. this.messageAuth();
  1154. }
  1155. },
  1156. // 去产品页
  1157. goToPruduct() {
  1158. wx.navigateTo({
  1159. url: `../product/product?price=${this.data.myData.price}`
  1160. });
  1161. },
  1162. // 授权
  1163. messageAuth() {
  1164. if (!wx.getStorageSync('message')) {
  1165. wx.requestSubscribeMessage({
  1166. tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1167. '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1168. ],
  1169. success: (res) => {
  1170. console.log(res)
  1171. if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1172. console.log('用户不同意订阅')
  1173. wx.setStorageSync('message', false)
  1174. } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1175. console.log('订阅成功')
  1176. wx.setStorageSync('message', true)
  1177. }
  1178. this.order();
  1179. },
  1180. fail: () => {
  1181. this.order();
  1182. }
  1183. })
  1184. } else {
  1185. this.order();
  1186. }
  1187. },
  1188. // 支付
  1189. order() {
  1190. // 渠道id
  1191. const productId = wx.getStorageSync('productId');
  1192. httpRequestApi.createOrder(productId).success(res => {
  1193. console.log(res.data.data.package);
  1194. const timeStamp = res.data.data.timeStamp;
  1195. const nonceStr = res.data.data.nonceStr;
  1196. const packages = res.data.data.package;
  1197. const paySign = res.data.data.sign;
  1198. wx.requestPayment({
  1199. timeStamp,
  1200. nonceStr,
  1201. package: packages,
  1202. signType: 'MD5',
  1203. paySign,
  1204. success: (res) => {
  1205. if (this.data.iphoneType === 'iphone') {
  1206. this.setData({
  1207. tipsType: 'tips',
  1208. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/success.png'
  1209. })
  1210. }
  1211. httpRequestApi.getAuthActivity().success(res => {
  1212. if (!res.data.data) {
  1213. wx.setStorageSync('vip', false)
  1214. wx.setStorageSync('date', '')
  1215. } else {
  1216. wx.setStorageSync('vip', true)
  1217. wx.setStorageSync('date', res.data.data)
  1218. this.setData({
  1219. ['myData.isVIP']: true,
  1220. ['myData.date']: res.data.data
  1221. })
  1222. this.showGift();
  1223. }
  1224. }).fail(error => {
  1225. console.log(error)
  1226. })
  1227. },
  1228. fail(res) {}
  1229. })
  1230. })
  1231. },
  1232. // 助力或者支付提示
  1233. tips() {
  1234. console.log('支付完了')
  1235. this.setData({
  1236. helpPayHide: true
  1237. })
  1238. this.updateData("2");
  1239. },
  1240. // 购买成功告诉首页显示邀请有礼
  1241. showGift() {
  1242. console.log('通知')
  1243. this.setData({
  1244. isVip: true
  1245. })
  1246. },
  1247. // 首页获取权限
  1248. getHelpAuth() {
  1249. httpRequestApi.getAuthActivity().success(res => {
  1250. if (!res.data.data) {
  1251. wx.setStorageSync('vip', false)
  1252. wx.setStorageSync('date', '')
  1253. this.setData({
  1254. isVip: false
  1255. })
  1256. } else {
  1257. wx.setStorageSync('vip', true)
  1258. wx.setStorageSync('date', res.data.data)
  1259. this.setData({
  1260. isVip: true
  1261. })
  1262. }
  1263. }).fail(error => {
  1264. console.log(error)
  1265. })
  1266. },
  1267. // 分享作品逻辑
  1268. creatShare(video) {
  1269. return new Promise((resolve, reject) => {
  1270. let context = wx.createSelectorQuery();
  1271. context
  1272. .select('#share')
  1273. .fields({
  1274. node: true,
  1275. size: true
  1276. }).exec((res) => {
  1277. const canvas = res[0].node;
  1278. const ctx = canvas.getContext('2d');
  1279. const dpr = wx.getSystemInfoSync().pixelRatio;
  1280. canvas.width = res[0].width * dpr;
  1281. canvas.height = res[0].height * dpr;
  1282. ctx.scale(dpr, dpr);
  1283. ctx.font = '14px PingFang';
  1284. let pic = canvas.createImage();
  1285. pic.src = video.coverImg; //可以是本地,也可以是网络图片
  1286. pic.onload = () => {
  1287. ctx.drawImage(pic, 0, 0, 375, 211);
  1288. }
  1289. let peiyin = canvas.createImage();
  1290. peiyin.src = '/static/image/peiyin.jpg';
  1291. peiyin.onload = () => {
  1292. ctx.drawImage(peiyin, 0, 211, 375, 89);
  1293. // 收藏,一个一个渲染
  1294. let sc = canvas.createImage();
  1295. sc.src = '/static/image/no_collect.png'
  1296. sc.onload = () => {
  1297. ctx.drawImage(sc, 12, 220, 20, 20)
  1298. ctx.fillText('收藏', 36, 238)
  1299. //分享
  1300. let fx = canvas.createImage();
  1301. fx.src = '/static/index/share.png'
  1302. fx.onload = () => {
  1303. ctx.drawImage(fx, 78, 220, 22, 22)
  1304. ctx.fillText('分享', 104, 238)
  1305. //点赞
  1306. let dz = canvas.createImage();
  1307. dz.src = video.isLike ? '/static/index/heart_colored.png' : '/static/index/heart.png'
  1308. dz.onload = () => {
  1309. ctx.drawImage(dz, 258, 222, 22, 22)
  1310. ctx.fillText(video.likes, 284, 238)
  1311. //评论
  1312. let pl = canvas.createImage();
  1313. pl.src = '/static/index/comment.png'
  1314. pl.onload = () => {
  1315. ctx.drawImage(pl, 318, 222, 22, 22)
  1316. ctx.fillText(video.commentAmount, 340, 238)
  1317. setTimeout(() => {
  1318. wx.canvasToTempFilePath({
  1319. canvas: canvas,
  1320. success(res) {
  1321. resolve({
  1322. title: '请欣赏我的课文朗读作品,点赞+评论。',
  1323. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1324. imageUrl: res.tempFilePath
  1325. })
  1326. },
  1327. fail(res) {
  1328. reject()
  1329. }
  1330. }, this)
  1331. }, 500)
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. })
  1338. })
  1339. },
  1340. onShareAppMessage({
  1341. target
  1342. }) {
  1343. let video = target.dataset.info
  1344. console.log(`/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`)
  1345. const promise = new Promise(resolve => {
  1346. this.creatShare(video).then(res => {
  1347. resolve(res)
  1348. })
  1349. })
  1350. return {
  1351. title: '请欣赏我的课文朗读作品,点赞+评论。',
  1352. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1353. imageUrl: video.coverImg,
  1354. promise
  1355. }
  1356. }
  1357. })