TabDetailView.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <!-- 文物详情页 -->
  3. <div class="main-background">
  4. <div class="nav-placeholder"></div>
  5. <!-- 新闻 -->
  6. <section class="main-section main-background main-background-type0 small-h">
  7. <SimplePageContentLoader :loader="loader">
  8. <div v-if="loader.content.value" class="content news-detail">
  9. <div class="d-flex flex-row justify-content-start">
  10. <div class="back-button2" @click="back">
  11. <img src="@/assets/images/news/IconBack.png" />
  12. <span>返回列表</span>
  13. </div>
  14. </div>
  15. <h1>{{ loader.content.value.title }}</h1>
  16. <p class="small-info">
  17. {{ loader.content.value.address }}
  18. </p>
  19. <!-- Tab -->
  20. <TagBar
  21. class="mb-3"
  22. :tags="contentProps.tabs.filter(p => p.visible).map((p, i) => ({ id: i, name: p.text })) || []"
  23. :margin="[30, 70]"
  24. v-model:selectedTag="currentTabIndex"
  25. />
  26. <!-- 基础信息 -->
  27. <div v-if="currentTabIndex==0">
  28. <!-- 轮播 -->
  29. <Carousel
  30. :itemsToShow="1"
  31. wrapAround
  32. :autoPlay="5000"
  33. class="carousel"
  34. >
  35. <Slide v-for="(image, key) in loader.content.value.images" :key="key">
  36. <img :src="image" />
  37. </Slide>
  38. <template #addons>
  39. <Navigation />
  40. <Pagination />
  41. </template>
  42. </Carousel>
  43. <slot name="extraInfo" :content="loader.content.value" />
  44. <SimpleRichHtml
  45. class="news-content"
  46. :contents="[
  47. loader.content.value.intro,
  48. loader.content.value.value,
  49. loader.content.value.content,
  50. ]"
  51. />
  52. </div>
  53. <!-- 图片 -->
  54. <div v-else-if="currentTabIndex==1">
  55. <ImageGrid
  56. v-if="loader.content.value.images && loader.content.value.images.length > 0"
  57. :data="loader.content.value.images"
  58. imageHeight="300px"
  59. @itemClick="handleShowImage"
  60. >
  61. </ImageGrid>
  62. <a-empty v-else />
  63. </div>
  64. <!-- 视频 -->
  65. <div v-else-if="currentTabIndex==2">
  66. <video
  67. v-if="loader.content.value.video"
  68. class="news-video mt-3"
  69. controls
  70. :src="loader.content.value.video"
  71. />
  72. <video
  73. v-if="loader.content.value.audio"
  74. class="news-video mt-3"
  75. controls
  76. :src="loader.content.value.audio"
  77. />
  78. <a-empty v-if="!loader.content.value.video && !loader.content.value.audio" />
  79. </div>
  80. <!-- 其他 -->
  81. <div v-else>
  82. <slot name="extraTab" :currentTabIndex="currentTabIndex" :content="loader.content.value" />
  83. </div>
  84. <ContentNode />
  85. <div class="row d-flex justify-content-center">
  86. <div class="back-button" @click="back">
  87. <img src="@/assets/images/news/IconBack.png" />
  88. <span>返回列表</span>
  89. </div>
  90. </div>
  91. </div>
  92. </SimplePageContentLoader>
  93. </section>
  94. <a-image
  95. :width="200"
  96. :style="{ display: 'none' }"
  97. :preview="{
  98. visible: imagePreviewVisible,
  99. onVisibleChange: (v: boolean) => imagePreviewVisible = v,
  100. }"
  101. :src="imagePreviewSrc"
  102. />
  103. </div>
  104. </template>
  105. <script setup lang="ts">
  106. import { Carousel, Slide, Pagination, Navigation } from 'vue3-carousel'
  107. import type { GetContentDetailItem } from '@/api/CommonContent';
  108. import SimplePageContentLoader from '@/components/content/SimplePageContentLoader.vue';
  109. import SimpleRichHtml from '@/components/display/SimpleRichHtml.vue';
  110. import { useLoadQuerys } from '@/composeable/PageQuerys';
  111. import { useSimpleDataLoader } from '@/composeable/SimpleDataLoader';
  112. import { useRouter } from 'vue-router';
  113. import ContentNode from '@/components/content/ContentNode.vue';
  114. import { computed, ref, type PropType } from 'vue';
  115. import TagBar from '@/components/content/TagBar.vue';
  116. import ImageGrid from '@/components/content/ImageGrid.vue';
  117. const props = defineProps({
  118. load: {
  119. type: Function as PropType<(id: number) => Promise<GetContentDetailItem>>,
  120. default: null,
  121. }
  122. })
  123. const imagePreviewVisible = ref(false);
  124. const imagePreviewSrc = ref('');
  125. function handleShowImage(url: string) {
  126. imagePreviewVisible.value = true;
  127. imagePreviewSrc.value = url;
  128. }
  129. const router = useRouter();
  130. const loader = useSimpleDataLoader<
  131. GetContentDetailItem,
  132. { id: number }
  133. >(async (params) => {
  134. if (!params)
  135. throw new Error("!params");
  136. if (!props.load)
  137. throw new Error("!props.load");
  138. return props.load(params.id);
  139. });
  140. const currentTabIndex = ref(0);
  141. const contentProps = computed(() => {
  142. return loader.content.value?.contentProps as {
  143. tabs: {
  144. text: string,
  145. visible: boolean,
  146. }[],
  147. } ?? {
  148. tabs: [],
  149. };
  150. })
  151. useLoadQuerys({
  152. id: 0
  153. }, async ({ id }) => {
  154. if (id <= 0) {
  155. router.push({ name: 'NotFound' });
  156. return;
  157. }
  158. loader.loadData({ id });
  159. })
  160. function back() {
  161. router.back();
  162. }
  163. </script>
  164. <style lang="scss">
  165. </style>