article-detail.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="article-detail">
  3. <custom-nav ref="ltm" :title="title" />
  4. <view class="content">
  5. <view class="article-header">
  6. <image class="head-pic" :src="article.avatar"></image>
  7. <view class="name">
  8. <text>{{ article.author }}</text>
  9. <text v-if="article.off == 1" class="identity">官方</text>
  10. </view>
  11. <text class="time">{{ article.created_at | DistanceNow }}</text>
  12. </view>
  13. <view class="webview">
  14. <web-view :webview-styles="webviewStyles" :src="baseURL + '?id=' + article.id"></web-view>
  15. </view>
  16. <view class="article-footer">
  17. <view class="footer-item" @tap="like()">
  18. <text v-if="article.like" class="cuIcon-appreciatefill fill icon-right left"></text>
  19. <text v-else class="cuIcon-appreciate icon-right left"></text>
  20. <text>点赞</text>
  21. </view>
  22. <view class="footer-item center" @tap="collection()">
  23. <text v-if="article.collection" class="cuIcon-likefill fill icon-right"></text>
  24. <text v-else class="cuIcon-like icon-right"></text>
  25. <text>收藏</text>
  26. </view>
  27. <view class="footer-item" @tap="share">
  28. <text class="cuIcon-forward icon-right right"></text>
  29. <text>分享</text>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import _share from '@/common/util/share.js'
  37. import { ArticleURL } from '@/common/util/request.js'
  38. export default {
  39. data() {
  40. return {
  41. typeIndex: -1,
  42. listIndex: -1,
  43. isIndex: false,
  44. baseURL: ArticleURL,
  45. webviewStyles: {
  46. progress: {
  47. color: '#F76454'
  48. }
  49. }
  50. }
  51. },
  52. computed: {
  53. article() {
  54. if (this.isIndex) {
  55. return this.$store.state.article.index
  56. } else {
  57. return this.$store.state.article.lists[this.typeIndex][this.listIndex]
  58. }
  59. },
  60. title() {
  61. return this.article.type === 1 ? '视频详情' : '文章详情'
  62. }
  63. },
  64. onLoad(opt) {
  65. if (opt.fromIndex) { // 是否是从首页的文章点进来的
  66. this.isIndex = true
  67. } else {
  68. this.typeIndex = +opt.type
  69. this.listIndex = +opt.index
  70. }
  71. setTimeout(() => console.log(this.article), 1234)
  72. this.$offset('.webview').then(res => {
  73. setTimeout(() => {
  74. this.$mp.page.$getAppWebview().children()[0].setStyle({ top: res.top, height: res.height })
  75. }, 345)
  76. })
  77. },
  78. onBackPress() { // 返回时收起分享
  79. if (uni._SHARE && uni._SHARE.isVisible()) {
  80. uni._MASK.hide()
  81. uni._SHARE.hide()
  82. return true
  83. }
  84. },
  85. methods: {
  86. like() { // 点赞
  87. if (this.isIndex) {
  88. this.$store.commit('article/LIKEINDEX')
  89. } else {
  90. this.$store.commit('article/LIKE', { listsIndex: this.typeIndex, commuIndex: this.listIndex })
  91. }
  92. },
  93. collection() { // 收藏
  94. if (this.isIndex) {
  95. this.$store.commit('article/COLLECTIONINDEX')
  96. } else {
  97. this.$store.commit('article/COLLECTION', { listsIndex: this.typeIndex, commuIndex: this.listIndex })
  98. }
  99. },
  100. share() {
  101. _share({
  102. type: 0,
  103. title: this.article.title,
  104. summary: this.article.summary,
  105. imageUrl: this.article.imgurl[0],
  106. href: ArticleURL + '?id=' + this.article.id
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss">
  113. .article-detail {
  114. @include page();
  115. .content {
  116. @include flex(column);
  117. background: #FFFFFF;
  118. .article-header {
  119. width: 100%;
  120. padding: 0 30rpx;
  121. box-sizing: border-box;
  122. }
  123. .webview {
  124. flex: 1;
  125. width: 100%;
  126. }
  127. .article-footer {
  128. width: 100%;
  129. height: 88rpx;
  130. }
  131. }
  132. }
  133. </style>