license_info.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. // 全局变量定义
  2. let page = 11; // 初始页码为1,代表从第1条数据开始获取
  3. let pageSize = 20; // 初始每次固定获取10条数据
  4. let total = 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. const currentUserInfo = fetchUsername(); // 获取当前用户登录信息
  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. // 获取所有菜单项
  45. const menuItems = document.querySelectorAll('nav ul li a');
  46. // 为每个菜单项添加点击事件监听器
  47. menuItems.forEach(item => {
  48. item.addEventListener('click', function() {
  49. // 移除其他项的 active 类
  50. menuItems.forEach(i => i.classList.remove('active'));
  51. // 为当前点击的项添加 active 类
  52. this.classList.add('active');
  53. });
  54. });
  55. //用户管理-
  56. //获取用户管理和 License 信息按钮
  57. const userManagementLink = document.getElementById('user-management-link');
  58. const licenseInfoLink = document.getElementById('license-info-link');
  59. const roleManagementLink = document.getElementById('role-management-link');
  60. // 监听用户管理按钮的点击事件
  61. userManagementLink.addEventListener('click', function(event) {
  62. event.preventDefault(); // 阻止默认的跳转行为
  63. removeScrollListeners(); // 移除滚动监听器
  64. // 使用 fetch 来加载 user_management.html 的内容
  65. fetch('../user/user_management.html')
  66. .then(response => response.text())
  67. .then(data => {
  68. // 将 user_management.html 的内容插入到主内容区域
  69. license_info_mainElement.innerHTML = data;
  70. // 动态引入 user.js 文件
  71. const script = document.createElement('script');
  72. script.src = '../user/user.js';
  73. document.body.appendChild(script);
  74. })
  75. .catch(error => console.error('加载用户管理页面失败:', error));
  76. });
  77. // 监听 License 信息按钮的点击事件
  78. licenseInfoLink.addEventListener('click', function(event) {
  79. event.preventDefault(); // 阻止默认的跳转行为
  80. // 将瀑布流的 License 信息内容恢复到主内容区域
  81. const licenseInfoHtml = `
  82. <!-- 包裹搜索框、下拉框、时间选择框和确定按钮的 div -->
  83. <div class="search-container">
  84. <!-- License 状态下拉框 -->
  85. <select id="license-status-filter" aria-label="选择 License 状态">
  86. <option value="">License 状态</option>
  87. <option value="已生成">已生成</option>
  88. <option value="未生成">未生成</option>
  89. <option value="已失效">已失效</option>
  90. </select>
  91. <!-- 开始时间选择框,类型改为 date -->
  92. <input type="date" id="start-date" placeholder="开始时间" />
  93. <!-- 结束时间选择框,类型改为 date -->
  94. <input type="date" id="end-date" placeholder="结束时间" />
  95. <!-- 搜索框 -->
  96. <input type="text" id="search-bar" placeholder="搜索..." />
  97. <!-- 确定按钮 -->
  98. <button id="submit-button">确定</button>
  99. </div>
  100. <div class="license-info-container" id="license-info-restaurant-list"> </div>
  101. `; // 这是原来的 License 信息区域 HTML
  102. //mainContainer.innerHTML = licenseInfoHtml;
  103. license_info_mainElement.innerHTML = licenseInfoHtml;
  104. //清楚lic信息组的数据
  105. LicApplicationData = [];
  106. initializeScrollListeners(); // 重新初始化滚动监听器
  107. // 再次加载 License 信息数据并渲染卡片
  108. (async function() {
  109. const data = await fetchLicenseData(1, 10);
  110. if (data.length > 0) {
  111. console.log('加载的数据:', data); // 检查是否成功获取数据
  112. renderLicenseCards(data, true); // 渲染数据到页面并清空之前的内容
  113. } else {
  114. console.error('未加载到数据');
  115. }
  116. })();
  117. });
  118. roleManagementLink.addEventListener('click', function(event) {
  119. event.preventDefault(); // 阻止默认的跳转行为
  120. removeScrollListeners(); // 移除滚动监听器
  121. // 使用 fetch 来加载 user_management.html 的内容
  122. fetch('../role/role.html')
  123. .then(response => response.text())
  124. .then(data => {
  125. // 将 user_management.html 的内容插入到主内容区域
  126. license_info_mainElement.innerHTML = data;
  127. // 动态引入 user.js 文件
  128. const script = document.createElement('script');
  129. script.src = '../role/role.js';
  130. document.body.appendChild(script);
  131. })
  132. .catch(error => console.error('加载用户管理页面失败:', error));
  133. });
  134. //-------license数据显示------------------------------------------------------
  135. // 获取数据函数
  136. async function fetchLicenseData(page, pageSize) {
  137. try {
  138. const response = await fetch(`http://127.0.0.1:8080/api/admin/GetAllLicenseInfo?page=${page}&pageSize=${pageSize}`, {
  139. method: 'GET',
  140. headers: {
  141. 'Authorization': `Bearer ${authToken}`,
  142. 'Content-Type': 'application/json'
  143. }
  144. });
  145. const result = await response.json();
  146. // 设置总量,如果第一次加载,获取total字段
  147. if (total === 0 && result.total) {
  148. total = result.total;
  149. }
  150. // 使用 concat 方法将新数据与之前的数据进行累加
  151. LicApplicationData = LicApplicationData.concat(result.data || []);
  152. console.log("LicApplicationData: ",LicApplicationData);
  153. return result.data || [];
  154. } catch (error) {
  155. console.error("加载数据失败", error);
  156. return []; // 返回空数组,防止后续操作出错
  157. }
  158. }
  159. // 渲染 license_info 卡片数据函数
  160. function renderLicenseCards(data, clearContainer = false) {
  161. console.log("-----------渲染次数");
  162. // 获取与 license_info 相关的 HTML 元素
  163. const license_info_container = document.getElementById('license-info-restaurant-list'); // 卡片列表容器
  164. if (clearContainer) {
  165. license_info_container.innerHTML = ''; // 清空容器内容
  166. isLoading = false; // 重置加载状态
  167. loadedItems = 0; // 重置已加载项数
  168. page = 11; // 每次请求后,page 增加10,表示从下一组数据开始
  169. pageSize = 20; // pageSize 每次递增10
  170. console.log("-----------渲染清除");
  171. }
  172. console.log("-----------data:",data);
  173. data.forEach(group => {
  174. const firstItem = group[0]; // 获取该组的第一个数据项
  175. // 获取子行的数量
  176. const childRowCount = group.length;
  177. let statusClass = '';
  178. if (firstItem.LicenseFlage === '已生成') {
  179. statusClass = 'license-status-green';
  180. } else if (firstItem.LicenseFlage === '未生成') {
  181. statusClass = 'license-status-yellow';
  182. } else if (firstItem.LicenseFlage === '已失效') {
  183. statusClass = 'license-status-red';
  184. }
  185. const card = document.createElement('div');
  186. card.className = 'license-info-card';
  187. // 给卡片添加一个唯一标识符的 data 属性
  188. card.setAttribute('data-oa-request-id', firstItem.oa_request_id);
  189. // 在卡片的第一行显示申请时间
  190. card.innerHTML = `
  191. <div class="license-info-card-header">
  192. <h3 class="card-title">${firstItem.GlxmName}</h3>
  193. </div>
  194. <div class="license-info-card-content">
  195. <p class="card-text">${firstItem.ApplicationDate} ${firstItem.ApplicationTime}</p> <!-- 显示日期和时间 -->
  196. <p class="card-text">创建者:${firstItem.Creator}</p>
  197. <p class="card-text">公司:${firstItem.Company}</p>
  198. <p class="card-text">集群:${childRowCount} 套 共计:${firstItem.TotalNodes} 节点</p>
  199. <p class="card-text license-status ${statusClass}">许可证状态:${firstItem.LicenseFlage}</p>
  200. <p class="card-text">oa_request_id:${firstItem.oa_request_id}</p>
  201. </div>
  202. `;
  203. // 给卡片添加点击事件,点击后显示模态框
  204. card.addEventListener('click', () => {
  205. // 传递当前卡片的详细数据到模态框
  206. const oaRequestId = card.getAttribute('data-oa-request-id');
  207. showModalForCard(group, oaRequestId); // 传递 oa_request_id
  208. //showModalForCard(group); // 传递当前卡片的详细数据到模态框
  209. });
  210. // 将卡片添加到容器中
  211. license_info_container.appendChild(card);
  212. });
  213. }
  214. // 检查是否滚动到底部并触发加载
  215. // async function checkAndLoadMore(scrollHeight, scrollTop, clientHeight) {
  216. // if (isLoading || loadedItems >= total) return; // 如果正在加载或已加载完所有数据则退出
  217. // // console.log(`Scroll Info - scrollHeight: ${scrollHeight}, scrollTop: ${scrollTop}, clientHeight: ${clientHeight}`);
  218. // if (scrollTop + clientHeight >= scrollHeight - preLoadDistance) {
  219. // console.log(`触发加载更多数据:page=${page}, pageSize=${pageSize}`); // 每次触发时打印输出
  220. // await loadMoreData();
  221. // }
  222. // }
  223. // 加载更多数据函数
  224. async function loadMoreData() {
  225. if (isLoading) return; // 防止重复加载
  226. isLoading = true;
  227. console.log('开始加载更多数据');
  228. // 显示加载提示
  229. // license_info_loadingIndicator.style.display = 'block'; // 显示提示
  230. // license_info_loadingIndicator.innerText = '正在加载...'; // 重置加载提示
  231. // 设置超时处理
  232. const timeout = setTimeout(() => {
  233. license_info_loadingIndicator.innerText = '加载超时,请重试'; // 修改提示语为超时提示
  234. isLoading = false;
  235. license_info_loadingIndicator.style.display = 'none'; // 超时后隐藏加载提示
  236. }, timeoutDuration);
  237. // 获取数据
  238. const data = await fetchLicenseData(page, pageSize);
  239. console.log(`加载的新数据 data`,data); // 每次触发时打印输出
  240. // 清除超时定时器
  241. clearTimeout(timeout);
  242. if (data.length > 0) {
  243. // 更新 page 和 pageSize,下一次请求从新的位置开始
  244. page += 10; // 每次请求后,page 增加10,表示从下一组数据开始
  245. pageSize += 10; // pageSize 每次递增10
  246. // 更新已加载的条目数
  247. loadedItems += data.length;
  248. // 渲染数据到页面
  249. renderLicenseCards(data);
  250. console.log('数据加载完成,更新页面');
  251. }
  252. // 隐藏加载提示
  253. //license_info_loadingIndicator.style.display = 'none'; // 加载完成后隐藏提示
  254. isLoading = false; // 请求完成,允许下次请求
  255. // 检查内容高度,必要时继续加载
  256. //checkContentHeight();
  257. checkAndLoadMore();
  258. }
  259. //--------------------------监听 window 滚动---监听 main 容器的滚动-----------------------------------------------
  260. // // 监听 window 滚动
  261. // window.addEventListener('scroll', () => {
  262. // checkAndLoadMore(document.body.scrollHeight, window.scrollY, window.innerHeight);
  263. // });
  264. // // 监听 main 容器的滚动
  265. // license_info_mainElement.addEventListener('scroll', () => {
  266. // checkAndLoadMore(license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  267. // });
  268. function initializeScrollListeners() {
  269. // 只监听 main 容器的滚动
  270. license_info_mainElement.addEventListener('scroll', handleMainScroll);
  271. // console.log('滚动监听已初始化');
  272. }
  273. function removeScrollListeners() {
  274. // 移除 main 容器的滚动监听
  275. license_info_mainElement.removeEventListener('scroll', handleMainScroll);
  276. }
  277. // 新增一个重启滑动监听功能函数,当用户清空搜索条件时调用
  278. function restartScrollListeners() {
  279. // 重新绑定滑动监听器
  280. initializeScrollListeners();
  281. }
  282. function handleMainScroll() {
  283. // console.log('handleMainScroll', license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  284. checkAndLoadMore(license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
  285. }
  286. async function checkAndLoadMore(scrollHeight, scrollTop, clientHeight) {
  287. if (isLoading || loadedItems >= total) return; // 如果正在加载或已加载完所有数据则退出
  288. // console.log(`Scroll Info - scrollHeight: ${scrollHeight}, scrollTop: ${scrollTop}, clientHeight: ${clientHeight}`);
  289. if (scrollTop + clientHeight >= scrollHeight - preLoadDistance) {
  290. console.log(`触发加载更多数据:page=${page}, pageSize=${pageSize}`); // 每次触发时打印输出
  291. await loadMoreData();
  292. }
  293. }
  294. //-----------------------------------------------------------------------------------------
  295. // 初始化加载第一页
  296. (async function() {
  297. const data = await fetchLicenseData(1, 10);
  298. if (data.length > 0) {
  299. renderLicenseCards(data); // 渲染数据到页面
  300. loadedItems += data.length; // 更新已加载的条目数
  301. }
  302. //license_info_loadingIndicator.style.display = 'none'; // 初始化后隐藏加载提示
  303. // 检查内容高度
  304. // checkContentHeight();
  305. checkAndLoadMore()
  306. })();
  307. //初始化监听滚动条
  308. initializeScrollListeners()
  309. //-----------点击卡片弹出模态框------------------------------------------------------
  310. // 模态框显示函数
  311. // 模态框显示函数
  312. function showModalForCard(item,oaRequestId) {
  313. const modal = document.getElementById('license-info-modal');
  314. const modalContent = document.querySelector('.license-info-modal-content');
  315. const modalBody = document.getElementById('license-info-modal-body'); // 获取下半部分容器
  316. console.log(`当前点击的卡片 ID: ${oaRequestId}`);
  317. // 设置分页相关的变量
  318. let currentPage = 1;
  319. const itemsPerPage = 3; // 每页显示两组
  320. // 对 item 数组按 oa_id 进行升序排序
  321. const sortedItem = item.sort((a, b) => a.oa_id - b.oa_id);
  322. const totalPages = Math.ceil(sortedItem.length / itemsPerPage); // 计算总页数
  323. // 获取分页容器
  324. const paginationContainer = document.querySelector('.license-info-modal-pagination');
  325. // 清空分页容器,避免重复创建元素
  326. paginationContainer.innerHTML = '';
  327. // 创建"上一页"按钮
  328. const prevButton = document.createElement('button');
  329. prevButton.classList.add('prev-page');
  330. prevButton.innerText = '上一页';
  331. paginationContainer.appendChild(prevButton);
  332. // 创建下拉框
  333. const selectPageDropdown = document.createElement('select');
  334. paginationContainer.appendChild(selectPageDropdown);
  335. // 创建"下一页"按钮
  336. const nextButton = document.createElement('button');
  337. nextButton.classList.add('next-page');
  338. nextButton.innerText = '下一页';
  339. paginationContainer.appendChild(nextButton);
  340. // 初始化上半部分内容(Company, Creator, ApplicationDate, ApplicationTime 和两个按钮)
  341. function initializeHeaderContent(firstItem,sortedItem) {
  342. console.log("initializeHeaderContent"); // 检查是否找到按钮
  343. // 清空上半部分内容
  344. const modalHeader = document.querySelector('.license-info-modal-header');
  345. modalHeader.innerHTML = ''; // 确保不会重复创建
  346. let statusClass = '';
  347. if (firstItem.LicenseFlage === '已生成') {
  348. statusClass = 'license-status-green';
  349. } else if (firstItem.LicenseFlage === '未生成') {
  350. statusClass = 'license-status-yellow';
  351. } else if (firstItem.LicenseFlage === '已失效') {
  352. statusClass = 'license-status-red';
  353. }
  354. // 检查当前用户是否有权限生成或分发
  355. const hasGeneratePermission = currentUserPermissions.includes('generate_license');
  356. const hasDispatchPermission = currentUserPermissions.includes('dispat_license');
  357. console.log(`当前用户是否有生成权限: ${hasGeneratePermission}, ${hasDispatchPermission}`);
  358. // 设置卡片内容
  359. modalHeader.innerHTML = `
  360. <div class="license-info-card-header">
  361. <h3 class="card-title">${firstItem.GlxmName}</h3>
  362. </div>
  363. <div class="license-info-card-content">
  364. <p class="card-text">${firstItem.ApplicationDate} ${firstItem.ApplicationTime}</p> <!-- 显示日期和时间 -->
  365. <p class="card-text">公司:${firstItem.Company}</p>
  366. <p class="card-text">${firstItem.Project}</p>
  367. <p class="card-text">创建者:${firstItem.Creator}</p>
  368. <p class="card-text license-status ${statusClass}">许可证状态:${firstItem.LicenseFlage}</p>
  369. <div class="license-info-card-buttons">
  370. ${
  371. firstItem.LicenseFlage === '已生成' && hasDispatchPermission
  372. ? `<button class="license-info-modal-button" id="generateOrDistribute">分发</button>`
  373. : firstItem.LicenseFlage !== '已生成' && hasGeneratePermission
  374. ? `<button class="license-info-modal-button" id="generateOrDistribute">生成</button>`
  375. : ''
  376. }
  377. <button class="license-info-modal-button" id="downloadAllLicenses-button">打包下载所有license.dat</button>
  378. <button id="viewDistributionHistory-button">查看分发历史</button>
  379. </div>
  380. </div>
  381. `;
  382. // 绑定 button1 的点击事件(如果按钮存在)
  383. const generateOrDistribute = modalHeader.querySelector('#generateOrDistribute');
  384. console.log("generateOrDistribute",generateOrDistribute); // 检查是否找到按钮
  385. if (generateOrDistribute) {
  386. generateOrDistribute.addEventListener('click', () => {
  387. if (firstItem.LicenseFlage === '已生成') {
  388. // 执行分发逻辑
  389. showDistributeModal(firstItem);
  390. } else {
  391. // 执行生成逻辑
  392. const oaRequestID = parseInt(firstItem.oa_request_id, 10); // 10 表示10进制
  393. generateLicense(oaRequestID, true);
  394. }
  395. console.log('Button 1 clicked');
  396. });
  397. }
  398. ;
  399. // 绑定 "打包下载所有license.dat" 按钮的点击事件
  400. const downloadButton = modalHeader.querySelector('#downloadAllLicenses-button');
  401. // 如果 LicenseFlage 是 "未生成" 或 "已失效",按钮变灰且不可点击
  402. if (firstItem.LicenseFlage === '未生成' || firstItem.LicenseFlage === '已失效') {
  403. downloadButton.disabled = true;
  404. downloadButton.style.backgroundColor = '#ccc'; // 设置为灰色
  405. downloadButton.style.cursor = 'not-allowed'; // 修改鼠标样式
  406. } else {
  407. // 只有当 LicenseFlage 是 "已生成" 时,才能点击下载按钮
  408. downloadButton.addEventListener('click', () => {
  409. downloadAllLicenses(sortedItem);
  410. });
  411. }
  412. // 在初始化完成后绑定 "查看分发历史" 按钮的点击事件
  413. const viewDistributionHistoryButton = document.getElementById('viewDistributionHistory-button');
  414. if (viewDistributionHistoryButton) {
  415. viewDistributionHistoryButton.addEventListener('click', () => {
  416. showDistributionHistory(firstItem);
  417. });
  418. }
  419. }
  420. // 初始化下拉框的页码选项
  421. function initializeDropdown() {
  422. selectPageDropdown.innerHTML = ''; // 清空下拉框中的选项
  423. for (let page = 1; page <= totalPages; page++) {
  424. const option = document.createElement('option');
  425. option.value = page;
  426. option.innerText = `第 ${page} 页`;
  427. selectPageDropdown.appendChild(option);
  428. }
  429. selectPageDropdown.value = currentPage; // 设置默认选项为当前页
  430. }
  431. // 渲染当前页内容
  432. function ModalForCardRenderPage(page) {
  433. modalBody.innerHTML = ''; // 清空之前的内容
  434. // 计算当前页的起始和结束索引
  435. const startIndex = (page - 1) * itemsPerPage;
  436. const endIndex = Math.min(startIndex + itemsPerPage, sortedItem.length);
  437. // 更新上半部分的字段内容 (以第一个元素为例)
  438. const firstItem = sortedItem[0];
  439. initializeHeaderContent(firstItem,sortedItem); // 动态生成上半部分内容
  440. // 遍历当前页的数据
  441. for (let i = startIndex; i < endIndex; i++) {
  442. const group = sortedItem[i];
  443. const groupBox = document.createElement('div');
  444. groupBox.classList.add('license-info-group-box');
  445. // 动态生成组内容,显示编号为 i+1(表示组1, 组2...)
  446. groupBox.innerHTML = `
  447. <div class="license-info-group-title">集群 ${i + 1} :</div>
  448. <p><strong>节点数:</strong> ${group.NodeCount}</p>
  449. <p><strong>数据库版本: </strong> ${group.ProductName}${group.ProductVersion}</p>
  450. <p><strong>CPU 型号:</strong> ${group.oa_cpu}</p>
  451. <p><strong>操作系统环境:</strong> ${group.oa_operating_system}</p>
  452. <p><strong>以下为测试显示:</strong> </p>
  453. <p><strong>oa_id:</strong> ${group.oa_id}</p>
  454. <p><strong>oa_request_id:</strong> ${group.oa_request_id}</p>
  455. `;
  456. // 将生成的组内容加入到 modalBody
  457. modalBody.appendChild(groupBox);
  458. }
  459. // 更新下拉框的值
  460. selectPageDropdown.value = page;
  461. // 更新按钮状态
  462. prevButton.disabled = (page === 1);
  463. nextButton.disabled = (page === totalPages);
  464. }
  465. // 下拉框页码选择事件
  466. selectPageDropdown.addEventListener('change', function() {
  467. currentPage = parseInt(this.value);
  468. ModalForCardRenderPage(currentPage); // 根据选择的页码渲染对应页面
  469. });
  470. // 上一页按钮点击事件
  471. prevButton.addEventListener('click', function() {
  472. if (currentPage > 1) {
  473. currentPage--;
  474. ModalForCardRenderPage(currentPage);
  475. }
  476. });
  477. // 下一页按钮点击事件
  478. nextButton.addEventListener('click', function() {
  479. if (currentPage < totalPages) {
  480. currentPage++;
  481. ModalForCardRenderPage(currentPage);
  482. }
  483. });
  484. // 显示或隐藏分页相关控件
  485. function togglePaginationVisibility() {
  486. if (totalPages <= 1) {
  487. // 隐藏下拉框和分页容器
  488. paginationContainer.style.display = 'none';
  489. } else {
  490. // 显示下拉框和分页容器
  491. paginationContainer.style.display = 'flex';
  492. }
  493. }
  494. // 初始化下拉框并渲染第一页
  495. initializeDropdown();
  496. // 渲染模态框内容
  497. ModalForCardRenderPage(currentPage);
  498. // 根据页数决定是否显示分页控件
  499. togglePaginationVisibility();
  500. // 显示模态框
  501. modal.style.display = 'flex'; // 显示模态框背景
  502. setTimeout(() => {
  503. modalContent.classList.add('show'); // 添加动画效果
  504. }, 10); // 延时确保动画生效
  505. // 关闭模态框逻辑
  506. const closeModal = document.querySelector('.license-info-close');
  507. closeModal.addEventListener('click', () => {
  508. modalContent.classList.remove('show'); // 移除动画类
  509. setTimeout(() => {
  510. modal.style.display = 'none'; // 完全隐藏模态框
  511. }, 500); // 等待动画结束后再隐藏
  512. });
  513. // 点击模态框外部关闭模态框
  514. window.addEventListener('click', (event) => {
  515. if (event.target === modal) {
  516. modalContent.classList.remove('show');
  517. setTimeout(() => {
  518. modal.style.display = 'none'; // 完全隐藏模态框
  519. }, 500); // 等待动画结束后再隐藏
  520. }
  521. });
  522. }
  523. //-------下载全部licstr按钮
  524. // 下载许可证功能
  525. function downloadAllLicenses(sortedApplicationArray) {
  526. const zip = new JSZip();
  527. console.log("传进来的 sortedApplicationArray:", sortedApplicationArray);
  528. // 初始化计数器,从1开始
  529. let idCounter = 1;
  530. let Project = sortedApplicationArray[0].Project;
  531. console.log("Project", Project);
  532. // 遍历 sortedApplicationArray,下载 lic1 和 lic2 数据
  533. sortedApplicationArray.forEach(row => {
  534. if (row.LicenseFlage === "已生成") {
  535. // 替换 oa_main_mac 和 oa_second_mac 中的冒号为点
  536. const mainMac = row.oa_main_mac.replace(/:/g, '.');
  537. const secondMac = row.oa_second_mac.replace(/:/g, '.');
  538. // 使用递增的 idCounter 替换 row.oa_id
  539. if (row.lic1) {
  540. const filename1 = `${idCounter}_license.dat_1_${mainMac}`;
  541. zip.file(filename1, row.lic1);
  542. }
  543. if (row.lic2) {
  544. const filename2 = `${idCounter}_license.dat_2_${secondMac}`;
  545. zip.file(filename2, row.lic2);
  546. }
  547. // 每次循环后递增计数器
  548. idCounter++;
  549. }
  550. });
  551. // 生成 ZIP 文件并触发下载
  552. zip.generateAsync({ type: "blob" }).then(content => {
  553. const link = document.createElement('a');
  554. link.href = URL.createObjectURL(content);
  555. link.download = `${Project}_license.zip`;
  556. link.click();
  557. });
  558. }
  559. //分发
  560. let userMap = {};
  561. // 打开分发模态框
  562. function showDistributeModal(firstItem) {
  563. console.log("showDistributeModal firstItem", firstItem);
  564. const modal = document.getElementById('distribute-modal');
  565. const emailInputs = document.getElementById('emailInputs');
  566. const userInputs = document.getElementById('userInputs');
  567. let usedUsernames = []; // 存储已选择的用户
  568. // 清空内容
  569. emailInputs.innerHTML = '';
  570. userInputs.innerHTML = '';
  571. // 动态生成分发邮箱部分
  572. if (firstItem.SupportEmail) {
  573. emailInputs.innerHTML += `<div><input type="checkbox" id="supportEmail" value="${firstItem.SupportEmail}"> 运维邮箱: ${firstItem.SupportEmail}</div>`;
  574. }
  575. if (firstItem.SalesEmail) {
  576. emailInputs.innerHTML += `<div><input type="checkbox" id="salesEmail" value="${firstItem.SalesEmail}"> 销售邮箱: ${firstItem.SalesEmail}</div>`;
  577. }
  578. // 调用 API 获取用户信息并填充第一个用户输入框
  579. fetch('http://127.0.0.1:8080/api/admin/distributeLicenseByUserInfo', {
  580. method: 'GET',
  581. headers: {
  582. 'Authorization': `Bearer ${authToken}`, // 确保 token 已经定义
  583. 'Content-Type': 'application/json'
  584. }
  585. })
  586. .then(response => response.json())
  587. .then(data => {
  588. // 初始化 userMap
  589. userMap = {};
  590. const availableUsers = data.data
  591. .map(user => {
  592. // 将用户信息存储在 userMap 中
  593. userMap[user.Username] = {
  594. Account: user.Account,
  595. UniqueID: user.UniqueID,
  596. Username: user.Username,
  597. Email: user.Email,
  598. Role: user.Role,
  599. Telephone: user.Telephone
  600. };
  601. return user.Username;
  602. })
  603. .filter(user => user !== 'admin'); // 排除用户名为 "admin"
  604. // createUserSelect(userInputs, availableUsers, usedUsernames); // 创建第一个下拉框
  605. // 创建“添加用户”按钮
  606. const addButton = document.createElement('button');
  607. addButton.className = 'distribute-add-user-button';
  608. addButton.textContent = '添加用户';
  609. addButton.addEventListener('click', () => {
  610. createUserSelect(userInputs, availableUsers, usedUsernames); // 添加新的下拉框
  611. });
  612. userInputs.appendChild(addButton);
  613. // 创建“确定分发”按钮
  614. const distributeButton = document.createElement('button');
  615. distributeButton.className = 'distribute-confirm-button';
  616. distributeButton.textContent = '确定分发';
  617. distributeButton.addEventListener('click', () => {
  618. // 弹出确认框
  619. if (confirm('确定要分发许可证吗?')) {
  620. // 获取选中的用户信息
  621. const selectedUserInputs = Array.from(document.querySelectorAll('select.distribute-user-select'));
  622. const userIds = selectedUserInputs.map(select => userMap[select.value].UniqueID);
  623. const userAccounts = selectedUserInputs.map(select => userMap[select.value].Account);
  624. const userNames = selectedUserInputs.map(select => userMap[select.value].Username);
  625. // 将提前获取的用户信息传递给 distributeLicenseToUsers 函数
  626. distributeLicenseToUsers(firstItem, userIds, userAccounts, userNames);
  627. }
  628. });
  629. userInputs.appendChild(distributeButton);
  630. })
  631. .catch(error => console.error('获取用户信息失败:', error));
  632. // 显示模态框
  633. modal.style.display = 'flex';
  634. // 关闭按钮事件
  635. const closeButton = document.querySelector('#distribute-modal .distribute-close');
  636. closeButton.addEventListener('click', () => {
  637. modal.style.display = 'none';
  638. });
  639. // 点击模态框外部区域时关闭模态框
  640. window.addEventListener('click', function(event) {
  641. if (event.target === modal) {
  642. modal.style.display = 'none';
  643. }
  644. });
  645. }
  646. //分发license 到用户
  647. function distributeLicenseToUsers(selectedRowData, userIds, userAccounts, userNames) {
  648. console.log('Distribute button clicked');
  649. console.log('userIds', userIds);
  650. console.log('userAccounts', userAccounts);
  651. console.log('userNames', userNames);
  652. // 显示加载进度条并设置动态提示信息
  653. showLoadingModal('正在分发 License...');
  654. const operatorUniqueID = userMap[currentUserName].UniqueID;
  655. if (userIds.length === 0) {
  656. alert('请至少选择一个用户。');
  657. hideLoadingModal();
  658. return;
  659. }
  660. const requestData = {
  661. LicenseUniqueID: selectedRowData.UniqueID, // 当前选中的 License ID
  662. Oa_request_id: selectedRowData.oa_request_id, // 当前选中的 OA 请求 ID
  663. UserUniqueIDs: userIds, // 用户 ID 数组
  664. UserAccounts: userAccounts, // 用户账号数组
  665. UserNames: userNames, // 用户名数组
  666. Emails: '', // 邮箱(可以根据需要添加或删除)
  667. OperatorUniqueID: operatorUniqueID // 操作者的唯一 ID
  668. };
  669. console.log('requestData:', requestData);
  670. // 发起 POST 请求到分发 License 的 API
  671. fetch('http://127.0.0.1:8080/api/admin/DistributeLicenseToUser', {
  672. method: 'POST',
  673. headers: {
  674. 'Authorization': `Bearer ${authToken}`,
  675. 'Content-Type': 'application/json'
  676. },
  677. body: JSON.stringify(requestData)
  678. })
  679. .then(response => response.json())
  680. .then(data => {
  681. hideLoadingModal();
  682. if (data.success) {
  683. alert('分发成功!');
  684. closeModal('distribute-modal'); // 关闭模态框
  685. } else {
  686. const errorMessage = data.error || '分发失败。';
  687. alert(`分发失败: ${errorMessage}`);
  688. }
  689. })
  690. .catch(error => {
  691. hideLoadingModal();
  692. console.error('Error occurred during license distribution:', error);
  693. alert('分发失败,请检查网络或后端服务。');
  694. });
  695. }
  696. // 创建新的下拉框并过滤掉已选择的用户
  697. // 创建新的下拉框并过滤掉已选择的用户
  698. function createUserSelect(container, availableUsers, usedUsernames) {
  699. // 创建下拉框容器
  700. const userSelectContainer = document.createElement('div');
  701. userSelectContainer.className = 'distribute-modal-user-select-container';
  702. // 创建下拉框
  703. const userSelect = document.createElement('select');
  704. userSelect.className = 'distribute-modal-user-select';
  705. // 过滤掉已经选中的用户
  706. const filteredUsers = availableUsers.filter(user => !usedUsernames.includes(user));
  707. // 填充下拉框选项
  708. filteredUsers.forEach(user => {
  709. const option = document.createElement('option');
  710. option.value = user;
  711. option.textContent = user;
  712. userSelect.appendChild(option);
  713. });
  714. // 创建关闭按钮
  715. const closeButton = document.createElement('span');
  716. closeButton.textContent = 'X';
  717. closeButton.className = 'distribute-modal-close-select'; // 添加类名以便样式化
  718. closeButton.style.cursor = 'pointer'; // 鼠标样式
  719. closeButton.style.marginLeft = '10px'; // 与下拉框之间的间距
  720. // 关闭按钮点击事件,删除下拉框和自身,并从已选择用户名数组中移除
  721. closeButton.addEventListener('click', function() {
  722. // 从已选择的用户名中移除
  723. const selectedValue = userSelect.value;
  724. const index = usedUsernames.indexOf(selectedValue);
  725. if (index > -1) {
  726. usedUsernames.splice(index, 1); // 移除已选择的用户名
  727. }
  728. container.removeChild(userSelectContainer); // 删除下拉框容器
  729. });
  730. // 将下拉框和关闭按钮添加到容器中
  731. userSelectContainer.appendChild(userSelect);
  732. userSelectContainer.appendChild(closeButton);
  733. // 将下拉框容器添加到父容器中
  734. container.appendChild(userSelectContainer);
  735. // 当选择新用户时,将其添加到已选择的用户名数组中
  736. userSelect.addEventListener('change', function() {
  737. const previousValue = usedUsernames.find(u => u === this.defaultValue);
  738. if (previousValue) {
  739. // 如果之前的值存在且不同于新值,则移除之前的值
  740. usedUsernames.splice(usedUsernames.indexOf(previousValue), 1);
  741. }
  742. usedUsernames.push(this.value); // 添加新选中的用户名
  743. this.defaultValue = this.value; // 更新默认值
  744. console.log('已选择的用户:', usedUsernames);
  745. });
  746. }
  747. // 更新下拉框选项,过滤掉已选择的用户名
  748. function updateUserSelectOptions(availableUsers, usedUsernames, container) {
  749. const allSelects = container.querySelectorAll('.distribute-modal-user-select');
  750. allSelects.forEach(select => {
  751. const currentValue = select.value; // 保存当前选中值
  752. // 清空下拉框
  753. select.innerHTML = '';
  754. // 重新填充选项,排除已选中的用户,确保当前选择保留
  755. availableUsers.forEach(user => {
  756. if (!usedUsernames.includes(user) || user === currentValue) {
  757. const option = document.createElement('option');
  758. option.value = user;
  759. option.textContent = user;
  760. if (user === currentValue) {
  761. option.selected = true; // 保留当前选中项
  762. }
  763. select.appendChild(option);
  764. }
  765. });
  766. });
  767. }
  768. // 刷新数据并滚动到目标卡片的函数
  769. // 刷新数据并滚动到目标卡片,同时重新打开目标卡片的模态框
  770. async function refreshLicenseDataAndScrollAndOpenModal(selfPage,selfPageSize, targetCardId) {
  771. const data = await fetchLicenseData(selfPage, selfPageSize);
  772. if (data.length > 0) {
  773. isLoading = true;
  774. console.log('加载的数据:', data); // 检查是否成功获取数据
  775. renderLicenseCards(data, true); // 渲染数据到页面并清空之前的内容
  776. page = selfPageSize+1;
  777. pageSize= selfPageSize +10;
  778. // 滚动到目标卡片
  779. if (targetCardId) {
  780. const targetCard = document.querySelector(`[data-oa-request-id="${targetCardId}"]`);
  781. if (targetCard) {
  782. targetCard.scrollIntoView({ behavior: 'smooth', block: 'center' });
  783. // 延迟打开模态框,确保页面滚动完成
  784. setTimeout(() => {
  785. targetCard.click(); // 模拟点击卡片,触发模态框
  786. }, 500); // 延时500ms确保滚动完成
  787. }
  788. }
  789. setTimeout(() => {
  790. isLoading = false;
  791. }, 2000);
  792. } else {
  793. console.error('未加载到数据');
  794. }
  795. }
  796. function generateLicense(id, isParentRow) {
  797. // 显示加载进度条并设置动态提示信息
  798. showLoadingModal('正在生成 License...');
  799. // const payload = isParentRow ? { oa_request_id: JSON.stringify(id) } : { uniqueID:JSON.stringify(id) };
  800. const payload = isParentRow
  801. ? { oa_request_id: parseInt(id, 10) } // 将 id 转换为整数
  802. : { uniqueID: parseInt(id, 10) }; // 将 id 转换为整数
  803. console.log("generateLicense",payload ,id, isParentRow)
  804. fetch('http://127.0.0.1:8080/api/admin/GenerateLicense', {
  805. method: 'POST',
  806. headers: {
  807. 'Authorization': `Bearer ${authToken}`,
  808. 'Content-Type': 'application/json'
  809. },
  810. body: JSON.stringify(payload)
  811. })
  812. .then(response => response.json())
  813. .then(data => {
  814. if (data.success) {
  815. // 隐藏加载进度条
  816. hideLoadingModal();
  817. alert('License 生成成功!');
  818. //刷新页面
  819. // 调用封装的更新方法
  820. //updateCardAndModalStatus(id, isParentRow);
  821. // 调用刷新函数,传入当前的 page 和 pageSize
  822. refreshLicenseDataAndScrollAndOpenModal(1,pageSize,id);
  823. } else {
  824. // 请求失败时隐藏加载进度条
  825. hideLoadingModal();
  826. alert('License 生成失败:' + data.error);
  827. }
  828. })
  829. .catch(error => {
  830. console.error('生成过程中出现错误Error:', error);
  831. // 请求失败时隐藏加载进度条
  832. hideLoadingModal();
  833. alert('生成过程中出现错误,请稍后再试。',error);
  834. });
  835. }
  836. //更新卡片样式
  837. function updateCardAndModalStatus(id, isParentRow) {
  838. // 获取对应的卡片元素,通过 oa_request_id 或 uniqueID 定位
  839. const cardSelector = isParentRow ? `[data-oa-request-id="${id}"]` : `[data-unique-id="${id}"]`;
  840. const card = document.querySelector(cardSelector);
  841. console.log("generateLicense card", cardSelector, card);
  842. if (card) {
  843. // 1. 更新卡片内许可证状态
  844. const statusElement = card.querySelector('.license-status');
  845. console.log("statusElement:", statusElement); // 检查状态元素是否存在
  846. if (statusElement) {
  847. // 只更新许可证状态部分的文本,而不是整个 p 标签
  848. statusElement.innerHTML = '许可证状态:已生成';
  849. // 更新状态的 CSS 类
  850. statusElement.classList.remove('license-status-yellow', 'license-status-red');
  851. statusElement.classList.add('license-status-green');
  852. } else {
  853. console.error('找不到 .license-status 元素');
  854. }
  855. // 2. 更新模态框中的状态(如果模态框已经打开)
  856. const modalStatusElement = document.querySelector('.license-info-modal-header .license-status');
  857. console.log("modalStatusElement:", modalStatusElement); // 检查状态元素是否存在
  858. if (modalStatusElement) {
  859. modalStatusElement.textContent = '许可证状态:已生成';
  860. modalStatusElement.classList.remove('license-status-yellow', 'license-status-red');
  861. modalStatusElement.classList.add('license-status-green');
  862. } else {
  863. console.error('找不到 #license-info-modal-body .license-status 元素');
  864. }
  865. // 3. 更新模态框中的按钮为“分发”
  866. const generateButton = document.getElementById('button1'); // 获取生成按钮
  867. if (generateButton) {
  868. generateButton.textContent = '分发'; // 修改按钮文本为“分发”
  869. generateButton.removeEventListener('click', generateLicense); // 移除生成逻辑
  870. generateButton.addEventListener('click', () => {
  871. distributeLicense(id); // 添加分发逻辑
  872. });
  873. }
  874. // 4. 启用 #downloadAllLicenses-button
  875. const downloadButton = document.getElementById('downloadAllLicenses-button');
  876. if (downloadButton) {
  877. downloadButton.disabled = false; // 启用按钮
  878. downloadButton.style.backgroundColor = '#007aff'; // 恢复正常的背景颜色
  879. downloadButton.style.cursor = 'pointer'; // 修改鼠标样式为可点击
  880. }
  881. } else {
  882. console.error(`找不到与 ID ${id} 对应的卡片`);
  883. }
  884. }
  885. ///-----------获取登录用户信息----------------------------------------
  886. async function fetchUsername() {
  887. try {
  888. const response = await fetch(`http://127.0.0.1:8080/api/admin/userInfo`, {
  889. method: 'GET',
  890. headers: {
  891. 'Authorization': `Bearer ${authToken}`,
  892. 'Content-Type': 'application/json'
  893. }
  894. });
  895. const data = await response.json();
  896. currentUserRole = data.data.Role; // 存储当前用户的角色
  897. currentUserName = data.data.Username;
  898. // 使用获取到的角色,调用获取权限的接口
  899. await fetchPermissionsByRole(currentUserRole);
  900. return data.data; // 返回获取到的用户信息数据
  901. } catch (error) {
  902. console.error('Error fetching user info or permissions:', error);
  903. }
  904. }
  905. // 将 fetchPermissionsByRole 转换为异步函数
  906. async function fetchPermissionsByRole(role) {
  907. try {
  908. const response = await fetch(`http://127.0.0.1:8080/api/admin/GetSelfRoles`, {
  909. method: 'POST',
  910. headers: {
  911. 'Authorization': `Bearer ${authToken}`,
  912. 'Content-Type': 'application/json'
  913. },
  914. body: JSON.stringify({ name: role })
  915. });
  916. const data = await response.json();
  917. currentUserPermissions = data.data.Permissions; // 获取用户的权限数组
  918. console.log('currentUserPermissions:', currentUserPermissions);
  919. // 定义权限类别
  920. // const licensePermissions = ['upload_license', 'read_license'];
  921. // const userPermissionsCheck = ['create_user', 'read_user', 'update_user', 'delete_user'];
  922. // const rolePermissions = ['create_role', 'delete_role', 'update_role', 'get_role'];
  923. // const hasLicenseAccess = licensePermissions.some(permission => userPermissions.includes(permission));
  924. // const hasUserManagementAccess = userPermissionsCheck.some(permission => userPermissions.includes(permission));
  925. // const hasRoleManagementAccess = rolePermissions.some(permission => userPermissions.includes(permission));
  926. // 根据权限渲染菜单并显示初始页面
  927. //renderMenuAndInitialPage(hasLicenseAccess, hasUserManagementAccess, hasRoleManagementAccess);
  928. } catch (error) {
  929. console.error('Error fetching permissions:', error);
  930. }
  931. }
  932. //--------------进度条-------------------------------------------------
  933. // 创建模态框的 DOM 元素并插入到 body 中
  934. function createLoadingModal() {
  935. const modalHTML = `
  936. <div id="loadingModal" class="loading-modal" style="display: none;">
  937. <div class="loading-modal-content">
  938. <div class="spinner"></div>
  939. <p id="loadingMessage">加载中...</p>
  940. </div>
  941. </div>
  942. `;
  943. document.body.insertAdjacentHTML('beforeend', modalHTML);
  944. }
  945. // 显示加载模态框
  946. function showLoadingModal(message = "加载中...") {
  947. const loadingModal = document.getElementById('loadingModal');
  948. const loadingMessage = document.getElementById('loadingMessage');
  949. if (loadingModal && loadingMessage) {
  950. loadingMessage.textContent = message; // 设置显示的消息
  951. loadingModal.style.display = 'flex'; // 显示模态框
  952. }
  953. }
  954. // 隐藏加载模态框
  955. function hideLoadingModal() {
  956. const loadingModal = document.getElementById('loadingModal');
  957. if (loadingModal) {
  958. loadingModal.style.display = 'none'; // 隐藏模态框
  959. }
  960. }
  961. // 页面加载时创建模态框
  962. document.addEventListener('DOMContentLoaded', createLoadingModal);
  963. //-----------搜索栏----------------------------
  964. // 获取搜索框元素
  965. // 获取搜索框、状态下拉框、时间选择框和按钮元素
  966. // 获取搜索框、状态下拉框、时间选择框和按钮元素
  967. const searchBar = document.getElementById('search-bar');
  968. const statusFilter = document.getElementById('license-status-filter');
  969. const startDate = document.getElementById('start-date');
  970. const endDate = document.getElementById('end-date');
  971. const submitButton = document.getElementById('submit-button');
  972. const licenseInfoContainer = document.getElementById('license-info-restaurant-list');
  973. // 过滤功能实现
  974. function filterContent() {
  975. console.log('过滤功能触发');
  976. // 移除滚动监听器,停止滚动加载
  977. // removeScrollListeners();
  978. // 构建请求体参数
  979. const requestData = {
  980. license_flag: statusFilter.value || undefined,
  981. starting_date: startDate.value || undefined,
  982. end_date: endDate.value || undefined,
  983. any_search: searchBar.value || undefined,
  984. };
  985. console.log("requestData",requestData);
  986. // 发送 POST 请求到接口
  987. fetch('http://127.0.0.1:8080/api/admin/GetConditionalSearch', {
  988. method: 'POST',
  989. headers: {
  990. 'Authorization': `Bearer ${authToken}`,
  991. 'Content-Type': 'application/json',
  992. },
  993. body: JSON.stringify(requestData),
  994. })
  995. .then(response => response.json())
  996. .then(data => {
  997. console.log('成功获取数据:', data);
  998. // 处理返回的数据并更新界面
  999. displayLicenseInfo(data.data);
  1000. })
  1001. .catch(error => {
  1002. console.error('获取数据时发生错误:', error);
  1003. });
  1004. }
  1005. // 处理并显示返回的 License 信息
  1006. function displayLicenseInfo(data) {
  1007. // 清空之前的结果
  1008. licenseInfoContainer.innerHTML = '';
  1009. LicApplicationData =[];
  1010. // 遍历返回的数据,生成并插入卡片
  1011. // 处理返回的数据并更新界面,使用 renderLicenseCards 方法进行渲染
  1012. renderLicenseCards(data, true);
  1013. }
  1014. // 确定按钮点击事件的修改(停止滚动监听)
  1015. submitButton.addEventListener('click', function() {
  1016. // 执行过滤内容功能
  1017. filterContent();
  1018. // 隐藏滚动加载,防止继续加载更多内容
  1019. removeScrollListeners();
  1020. });
  1021. // 监听返回按钮的点击事件,刷新页面并恢复滚动监听
  1022. const resetButton = document.getElementById('reset-button');
  1023. resetButton.addEventListener('click', function() {
  1024. // 刷新页面
  1025. location.reload();
  1026. });
  1027. // 修改当搜索栏没有输入时,重新启动滚动监听
  1028. searchBar.addEventListener('input', function() {
  1029. if (!searchBar.value && !statusFilter.value && !startDate.value && !endDate.value) {
  1030. console.log("搜索条件清空,重新启动滚动监听");
  1031. restartScrollListeners();
  1032. }
  1033. });