NewsView.vue 5.2 KB

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