search.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <!-- 分类 -->
  3. <div class="main-background">
  4. <!-- SEO -->
  5. <Head>
  6. <Title>厦门市文化遗产保护中心 - 搜索</Title>
  7. <Meta name="description" content="" />
  8. <Meta name="keywords" content="" />
  9. </Head>
  10. <!-- 主要内容 -->
  11. <div class="main-content">
  12. <div class="container">
  13. <div class="row justify-content-center">
  14. <!-- 右侧内容 -->
  15. <div class="col-12 col-sm-12 col-md-8 col-lg-9">
  16. <div class="content">
  17. <div class="section-title">
  18. <h2 class="icon">搜索结果:{{ keyword }}</h2>
  19. <nav aria-label="breadcrumb">
  20. <ol class="breadcrumb">
  21. <li class="breadcrumb-item"><router-link to="/">首页</router-link></li>
  22. <li class="breadcrumb-item active" aria-current="page">搜索</li>
  23. </ol>
  24. </nav>
  25. </div>
  26. <!-- 文章列表 -->
  27. <SimplePageContentLoader :loader="articlesData">
  28. <div class="news-list">
  29. <div v-for="(item, key) in articlesData.content.value?.items" :key="key" class="news-item">
  30. <router-link :to="'/page/' + item.id" class="title">{{ item.title }}</router-link>
  31. <span class="date">{{ DateUtils.formatDate(new Date((item.publishtime || item.createtime) * 1000), 'yyyy-MM-dd') }}</span>
  32. </div>
  33. <div v-if="!articlesData.content.value || articlesData.content.value.empty" class="no-news">暂无相关文章</div>
  34. </div>
  35. <!-- 分页 -->
  36. <SimplePagination
  37. v-if="articlesData.content.value"
  38. :currPage="articlesData.content.value.pageIndex"
  39. :allPage="articlesData.content.value.allPage"
  40. :maxCount="10"
  41. />
  42. </SimplePageContentLoader>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup lang="ts">
  51. import { computed } from 'vue';
  52. import { useSSrSimpleDataLoader } from '@/composeable/SimpleDataLoader';
  53. import { DateUtils } from '@imengyu/imengyu-utils';
  54. import SimplePagination from '~/components/content/SimplePagination.vue';
  55. const route = useRoute();
  56. const keyword = route.query.keyword as string;
  57. const articlesData = await useSSrSimpleDataLoader('articles' + keyword, async () => {
  58. const res = await $fetch('/api/ecms/article/search', {
  59. method: 'GET',
  60. query: {
  61. search: keyword,
  62. page: route.query.page || 1,
  63. pageSize: 10,
  64. }
  65. });
  66. if (!res.status)
  67. throw new Error(res.message);
  68. return res.data;
  69. });
  70. watch(route, async (newVal, oldVal) => {
  71. if (newVal !== oldVal) {
  72. articlesData.loadData(undefined, true);
  73. }
  74. });
  75. </script>
  76. <style lang="scss">
  77. @use "sass:list";
  78. @use "sass:math";
  79. </style>