zhengCeFaGui.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. require_once 'CommonQuery.php';
  3. // 轮播图数据 - 修改为单张图片
  4. $carouselItems = [
  5. [
  6. "image" => "/uploads/20251013/6af88ead615998ad6c789327b26f7bbe.jpg",
  7. "alt" => "政策法规"
  8. ]
  9. ];
  10. // 获取URL参数 - 当前页码、选中的分类和搜索关键词
  11. $currentPage = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0 ? intval($_GET['page']) : 1;
  12. $selectedCategory = isset($_GET['category']) ? $_GET['category'] : '国家法律法规';
  13. $searchKeyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
  14. // 每页显示的文章数量
  15. $pageSize = 12;
  16. // 使用loadListByChannelNameAndPage函数获取政策法规数据,并传入搜索关键词
  17. $articleResult = loadListByChannelNameAndPage($pageSize, $selectedCategory, $currentPage, $searchKeyword);
  18. $policyItems = $articleResult['list'];
  19. $totalPages = $articleResult['totalPages'];
  20. ?>
  21. <!DOCTYPE html>
  22. <html lang="zh-CN">
  23. <head>
  24. <meta charset="UTF-8">
  25. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  26. <title>厦门市文化遗产保护中心 - 政策法规</title>
  27. <link rel="stylesheet" href="/css/fonts.css">
  28. <link rel="stylesheet" href="/css/fontawesome.min.css">
  29. <link rel="stylesheet" href="/css/bootstrap.min.css">
  30. <link rel="stylesheet" href="/css/swiper-bundle.min.css">
  31. <link rel="stylesheet" href="/css/style.css">
  32. <script src="/js/jquery-3.7.1.js"></script>
  33. <script src="/js/bootstrap.bundle.js"></script>
  34. <script src="/js/swiper-bundle.min.js"></script>
  35. </head>
  36. <body>
  37. <?php include __DIR__ . '/components/navbar.php'; ?>
  38. <!-- 轮播图 -->
  39. <div class="swiper mySwiper" style="width: 100%; height: 400px;">
  40. <div class="swiper-wrapper">
  41. <?php foreach ($carouselItems as $item): ?>
  42. <div class="swiper-slide">
  43. <img src="<?php echo $item['image']; ?>" alt="<?php echo $item['alt']; ?>" style="width: 100%; height: 100%; object-fit: cover;">
  44. </div>
  45. <?php endforeach; ?>
  46. </div>
  47. <div class="swiper-pagination"></div>
  48. <div class="swiper-button-prev"></div>
  49. <div class="swiper-button-next"></div>
  50. </div>
  51. <!-- 主要内容 -->
  52. <div class="main-content">
  53. <div class="container">
  54. <div class="row">
  55. <!-- 右侧内容 -->
  56. <div class="col-12">
  57. <div class="content">
  58. <div class="section-title center large">
  59. <h2 class="icon">政策法规</h2>
  60. </div>
  61. <!-- 搜索区域 -->
  62. <div class="d-flex justify-content-center align-items-center gap-3 mb-4">
  63. <button
  64. class="bordered <?php echo $selectedCategory === '国家法律法规' ? 'active' : ''; ?>"
  65. onclick="location.href='?category=国家法律法规&page=1<?php echo !empty($searchKeyword) ? '&keyword=' . urlencode($searchKeyword) : ''; ?>'"
  66. >
  67. 国家法律法规
  68. </button>
  69. <button
  70. class="bordered <?php echo $selectedCategory === '地方政策文件' ? 'active' : ''; ?>"
  71. onclick="location.href='?category=地方政策文件&page=1<?php echo !empty($searchKeyword) ? '&keyword=' . urlencode($searchKeyword) : ''; ?>'"
  72. >
  73. 地方政策文件
  74. </button>
  75. <div class="bordered-input">
  76. <input
  77. type="text"
  78. id="search-input"
  79. placeholder="输入关键字搜索政策法规"
  80. value="<?php echo htmlspecialchars($searchKeyword); ?>"
  81. >
  82. </div>
  83. <button
  84. class="bordered active"
  85. onclick="performSearch()"
  86. >
  87. 搜索
  88. </button>
  89. </div>
  90. <!-- 文章列表 -->
  91. <div class="news-list">
  92. <?php if (!empty($policyItems)): ?>
  93. <?php foreach ($policyItems as $item): ?>
  94. <div class="news-item dark">
  95. <a
  96. href="/xinWenXiangQing/?id=<?php echo isset($item['id']) ? $item['id'] : ''; ?>"
  97. class="title"
  98. >
  99. <?php echo isset($item['title']) ? $item['title'] : ''; ?>
  100. </a>
  101. <span class="date">
  102. <?php echo isset($item['createtime']) ? date('Y-m-d', strtotime($item['createtime'])) : ''; ?>
  103. </span>
  104. </div>
  105. <?php endforeach; ?>
  106. <?php else: ?>
  107. <div class="no-news text-center">
  108. <?php echo !empty($searchKeyword) ? '没有找到与"' . htmlspecialchars($searchKeyword) . '"相关的数据' : '暂无相关数据'; ?>
  109. </div>
  110. <?php endif; ?>
  111. </div>
  112. <!-- 分页 -->
  113. <?php if ($totalPages > 1): ?>
  114. <nav aria-label="List Page navigation">
  115. <ul class="pagination mt-4">
  116. <!-- 上一页 -->
  117. <li class="page-item <?php echo $currentPage <= 1 ? 'disabled' : ''; ?>">
  118. <a
  119. class="page-link"
  120. href="?category=<?php echo urlencode($selectedCategory); ?>&page=<?php echo $currentPage - 1; ?><?php echo !empty($searchKeyword) ? '&keyword=' . urlencode($searchKeyword) : ''; ?>"
  121. aria-label="Previous"
  122. >
  123. <span aria-hidden="true">&laquo;</span>
  124. </a>
  125. </li>
  126. <!-- 页码 -->
  127. <?php for ($i = 1; $i <= $totalPages; $i++): ?>
  128. <li class="page-item <?php echo $i == $currentPage ? 'active' : ''; ?>">
  129. <a
  130. class="page-link"
  131. href="?category=<?php echo urlencode($selectedCategory); ?>&page=<?php echo $i; ?><?php echo !empty($searchKeyword) ? '&keyword=' . urlencode($searchKeyword) : ''; ?>"
  132. >
  133. <?php echo $i; ?>
  134. </a>
  135. </li>
  136. <?php endfor; ?>
  137. <!-- 下一页 -->
  138. <li class="page-item <?php echo $currentPage >= $totalPages ? 'disabled' : ''; ?>">
  139. <a
  140. class="page-link"
  141. href="?category=<?php echo urlencode($selectedCategory); ?>&page=<?php echo $currentPage + 1; ?><?php echo !empty($searchKeyword) ? '&keyword=' . urlencode($searchKeyword) : ''; ?>"
  142. aria-label="Next"
  143. >
  144. <span aria-hidden="true">&raquo;</span>
  145. </a>
  146. </li>
  147. </ul>
  148. </nav>
  149. <?php endif; ?>
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. <?php include __DIR__ . '/components/footer.php'; ?>
  156. <script>
  157. $(document).ready(function() {
  158. // 初始化 Swiper
  159. const swiper = new Swiper(".mySwiper", {
  160. slidesPerView: 1,
  161. spaceBetween: 30,
  162. loop: true,
  163. pagination: {
  164. el: ".swiper-pagination",
  165. clickable: true,
  166. },
  167. navigation: {
  168. nextEl: ".swiper-button-next",
  169. prevEl: ".swiper-button-prev",
  170. },
  171. autoplay: {
  172. delay: 5000,
  173. disableOnInteraction: false,
  174. },
  175. });
  176. // 为搜索输入框添加回车事件
  177. $('#search-input').on('keypress', function(e) {
  178. if (e.key === 'Enter') {
  179. performSearch();
  180. }
  181. });
  182. });
  183. // 执行搜索函数
  184. function performSearch() {
  185. const keyword = $('#search-input').val().trim();
  186. const currentCategory = '<?php echo $selectedCategory; ?>';
  187. location.href = '?category=' + encodeURIComponent(currentCategory) + '&page=1&keyword=' + encodeURIComponent(keyword);
  188. }
  189. </script>
  190. </body>
  191. </html>