index.js 49 KB

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