index.js 50 KB

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