index.js 49 KB

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