license_info.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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. function checkPermissionsAndShowButton() {
  86. console.log("checkPermissionsAndShowButton ", currentUserPermissions);
  87. if (currentUserPermissions.includes('capture_license_once_to_db')) {
  88. const captureLicenseBtn = document.getElementById('capture-license-btn');
  89. captureLicenseBtn.style.display = 'block';
  90. // 为按钮添加点击事件监听
  91. captureLicenseBtn.addEventListener('click', CaptureLicenseOncefunc);
  92. }
  93. }
  94. // 主动抓取一次License数据函数
  95. function CaptureLicenseOncefunc() {
  96. // 显示加载模态框
  97. const loadingModal = document.createElement('div');
  98. loadingModal.classList.add('modal-content', 'apple-modal-content');
  99. loadingModal.innerHTML = `
  100. <h3>正在获取 License 信息...</h3>
  101. <div class="progress-bar" style="width: 100%; height: 20px; background-color: #e0e0e0;">
  102. <div class="progress" style="width: 50%; height: 100%; background-color: #007aff;"></div>
  103. </div>
  104. `;
  105. document.body.appendChild(loadingModal);
  106. // 定义超时函数
  107. const timeoutPromise = new Promise((_, reject) => {
  108. setTimeout(() => {
  109. reject(new Error('获取超时'));
  110. }, 10000); // 10秒超时
  111. });
  112. // 发起 GET 请求的 Promise
  113. const fetchPromise = fetch('http://127.0.0.1:8080/api/admin/GetCaptureLicenseOnce', {
  114. method: 'GET',
  115. headers: {
  116. 'Authorization': `Bearer ${authToken}`, // 假设 token 已定义
  117. 'Content-Type': 'application/json'
  118. }
  119. }).then(response => response.json());
  120. // 使用 Promise.race 来竞争两个 Promise,哪个先返回就使用哪个
  121. Promise.race([fetchPromise, timeoutPromise])
  122. .then(data => {
  123. // 先关闭进度条
  124. document.body.removeChild(loadingModal);
  125. // 显示成功或失败提示
  126. if (data.success) {
  127. alert('License 获取成功!');
  128. } else {
  129. alert('获取失败:' + data.error);
  130. }
  131. })
  132. .catch(error => {
  133. // 先关闭进度条
  134. document.body.removeChild(loadingModal);
  135. // 显示错误提示
  136. alert(error.message); // 如果超时或请求失败
  137. });
  138. }
  139. //-----------侧边栏----------------------------
  140. // 获取所有菜单项
  141. const menuItems = document.querySelectorAll('nav ul li a');
  142. // 为每个菜单项添加点击事件监听器
  143. menuItems.forEach(item => {
  144. item.addEventListener('click', function() {
  145. // 移除其他项的 active 类
  146. menuItems.forEach(i => i.classList.remove('active'));
  147. // 为当前点击的项添加 active 类
  148. this.classList.add('active');
  149. });
  150. });
  151. //用户管理-
  152. //获取用户管理和 License 信息按钮
  153. const userManagementLink = document.getElementById('user-management-link');
  154. const licenseInfoLink = document.getElementById('license-info-link');
  155. const roleManagementLink = document.getElementById('role-management-link');
  156. // 根据用户权限控制菜单显示
  157. function updateMenuVisibility() {
  158. console.log("updateMenuVisibility: ",currentUserPermissions);
  159. if (currentUserPermissions) {
  160. userManagementLink.style.display = currentUserPermissions.includes('read_user') ? 'block' : 'none';
  161. roleManagementLink.style.display = currentUserPermissions.includes('get_role') ? 'block' : 'none';
  162. licenseInfoLink.style.display = (currentUserPermissions.includes('read_license') || currentUserPermissions.includes('read_all_license')) ? 'block' : 'none';
  163. }
  164. // 调用函数检查权限并显示按钮
  165. checkPermissionsAndShowButton();
  166. }
  167. // 监听用户管理按钮的点击事件
  168. userManagementLink.addEventListener('click', function(event) {
  169. event.preventDefault(); // 阻止默认的跳转行为
  170. removeScrollListeners(); // 移除滚动监听器
  171. // 使用 fetch 来加载 user_management.html 的内容
  172. fetch('../user/user_management.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 = '../user/user.js';
  180. document.body.appendChild(script);
  181. })
  182. .catch(error => console.error('加载用户管理页面失败:', error));
  183. });
  184. // 监听 License 信息按钮的点击事件
  185. licenseInfoLink.addEventListener('click', function(event) {
  186. event.preventDefault(); // 阻止默认的跳转行为
  187. // 将瀑布流的 License 信息内容恢复到主内容区域
  188. const licenseInfoHtml = `
  189. <!-- 包裹搜索框、下拉框、时间选择框和确定按钮的 div -->
  190. <div class="search-container">
  191. <!-- License 状态下拉框 -->
  192. <select id="license-status-filter" aria-label="选择 License 状态">
  193. <option value="">License 状态</option>
  194. <option value="已生成">已生成</option>
  195. <option value="未生成">未生成</option>
  196. <option value="已失效">已失效</option>
  197. </select>
  198. <!-- 开始时间选择框,类型改为 date -->
  199. <input type="date" id="start-date" placeholder="开始时间" />
  200. <!-- 结束时间选择框,类型改为 date -->
  201. <input type="date" id="end-date" placeholder="结束时间" />
  202. <!-- 搜索框 -->
  203. <input type="text" id="search-bar" placeholder="搜索..." />
  204. <!-- 确定按钮 -->
  205. <button id="submit-button">确定</button>
  206. </div>
  207. <div class="license-info-container" style="display: none;" id="license-info-restaurant-list"> </div>
  208. `; // 这是原来的 License 信息区域 HTML
  209. //mainContainer.innerHTML = licenseInfoHtml;
  210. license_info_mainElement.innerHTML = licenseInfoHtml;
  211. //清楚lic信息组的数据
  212. LicApplicationData = [];
  213. initializeScrollListeners(); // 重新初始化滚动监听器
  214. // 再次加载 License 信息数据并渲染卡片
  215. (async function() {
  216. const data = await fetchLicenseData(1, 10);
  217. if (data.length > 0) {
  218. console.log('加载的数据:', data); // 检查是否成功获取数据
  219. renderLicenseCards(data, true); // 渲染数据到页面并清空之前的内容
  220. } else {
  221. console.error('未加载到数据');
  222. }
  223. })();
  224. });
  225. roleManagementLink.addEventListener('click', function(event) {
  226. event.preventDefault(); // 阻止默认的跳转行为
  227. removeScrollListeners(); // 移除滚动监听器
  228. // 使用 fetch 来加载 user_management.html 的内容
  229. fetch('../role/role.html')
  230. .then(response => response.text())
  231. .then(data => {
  232. // 将 user_management.html 的内容插入到主内容区域
  233. license_info_mainElement.innerHTML = data;
  234. // 动态引入 user.js 文件
  235. const script = document.createElement('script');
  236. script.src = '../role/role.js';
  237. document.body.appendChild(script);
  238. })
  239. .catch(error => console.error('加载用户管理页面失败:', error));
  240. });
  241. //-------license数据显示------------------------------------------------------
  242. // 获取数据函数
  243. async function fetchLicenseData(page, pageSize) {
  244. try {
  245. const response = await fetch(`http://127.0.0.1:8080/api/admin/GetAllLicenseInfo?page=${page}&pageSize=${pageSize}`, {
  246. method: 'GET',
  247. headers: {
  248. 'Authorization': `Bearer ${authToken}`,
  249. 'Content-Type': 'application/json'
  250. }
  251. });
  252. const result = await response.json();
  253. // 设置总量,如果第一次加载,获取total字段
  254. if (licenseTotal === 0 && result.total) {
  255. licenseTotal = result.total;
  256. }
  257. console.log("result total ",licenseTotal,result.total);
  258. // 使用 concat 方法将新数据与之前的数据进行累加
  259. LicApplicationData = LicApplicationData.concat(result.data || []);
  260. console.log("LicApplicationData: ",LicApplicationData,licenseTotal,result);
  261. return result.data || [];
  262. } catch (error) {
  263. console.error("加载数据失败", error);
  264. return []; // 返回空数组,防止后续操作出错
  265. }
  266. }
  267. // 渲染 license_info 卡片数据函数
  268. function renderLicenseCards(data, clearContainer = false) {
  269. console.log("-----------渲染次数");
  270. // 获取与 license_info 相关的 HTML 元素
  271. const license_info_container = document.getElementById('license-info-restaurant-list'); // 卡片列表容器
  272. if (clearContainer) {
  273. license_info_container.innerHTML = ''; // 清空容器内容
  274. isLoading = false; // 重置加载状态
  275. loadedItems = 0; // 重置已加载项数
  276. page = 21; // 每次请求后,page 增加10,表示从下一组数据开始
  277. pageSize = 30; // pageSize 每次递增10
  278. console.log("-----------渲染清除");
  279. }
  280. console.log("-----------data:",data);
  281. data.forEach(group => {
  282. const firstItem = group[0]; // 获取该组的第一个数据项
  283. // 获取子行的数量
  284. const childRowCount = group.length;
  285. let statusClass = '';
  286. if (firstItem.LicenseFlage === '已生成') {
  287. statusClass = 'license-status-green';
  288. } else if (firstItem.LicenseFlage === '未生成') {
  289. statusClass = 'license-status-yellow';
  290. } else if (firstItem.LicenseFlage === '已失效') {
  291. statusClass = 'license-status-red';
  292. }
  293. /*筛选名字*/
  294. let creatorUser = firstItem.Creator;
  295. if (creatorUser.includes('-')) {
  296. let firstDashIndex = creatorUser.indexOf('-');
  297. let secondDashIndex = creatorUser.indexOf('-', firstDashIndex + 1);
  298. creatorUser = creatorUser.substring(firstDashIndex + 1, secondDashIndex);
  299. }
  300. const card = document.createElement('div');
  301. card.className = 'license-info-card';
  302. // 给卡片添加一个唯一标识符的 data 属性
  303. card.setAttribute('data-oa-request-id', firstItem.oa_request_id);
  304. // 在卡片的第一行显示申请时间
  305. //<p class="card-text">oa_request_id:${firstItem.oa_request_id}</p>
  306. card.innerHTML = `
  307. <div class="license-info-card-header">
  308. <h3 class="card-title">${firstItem.GlxmName}</h3>
  309. </div>
  310. <div class="license-info-card-content">
  311. <p class="card-text date-time">${firstItem.ApplicationDate} ${firstItem.ApplicationTime}</p> <!-- 显示日期和时间 -->
  312. <p class="card-text">创建者:${creatorUser}</p>
  313. <p class="card-text">公司:${firstItem.Company}</p>
  314. <p class="card-text">集群:${childRowCount} 套 共计:${firstItem.TotalNodes} 节点</p>
  315. <p class="card-text license-status ${statusClass}">许可证状态:${firstItem.LicenseFlage}</p>
  316. </div>
  317. `;
  318. // 给卡片添加点击事件,点击后显示模态框
  319. card.addEventListener('click', () => {
  320. // 传递当前卡片的详细数据到模态框
  321. const oaRequestId = card.getAttribute('data-oa-request-id');
  322. showModalForCard(group, oaRequestId); // 传递 oa_request_id
  323. //showModalForCard(group); // 传递当前卡片的详细数据到模态框
  324. });
  325. // 将卡片添加到容器中
  326. license_info_container.appendChild(card);
  327. });
  328. }
  329. // 检查是否滚动到底部并触发加载
  330. // async function checkAndLoadMore(scrollHeight, scrollTop, clientHeight) {
  331. // if (isLoading || loadedItems >= licenseTotal) return; // 如果正在加载或已加载完所有数据则退出
  332. // // console.log(`Scroll Info - scrollHeight: ${scrollHeight}, scrollTop: ${scrollTop}, clientHeight: ${clientHeight}`);
  333. // if (scrollTop + clientHeight >= scrollHeight - preLoadDistance) {
  334. // console.log(`触发加载更多数据:page=${page}, pageSize=${pageSize}`); // 每次触发时打印输出
  335. // await loadMoreData();
  336. // }
  337. // }
  338. // 加载更多数据函数
  339. async function loadMoreData() {
  340. if (isLoading) return; // 防止重复加载
  341. isLoading = true;
  342. console.log('开始加载更多数据');
  343. // 显示加载提示
  344. // license_info_loadingIndicator.style.display = 'block'; // 显示提示
  345. // license_info_loadingIndicator.innerText = '正在加载...'; // 重置加载提示
  346. // 设置超时处理
  347. const timeout = setTimeout(() => {
  348. license_info_loadingIndicator.innerText = '加载超时,请重试'; // 修改提示语为超时提示
  349. isLoading = false;
  350. license_info_loadingIndicator.style.display = 'none'; // 超时后隐藏加载提示
  351. }, timeoutDuration);
  352. // 获取数据
  353. const data = await fetchLicenseData(page, pageSize);
  354. console.log(`加载的新数据 data`,data); // 每次触发时打印输出
  355. // 清除超时定时器
  356. clearTimeout(timeout);
  357. if (data.length > 0) {
  358. // 更新 page 和 pageSize,下一次请求从新的位置开始
  359. page += 10; // 每次请求后,page 增加10,表示从下一组数据开始
  360. pageSize += 10; // pageSize 每次递增10
  361. // 更新已加载的条目数
  362. loadedItems += data.length;
  363. // 渲染数据到页面
  364. renderLicenseCards(data);
  365. console.log('数据加载完成,更新页面');
  366. }
  367. // 隐藏加载提示
  368. //license_info_loadingIndicator.style.display = 'none'; // 加载完成后隐藏提示
  369. isLoading = false; // 请求完成,允许下次请求
  370. // 检查内容高度,必要时继续加载
  371. //checkContentHeight();
  372. checkAndLoadMore();
  373. }
  374. //--------------------------监听 window 滚动---监听 main 容器的滚动-----------------------------------------------
  375. // // 监听 window 滚动
  376. // window.addEventListener('scroll', () => {
  377. // checkAndLoadMore(document.body.scrollHeight, window.scrollY, window.innerHeight);
  378. // });
  379. // // 监听 main 容器的滚动
  380. // license_info_mainElement.addEventListener('scroll', () => {
  381. // checkAndLoadMore(license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  382. // });
  383. function initializeScrollListeners() {
  384. // 只监听 main 容器的滚动
  385. license_info_mainElement.addEventListener('scroll', handleMainScroll);
  386. // console.log('滚动监听已初始化');
  387. }
  388. function removeScrollListeners() {
  389. // 移除 main 容器的滚动监听
  390. license_info_mainElement.removeEventListener('scroll', handleMainScroll);
  391. }
  392. // 新增一个重启滑动监听功能函数,当用户清空搜索条件时调用
  393. function restartScrollListeners() {
  394. // 重新绑定滑动监听器
  395. initializeScrollListeners();
  396. }
  397. function handleMainScroll() {
  398. // console.log('handleMainScroll', license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  399. checkAndLoadMore(license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  400. }
  401. async function checkAndLoadMore(scrollHeight, scrollTop, clientHeight) {
  402. if (isLoading || loadedItems >= licenseTotal) return; // 如果正在加载或已加载完所有数据则退出
  403. // console.log(`Scroll Info - scrollHeight: ${scrollHeight}, scrollTop: ${scrollTop}, clientHeight: ${clientHeight}`);
  404. if (scrollTop + clientHeight >= scrollHeight - preLoadDistance) {
  405. console.log(`触发加载更多数据:page=${page}, pageSize=${pageSize}`); // 每次触发时打印输出
  406. await loadMoreData();
  407. }
  408. }
  409. //-----------------------------------------------------------------------------------------
  410. // 初始化加载第一页
  411. (async function() {
  412. const data = await fetchLicenseData(1, 20);
  413. if (data.length > 0) {
  414. renderLicenseCards(data); // 渲染数据到页面
  415. loadedItems += data.length; // 更新已加载的条目数
  416. }
  417. //license_info_loadingIndicator.style.display = 'none'; // 初始化后隐藏加载提示
  418. // 检查内容高度
  419. // checkContentHeight();
  420. checkAndLoadMore()
  421. })();
  422. //初始化监听滚动条
  423. initializeScrollListeners()
  424. ///-----------获取登录用户信息----------------------------------------
  425. async function fetchUsername() {
  426. try {
  427. const response = await fetch(`http://127.0.0.1:8080/api/admin/userInfo`, {
  428. method: 'GET',
  429. headers: {
  430. 'Authorization': `Bearer ${authToken}`,
  431. 'Content-Type': 'application/json'
  432. }
  433. });
  434. const data = await response.json();
  435. currentUserRole = data.data.Role; // 存储当前用户的角色
  436. currentUserName = data.data.Username;
  437. // 使用获取到的角色,调用获取权限的接口
  438. await fetchPermissionsByRole(currentUserRole);
  439. console.log('当前用户角色:', data);
  440. currentUserInfo = data.data;
  441. // 调用该函数,初始化模态框
  442. setupUserInfoModal(currentUserInfo);
  443. updateMenuVisibility();
  444. return data.data; // 返回获取到的用户信息数据
  445. } catch (error) {
  446. console.error('Error fetching user info or permissions:', error);
  447. }
  448. }
  449. fetchUsername();
  450. // 调用函数更新菜单可见性
  451. // 将 fetchPermissionsByRole 转换为异步函数
  452. async function fetchPermissionsByRole(role) {
  453. try {
  454. const response = await fetch(`http://127.0.0.1:8080/api/admin/GetSelfRoles`, {
  455. method: 'POST',
  456. headers: {
  457. 'Authorization': `Bearer ${authToken}`,
  458. 'Content-Type': 'application/json'
  459. },
  460. body: JSON.stringify({ name: role })
  461. });
  462. const data = await response.json();
  463. currentUserPermissions = data.data.Permissions; // 获取用户的权限数组
  464. console.log('currentUserPermissions:', currentUserPermissions);
  465. // 检查用户是否有读取许可证的权限
  466. const hasReadLicensePermission = currentUserPermissions.includes("read_license");
  467. const hasReadUserPermission = currentUserPermissions.includes("read_user");
  468. const hasReadRolePermission = currentUserPermissions.includes("get_role");
  469. if (hasReadUserPermission){
  470. // 如果有读取许可证的权限,则触发用户管理按钮的点击事件
  471. document.getElementById('user-management-link').click();
  472. }else if (hasReadRolePermission) {// 根据权限触发相应的按钮点击事件
  473. // 如果没有读取许可证的权限,则触发角色管理按钮的点击事件
  474. document.getElementById('role-management-link').click();
  475. } else if (hasReadLicensePermission) {
  476. document.getElementById('license-info-link').click();
  477. }
  478. // 定义权限类别
  479. // const licensePermissions = ['upload_license', 'read_license'];
  480. // const userPermissionsCheck = ['create_user', 'read_user', 'update_user', 'delete_user'];
  481. // const rolePermissions = ['create_role', 'delete_role', 'update_role', 'get_role'];
  482. // const hasLicenseAccess = licensePermissions.some(permission => userPermissions.includes(permission));
  483. // const hasUserManagementAccess = userPermissionsCheck.some(permission => userPermissions.includes(permission));
  484. // const hasRoleManagementAccess = rolePermissions.some(permission => userPermissions.includes(permission));
  485. // 根据权限渲染菜单并显示初始页面
  486. //renderMenuAndInitialPage(hasLicenseAccess, hasUserManagementAccess, hasRoleManagementAccess);
  487. } catch (error) {
  488. console.error('Error fetching permissions:', error);
  489. }
  490. }
  491. //--------------进度条-------------------------------------------------
  492. // 创建模态框的 DOM 元素并插入到 body 中
  493. function createLoadingModal() {
  494. const modalHTML = `
  495. <div id="loadingModal" class="loading-modal" style="display: none;">
  496. <div class="loading-modal-content">
  497. <div class="spinner"></div>
  498. <p id="loadingMessage">加载中...</p>
  499. </div>
  500. </div>
  501. `;
  502. document.body.insertAdjacentHTML('beforeend', modalHTML);
  503. }
  504. // 显示加载模态框
  505. function showLoadingModal(message = "加载中...") {
  506. const loadingModal = document.getElementById('loadingModal');
  507. const loadingMessage = document.getElementById('loadingMessage');
  508. if (loadingModal && loadingMessage) {
  509. loadingMessage.textContent = message; // 设置显示的消息
  510. loadingModal.style.display = 'flex'; // 显示模态框
  511. }
  512. }
  513. // 隐藏加载模态框
  514. function hideLoadingModal() {
  515. const loadingModal = document.getElementById('loadingModal');
  516. if (loadingModal) {
  517. loadingModal.style.display = 'none'; // 隐藏模态框
  518. }
  519. }
  520. // 页面加载时创建模态框
  521. document.addEventListener('DOMContentLoaded', createLoadingModal);
  522. //-----------搜索栏----------------------------
  523. // 获取搜索框元素
  524. // 获取搜索框、状态下拉框、时间选择框和按钮元素
  525. // 获取搜索框、状态下拉框、时间选择框和按钮元素
  526. const searchBar = document.getElementById('search-bar');
  527. const statusFilter = document.getElementById('license-status-filter');
  528. const startDate = document.getElementById('start-date');
  529. const endDate = document.getElementById('end-date');
  530. const submitButton = document.getElementById('submit-button');
  531. const licenseInfoContainer = document.getElementById('license-info-restaurant-list');
  532. // 过滤功能实现
  533. function filterContent() {
  534. console.log('过滤功能触发');
  535. // 移除滚动监听器,停止滚动加载
  536. // removeScrollListeners();
  537. console.log('statusFilter.valuesdaad撒大啊', statusFilter.value,startDate.value ,endDate.value,searchBar.value );
  538. // 检查如果所有输入框都是默认值,则直接返回,不发送数据
  539. if (!statusFilter.value && !startDate.value && !endDate.value && !searchBar.value) {
  540. console.log("所有过滤条件为空,不发送请求");
  541. return; // 不发送请求
  542. }
  543. // 构建请求体参数
  544. const requestData = {
  545. license_flag: statusFilter.value || undefined,
  546. starting_date: startDate.value || undefined,
  547. end_date: endDate.value || undefined,
  548. any_search: searchBar.value || undefined,
  549. };
  550. console.log("requestData",requestData);
  551. // 发送 POST 请求到接口
  552. fetch('http://127.0.0.1:8080/api/admin/GetConditionalSearch', {
  553. method: 'POST',
  554. headers: {
  555. 'Authorization': `Bearer ${authToken}`,
  556. 'Content-Type': 'application/json',
  557. },
  558. body: JSON.stringify(requestData),
  559. })
  560. .then(response => response.json())
  561. .then(data => {
  562. console.log('成功获取数据:', data);
  563. // 处理返回的数据并更新界面
  564. displayLicenseInfo(data.data);
  565. })
  566. .catch(error => {
  567. console.error('获取数据时发生错误:', error);
  568. });
  569. }
  570. // 处理并显示返回的 License 信息
  571. function displayLicenseInfo(data) {
  572. // 清空之前的结果
  573. licenseInfoContainer.innerHTML = '';
  574. LicApplicationData =[];
  575. // 遍历返回的数据,生成并插入卡片
  576. // 处理返回的数据并更新界面,使用 renderLicenseCards 方法进行渲染
  577. renderLicenseCards(data, true);
  578. }
  579. // 确定按钮点击事件的修改(停止滚动监听)
  580. submitButton.addEventListener('click', function() {
  581. // 检查下拉框和时间选择框是否为默认值
  582. if (!statusFilter.value && !startDate.value && !endDate.value) {
  583. // 如果都是默认值,则刷新页面
  584. location.reload();
  585. } else {
  586. // 否则,执行过滤内容功能
  587. filterContent();
  588. // 隐藏滚动加载,防止继续加载更多内容
  589. removeScrollListeners();
  590. }
  591. });
  592. // 监听返回按钮的点击事件,刷新页面并恢复滚动监听
  593. const resetButton = document.getElementById('reset-button');
  594. resetButton.addEventListener('click', function() {
  595. // 刷新页面
  596. location.reload();
  597. });
  598. // 修改当搜索栏没有输入时,重新启动滚动监听
  599. searchBar.addEventListener('input', function() {
  600. if (!searchBar.value && !statusFilter.value && !startDate.value && !endDate.value) {
  601. console.log("搜索条件清空,重新启动滚动监听");
  602. restartScrollListeners();
  603. }
  604. });