detail.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view v-if="!isLoading" class="container b-f p-b">
  3. <view class="article-title">
  4. <text class="f-32">{{ detail.title }}</text>
  5. </view>
  6. <view class="article-little dis-flex flex-x-between m-top10">
  7. <view class="article-little__left">
  8. <text class="article-views f-24 col-8">{{ detail.show_views }}次浏览</text>
  9. </view>
  10. <view class="article-little__right">
  11. <text class="article-views f-24 col-8">{{ detail.view_time }}</text>
  12. </view>
  13. </view>
  14. <view class="article-content m-top20">
  15. <jyf-parser :html="detail.content"></jyf-parser>
  16. </view>
  17. <!-- 快捷导航 -->
  18. <shortcut />
  19. </view>
  20. </template>
  21. <script>
  22. import jyfParser from '@/components/jyf-parser/jyf-parser'
  23. import Shortcut from '@/components/shortcut'
  24. import * as ArticleApi from '@/api/article'
  25. export default {
  26. components: {
  27. Shortcut
  28. },
  29. data() {
  30. return {
  31. // 当前文章ID
  32. articleId: null,
  33. // 加载中
  34. isLoading: true,
  35. // 当前文章详情
  36. detail: null
  37. }
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. onLoad(options) {
  43. // 记录文章ID
  44. this.articleId = options.articleId
  45. // 获取文章详情
  46. this.getArticleDetail()
  47. },
  48. methods: {
  49. // 获取文章详情
  50. getArticleDetail() {
  51. const app = this
  52. app.isLoading = true
  53. ArticleApi.detail(app.articleId)
  54. .then(result => {
  55. app.detail = result.data.detail
  56. })
  57. .finally(() => app.isLoading = false)
  58. }
  59. },
  60. /**
  61. * 分享当前页面
  62. */
  63. onShareAppMessage() {
  64. const app = this
  65. // 构建页面参数
  66. const params = app.$getShareUrlParams({ articleId: app.articleId });
  67. return {
  68. title: app.detail.title,
  69. path: "/pages/article/detail?" + params
  70. }
  71. },
  72. /**
  73. * 分享到朋友圈
  74. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  75. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  76. */
  77. onShareTimeline() {
  78. const app = this
  79. // 构建页面参数
  80. const params = app.$getShareUrlParams({ articleId: app.articleId });
  81. return {
  82. title: app.detail.title,
  83. path: "/pages/article/detail?" + params
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .container {
  90. min-height: 100vh;
  91. padding: 20rpx;
  92. background: #fff;
  93. }
  94. .article-content {
  95. font-size: 28rpx;
  96. }
  97. </style>