Index.vue 4.1 KB

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