index.js 50 KB

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