detail.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view v-if="ready" class="page-container">
  3. <vb-cell-group>
  4. <view class="flex-column pos-r p-15">
  5. <view class="py-5 fs-20 font-bold">{{ news.title }}</view>
  6. <view class="d-flex justify-between align-center">
  7. <view class="d-fcv py-10 ps-5 text-gray-5">
  8. {{ formatDate(news.date, "YYYY-MM-DD") }} {{ news.categoryName }}
  9. </view>
  10. <vb-share :title="news.title" :path="`/sub-page/news/detail?id=${news.newsId}`" :type="0"></vb-share>
  11. </view>
  12. <view class="my-5">
  13. <rich-text :nodes="news.content"></rich-text>
  14. </view>
  15. <view class="mt-10" v-if="images.length > 0">
  16. <vb-image :images="images"></vb-image>
  17. </view>
  18. </view>
  19. </vb-cell-group>
  20. <Comment :source-id="newsId" source-type="news"></Comment>
  21. </view>
  22. <view v-else class="d-fc h-200px bg-tran">
  23. <vb-loading color="var(--vb-color)" :show-text="true"></vb-loading>
  24. </view>
  25. </template>
  26. <script lang="ts" setup>
  27. import dayjs from "dayjs"
  28. import apis from "@/api"
  29. import route from "@/route"
  30. import configs from "@/core/config"
  31. import Comment from "@/components/comment.vue"
  32. const params = route.getRouteParams("newsDetail")
  33. const ready = ref(false)
  34. const news = ref<any>({})
  35. const newsId = ref(params.id)
  36. function formatDate(date: any, format = "YYYY-MM-DD") {
  37. return dayjs(new Date(date)).format(format)
  38. }
  39. const images = computed(() => {
  40. if (news.value.images) {
  41. return news.value.images.split(",").map((item: string) => configs.baseUrl + "/oss/preview/" + item)
  42. }
  43. return []
  44. })
  45. function loadData() {
  46. if (newsId.value) {
  47. apis.amActivity.newsApi.getNews(newsId.value).then((res) => {
  48. news.value = res
  49. ready.value = true
  50. })
  51. }
  52. }
  53. function read() {
  54. if (newsId.value) {
  55. apis.amActivity.statisticsApi.read(newsId.value, "news").then(() => {})
  56. }
  57. }
  58. onLoad((e:any) => {
  59. if (!newsId.value&&e.hasOwnProperty('id')) {
  60. newsId.value=e.id
  61. }
  62. read()
  63. })
  64. onShow(loadData)
  65. </script>
  66. <style scoped></style>