index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const App = getApp();
  2. // 富文本插件
  3. import wxParse from '../../../wxParse/wxParse.js';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. // 文章详情
  10. detail: {},
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. // 获取文章详情
  17. this.getArticleDetail(options.article_id);
  18. },
  19. /**
  20. * 获取文章详情
  21. */
  22. getArticleDetail(article_id) {
  23. let _this = this;
  24. App._get('article/detail', {
  25. article_id
  26. }, function (result) {
  27. let detail = result.data.detail;
  28. // 富文本转码
  29. if (detail.article_content.length > 0) {
  30. wxParse.wxParse('content', 'html', detail.article_content, _this, 0);
  31. }
  32. _this.setData({
  33. detail
  34. });
  35. });
  36. },
  37. /**
  38. * 分享当前页面
  39. */
  40. onShareAppMessage() {
  41. // 构建页面参数
  42. const params = App.getShareUrlParams({
  43. 'article_id': this.data.detail.article_id
  44. });
  45. return {
  46. title: this.data.detail.article_title,
  47. path: "/pages/article/detail/index?" + params
  48. };
  49. },
  50. /**
  51. * 分享到朋友圈
  52. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  53. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  54. */
  55. onShareTimeline() {
  56. // 构建页面参数
  57. const params = App.getShareUrlParams({
  58. 'article_id': this.data.detail.article_id
  59. });
  60. return {
  61. // title: this.data.detail.article_title,
  62. path: "/pages/article/detail/index?" + params
  63. };
  64. }
  65. })