Index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <app-view class="news-details">
  3. <template #header>
  4. <app-navbar title="资讯详情">
  5. <!-- <template #right>
  6. <div @click="sendShareMessage" v-if="plus.hasPlus()">
  7. <Icon name="share" size=".36rem" />
  8. </div>
  9. <div :data-clipboard-text="getNewsShareUrl(newsId)" v-copy="onCopy" v-else>
  10. <Icon name="share" size=".36rem" />
  11. </div>
  12. </template> -->
  13. </app-navbar>
  14. </template>
  15. <section class="news-details__container" v-if="data">
  16. <h1>{{ data.title }}</h1>
  17. <h4>
  18. <span>来源:</span>
  19. <img :src="getFileUrl(data.srclogo)" v-if="data.srclogo" />
  20. <span @click="openUrl(data?.srcurl)" style="color:dodgerblue" v-if="data.srcname">{{ data.srcname }}</span>
  21. <span>{{ formatDate(data.publishdate, 'YYYY-MM-DD') }}</span>
  22. <span style="margin-left: auto;">阅览数: {{ data.hits }}</span>
  23. </h4>
  24. <HtmlContainer :context="formatHtmlString(data.context)" v-if="data.context" />
  25. <p style="color: #999;margin-top: .24rem;font-size: .24rem;" v-if="data.author">作者: {{ data.author }}</p>
  26. </section>
  27. <template v-if="dataList.length">
  28. <Divider>热门资讯</Divider>
  29. <CellGroup class="news-details__list">
  30. <template v-for="(item, index) in dataList" :key="index">
  31. <Cell class="article-item" title-class="article-item__title" value-class="article-item__time"
  32. :title="item.title" :value="formatDate(item.publishdate, 'MM/DD')"
  33. :to="{ name: 'news-details', query: { id: item.id } }" replace />
  34. </template>
  35. </CellGroup>
  36. </template>
  37. </app-view>
  38. </template>
  39. <script lang="ts" setup>
  40. import { CellGroup, Cell, Divider, showFailToast, showToast, Icon } from 'vant'
  41. import { formatDate, getFileUrl, getNewsShareUrl, formatHtmlString } from '@/filters'
  42. import { useNavigation } from '@/hooks/navigation'
  43. import { useRequest } from '@/hooks/request'
  44. import { queryNewTitles, queryNewContents } from '@/services/api/news'
  45. import plus from '@/utils/h5plus'
  46. import HtmlContainer from '@mobile/components/base/html-container/index.vue'
  47. const { getQueryString } = useNavigation()
  48. const newsId = getQueryString('id')
  49. const { dataList, run } = useRequest(queryNewTitles, {
  50. manual: true,
  51. params: {
  52. pagesize: 10,
  53. },
  54. onSuccess: (res) => {
  55. dataList.value = res.data.filter((e) => e.id.toString() !== newsId)
  56. }
  57. })
  58. const { data } = useRequest(queryNewContents, {
  59. params: {
  60. ids: newsId
  61. },
  62. onSuccess: (res) => {
  63. if (res.data.length) {
  64. const details = res.data[0]
  65. data.value = details
  66. run({ columnid: details.columnid })
  67. } else {
  68. run()
  69. }
  70. }
  71. })
  72. // 跳转链接
  73. const openUrl = (url?: string) => {
  74. if (url) {
  75. plus.openURL(url)
  76. }
  77. }
  78. // 分享消息
  79. const sendShareMessage = () => {
  80. if (data.value) {
  81. plus.systemShare({
  82. title: data.value.title,
  83. href: getNewsShareUrl(newsId),
  84. }).catch((err) => {
  85. showFailToast(err)
  86. })
  87. } else {
  88. showFailToast('文章不存在,分享失败')
  89. }
  90. }
  91. const onCopy = (status: boolean) => {
  92. if (status) {
  93. showToast({
  94. message: '已复制,快去粘贴吧~',
  95. position: 'bottom',
  96. })
  97. } else {
  98. showFailToast('复制失败')
  99. }
  100. }
  101. </script>
  102. <style lang="less">
  103. @import './index.less';
  104. </style>