index.js 49 KB

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