index.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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. let str = `videoList[${this.data.commentIndex}].commentAmount`;
  758. this.setData({
  759. [str]: res.data.data.userRead.commentAmount
  760. })
  761. })
  762. }
  763. this.setData({
  764. commentShow: false
  765. })
  766. }
  767. },
  768. touchMove: function(e) {
  769. return
  770. },
  771. // 打开评论
  772. openComment: function(e) {
  773. //
  774. console.log('id', e.detail.activeId)
  775. console.log('id', e)
  776. this.setData({
  777. commentShow: !this.data.commentShow,
  778. commentId: e.detail.activeId,
  779. commentIndex: e.detail.activeIndex
  780. // commentList: []
  781. });
  782. // this.getReply(e.detail.activeId);
  783. },
  784. // 获取评论信息
  785. getReply: function(columnId) {
  786. debugger
  787. // let columnId = this.data.id;
  788. console.log(123123123, columnId)
  789. // let pageNo = this.data.pageNo;
  790. // let pageSize = this.data.pageSize;
  791. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  792. console.log('reply', res)
  793. const commentList = res.data.data.list;
  794. const commentNum = res.data.data.totalSize;
  795. console.log('评论数量', commentNum)
  796. commentList.forEach((item) => {
  797. const temp = {};
  798. temp.nickName = item.user.nickName;
  799. temp.avatar = item.user.avatar;
  800. temp.uid = item.user.uid;
  801. temp.text = item.detailDesc;
  802. temp.id = item.id;
  803. temp.replyCount = item.replyCount;
  804. temp.time = formatDate(item.gmtCreated, 3);
  805. temp.likes = item.postsAttributeInfo.favors || 0;
  806. temp.isLike = item.isLike;
  807. temp.replyList = item.replyVOList;
  808. this.data.commentList.push(temp);
  809. });
  810. this.setData({
  811. commentList: this.data.commentList,
  812. commentNum: commentNum
  813. })
  814. });
  815. },
  816. // 发布回复
  817. sendReply: function(e) {
  818. console.log('triger', e.detail.content);
  819. let data = {
  820. columnId: this.data.commentId,
  821. colunmNames: 'what',
  822. detailDesc: e.detail.content,
  823. // productId: this.data.productId
  824. }
  825. httpRequestApi.postReply(this.uid, data).success(res => {
  826. console.log(res)
  827. this.setData({
  828. pageNo: 1,
  829. commentList: []
  830. }, () => {
  831. this.getReply(this.data.commentId);
  832. })
  833. });
  834. },
  835. gradeTap: function() {
  836. // console.log("组件回调,返回上一页");
  837. this.setData({
  838. isGradeShow: true
  839. })
  840. },
  841. onShareAppMessage: function(res) {
  842. if (res.from === 'button') {
  843. return {
  844. title: '请欣赏我的课文朗读作品,点赞+评论。',
  845. path: `/pages/index/index?readId=${this.data.shareId}&activity=${this.data.ifTapActivity}`,
  846. imageUrl: this.data.shareImg
  847. }
  848. } else {
  849. return {
  850. title: '课文朗读,从未如此有趣。',
  851. path: '/pages/index/index',
  852. }
  853. }
  854. },
  855. openShare: function(e) {
  856. console.log('点击分享', e)
  857. /* this.setData({
  858. shareTitle: e.detail.currentTarget.dataset.title,
  859. shareId: e.detail.currentTarget.dataset.id,
  860. shareImg: e.detail.currentTarget.dataset.shareimg,
  861. goToShare: true,
  862. ifTapActivity: e.detail.currentTarget.dataset.activity
  863. }) */
  864. },
  865. // 选择年纪
  866. selectGrade({
  867. target
  868. }) {
  869. let code = target.dataset.code
  870. if (!code) {
  871. return
  872. }
  873. this.setData({
  874. temporaryGrade: code
  875. })
  876. console.log(code);
  877. },
  878. // 修改年级
  879. changeGrade: function(e) {
  880. const grade = this.data.temporaryGrade
  881. if (!grade) {
  882. return wx.showToast({
  883. title: '请选择年级',
  884. icon: 'none',
  885. duration: 2000
  886. })
  887. }
  888. wx.setStorageSync('grade', grade)
  889. this.setData({
  890. isGradeShow: false,
  891. grade
  892. })
  893. let data = {
  894. grade
  895. };
  896. httpRequestApi.settingUserInfo(data).success(res => {
  897. this.showPage()
  898. })
  899. return;
  900. },
  901. getFollowData: function() {
  902. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  903. if (res.data.data.totalSize === 0) {
  904. this.setData({
  905. videoList: [],
  906. noFollow: true
  907. })
  908. console.log('没有关注人或关注的人没有发过作品')
  909. return
  910. } else {
  911. this.setData({
  912. noFollow: false
  913. })
  914. }
  915. console.log('关注列表', res)
  916. const followData = res.data.data.list;
  917. // const videoList = [];
  918. this.formatWorksList(followData);
  919. });
  920. httpRequestApi.userEvent('SUBSCRIBE');
  921. },
  922. // 点击用户头像区域
  923. headTapHandler: function(e) {
  924. console.log('点击头像', e)
  925. let tapId = e.detail.activeId;
  926. // 点击头像既关注 测试
  927. httpRequestApi.followUser(this.uid, tapId).success(res => {
  928. console.log(res)
  929. })
  930. },
  931. getCoursesList: function() {
  932. const grade = wx.getStorageSync('grade');
  933. const data = {
  934. pageNo: this.data.coursePageNo,
  935. pageSize: 6,
  936. grade,
  937. type: 'EXAMPLE'
  938. };
  939. console.log('资源', data)
  940. httpRequestApi.getClassRead(data).success(res => {
  941. console.log('资源', this.data.coursesData)
  942. this.setData({
  943. coursesData: this.data.coursesData.concat(res.data.data.list),
  944. noMoreWork: res.data.data.list.length <= 0 ? true : false
  945. }, () => {
  946. console.log(this.data.coursesData)
  947. })
  948. })
  949. httpRequestApi.userEvent('RESOURCES');
  950. },
  951. goToReading: function(e) {
  952. console.log('去朗读', e)
  953. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  954. const index = e.currentTarget.dataset.index;
  955. this.setData({
  956. goToCoursesId: id,
  957. goToCoursesIndex: index
  958. })
  959. wx.navigateTo({
  960. url: `../../pages/reading/reading?id=${id}`
  961. });
  962. httpRequestApi.userEvent('REC_READ');
  963. },
  964. refreshCourseAmount() {
  965. console.log(this.data.goToCoursesId)
  966. console.log(this.data.goToCoursesIndex)
  967. if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
  968. httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
  969. console.log('刷新', res.data.data.userRead)
  970. let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
  971. let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
  972. let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
  973. let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
  974. let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
  975. console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
  976. console.log(2, res.data.data.userRead.likeAmount)
  977. this.setData({
  978. [likeStr]: res.data.data.userRead.likeAmount,
  979. [commentStr]: res.data.data.userRead.commentAmount,
  980. [playStr]: res.data.data.userRead.playAmount,
  981. [shareStr]: res.data.data.userRead.shareAmount,
  982. [collectStr]: res.data.data.userRead.collectAmount,
  983. }, () => {
  984. console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
  985. })
  986. })
  987. }
  988. },
  989. courseCollectTap: function collectClass(e) {
  990. console.log('收藏按钮', e);
  991. const data = {
  992. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  993. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  994. }
  995. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  996. let str = `coursesData[${index}].isFavorites`
  997. httpRequestApi.collectClass(data).success((res) => {
  998. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  999. this.setData({
  1000. [str]: !this.data.coursesData[index].isFavorites
  1001. })
  1002. });
  1003. },
  1004. coursesOpenShare: function coursesOpenShare(e) {
  1005. const obj = e.currentTarget.dataset
  1006. console.log('分享', obj)
  1007. console.log('分享', e)
  1008. if (1) {
  1009. this.shareDialog = this.selectComponent("#share-dialog");
  1010. const data = {
  1011. avatar: obj.avatar,
  1012. author: obj.author,
  1013. iconImg: obj.iconImg,
  1014. title: obj.title,
  1015. path: `pages/index/index`,
  1016. scene: obj.id,
  1017. productId: 1
  1018. // tip: this.data.tip,
  1019. }
  1020. // console.log(data)
  1021. this.setData({
  1022. noScroll: 'noScroll',
  1023. shareTitle: obj.title,
  1024. shareId: obj.id,
  1025. shareImg: obj.shareimg
  1026. })
  1027. this.shareDialog.share(data);
  1028. }
  1029. },
  1030. collectTap: function(e) {
  1031. const index = e.detail.index;
  1032. let str = `videoList[${index}].isFavorite`;
  1033. let str2 = `videoList[${index}].favoritesAmount`;
  1034. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  1035. this.setData({
  1036. [str]: e.detail.isCollect,
  1037. [str2]: favoritesAmount
  1038. })
  1039. },
  1040. likeTap: function(e) {
  1041. console.log('点赞', e)
  1042. const index = e.detail.index;
  1043. let likeStr = `videoList[${index}].isLike`;
  1044. let likeNumStr = `videoList[${index}].likes`;
  1045. this.setData({
  1046. [likeStr]: true,
  1047. [likeNumStr]: this.data.videoList[index].likes + 1
  1048. })
  1049. },
  1050. addShareAmount: function(e) {
  1051. let str = `videoList[${e.detail.index}].shareAmount`;
  1052. this.setData({
  1053. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  1054. })
  1055. },
  1056. /**
  1057. * 跳转到活动页
  1058. */
  1059. goToActivity() {
  1060. httpRequestApi.postActEvent('BANNER').success(res => {
  1061. console.log('活动banner', res)
  1062. })
  1063. // wx.navigateTo({
  1064. // url: `../activity/index/index`
  1065. // // url: `../activity/rule/rule`
  1066. // });
  1067. wx.navigateTo({
  1068. url: `../activity/goodList/goodList`
  1069. });
  1070. },
  1071. /**
  1072. * banner点击
  1073. */
  1074. bannerTap() {
  1075. if (!this.data.isLogin) {
  1076. wx.navigateTo({
  1077. url: `../../pages/login/login?index=0`
  1078. });
  1079. return;
  1080. }
  1081. if (this.data.isIos || this.data.isVip) {
  1082. this.myPlase();
  1083. } else {
  1084. this.messageAuth();
  1085. }
  1086. },
  1087. /**活动改版 */
  1088. // myPlase() {
  1089. // if (!wx.getStorageSync('message')) {
  1090. // wx.requestSubscribeMessage({
  1091. // tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1092. // '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1093. // ],
  1094. // success: (res) => {
  1095. // console.log(res)
  1096. // if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1097. // console.log('用户不同意订阅')
  1098. // // 用户不同意订阅
  1099. // wx.setStorageSync('message', false)
  1100. // } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1101. // console.log('订阅成功')
  1102. // // 用户点击统一订阅
  1103. // wx.setStorageSync('message', true)
  1104. // }
  1105. // wx.navigateTo({
  1106. // url: `../vipActivity/vipActivity`
  1107. // });
  1108. // },
  1109. // fail: () => {
  1110. // wx.navigateTo({
  1111. // url: `../vipActivity/vipActivity`
  1112. // });
  1113. // }
  1114. // })
  1115. // } else {
  1116. // wx.navigateTo({
  1117. // url: `../vipActivity/vipActivity`
  1118. // });
  1119. // }
  1120. // },
  1121. // 弹窗提示
  1122. helpPayHideEvent() {
  1123. this.setData({
  1124. helpPayHide: !this.data.helpPayHide
  1125. })
  1126. },
  1127. // 支付或者助力
  1128. payAndHelp() {
  1129. if (!this.data.isLogin) {
  1130. wx.navigateTo({
  1131. url: `../../pages/login/login?index=0`
  1132. });
  1133. return;
  1134. }
  1135. if (this.data.iphoneType === 'ios') {
  1136. httpRequestApi.postUserHelp().success(res => {
  1137. console.log(res)
  1138. if (res.data.data) {
  1139. this.setData({
  1140. tipsType: 'tips',
  1141. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/help_success.png'
  1142. })
  1143. } else {
  1144. this.setData({
  1145. tipsType: 'tips',
  1146. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/helped.png'
  1147. })
  1148. }
  1149. })
  1150. } else {
  1151. // 去支付需要获取权限
  1152. this.messageAuth();
  1153. }
  1154. },
  1155. // 去产品页
  1156. goToPruduct() {
  1157. wx.navigateTo({
  1158. url: `../product/product?price=${this.data.myData.price}`
  1159. });
  1160. },
  1161. // 授权
  1162. messageAuth() {
  1163. if (!wx.getStorageSync('message')) {
  1164. wx.requestSubscribeMessage({
  1165. tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1166. '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1167. ],
  1168. success: (res) => {
  1169. console.log(res)
  1170. if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1171. console.log('用户不同意订阅')
  1172. wx.setStorageSync('message', false)
  1173. } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1174. console.log('订阅成功')
  1175. wx.setStorageSync('message', true)
  1176. }
  1177. this.order();
  1178. },
  1179. fail: () => {
  1180. this.order();
  1181. }
  1182. })
  1183. } else {
  1184. this.order();
  1185. }
  1186. },
  1187. // 支付
  1188. order() {
  1189. // 渠道id
  1190. const productId = wx.getStorageSync('productId');
  1191. httpRequestApi.createOrder(productId).success(res => {
  1192. console.log(res.data.data.package);
  1193. const timeStamp = res.data.data.timeStamp;
  1194. const nonceStr = res.data.data.nonceStr;
  1195. const packages = res.data.data.package;
  1196. const paySign = res.data.data.sign;
  1197. wx.requestPayment({
  1198. timeStamp,
  1199. nonceStr,
  1200. package: packages,
  1201. signType: 'MD5',
  1202. paySign,
  1203. success: (res) => {
  1204. if (this.data.iphoneType === 'iphone') {
  1205. this.setData({
  1206. tipsType: 'tips',
  1207. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/success.png'
  1208. })
  1209. }
  1210. httpRequestApi.getAuthActivity().success(res => {
  1211. if (!res.data.data) {
  1212. wx.setStorageSync('vip', false)
  1213. wx.setStorageSync('date', '')
  1214. } else {
  1215. wx.setStorageSync('vip', true)
  1216. wx.setStorageSync('date', res.data.data)
  1217. this.setData({
  1218. ['myData.isVIP']: true,
  1219. ['myData.date']: res.data.data
  1220. })
  1221. this.showGift();
  1222. }
  1223. }).fail(error => {
  1224. console.log(error)
  1225. })
  1226. },
  1227. fail(res) {}
  1228. })
  1229. })
  1230. },
  1231. // 助力或者支付提示
  1232. tips() {
  1233. console.log('支付完了')
  1234. this.setData({
  1235. helpPayHide: true
  1236. })
  1237. this.updateData("2");
  1238. },
  1239. // 购买成功告诉首页显示邀请有礼
  1240. showGift() {
  1241. console.log('通知')
  1242. this.setData({
  1243. isVip: true
  1244. })
  1245. },
  1246. // 首页获取权限
  1247. getHelpAuth() {
  1248. httpRequestApi.getAuthActivity().success(res => {
  1249. if (!res.data.data) {
  1250. wx.setStorageSync('vip', false)
  1251. wx.setStorageSync('date', '')
  1252. this.setData({
  1253. isVip: false
  1254. })
  1255. } else {
  1256. wx.setStorageSync('vip', true)
  1257. wx.setStorageSync('date', res.data.data)
  1258. this.setData({
  1259. isVip: true
  1260. })
  1261. }
  1262. }).fail(error => {
  1263. console.log(error)
  1264. })
  1265. },
  1266. // 分享作品逻辑
  1267. creatShare(video) {
  1268. return new Promise((resolve, reject) => {
  1269. let context = wx.createSelectorQuery();
  1270. context
  1271. .select('#share')
  1272. .fields({
  1273. node: true,
  1274. size: true
  1275. }).exec((res) => {
  1276. const canvas = res[0].node;
  1277. const ctx = canvas.getContext('2d');
  1278. const dpr = wx.getSystemInfoSync().pixelRatio;
  1279. canvas.width = res[0].width * dpr;
  1280. canvas.height = res[0].height * dpr;
  1281. ctx.scale(dpr, dpr);
  1282. ctx.font = '14px PingFang';
  1283. let pic = canvas.createImage();
  1284. pic.src = video.coverImg; //可以是本地,也可以是网络图片
  1285. pic.onload = () => {
  1286. ctx.drawImage(pic, 0, 0, 375, 211);
  1287. }
  1288. let peiyin = canvas.createImage();
  1289. peiyin.src = '/static/image/peiyin.jpg';
  1290. peiyin.onload = () => {
  1291. ctx.drawImage(peiyin, 0, 211, 375, 89);
  1292. // 收藏,一个一个渲染
  1293. let sc = canvas.createImage();
  1294. sc.src = '/static/image/no_collect.png'
  1295. sc.onload = () => {
  1296. ctx.drawImage(sc, 12, 220, 20, 20)
  1297. ctx.fillText('收藏', 36, 238)
  1298. //分享
  1299. let fx = canvas.createImage();
  1300. fx.src = '/static/index/share.png'
  1301. fx.onload = () => {
  1302. ctx.drawImage(fx, 78, 220, 22, 22)
  1303. ctx.fillText('分享', 104, 238)
  1304. //点赞
  1305. let dz = canvas.createImage();
  1306. dz.src = video.isLike ? '/static/index/heart_colored.png' : '/static/index/heart.png'
  1307. dz.onload = () => {
  1308. ctx.drawImage(dz, 258, 222, 22, 22)
  1309. ctx.fillText(video.likes, 284, 238)
  1310. //评论
  1311. let pl = canvas.createImage();
  1312. pl.src = '/static/index/comment.png'
  1313. pl.onload = () => {
  1314. ctx.drawImage(pl, 318, 222, 22, 22)
  1315. ctx.fillText(video.commentAmount, 340, 238)
  1316. setTimeout(() => {
  1317. wx.canvasToTempFilePath({
  1318. canvas: canvas,
  1319. success(res) {
  1320. resolve({
  1321. title: '请欣赏我的课文朗读作品,点赞+评论。',
  1322. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1323. imageUrl: res.tempFilePath
  1324. })
  1325. },
  1326. fail(res) {
  1327. reject()
  1328. }
  1329. }, this)
  1330. }, 500)
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. })
  1337. })
  1338. },
  1339. onShareTimeline: function() {
  1340. return {
  1341. title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
  1342. query: `uid=${wx.getStorageSync('uid')}`,
  1343. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
  1344. }
  1345. },
  1346. onShareAppMessage({
  1347. target
  1348. }) {
  1349. let video = target.dataset.info
  1350. const promise = new Promise(resolve => {
  1351. this.creatShare(video).then(res => {
  1352. resolve(res)
  1353. })
  1354. })
  1355. return {
  1356. title: '请欣赏我的课文朗读作品,点赞+评论。',
  1357. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1358. imageUrl: video.coverImg,
  1359. promise
  1360. }
  1361. }
  1362. })