index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. <img :src="item.image" alt="新闻图片" />
  68. <TitleDescBlock
  69. :title="item.title"
  70. :desc="item.desc || item.title"
  71. :date="DateUtils.formatDate(item.publishAt, DateUtils.FormatStrings.YearCommonShort)"
  72. />
  73. </NuxtLink>
  74. </SimplePageContentLoader>
  75. <!-- 分页 -->
  76. <Pagination2
  77. v-model:currentPage="newsLoader.page.value"
  78. :totalPages="newsLoader.totalPages.value"
  79. :ssrUrl="router.resolve(route).href"
  80. />
  81. </div>
  82. </section>
  83. </div>
  84. </template>
  85. <script setup lang="ts">
  86. import { Carousel, Slide, Pagination } from 'vue3-carousel'
  87. import { onMounted, ref, watch } from 'vue';
  88. import { useSSrSimplePagerDataLoader } from '@/composeable/SimplePagerDataLoader';
  89. import { useRouter } from 'vue-router';
  90. import Dropdown from '@/components/controls/Dropdown.vue';
  91. import SimpleInput from '@/components/controls/SimpleInput.vue';
  92. import Pagination2 from '@/components/controls/Pagination.vue';
  93. import TitleDescBlock from '@/components/parts/TitleDescBlock.vue';
  94. import NewsIndexContent from '@/api/news/NewsIndexContent';
  95. import CommonContent, { GetContentListParams } from '@/api/CommonContent';
  96. import DateUtils from '@/common/utils/DateUtils';
  97. import SimplePageContentLoader from '@/components/content/SimplePageContentLoader.vue';
  98. import ActivityContent from '@/api/inheritor/ActivityContent';
  99. const carouselConfig = {
  100. itemsToShow: 1,
  101. wrapAround: true,
  102. autoPlay: 5000,
  103. }
  104. const mainTabs = [
  105. { title: '活动公告', value: 0 },
  106. { title: '非遗活动', value: 1 },
  107. //{ title: '活动报名', value: 2 },
  108. ]
  109. const mainTabActive = ref(0);
  110. const router = useRouter();
  111. const route = useRoute();
  112. const searchValue = ref('');
  113. const searchRegion = ref(0);
  114. const regionData = ref([
  115. { title: '不限', value: 0 },
  116. ]);
  117. const newsLoader = await useSSrSimplePagerDataLoader('news', Number(route.query.page as string || 1), 10, async (page, pageSize) => {
  118. let res
  119. switch(mainTabActive.value) {
  120. default:
  121. case 0:
  122. res = await NewsIndexContent.getContentList(new GetContentListParams()
  123. .setMainBodyColumnId([ 228/* , 298, 299 */ ])
  124. .setKeywords(searchValue.value)
  125. .setSelfValues({
  126. region: searchRegion.value === 0 ? undefined : searchRegion.value,
  127. })
  128. , page, pageSize);
  129. break;
  130. case 1:
  131. res = await ActivityContent.getContentList(new GetContentListParams()
  132. .setKeywords(searchValue.value)
  133. .setSelfValues({
  134. region: searchRegion.value === 0 ? undefined : searchRegion.value,
  135. })
  136. , page, pageSize);
  137. break;
  138. }
  139. return {
  140. data: res.list.map(p => p.toJSON()),
  141. total: res.total,
  142. };
  143. });
  144. watch(mainTabActive, () => {
  145. newsLoader.loadData(undefined, true);
  146. });
  147. watch(searchRegion, () => {
  148. newsLoader.loadData(undefined, true);
  149. });
  150. onMounted(async () => {
  151. regionData.value = [
  152. { title: '不限', value: 0 },
  153. ...((await CommonContent.getCategoryList(1)).map(p => ({
  154. title: p.title,
  155. value: p.id,
  156. }))),
  157. ]
  158. })
  159. </script>