details.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="d-flex flex-column bg-base pb-45">
  3. <SimplePageContentLoader :loader="loader">
  4. <template v-if="loader.content.value">
  5. <view class="d-flex flex-col">
  6. <swiper
  7. v-if="loader.content.value.images.length > 0"
  8. circular
  9. :indicator-dots="true"
  10. :autoplay="true"
  11. :interval="3000"
  12. :duration="1000"
  13. class="height-500"
  14. >
  15. <swiper-item v-for="(item, key) in loader.content.value.images" :key="key">
  16. <view class="item">
  17. <image
  18. :src="item"
  19. class="w-100 height-500 radius-base"
  20. mode="aspectFill"
  21. @click="onPreviewImage(key)"
  22. />
  23. </view>
  24. </swiper-item>
  25. </swiper>
  26. <image
  27. v-else-if="loader.content.value.image"
  28. class="w-100 radius-base"
  29. :src="loader.content.value.image"
  30. mode="widthFix"
  31. />
  32. <view class="d-flex flex-col p-3">
  33. <view class="size-ll color-title-text">{{ loader.content.value.title }}</view>
  34. <view class="d-flex flex-row mt-2">
  35. <text v-if="loader.content.value.from" class="size-s color-text-content-second">来源:{{ loader.content.value.from }}</text>
  36. <text class="ml-2 size-s color-text-content-second">{{ DataDateUtils.formatDate(loader.content.value.publishAt, 'YYYY-MM-dd') }}</text>
  37. </view>
  38. </view>
  39. <view class="p-3 radius-ll bg-light mt-3">
  40. <u-parse
  41. v-if="loader.content.value.content"
  42. :content="loader.content.value.content"
  43. :tagStyle="commonParserStyle"
  44. ></u-parse>
  45. </view>
  46. <ContentNote />
  47. </view>
  48. <view class="bottom-actions">
  49. <view class="action">
  50. <text class="iconfont icon-read"></text>
  51. {{ loader.content.value.views }}
  52. </view>
  53. <view class="action">
  54. <text class="iconfont icon-like" v-if="!loader.content.value.isLike"></text>
  55. <text class="iconfont icon-liked" v-else></text>
  56. {{ loader.content.value.likes }}
  57. </view>
  58. </view>
  59. </template>
  60. </SimplePageContentLoader>
  61. </view>
  62. </template>
  63. <script setup lang="ts">
  64. import type { GetContentDetailItem } from "@/api/CommonContent";
  65. import { onShareTimeline, onShareAppMessage } from "@dcloudio/uni-app";
  66. import { DataDateUtils } from "@imengyu/js-request-transform";
  67. import { useSimplePageContentLoader } from "@/common/composeabe/SimplePageContentLoader";
  68. import { useSwiperImagePreview } from "@/common/composeabe/SwiperImagePreview";
  69. import { useLoadQuerys } from "@/common/composeabe/LoadQuerys";
  70. import NewsIndexContent from "@/api/news/NewsIndexContent";
  71. import commonParserStyle from "@/common/style/commonParserStyle";
  72. import SimplePageContentLoader from "@/common/components/SimplePageContentLoader.vue";
  73. import ContentNote from "../parts/ContentNote.vue";
  74. const loader = useSimplePageContentLoader<
  75. GetContentDetailItem,
  76. { id: number }
  77. >(async (params) => {
  78. if (!params)
  79. throw new Error("!params");
  80. const res = await NewsIndexContent.getContentDetail(params.id);
  81. //console.log(res);
  82. uni.setNavigationBarTitle({ title: res.title });
  83. return res;
  84. });
  85. const { onPreviewImage } = useSwiperImagePreview(() => loader.content.value?.images || [])
  86. useLoadQuerys({ id : 0, }, (p) => loader.loadData(p));
  87. function getPageShareData() {
  88. if (!loader.content.value)
  89. return { title: '文章详情', imageUrl: '' }
  90. return {
  91. title: loader.content.value.title,
  92. imageUrl: loader.content.value.images[0],
  93. }
  94. }
  95. onShareTimeline(() => {
  96. return getPageShareData();
  97. })
  98. onShareAppMessage(() => {
  99. return getPageShareData();
  100. })
  101. </script>
  102. <style lang="scss" scoped>
  103. .bottom-actions {
  104. position: fixed;
  105. bottom: 0;
  106. left: 0;
  107. right: 0;
  108. display: flex;
  109. align-items: center;
  110. justify-content: flex-end;
  111. width: 100%;
  112. height: 75rpx;
  113. background: #FFFFFF;
  114. .action {
  115. margin-left: 48rpx;
  116. font-weight: 800;
  117. font-size: 24rpx;
  118. color: #191919;
  119. display: flex;
  120. align-items: center;
  121. &:last-child {
  122. margin-right: 70rpx;
  123. }
  124. .iconfont {
  125. font-size: 30rpx;
  126. margin-right: 14rpx;
  127. }
  128. .iconfont.icon-liked {
  129. color: #FF8719;
  130. }
  131. }
  132. }
  133. </style>