index.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  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. console.log(item);
  475. const temp = {};
  476. temp.title = item.userRead.title;
  477. temp.summary = item.userRead.summary;
  478. temp.img = item.userRead.iconImg;
  479. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  480. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  481. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  482. temp.shareAmount = item.userRead.shareAmount;
  483. temp.favoritesAmount = item.userRead.favoritesAmount;
  484. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  485. temp.time = formatDate(item.userRead.gmtCreated, 3);
  486. temp.avatar = item.user.avatar;
  487. temp.profession = item.user.profession;
  488. temp.uid = item.user.uid;
  489. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  490. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  491. temp.id = item.userRead.id;
  492. temp.type = item.userRead.type;
  493. temp.nickName = item.user.nickName || item.user.eid;
  494. temp.isLike = item.isLike;
  495. temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
  496. temp.isFavorite = item.isFavorites;
  497. temp.isEfun = item.user.profession === '官方' ? true : false;
  498. temp.hasTag = item.userRead.tag && item.userRead.tag !== 'EXAMPLE' ? true : false;
  499. temp.tagUrl = item.userRead.tag ? item.userRead.tag === 'HOT' ? '../../static/index/hot_tag.png' : '../../static/index/new_tag.png' : ''
  500. temp.status = item.userRead.status;
  501. temp.coverImg = item.userRead.coverImg;
  502. temp.shareImg = item.userRead.shareImg;
  503. temp.grade = item.userRead.grade;
  504. temp.videoShow = false;
  505. item.isActivity && (temp.activity = true);
  506. this.data.videoList.push(temp);
  507. // tempList.push(temp);
  508. });
  509. console.log('当前list', this.data.videoList)
  510. // if (!notSet) {
  511. this.setData({
  512. videoList: this.data.videoList
  513. })
  514. // }
  515. },
  516. // 获取用户信息
  517. getUserWorksInfo: function(flag) {
  518. if (flag) {
  519. httpRequestApi.getUserWorksInfo().success(res => {
  520. const userInfo = this.formatGrade(res.data.data.user);
  521. const str = 'myData.userInfo.nickName';
  522. const avatarStr = 'myData.userInfo.avatar';
  523. const gradeTextStr = 'myData.userInfo.gradeText';
  524. this.setData({
  525. [str]: userInfo.nickName,
  526. [avatarStr]: userInfo.avatar,
  527. [gradeTextStr]: userInfo.gradeText
  528. })
  529. })
  530. return;
  531. }
  532. httpRequestApi.getUserWorksInfo().success(res => {
  533. this.data.myData.user = res.data.data;
  534. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  535. if (res.data.data.myRead) {
  536. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  537. }
  538. res.data.data.user = this.formatGrade(res.data.data.user);
  539. this.setData({
  540. // myData: res.data.data,
  541. ['myData.user']: res.data.data,
  542. ['myData.userInfo']: res.data.data.user,
  543. ['myData.isIOS']: app.globalData.isIOS
  544. }, () => {
  545. this.getMyRead()
  546. });
  547. }).fail(error => {
  548. console.log(error)
  549. })
  550. },
  551. formatGrade(userInfo) {
  552. switch (userInfo.grade) {
  553. case 'PRESCHOOL':
  554. userInfo.gradeText = '学前班'
  555. break;
  556. case 'PRIMARY_FIRST_GRADE':
  557. userInfo.gradeText = '一年级'
  558. break;
  559. case 'PRIMARY_SECOND_GRADE':
  560. userInfo.gradeText = '二年级'
  561. break;
  562. case 'PRIMARY_THREE_GRADE':
  563. userInfo.gradeText = '三年级'
  564. break;
  565. case 'PRIMARY_SENIOR_GRADE':
  566. userInfo.gradeText = '四年级';
  567. break;
  568. }
  569. return userInfo;
  570. },
  571. videoChange: function(e) {
  572. if (e.detail.activeId === this.data.updateId) {
  573. console.log('应该刷新')
  574. if (this.data.myIndex === 1) {
  575. this.setData({
  576. followPageNo: this.data.followPageNo + 1
  577. }, () => {
  578. this.getFollowData()
  579. })
  580. }
  581. if (this.data.myIndex === 0) {
  582. console.log('首页加载第二页')
  583. this.setData({
  584. recommendPageNo: this.data.recommendPageNo + 1
  585. }, () => {
  586. this.getHotRecommend()
  587. })
  588. }
  589. }
  590. },
  591. // 触底加载
  592. onReachBottom: function() {
  593. if (this.data.myIndex === 2) {
  594. this.setData({
  595. coursePageNo: this.data.coursePageNo + 1
  596. }, () => {
  597. this.getCoursesList()
  598. })
  599. }
  600. if (this.data.myIndex === 1) {
  601. this.setData({
  602. followPageNo: this.data.followPageNo + 1
  603. }, () => {
  604. this.getFollowData()
  605. })
  606. }
  607. if (this.data.myIndex === 0) {
  608. console.log('首页加载第二页')
  609. this.setData({
  610. recommendPageNo: this.data.recommendPageNo + 1
  611. }, () => {
  612. this.getHotRecommend()
  613. })
  614. }
  615. },
  616. onPullDownRefresh: function() {
  617. //当前在团购页下拉加载
  618. this.updateData(this.data.myIndex)
  619. wx.showNavigationBarLoading() //在标题栏中显示加载
  620. //模拟加载
  621. setTimeout(function() {
  622. wx.hideNavigationBarLoading() //完成停止加载
  623. wx.stopPullDownRefresh() //停止下拉刷新
  624. }, 1000);
  625. },
  626. goToMessage: function() {
  627. wx.navigateTo({
  628. url: `../../pages/social/insideMessage/insideMessage`
  629. });
  630. const str = 'hotData.unReadMessageNum';
  631. httpRequestApi.userEvent('MESSAGE');
  632. this.setData({
  633. [str]: 0
  634. })
  635. },
  636. goToService: function() {
  637. httpRequestApi.userEvent('SERVICE');
  638. },
  639. toMyCollage: function(e) {
  640. if (app.globalData.isIOS) {
  641. wx.navigateTo({
  642. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  643. });
  644. } else {
  645. wx.navigateTo({
  646. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  647. });
  648. }
  649. },
  650. toMyCourse: function() {
  651. wx.navigateTo({
  652. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  653. });
  654. },
  655. goToFlower: function() {
  656. wx.navigateTo({
  657. url: `../../pages/social/littleFlower/littleFlower`
  658. });
  659. httpRequestApi.userEvent('INTEGRAL');
  660. },
  661. signInBtn: function(e) {
  662. this.setData({
  663. indexSignDialog: false
  664. })
  665. console.log(e.detail.formId)
  666. httpRequestApi.postFormId(e.detail.formId).success(res => {
  667. console.log(res)
  668. })
  669. this.goToFlower();
  670. },
  671. missionBtn: function() {
  672. this.setData({
  673. indexMissionDialog: false
  674. })
  675. this.goToFlower();
  676. },
  677. getUserAuth: function() {
  678. httpRequestApi.getUserAuth().success(res => {
  679. console.log(res)
  680. const str = 'myData.isVIP'
  681. if (res.data.data) {
  682. this.setData({
  683. [str]: true
  684. })
  685. } else {
  686. this.setData({
  687. [str]: false
  688. })
  689. }
  690. })
  691. },
  692. delHideMyWork: function() {
  693. this.getMyRead()
  694. },
  695. // 获取我的朗读
  696. getMyRead: function() {
  697. httpRequestApi.myRead().success(res => {
  698. console.log(123123, res)
  699. console.log('mydata', this.data.myData)
  700. const myList = res.data.data;
  701. if (myList.length === 0) {
  702. this.setData({
  703. videoList: []
  704. })
  705. return
  706. }
  707. // this.formatWorksList(myList)
  708. // const recommendWorks = [];
  709. const myWorks = [];
  710. myList.forEach(item => {
  711. const temp = {};
  712. temp.title = item.userRead.title;
  713. temp.summary = item.userRead.summary;
  714. temp.img = item.userRead.iconImg;
  715. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  716. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  717. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  718. temp.shareAmount = item.userRead.shareAmount;
  719. temp.favoritesAmount = item.userRead.favoritesAmount;
  720. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  721. temp.time = formatDate(item.userRead.gmtCreated, 3);
  722. temp.avatar = item.user.avatar;
  723. temp.profession = item.user.profession;
  724. temp.uid = item.user.uid;
  725. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  726. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  727. temp.id = item.userRead.id;
  728. temp.type = item.userRead.type;
  729. temp.nickName = item.user.nickName;
  730. temp.isLike = item.isLike;
  731. temp.isFavorite = item.isFavorites;
  732. temp.showMyBtn = true;
  733. temp.nickName = this.data.myData.userInfo.nickName;
  734. temp.status = item.userRead.status;
  735. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  736. temp.coverImg = item.userRead.coverImg;
  737. temp.grade = item.userRead.grade
  738. temp.isFans = true;
  739. temp.videoShow = false;
  740. temp.shareImg = item.userRead.shareImg;
  741. item.isActivity && (temp.activity = true);
  742. myWorks.push(temp);
  743. });
  744. if (this.data.myIndex === 3) {
  745. this.setData({
  746. videoList: myWorks,
  747. noMoreWork: true
  748. })
  749. }
  750. })
  751. },
  752. // 评论区点击
  753. commentTap: function(e) {
  754. console.log('点击评论区', e)
  755. if (e.target.dataset.type === 'blank') {
  756. if (this.data.commentShow && this.data.commentId) {
  757. httpRequestApi.getClassDetail(this.data.commentId).success(res => {
  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}&uid=${wx.getStorageSync('uid')}`,
  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. onShareTimeline: function() {
  1341. return {
  1342. title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
  1343. query: `uid=${wx.getStorageSync('uid')}`,
  1344. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
  1345. }
  1346. },
  1347. onShareAppMessage({
  1348. from,
  1349. target
  1350. }) {
  1351. if (from == 'button') {
  1352. let video = target.dataset.info
  1353. const promise = new Promise(resolve => {
  1354. this.creatShare(video).then(res => {
  1355. resolve(res)
  1356. })
  1357. })
  1358. return {
  1359. title: '请欣赏我的课文朗读作品,点赞+评论。',
  1360. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1361. imageUrl: video.coverImg,
  1362. promise
  1363. }
  1364. } else {
  1365. return {
  1366. title: '课文朗读,从未如此有趣。',
  1367. path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
  1368. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
  1369. }
  1370. }
  1371. }
  1372. })