index.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  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. // 暂不跳转
  1062. // httpRequestApi.postActEvent('BANNER').success(res => {
  1063. // console.log('活动banner', res)
  1064. // })
  1065. // // wx.navigateTo({
  1066. // // url: `../activity/index/index`
  1067. // // // url: `../activity/rule/rule`
  1068. // // });
  1069. // wx.navigateTo({
  1070. // url: `../activity/goodList/goodList`
  1071. // });
  1072. },
  1073. /**
  1074. * banner点击
  1075. */
  1076. bannerTap() {
  1077. if (!this.data.isLogin) {
  1078. wx.navigateTo({
  1079. url: `../../pages/login/login?index=0`
  1080. });
  1081. return;
  1082. }
  1083. if (this.data.isIos || this.data.isVip) {
  1084. this.myPlase();
  1085. } else {
  1086. this.messageAuth();
  1087. }
  1088. },
  1089. /**活动改版 */
  1090. // myPlase() {
  1091. // if (!wx.getStorageSync('message')) {
  1092. // wx.requestSubscribeMessage({
  1093. // tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1094. // '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1095. // ],
  1096. // success: (res) => {
  1097. // console.log(res)
  1098. // if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1099. // console.log('用户不同意订阅')
  1100. // // 用户不同意订阅
  1101. // wx.setStorageSync('message', false)
  1102. // } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1103. // console.log('订阅成功')
  1104. // // 用户点击统一订阅
  1105. // wx.setStorageSync('message', true)
  1106. // }
  1107. // wx.navigateTo({
  1108. // url: `../vipActivity/vipActivity`
  1109. // });
  1110. // },
  1111. // fail: () => {
  1112. // wx.navigateTo({
  1113. // url: `../vipActivity/vipActivity`
  1114. // });
  1115. // }
  1116. // })
  1117. // } else {
  1118. // wx.navigateTo({
  1119. // url: `../vipActivity/vipActivity`
  1120. // });
  1121. // }
  1122. // },
  1123. // 弹窗提示
  1124. helpPayHideEvent() {
  1125. this.setData({
  1126. helpPayHide: !this.data.helpPayHide
  1127. })
  1128. },
  1129. // 支付或者助力
  1130. payAndHelp() {
  1131. if (!this.data.isLogin) {
  1132. wx.navigateTo({
  1133. url: `../../pages/login/login?index=0`
  1134. });
  1135. return;
  1136. }
  1137. if (this.data.iphoneType === 'ios') {
  1138. httpRequestApi.postUserHelp().success(res => {
  1139. console.log(res)
  1140. if (res.data.data) {
  1141. this.setData({
  1142. tipsType: 'tips',
  1143. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/help_success.png'
  1144. })
  1145. } else {
  1146. this.setData({
  1147. tipsType: 'tips',
  1148. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/helped.png'
  1149. })
  1150. }
  1151. })
  1152. } else {
  1153. // 去支付需要获取权限
  1154. this.messageAuth();
  1155. }
  1156. },
  1157. // 去产品页
  1158. goToPruduct() {
  1159. wx.navigateTo({
  1160. url: `../product/product?price=${this.data.myData.price}`
  1161. });
  1162. },
  1163. // 授权
  1164. messageAuth() {
  1165. if (!wx.getStorageSync('message')) {
  1166. wx.requestSubscribeMessage({
  1167. tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1168. '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1169. ],
  1170. success: (res) => {
  1171. console.log(res)
  1172. if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1173. console.log('用户不同意订阅')
  1174. wx.setStorageSync('message', false)
  1175. } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1176. console.log('订阅成功')
  1177. wx.setStorageSync('message', true)
  1178. }
  1179. this.order();
  1180. },
  1181. fail: () => {
  1182. this.order();
  1183. }
  1184. })
  1185. } else {
  1186. this.order();
  1187. }
  1188. },
  1189. // 支付
  1190. order() {
  1191. // 渠道id
  1192. const productId = wx.getStorageSync('productId');
  1193. httpRequestApi.createOrder(productId).success(res => {
  1194. console.log(res.data.data.package);
  1195. const timeStamp = res.data.data.timeStamp;
  1196. const nonceStr = res.data.data.nonceStr;
  1197. const packages = res.data.data.package;
  1198. const paySign = res.data.data.sign;
  1199. wx.requestPayment({
  1200. timeStamp,
  1201. nonceStr,
  1202. package: packages,
  1203. signType: 'MD5',
  1204. paySign,
  1205. success: (res) => {
  1206. if (this.data.iphoneType === 'iphone') {
  1207. this.setData({
  1208. tipsType: 'tips',
  1209. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/success.png'
  1210. })
  1211. }
  1212. httpRequestApi.getAuthActivity().success(res => {
  1213. if (!res.data.data) {
  1214. wx.setStorageSync('vip', false)
  1215. wx.setStorageSync('date', '')
  1216. } else {
  1217. wx.setStorageSync('vip', true)
  1218. wx.setStorageSync('date', res.data.data)
  1219. this.setData({
  1220. ['myData.isVIP']: true,
  1221. ['myData.date']: res.data.data
  1222. })
  1223. this.showGift();
  1224. }
  1225. }).fail(error => {
  1226. console.log(error)
  1227. })
  1228. },
  1229. fail(res) {}
  1230. })
  1231. })
  1232. },
  1233. // 助力或者支付提示
  1234. tips() {
  1235. console.log('支付完了')
  1236. this.setData({
  1237. helpPayHide: true
  1238. })
  1239. this.updateData("2");
  1240. },
  1241. // 购买成功告诉首页显示邀请有礼
  1242. showGift() {
  1243. console.log('通知')
  1244. this.setData({
  1245. isVip: true
  1246. })
  1247. },
  1248. // 首页获取权限
  1249. getHelpAuth() {
  1250. httpRequestApi.getAuthActivity().success(res => {
  1251. if (!res.data.data) {
  1252. wx.setStorageSync('vip', false)
  1253. wx.setStorageSync('date', '')
  1254. this.setData({
  1255. isVip: false
  1256. })
  1257. } else {
  1258. wx.setStorageSync('vip', true)
  1259. wx.setStorageSync('date', res.data.data)
  1260. this.setData({
  1261. isVip: true
  1262. })
  1263. }
  1264. }).fail(error => {
  1265. console.log(error)
  1266. })
  1267. },
  1268. // 分享作品逻辑
  1269. creatShare(video) {
  1270. return new Promise((resolve, reject) => {
  1271. let context = wx.createSelectorQuery();
  1272. context
  1273. .select('#share')
  1274. .fields({
  1275. node: true,
  1276. size: true
  1277. }).exec((res) => {
  1278. const canvas = res[0].node;
  1279. const ctx = canvas.getContext('2d');
  1280. const dpr = wx.getSystemInfoSync().pixelRatio;
  1281. canvas.width = res[0].width * dpr;
  1282. canvas.height = res[0].height * dpr;
  1283. ctx.scale(dpr, dpr);
  1284. ctx.font = '14px PingFang';
  1285. let pic = canvas.createImage();
  1286. pic.src = video.coverImg; //可以是本地,也可以是网络图片
  1287. pic.onload = () => {
  1288. ctx.drawImage(pic, 0, 0, 375, 211);
  1289. }
  1290. let peiyin = canvas.createImage();
  1291. peiyin.src = '/static/image/peiyin.jpg';
  1292. peiyin.onload = () => {
  1293. ctx.drawImage(peiyin, 0, 211, 375, 89);
  1294. // 收藏,一个一个渲染
  1295. let sc = canvas.createImage();
  1296. sc.src = '/static/image/no_collect.png'
  1297. sc.onload = () => {
  1298. ctx.drawImage(sc, 12, 220, 20, 20)
  1299. ctx.fillText('收藏', 36, 238)
  1300. //分享
  1301. let fx = canvas.createImage();
  1302. fx.src = '/static/index/share.png'
  1303. fx.onload = () => {
  1304. ctx.drawImage(fx, 78, 220, 22, 22)
  1305. ctx.fillText('分享', 104, 238)
  1306. //点赞
  1307. let dz = canvas.createImage();
  1308. dz.src = video.isLike ? '/static/index/heart_colored.png' : '/static/index/heart.png'
  1309. dz.onload = () => {
  1310. ctx.drawImage(dz, 258, 222, 22, 22)
  1311. ctx.fillText(video.likes, 284, 238)
  1312. //评论
  1313. let pl = canvas.createImage();
  1314. pl.src = '/static/index/comment.png'
  1315. pl.onload = () => {
  1316. ctx.drawImage(pl, 318, 222, 22, 22)
  1317. ctx.fillText(video.commentAmount, 340, 238)
  1318. setTimeout(() => {
  1319. wx.canvasToTempFilePath({
  1320. canvas: canvas,
  1321. success(res) {
  1322. resolve({
  1323. title: '请欣赏我的课文朗读作品,点赞+评论。',
  1324. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1325. imageUrl: res.tempFilePath
  1326. })
  1327. },
  1328. fail(res) {
  1329. reject()
  1330. }
  1331. }, this)
  1332. }, 500)
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. })
  1339. })
  1340. },
  1341. onShareTimeline: function() {
  1342. return {
  1343. title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
  1344. query: `uid=${wx.getStorageSync('uid')}`,
  1345. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
  1346. }
  1347. },
  1348. onShareAppMessage({
  1349. from,
  1350. target
  1351. }) {
  1352. if (from == 'button') {
  1353. let video = target.dataset.info
  1354. const promise = new Promise(resolve => {
  1355. this.creatShare(video).then(res => {
  1356. resolve(res)
  1357. })
  1358. })
  1359. return {
  1360. title: '请欣赏我的课文朗读作品,点赞+评论。',
  1361. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1362. imageUrl: video.coverImg,
  1363. promise
  1364. }
  1365. } else {
  1366. return {
  1367. title: '课文朗读,从未如此有趣。',
  1368. path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
  1369. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
  1370. }
  1371. }
  1372. }
  1373. })