index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <!-- 资讯动态页 -->
  3. <div class="main-background">
  4. <!-- 轮播 -->
  5. <Carousel v-bind="carouselConfig" class="main-header-box small carousel-light">
  6. <Slide class="main-header-box small">
  7. <img src="@/assets/images/news/Banner.jpg" />
  8. </Slide>
  9. <template #addons>
  10. <Pagination />
  11. </template>
  12. </Carousel>
  13. <!-- 头部搜索 -->
  14. <section class="main-section absolute light fit-small-header">
  15. <div class="content row">
  16. <div class="col-md-12 col-lg-8 col-xl-6">
  17. <div class="main-header-title d-flex flex-column">
  18. <h1 class="mt-3">闽南文化保护区资讯动态</h1>
  19. <p>查看最新相关资讯</p>
  20. <div class="d-flex flex-column flex-sm-row flex-md-row flex-lg-row">
  21. <Dropdown
  22. v-model:selectedValue="searchRegion"
  23. class="dark me-3 mb-3 mb-md-0 mb-lg-0"
  24. :options="regionData"
  25. />
  26. <SimpleInput
  27. v-model="searchValue"
  28. class="dark"
  29. placeholder="在此输入资讯动态关键词进行搜索"
  30. @search="newsLoader.loadData(undefined, true)"
  31. >
  32. <template #prefix>
  33. <img src="@/assets/images/news/IconSearch.png" alt="搜索" @click="newsLoader.loadData(undefined, true)" />
  34. </template>
  35. </SimpleInput>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="col-md-12 col-lg-4 col-xl-6">
  40. </div>
  41. </div>
  42. <!-- 头部TAB -->
  43. <!-- <div class="main-header-tab">
  44. <div class="list">
  45. <div
  46. v-for="(tab, k) in mainTabs"
  47. :key="k"
  48. :class="[ mainTabActive === tab.value ? 'active' : '' ]"
  49. @click="mainTabActive = tab.value"
  50. >
  51. {{ tab.title }}
  52. </div>
  53. </div>
  54. </div> -->
  55. </section>
  56. <!-- 新闻 -->
  57. <section class="main-section main-background main-background-type0">
  58. <div class="content news-list">
  59. <!-- 新闻列表 -->
  60. <SimplePageContentLoader :loader="newsLoader">
  61. <NuxtLink
  62. v-for="(item, k) in newsLoader.list.value"
  63. :key="item.id"
  64. class="item"
  65. :to="{ path: '/news/detail', query: { id: item.id }}"
  66. >
  67. <ImageTitleBlock
  68. :image="item.thumbnail || item.image"
  69. />
  70. <TitleDescBlock
  71. :title="item.title"
  72. :desc="item.desc || item.title"
  73. :date="DateUtils.formatDate(item.publishAt, DateUtils.FormatStrings.ShortDate)"
  74. />
  75. </NuxtLink>
  76. </SimplePageContentLoader>
  77. <!-- 分页 -->
  78. <Pagination2
  79. v-model:currentPage="newsLoader.page.value"
  80. :totalPages="newsLoader.totalPages.value"
  81. :ssrUrl="router.resolve(route).href"
  82. />
  83. </div>
  84. </section>
  85. </div>
  86. </template>
  87. <script setup lang="ts">
  88. import { Carousel, Slide, Pagination } from 'vue3-carousel'
  89. import { onMounted, ref, watch } from 'vue';
  90. import { useSSrSimplePagerDataLoader } from '@/composeable/SimplePagerDataLoader';
  91. import { useRouter } from 'vue-router';
  92. import Dropdown from '@/components/controls/Dropdown.vue';
  93. import SimpleInput from '@/components/controls/SimpleInput.vue';
  94. import Pagination2 from '@/components/controls/Pagination.vue';
  95. import TitleDescBlock from '@/components/parts/TitleDescBlock.vue';
  96. import NewsIndexContent from '@/api/news/NewsIndexContent';
  97. import CommonContent, { GetContentListParams } from '@/api/CommonContent';
  98. import { DateUtils } from '@imengyu/imengyu-utils';
  99. import SimplePageContentLoader from '@/components/content/SimplePageContentLoader.vue';
  100. import ActivityContent from '@/api/inheritor/ActivityContent';
  101. const carouselConfig = {
  102. itemsToShow: 1,
  103. wrapAround: true,
  104. autoPlay: 5000,
  105. }
  106. const mainTabs = [
  107. { title: '活动公告', value: 0 },
  108. { title: '非遗活动', value: 1 },
  109. //{ title: '活动报名', value: 2 },
  110. ]
  111. const mainTabActive = ref(0);
  112. const router = useRouter();
  113. const route = useRoute();
  114. const searchValue = ref('');
  115. const searchRegion = ref(0);
  116. const regionData = ref([
  117. { title: '不限', value: 0 },
  118. ]);
  119. const newsLoader = await useSSrSimplePagerDataLoader('news', Number(route.query.page as string || 1), 10, async (page, pageSize) => {
  120. let res
  121. switch(mainTabActive.value) {
  122. default:
  123. case 0:
  124. res = await NewsIndexContent.getContentList(new GetContentListParams()
  125. .setMainBodyColumnId([ 228/* , 298, 299 */ ])
  126. .setKeywords(searchValue.value)
  127. .setSelfValues({
  128. region: searchRegion.value === 0 ? undefined : searchRegion.value,
  129. })
  130. , page, pageSize);
  131. break;
  132. case 1:
  133. res = await ActivityContent.getContentList(new GetContentListParams()
  134. .setKeywords(searchValue.value)
  135. .setSelfValues({
  136. region: searchRegion.value === 0 ? undefined : searchRegion.value,
  137. })
  138. , page, pageSize);
  139. break;
  140. }
  141. return {
  142. data: res.list.map(p => p.toJSON()),
  143. total: res.total,
  144. };
  145. });
  146. watch(mainTabActive, () => {
  147. newsLoader.loadData(undefined, true);
  148. });
  149. watch(searchRegion, () => {
  150. newsLoader.loadData(undefined, true);
  151. });
  152. onMounted(async () => {
  153. regionData.value = [
  154. { title: '不限', value: 0 },
  155. ...((await CommonContent.getCategoryList(1)).map(p => ({
  156. title: p.title,
  157. value: p.id,
  158. }))),
  159. ]
  160. })
  161. </script>