index.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  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. return;
  930. /* getOpenidNoLogin((res) => {
  931. console.log('getOpenidNoLogin', res)
  932. // 登录或注册完成 展示页面
  933. if (res.data.data.nickName) {
  934. this.setData({
  935. isLogin: true
  936. })
  937. } else {
  938. this.setData({
  939. isLogin: false
  940. })
  941. }
  942. this.showPage()
  943. }, (error) => {
  944. console.log('获取失败')
  945. wx.setStorageSync('userSourseType', 'normal')
  946. this.setData({
  947. hide: !this.data.hide
  948. })
  949. }, grade); */
  950. },
  951. getFollowData: function() {
  952. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  953. if (res.data.data.totalSize === 0) {
  954. this.setData({
  955. videoList: [],
  956. noFollow: true
  957. })
  958. console.log('没有关注人或关注的人没有发过作品')
  959. return
  960. } else {
  961. this.setData({
  962. noFollow: false
  963. })
  964. }
  965. console.log('关注列表', res)
  966. const followData = res.data.data.list;
  967. // const videoList = [];
  968. this.formatWorksList(followData);
  969. });
  970. httpRequestApi.userEvent('SUBSCRIBE');
  971. },
  972. // 点击用户头像区域
  973. headTapHandler: function(e) {
  974. console.log('点击头像', e)
  975. let tapId = e.detail.activeId;
  976. // 点击头像既关注 测试
  977. httpRequestApi.followUser(this.uid, tapId).success(res => {
  978. console.log(res)
  979. })
  980. },
  981. getCoursesList: function() {
  982. const grade = wx.getStorageSync('grade');
  983. const data = {
  984. pageNo: this.data.coursePageNo,
  985. pageSize: 6,
  986. grade,
  987. type: 'EXAMPLE'
  988. };
  989. console.log('资源', data)
  990. httpRequestApi.getClassRead(data).success(res => {
  991. console.log('资源', this.data.coursesData)
  992. this.setData({
  993. coursesData: this.data.coursesData.concat(res.data.data.list),
  994. noMoreWork: res.data.data.list.length <= 0 ? true : false
  995. }, () => {
  996. console.log(this.data.coursesData)
  997. })
  998. })
  999. httpRequestApi.userEvent('RESOURCES');
  1000. },
  1001. goToReading: function(e) {
  1002. console.log('去朗读', e)
  1003. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  1004. const index = e.currentTarget.dataset.index;
  1005. this.setData({
  1006. goToCoursesId: id,
  1007. goToCoursesIndex: index
  1008. })
  1009. wx.navigateTo({
  1010. url: `../../pages/reading/reading?id=${id}`
  1011. });
  1012. httpRequestApi.userEvent('REC_READ');
  1013. },
  1014. refreshCourseAmount() {
  1015. console.log(this.data.goToCoursesId)
  1016. console.log(this.data.goToCoursesIndex)
  1017. if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
  1018. httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
  1019. console.log('刷新', res.data.data.userRead)
  1020. let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
  1021. let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
  1022. let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
  1023. let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
  1024. let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
  1025. console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
  1026. console.log(2, res.data.data.userRead.likeAmount)
  1027. this.setData({
  1028. [likeStr]: res.data.data.userRead.likeAmount,
  1029. [commentStr]: res.data.data.userRead.commentAmount,
  1030. [playStr]: res.data.data.userRead.playAmount,
  1031. [shareStr]: res.data.data.userRead.shareAmount,
  1032. [collectStr]: res.data.data.userRead.collectAmount,
  1033. }, () => {
  1034. console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
  1035. })
  1036. })
  1037. }
  1038. },
  1039. courseCollectTap: function collectClass(e) {
  1040. console.log('收藏按钮', e);
  1041. const data = {
  1042. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  1043. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  1044. }
  1045. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  1046. let str = `coursesData[${index}].isFavorites`
  1047. httpRequestApi.collectClass(data).success((res) => {
  1048. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  1049. this.setData({
  1050. [str]: !this.data.coursesData[index].isFavorites
  1051. })
  1052. });
  1053. },
  1054. coursesOpenShare: function coursesOpenShare(e) {
  1055. const obj = e.currentTarget.dataset
  1056. console.log('分享', obj)
  1057. console.log('分享', e)
  1058. if (1) {
  1059. this.shareDialog = this.selectComponent("#share-dialog");
  1060. const data = {
  1061. avatar: obj.avatar,
  1062. author: obj.author,
  1063. iconImg: obj.iconImg,
  1064. title: obj.title,
  1065. path: `pages/index/index`,
  1066. scene: obj.id,
  1067. productId: 1
  1068. // tip: this.data.tip,
  1069. }
  1070. // console.log(data)
  1071. this.setData({
  1072. noScroll: 'noScroll',
  1073. shareTitle: obj.title,
  1074. shareId: obj.id,
  1075. shareImg: obj.shareimg
  1076. })
  1077. this.shareDialog.share(data);
  1078. }
  1079. },
  1080. collectTap: function(e) {
  1081. const index = e.detail.index;
  1082. let str = `videoList[${index}].isFavorite`;
  1083. let str2 = `videoList[${index}].favoritesAmount`;
  1084. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  1085. this.setData({
  1086. [str]: e.detail.isCollect,
  1087. [str2]: favoritesAmount
  1088. })
  1089. },
  1090. likeTap: function(e) {
  1091. console.log('点赞', e)
  1092. const index = e.detail.index;
  1093. let likeStr = `videoList[${index}].isLike`;
  1094. let likeNumStr = `videoList[${index}].likes`;
  1095. this.setData({
  1096. [likeStr]: true,
  1097. [likeNumStr]: this.data.videoList[index].likes + 1
  1098. })
  1099. },
  1100. addShareAmount: function(e) {
  1101. let str = `videoList[${e.detail.index}].shareAmount`;
  1102. this.setData({
  1103. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  1104. })
  1105. },
  1106. /**
  1107. * 跳转到活动页
  1108. */
  1109. goToActivity() {
  1110. httpRequestApi.postActEvent('BANNER').success(res => {
  1111. console.log('活动banner', res)
  1112. })
  1113. // wx.navigateTo({
  1114. // url: `../activity/index/index`
  1115. // // url: `../activity/rule/rule`
  1116. // });
  1117. wx.navigateTo({
  1118. url: `../activity/goodList/goodList`
  1119. });
  1120. },
  1121. /**
  1122. * banner点击
  1123. */
  1124. bannerTap() {
  1125. if (!this.data.isLogin) {
  1126. wx.navigateTo({
  1127. url: `../../pages/login/login?index=0`
  1128. });
  1129. return;
  1130. }
  1131. if (this.data.isIos || this.data.isVip) {
  1132. this.myPlase();
  1133. } else {
  1134. this.messageAuth();
  1135. }
  1136. },
  1137. /**活动改版 */
  1138. // myPlase() {
  1139. // if (!wx.getStorageSync('message')) {
  1140. // wx.requestSubscribeMessage({
  1141. // tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1142. // '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1143. // ],
  1144. // success: (res) => {
  1145. // console.log(res)
  1146. // if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1147. // console.log('用户不同意订阅')
  1148. // // 用户不同意订阅
  1149. // wx.setStorageSync('message', false)
  1150. // } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1151. // console.log('订阅成功')
  1152. // // 用户点击统一订阅
  1153. // wx.setStorageSync('message', true)
  1154. // }
  1155. // wx.navigateTo({
  1156. // url: `../vipActivity/vipActivity`
  1157. // });
  1158. // },
  1159. // fail: () => {
  1160. // wx.navigateTo({
  1161. // url: `../vipActivity/vipActivity`
  1162. // });
  1163. // }
  1164. // })
  1165. // } else {
  1166. // wx.navigateTo({
  1167. // url: `../vipActivity/vipActivity`
  1168. // });
  1169. // }
  1170. // },
  1171. // 弹窗提示
  1172. helpPayHideEvent() {
  1173. this.setData({
  1174. helpPayHide: !this.data.helpPayHide
  1175. })
  1176. },
  1177. // 支付或者助力
  1178. payAndHelp() {
  1179. if (!this.data.isLogin) {
  1180. wx.navigateTo({
  1181. url: `../../pages/login/login?index=0`
  1182. });
  1183. return;
  1184. }
  1185. if (this.data.iphoneType === 'ios') {
  1186. httpRequestApi.postUserHelp().success(res => {
  1187. console.log(res)
  1188. if (res.data.data) {
  1189. this.setData({
  1190. tipsType: 'tips',
  1191. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/help_success.png'
  1192. })
  1193. } else {
  1194. this.setData({
  1195. tipsType: 'tips',
  1196. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/helped.png'
  1197. })
  1198. }
  1199. })
  1200. } else {
  1201. // 去支付需要获取权限
  1202. this.messageAuth();
  1203. }
  1204. },
  1205. // 去产品页
  1206. goToPruduct() {
  1207. wx.navigateTo({
  1208. url: `../product/product?price=${this.data.myData.price}`
  1209. });
  1210. },
  1211. // 授权
  1212. messageAuth() {
  1213. if (!wx.getStorageSync('message')) {
  1214. wx.requestSubscribeMessage({
  1215. tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1216. '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1217. ],
  1218. success: (res) => {
  1219. console.log(res)
  1220. if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1221. console.log('用户不同意订阅')
  1222. wx.setStorageSync('message', false)
  1223. } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1224. console.log('订阅成功')
  1225. wx.setStorageSync('message', true)
  1226. }
  1227. this.order();
  1228. },
  1229. fail: () => {
  1230. this.order();
  1231. }
  1232. })
  1233. } else {
  1234. this.order();
  1235. }
  1236. },
  1237. // 支付
  1238. order() {
  1239. // 渠道id
  1240. const productId = wx.getStorageSync('productId');
  1241. httpRequestApi.createOrder(productId).success(res => {
  1242. console.log(res.data.data.package);
  1243. const timeStamp = res.data.data.timeStamp;
  1244. const nonceStr = res.data.data.nonceStr;
  1245. const packages = res.data.data.package;
  1246. const paySign = res.data.data.sign;
  1247. wx.requestPayment({
  1248. timeStamp,
  1249. nonceStr,
  1250. package: packages,
  1251. signType: 'MD5',
  1252. paySign,
  1253. success: (res) => {
  1254. if (this.data.iphoneType === 'iphone') {
  1255. this.setData({
  1256. tipsType: 'tips',
  1257. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/success.png'
  1258. })
  1259. }
  1260. httpRequestApi.getAuthActivity().success(res => {
  1261. if (!res.data.data) {
  1262. wx.setStorageSync('vip', false)
  1263. wx.setStorageSync('date', '')
  1264. } else {
  1265. wx.setStorageSync('vip', true)
  1266. wx.setStorageSync('date', res.data.data)
  1267. this.setData({
  1268. ['myData.isVIP']: true,
  1269. ['myData.date']: res.data.data
  1270. })
  1271. this.showGift();
  1272. }
  1273. }).fail(error => {
  1274. console.log(error)
  1275. })
  1276. },
  1277. fail(res) {}
  1278. })
  1279. })
  1280. },
  1281. // 助力或者支付提示
  1282. tips() {
  1283. console.log('支付完了')
  1284. this.setData({
  1285. helpPayHide: true
  1286. })
  1287. this.updateData("2");
  1288. },
  1289. // 购买成功告诉首页显示邀请有礼
  1290. showGift() {
  1291. console.log('通知')
  1292. this.setData({
  1293. isVip: true
  1294. })
  1295. },
  1296. // 首页获取权限
  1297. getHelpAuth() {
  1298. httpRequestApi.getAuthActivity().success(res => {
  1299. if (!res.data.data) {
  1300. wx.setStorageSync('vip', false)
  1301. wx.setStorageSync('date', '')
  1302. this.setData({
  1303. isVip: false
  1304. })
  1305. } else {
  1306. wx.setStorageSync('vip', true)
  1307. wx.setStorageSync('date', res.data.data)
  1308. this.setData({
  1309. isVip: true
  1310. })
  1311. }
  1312. }).fail(error => {
  1313. console.log(error)
  1314. })
  1315. },
  1316. // 分享作品逻辑
  1317. creatShare(video) {
  1318. return new Promise((resolve, reject) => {
  1319. let context = wx.createSelectorQuery();
  1320. context
  1321. .select('#share')
  1322. .fields({
  1323. node: true,
  1324. size: true
  1325. }).exec((res) => {
  1326. const canvas = res[0].node;
  1327. const ctx = canvas.getContext('2d');
  1328. const dpr = wx.getSystemInfoSync().pixelRatio;
  1329. canvas.width = res[0].width * dpr;
  1330. canvas.height = res[0].height * dpr;
  1331. ctx.scale(dpr, dpr);
  1332. ctx.font = '14px PingFang';
  1333. let pic = canvas.createImage();
  1334. pic.src = video.coverImg; //可以是本地,也可以是网络图片
  1335. pic.onload = () => {
  1336. ctx.drawImage(pic, 0, 0, 375, 211);
  1337. }
  1338. let peiyin = canvas.createImage();
  1339. peiyin.src = '/static/image/peiyin.jpg';
  1340. peiyin.onload = () => {
  1341. ctx.drawImage(peiyin, 0, 211, 375, 89);
  1342. // 收藏,一个一个渲染
  1343. let sc = canvas.createImage();
  1344. sc.src = '/static/image/no_collect.png'
  1345. sc.onload = () => {
  1346. ctx.drawImage(sc, 12, 220, 20, 20)
  1347. ctx.fillText('收藏', 36, 238)
  1348. //分享
  1349. let fx = canvas.createImage();
  1350. fx.src = '/static/index/share.png'
  1351. fx.onload = () => {
  1352. ctx.drawImage(fx, 78, 220, 22, 22)
  1353. ctx.fillText('分享', 104, 238)
  1354. //点赞
  1355. let dz = canvas.createImage();
  1356. dz.src = video.isLike ? '/static/index/heart_colored.png' : '/static/index/heart.png'
  1357. dz.onload = () => {
  1358. ctx.drawImage(dz, 258, 222, 22, 22)
  1359. ctx.fillText(video.likes, 284, 238)
  1360. //评论
  1361. let pl = canvas.createImage();
  1362. pl.src = '/static/index/comment.png'
  1363. pl.onload = () => {
  1364. ctx.drawImage(pl, 318, 222, 22, 22)
  1365. ctx.fillText(video.commentAmount, 340, 238)
  1366. setTimeout(() => {
  1367. wx.canvasToTempFilePath({
  1368. canvas: canvas,
  1369. success(res) {
  1370. resolve({
  1371. title: video.title,
  1372. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1373. imageUrl: res.tempFilePath
  1374. })
  1375. },
  1376. fail(res) {
  1377. reject()
  1378. }
  1379. }, this)
  1380. }, 500)
  1381. }
  1382. }
  1383. }
  1384. }
  1385. }
  1386. })
  1387. })
  1388. },
  1389. onShareAppMessage({
  1390. target
  1391. }) {
  1392. let video = target.dataset.info
  1393. console.log(`/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`)
  1394. const promise = new Promise(resolve => {
  1395. this.creatShare(video).then(res => {
  1396. resolve(res)
  1397. })
  1398. })
  1399. return {
  1400. title: video.title,
  1401. path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
  1402. imageUrl: video.coverImg,
  1403. promise
  1404. }
  1405. }
  1406. })