license_info.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. // 全局变量定义
  2. let page = 21; // 初始页码为1,代表从第1条数据开始获取
  3. let pageSize = 30; // 初始每次固定获取10条数据
  4. let licenseTotal = 0; // 数据总量(从接口获取)
  5. let loadedItems = 0; // 已加载的数据条目数量
  6. let isLoading = false; // 防止多次加载
  7. const timeoutDuration = 10000; // 超时时间10秒
  8. const preLoadDistance = 300; // 距离底部300px时提前加载
  9. // 假设 Authorization 值存储在 localStorage 中,key 为 "authToken"
  10. const authToken = localStorage.getItem("Authorization");
  11. let currentUserInfo ; // 获取当前用户登录信息
  12. let currentUserPermissions; // 用于存储用户权限信息
  13. //获取 主内容区域
  14. const license_info_mainElement = document.querySelector('main'); // 主内容区域
  15. //模态框
  16. const license_info_modal = document.getElementById('license-info-modal'); // 模态框容器
  17. const license_info_modalContent = document.querySelector('.license-info-modal-content'); // 模态框内容区域
  18. const license_info_modalDescription = document.getElementById('license-info-modal-description'); // 模态框描述
  19. const license_info_modalPrice = document.getElementById('license-info-modal-price'); // 模态框产品信息
  20. const license_info_modalRating = document.getElementById('license-info-modal-rating'); // 模态框MAC地址
  21. const license_info_closeModal = document.querySelector('.license-info-close'); // 模态框关闭按钮
  22. const license_info_loadingIndicator = document.getElementById('loading-indicator'); // 加载提示元素
  23. //存储
  24. let LicApplicationData = []; // 用于存储从接口获取的数据
  25. // 统一的打开模态框函数
  26. function openModal(modalId) {
  27. const modal = document.getElementById(modalId);
  28. if (modal) {
  29. modal.style.display = "block"; // 显示模态框
  30. } else {
  31. console.error('模态框不存在,ID:', modalId);
  32. }
  33. }
  34. // 统一的关闭模态框函数
  35. function closeModal(modalId) {
  36. const modal = document.getElementById(modalId);
  37. if (modal) {
  38. modal.style.display = "none"; // 隐藏模态框
  39. } else {
  40. console.error('模态框不存在,ID:', modalId);
  41. }
  42. }
  43. //-----------头部--------------------------------
  44. function setupUserInfoModal(currentUserInfo) {
  45. console.log("currentUserInfo,", currentUserInfo);
  46. // 获取按钮、模态框和关闭按钮的 DOM 元素
  47. const loginButton = document.querySelector('.login-button');
  48. const loginModal = document.getElementById('loginModal');
  49. const loginModalClose = document.querySelector('.login-modal-close');
  50. const userInfoContainer = document.getElementById('userInfoContainer');
  51. // 设置按钮的显示内容为当前用户的名称
  52. loginButton.textContent = currentUserInfo.Username;
  53. // 点击按钮时显示模态框,并将用户信息填充到模态框中
  54. loginButton.addEventListener('click', () => {
  55. userInfoContainer.innerHTML = `
  56. <p><strong>用户名:</strong> ${currentUserInfo.Username}</p>
  57. <p><strong>邮箱:</strong> ${currentUserInfo.Email}</p>
  58. <p><strong>电话:</strong> ${currentUserInfo.Telephone}</p>
  59. <p><strong>账号:</strong> ${currentUserInfo.Account}</p>
  60. <p><strong>角色:</strong> ${currentUserInfo.Role}</p>
  61. <button class="logout-button">退出登录</button> <!-- 退出登录按钮 -->
  62. `;
  63. loginModal.style.display = 'flex';
  64. // 为退出登录按钮绑定点击事件
  65. const logoutButton = document.querySelector('.logout-button');
  66. logoutButton.addEventListener('click', logout);
  67. });
  68. // 点击关闭按钮时隐藏模态框
  69. loginModalClose.addEventListener('click', () => {
  70. loginModal.style.display = 'none';
  71. });
  72. // 点击模态框外部区域时关闭模态框
  73. window.addEventListener('click', (event) => {
  74. if (event.target === loginModal) {
  75. loginModal.style.display = 'none';
  76. }
  77. });
  78. }
  79. // 退出登录函数
  80. function logout() {
  81. localStorage.removeItem('Authorization');
  82. window.location.href = '/';
  83. }
  84. //-----------侧边栏----------------------------
  85. // 获取所有菜单项
  86. const menuItems = document.querySelectorAll('nav ul li a');
  87. // 为每个菜单项添加点击事件监听器
  88. menuItems.forEach(item => {
  89. item.addEventListener('click', function() {
  90. // 移除其他项的 active 类
  91. menuItems.forEach(i => i.classList.remove('active'));
  92. // 为当前点击的项添加 active 类
  93. this.classList.add('active');
  94. });
  95. });
  96. //用户管理-
  97. //获取用户管理和 License 信息按钮
  98. const userManagementLink = document.getElementById('user-management-link');
  99. const licenseInfoLink = document.getElementById('license-info-link');
  100. const roleManagementLink = document.getElementById('role-management-link');
  101. // 根据用户权限控制菜单显示
  102. function updateMenuVisibility() {
  103. console.log("updateMenuVisibility: ",currentUserPermissions);
  104. if (currentUserPermissions) {
  105. userManagementLink.style.display = currentUserPermissions.includes('read_user') ? 'block' : 'none';
  106. roleManagementLink.style.display = currentUserPermissions.includes('get_role') ? 'block' : 'none';
  107. licenseInfoLink.style.display = (currentUserPermissions.includes('read_license') || currentUserPermissions.includes('read_all_license')) ? 'block' : 'none';
  108. }
  109. }
  110. // 监听用户管理按钮的点击事件
  111. userManagementLink.addEventListener('click', function(event) {
  112. event.preventDefault(); // 阻止默认的跳转行为
  113. removeScrollListeners(); // 移除滚动监听器
  114. // 使用 fetch 来加载 user_management.html 的内容
  115. fetch('../user/user_management.html')
  116. .then(response => response.text())
  117. .then(data => {
  118. // 将 user_management.html 的内容插入到主内容区域
  119. license_info_mainElement.innerHTML = data;
  120. // 动态引入 user.js 文件
  121. const script = document.createElement('script');
  122. script.src = '../user/user.js';
  123. document.body.appendChild(script);
  124. })
  125. .catch(error => console.error('加载用户管理页面失败:', error));
  126. });
  127. // 监听 License 信息按钮的点击事件
  128. licenseInfoLink.addEventListener('click', function(event) {
  129. event.preventDefault(); // 阻止默认的跳转行为
  130. // 将瀑布流的 License 信息内容恢复到主内容区域
  131. const licenseInfoHtml = `
  132. <!-- 包裹搜索框、下拉框、时间选择框和确定按钮的 div -->
  133. <div class="search-container">
  134. <!-- License 状态下拉框 -->
  135. <select id="license-status-filter" aria-label="选择 License 状态">
  136. <option value="">License 状态</option>
  137. <option value="已生成">已生成</option>
  138. <option value="未生成">未生成</option>
  139. <option value="已失效">已失效</option>
  140. </select>
  141. <!-- 开始时间选择框,类型改为 date -->
  142. <input type="date" id="start-date" placeholder="开始时间" />
  143. <!-- 结束时间选择框,类型改为 date -->
  144. <input type="date" id="end-date" placeholder="结束时间" />
  145. <!-- 搜索框 -->
  146. <input type="text" id="search-bar" placeholder="搜索..." />
  147. <!-- 确定按钮 -->
  148. <button id="submit-button">确定</button>
  149. </div>
  150. <div class="license-info-container" id="license-info-restaurant-list"> </div>
  151. `; // 这是原来的 License 信息区域 HTML
  152. //mainContainer.innerHTML = licenseInfoHtml;
  153. license_info_mainElement.innerHTML = licenseInfoHtml;
  154. //清楚lic信息组的数据
  155. LicApplicationData = [];
  156. initializeScrollListeners(); // 重新初始化滚动监听器
  157. // 再次加载 License 信息数据并渲染卡片
  158. (async function() {
  159. const data = await fetchLicenseData(1, 10);
  160. if (data.length > 0) {
  161. console.log('加载的数据:', data); // 检查是否成功获取数据
  162. renderLicenseCards(data, true); // 渲染数据到页面并清空之前的内容
  163. } else {
  164. console.error('未加载到数据');
  165. }
  166. })();
  167. });
  168. roleManagementLink.addEventListener('click', function(event) {
  169. event.preventDefault(); // 阻止默认的跳转行为
  170. removeScrollListeners(); // 移除滚动监听器
  171. // 使用 fetch 来加载 user_management.html 的内容
  172. fetch('../role/role.html')
  173. .then(response => response.text())
  174. .then(data => {
  175. // 将 user_management.html 的内容插入到主内容区域
  176. license_info_mainElement.innerHTML = data;
  177. // 动态引入 user.js 文件
  178. const script = document.createElement('script');
  179. script.src = '../role/role.js';
  180. document.body.appendChild(script);
  181. })
  182. .catch(error => console.error('加载用户管理页面失败:', error));
  183. });
  184. //-------license数据显示------------------------------------------------------
  185. // 获取数据函数
  186. async function fetchLicenseData(page, pageSize) {
  187. try {
  188. const response = await fetch(`http://127.0.0.1:8080/api/admin/GetAllLicenseInfo?page=${page}&pageSize=${pageSize}`, {
  189. method: 'GET',
  190. headers: {
  191. 'Authorization': `Bearer ${authToken}`,
  192. 'Content-Type': 'application/json'
  193. }
  194. });
  195. const result = await response.json();
  196. // 设置总量,如果第一次加载,获取total字段
  197. if (licenseTotal === 0 && result.total) {
  198. licenseTotal = result.total;
  199. }
  200. console.log("result total ",licenseTotal,result.total);
  201. // 使用 concat 方法将新数据与之前的数据进行累加
  202. LicApplicationData = LicApplicationData.concat(result.data || []);
  203. console.log("LicApplicationData: ",LicApplicationData,licenseTotal,result);
  204. return result.data || [];
  205. } catch (error) {
  206. console.error("加载数据失败", error);
  207. return []; // 返回空数组,防止后续操作出错
  208. }
  209. }
  210. // 渲染 license_info 卡片数据函数
  211. function renderLicenseCards(data, clearContainer = false) {
  212. console.log("-----------渲染次数");
  213. // 获取与 license_info 相关的 HTML 元素
  214. const license_info_container = document.getElementById('license-info-restaurant-list'); // 卡片列表容器
  215. if (clearContainer) {
  216. license_info_container.innerHTML = ''; // 清空容器内容
  217. isLoading = false; // 重置加载状态
  218. loadedItems = 0; // 重置已加载项数
  219. page = 21; // 每次请求后,page 增加10,表示从下一组数据开始
  220. pageSize = 30; // pageSize 每次递增10
  221. console.log("-----------渲染清除");
  222. }
  223. console.log("-----------data:",data);
  224. data.forEach(group => {
  225. const firstItem = group[0]; // 获取该组的第一个数据项
  226. // 获取子行的数量
  227. const childRowCount = group.length;
  228. let statusClass = '';
  229. if (firstItem.LicenseFlage === '已生成') {
  230. statusClass = 'license-status-green';
  231. } else if (firstItem.LicenseFlage === '未生成') {
  232. statusClass = 'license-status-yellow';
  233. } else if (firstItem.LicenseFlage === '已失效') {
  234. statusClass = 'license-status-red';
  235. }
  236. const card = document.createElement('div');
  237. card.className = 'license-info-card';
  238. // 给卡片添加一个唯一标识符的 data 属性
  239. card.setAttribute('data-oa-request-id', firstItem.oa_request_id);
  240. // 在卡片的第一行显示申请时间
  241. card.innerHTML = `
  242. <div class="license-info-card-header">
  243. <h3 class="card-title">${firstItem.GlxmName}</h3>
  244. </div>
  245. <div class="license-info-card-content">
  246. <p class="card-text">${firstItem.ApplicationDate} ${firstItem.ApplicationTime}</p> <!-- 显示日期和时间 -->
  247. <p class="card-text">创建者:${firstItem.Creator}</p>
  248. <p class="card-text">公司:${firstItem.Company}</p>
  249. <p class="card-text">集群:${childRowCount} 套 共计:${firstItem.TotalNodes} 节点</p>
  250. <p class="card-text license-status ${statusClass}">许可证状态:${firstItem.LicenseFlage}</p>
  251. <p class="card-text">oa_request_id:${firstItem.oa_request_id}</p>
  252. </div>
  253. `;
  254. // 给卡片添加点击事件,点击后显示模态框
  255. card.addEventListener('click', () => {
  256. // 传递当前卡片的详细数据到模态框
  257. const oaRequestId = card.getAttribute('data-oa-request-id');
  258. showModalForCard(group, oaRequestId); // 传递 oa_request_id
  259. //showModalForCard(group); // 传递当前卡片的详细数据到模态框
  260. });
  261. // 将卡片添加到容器中
  262. license_info_container.appendChild(card);
  263. });
  264. }
  265. // 检查是否滚动到底部并触发加载
  266. // async function checkAndLoadMore(scrollHeight, scrollTop, clientHeight) {
  267. // if (isLoading || loadedItems >= licenseTotal) return; // 如果正在加载或已加载完所有数据则退出
  268. // // console.log(`Scroll Info - scrollHeight: ${scrollHeight}, scrollTop: ${scrollTop}, clientHeight: ${clientHeight}`);
  269. // if (scrollTop + clientHeight >= scrollHeight - preLoadDistance) {
  270. // console.log(`触发加载更多数据:page=${page}, pageSize=${pageSize}`); // 每次触发时打印输出
  271. // await loadMoreData();
  272. // }
  273. // }
  274. // 加载更多数据函数
  275. async function loadMoreData() {
  276. if (isLoading) return; // 防止重复加载
  277. isLoading = true;
  278. console.log('开始加载更多数据');
  279. // 显示加载提示
  280. // license_info_loadingIndicator.style.display = 'block'; // 显示提示
  281. // license_info_loadingIndicator.innerText = '正在加载...'; // 重置加载提示
  282. // 设置超时处理
  283. const timeout = setTimeout(() => {
  284. license_info_loadingIndicator.innerText = '加载超时,请重试'; // 修改提示语为超时提示
  285. isLoading = false;
  286. license_info_loadingIndicator.style.display = 'none'; // 超时后隐藏加载提示
  287. }, timeoutDuration);
  288. // 获取数据
  289. const data = await fetchLicenseData(page, pageSize);
  290. console.log(`加载的新数据 data`,data); // 每次触发时打印输出
  291. // 清除超时定时器
  292. clearTimeout(timeout);
  293. if (data.length > 0) {
  294. // 更新 page 和 pageSize,下一次请求从新的位置开始
  295. page += 10; // 每次请求后,page 增加10,表示从下一组数据开始
  296. pageSize += 10; // pageSize 每次递增10
  297. // 更新已加载的条目数
  298. loadedItems += data.length;
  299. // 渲染数据到页面
  300. renderLicenseCards(data);
  301. console.log('数据加载完成,更新页面');
  302. }
  303. // 隐藏加载提示
  304. //license_info_loadingIndicator.style.display = 'none'; // 加载完成后隐藏提示
  305. isLoading = false; // 请求完成,允许下次请求
  306. // 检查内容高度,必要时继续加载
  307. //checkContentHeight();
  308. checkAndLoadMore();
  309. }
  310. //--------------------------监听 window 滚动---监听 main 容器的滚动-----------------------------------------------
  311. // // 监听 window 滚动
  312. // window.addEventListener('scroll', () => {
  313. // checkAndLoadMore(document.body.scrollHeight, window.scrollY, window.innerHeight);
  314. // });
  315. // // 监听 main 容器的滚动
  316. // license_info_mainElement.addEventListener('scroll', () => {
  317. // checkAndLoadMore(license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  318. // });
  319. function initializeScrollListeners() {
  320. // 只监听 main 容器的滚动
  321. license_info_mainElement.addEventListener('scroll', handleMainScroll);
  322. // console.log('滚动监听已初始化');
  323. }
  324. function removeScrollListeners() {
  325. // 移除 main 容器的滚动监听
  326. license_info_mainElement.removeEventListener('scroll', handleMainScroll);
  327. }
  328. // 新增一个重启滑动监听功能函数,当用户清空搜索条件时调用
  329. function restartScrollListeners() {
  330. // 重新绑定滑动监听器
  331. initializeScrollListeners();
  332. }
  333. function handleMainScroll() {
  334. // console.log('handleMainScroll', license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  335. checkAndLoadMore(license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  336. }
  337. async function checkAndLoadMore(scrollHeight, scrollTop, clientHeight) {
  338. if (isLoading || loadedItems >= licenseTotal) return; // 如果正在加载或已加载完所有数据则退出
  339. // console.log(`Scroll Info - scrollHeight: ${scrollHeight}, scrollTop: ${scrollTop}, clientHeight: ${clientHeight}`);
  340. if (scrollTop + clientHeight >= scrollHeight - preLoadDistance) {
  341. console.log(`触发加载更多数据:page=${page}, pageSize=${pageSize}`); // 每次触发时打印输出
  342. await loadMoreData();
  343. }
  344. }
  345. //-----------------------------------------------------------------------------------------
  346. // 初始化加载第一页
  347. (async function() {
  348. const data = await fetchLicenseData(1, 20);
  349. if (data.length > 0) {
  350. renderLicenseCards(data); // 渲染数据到页面
  351. loadedItems += data.length; // 更新已加载的条目数
  352. }
  353. //license_info_loadingIndicator.style.display = 'none'; // 初始化后隐藏加载提示
  354. // 检查内容高度
  355. // checkContentHeight();
  356. checkAndLoadMore()
  357. })();
  358. //初始化监听滚动条
  359. initializeScrollListeners()
  360. ///-----------获取登录用户信息----------------------------------------
  361. async function fetchUsername() {
  362. try {
  363. const response = await fetch(`http://127.0.0.1:8080/api/admin/userInfo`, {
  364. method: 'GET',
  365. headers: {
  366. 'Authorization': `Bearer ${authToken}`,
  367. 'Content-Type': 'application/json'
  368. }
  369. });
  370. const data = await response.json();
  371. currentUserRole = data.data.Role; // 存储当前用户的角色
  372. currentUserName = data.data.Username;
  373. // 使用获取到的角色,调用获取权限的接口
  374. await fetchPermissionsByRole(currentUserRole);
  375. console.log('当前用户角色:', data);
  376. currentUserInfo = data.data;
  377. // 调用该函数,初始化模态框
  378. setupUserInfoModal(currentUserInfo);
  379. updateMenuVisibility();
  380. return data.data; // 返回获取到的用户信息数据
  381. } catch (error) {
  382. console.error('Error fetching user info or permissions:', error);
  383. }
  384. }
  385. fetchUsername();
  386. // 调用函数更新菜单可见性
  387. // 将 fetchPermissionsByRole 转换为异步函数
  388. async function fetchPermissionsByRole(role) {
  389. try {
  390. const response = await fetch(`http://127.0.0.1:8080/api/admin/GetSelfRoles`, {
  391. method: 'POST',
  392. headers: {
  393. 'Authorization': `Bearer ${authToken}`,
  394. 'Content-Type': 'application/json'
  395. },
  396. body: JSON.stringify({ name: role })
  397. });
  398. const data = await response.json();
  399. currentUserPermissions = data.data.Permissions; // 获取用户的权限数组
  400. console.log('currentUserPermissions:', currentUserPermissions);
  401. // 定义权限类别
  402. // const licensePermissions = ['upload_license', 'read_license'];
  403. // const userPermissionsCheck = ['create_user', 'read_user', 'update_user', 'delete_user'];
  404. // const rolePermissions = ['create_role', 'delete_role', 'update_role', 'get_role'];
  405. // const hasLicenseAccess = licensePermissions.some(permission => userPermissions.includes(permission));
  406. // const hasUserManagementAccess = userPermissionsCheck.some(permission => userPermissions.includes(permission));
  407. // const hasRoleManagementAccess = rolePermissions.some(permission => userPermissions.includes(permission));
  408. // 根据权限渲染菜单并显示初始页面
  409. //renderMenuAndInitialPage(hasLicenseAccess, hasUserManagementAccess, hasRoleManagementAccess);
  410. } catch (error) {
  411. console.error('Error fetching permissions:', error);
  412. }
  413. }
  414. //--------------进度条-------------------------------------------------
  415. // 创建模态框的 DOM 元素并插入到 body 中
  416. function createLoadingModal() {
  417. const modalHTML = `
  418. <div id="loadingModal" class="loading-modal" style="display: none;">
  419. <div class="loading-modal-content">
  420. <div class="spinner"></div>
  421. <p id="loadingMessage">加载中...</p>
  422. </div>
  423. </div>
  424. `;
  425. document.body.insertAdjacentHTML('beforeend', modalHTML);
  426. }
  427. // 显示加载模态框
  428. function showLoadingModal(message = "加载中...") {
  429. const loadingModal = document.getElementById('loadingModal');
  430. const loadingMessage = document.getElementById('loadingMessage');
  431. if (loadingModal && loadingMessage) {
  432. loadingMessage.textContent = message; // 设置显示的消息
  433. loadingModal.style.display = 'flex'; // 显示模态框
  434. }
  435. }
  436. // 隐藏加载模态框
  437. function hideLoadingModal() {
  438. const loadingModal = document.getElementById('loadingModal');
  439. if (loadingModal) {
  440. loadingModal.style.display = 'none'; // 隐藏模态框
  441. }
  442. }
  443. // 页面加载时创建模态框
  444. document.addEventListener('DOMContentLoaded', createLoadingModal);
  445. //-----------搜索栏----------------------------
  446. // 获取搜索框元素
  447. // 获取搜索框、状态下拉框、时间选择框和按钮元素
  448. // 获取搜索框、状态下拉框、时间选择框和按钮元素
  449. const searchBar = document.getElementById('search-bar');
  450. const statusFilter = document.getElementById('license-status-filter');
  451. const startDate = document.getElementById('start-date');
  452. const endDate = document.getElementById('end-date');
  453. const submitButton = document.getElementById('submit-button');
  454. const licenseInfoContainer = document.getElementById('license-info-restaurant-list');
  455. // 过滤功能实现
  456. function filterContent() {
  457. console.log('过滤功能触发');
  458. // 移除滚动监听器,停止滚动加载
  459. // removeScrollListeners();
  460. console.log('statusFilter.valuesdaad撒大啊', statusFilter.value,startDate.value ,endDate.value,searchBar.value );
  461. // 检查如果所有输入框都是默认值,则直接返回,不发送数据
  462. if (!statusFilter.value && !startDate.value && !endDate.value && !searchBar.value) {
  463. console.log("所有过滤条件为空,不发送请求");
  464. return; // 不发送请求
  465. }
  466. // 构建请求体参数
  467. const requestData = {
  468. license_flag: statusFilter.value || undefined,
  469. starting_date: startDate.value || undefined,
  470. end_date: endDate.value || undefined,
  471. any_search: searchBar.value || undefined,
  472. };
  473. console.log("requestData",requestData);
  474. // 发送 POST 请求到接口
  475. fetch('http://127.0.0.1:8080/api/admin/GetConditionalSearch', {
  476. method: 'POST',
  477. headers: {
  478. 'Authorization': `Bearer ${authToken}`,
  479. 'Content-Type': 'application/json',
  480. },
  481. body: JSON.stringify(requestData),
  482. })
  483. .then(response => response.json())
  484. .then(data => {
  485. console.log('成功获取数据:', data);
  486. // 处理返回的数据并更新界面
  487. displayLicenseInfo(data.data);
  488. })
  489. .catch(error => {
  490. console.error('获取数据时发生错误:', error);
  491. });
  492. }
  493. // 处理并显示返回的 License 信息
  494. function displayLicenseInfo(data) {
  495. // 清空之前的结果
  496. licenseInfoContainer.innerHTML = '';
  497. LicApplicationData =[];
  498. // 遍历返回的数据,生成并插入卡片
  499. // 处理返回的数据并更新界面,使用 renderLicenseCards 方法进行渲染
  500. renderLicenseCards(data, true);
  501. }
  502. // 确定按钮点击事件的修改(停止滚动监听)
  503. submitButton.addEventListener('click', function() {
  504. // 检查下拉框和时间选择框是否为默认值
  505. if (!statusFilter.value && !startDate.value && !endDate.value) {
  506. // 如果都是默认值,则刷新页面
  507. location.reload();
  508. } else {
  509. // 否则,执行过滤内容功能
  510. filterContent();
  511. // 隐藏滚动加载,防止继续加载更多内容
  512. removeScrollListeners();
  513. }
  514. });
  515. // 监听返回按钮的点击事件,刷新页面并恢复滚动监听
  516. const resetButton = document.getElementById('reset-button');
  517. resetButton.addEventListener('click', function() {
  518. // 刷新页面
  519. location.reload();
  520. });
  521. // 修改当搜索栏没有输入时,重新启动滚动监听
  522. searchBar.addEventListener('input', function() {
  523. if (!searchBar.value && !statusFilter.value && !startDate.value && !endDate.value) {
  524. console.log("搜索条件清空,重新启动滚动监听");
  525. restartScrollListeners();
  526. }
  527. });