1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276 |
- let page = 11;
- let pageSize = 20;
- let total = 0;
- let loadedItems = 0;
- let isLoading = false;
- const timeoutDuration = 10000;
- const preLoadDistance = 300;
- const authToken = localStorage.getItem("Authorization");
- const currentUserInfo = fetchUsername();
- let currentUserPermissions;
- const license_info_mainElement = document.querySelector('main');
- const license_info_modal = document.getElementById('license-info-modal');
- const license_info_modalContent = document.querySelector('.license-info-modal-content');
- const license_info_modalDescription = document.getElementById('license-info-modal-description');
- const license_info_modalPrice = document.getElementById('license-info-modal-price');
- const license_info_modalRating = document.getElementById('license-info-modal-rating');
- const license_info_closeModal = document.querySelector('.license-info-close');
- const license_info_loadingIndicator = document.getElementById('loading-indicator');
- let LicApplicationData = [];
- function openModal(modalId) {
- const modal = document.getElementById(modalId);
- if (modal) {
- modal.style.display = "block";
- } else {
- console.error('模态框不存在,ID:', modalId);
- }
- }
- function closeModal(modalId) {
- const modal = document.getElementById(modalId);
- if (modal) {
- modal.style.display = "none";
- } else {
- console.error('模态框不存在,ID:', modalId);
- }
- }
- const menuItems = document.querySelectorAll('nav ul li a');
- menuItems.forEach(item => {
- item.addEventListener('click', function() {
-
- menuItems.forEach(i => i.classList.remove('active'));
-
-
- this.classList.add('active');
- });
- });
- const userManagementLink = document.getElementById('user-management-link');
- const licenseInfoLink = document.getElementById('license-info-link');
- const roleManagementLink = document.getElementById('role-management-link');
- userManagementLink.addEventListener('click', function(event) {
- event.preventDefault();
- removeScrollListeners();
-
- fetch('../user/user_management.html')
- .then(response => response.text())
- .then(data => {
-
- license_info_mainElement.innerHTML = data;
-
- const script = document.createElement('script');
- script.src = '../user/user.js';
- document.body.appendChild(script);
-
- })
- .catch(error => console.error('加载用户管理页面失败:', error));
- });
- licenseInfoLink.addEventListener('click', function(event) {
- event.preventDefault();
-
- const licenseInfoHtml = `
- <!-- 包裹搜索框、下拉框、时间选择框和确定按钮的 div -->
- <div class="search-container">
- <!-- License 状态下拉框 -->
- <select id="license-status-filter" aria-label="选择 License 状态">
- <option value="">License 状态</option>
- <option value="已生成">已生成</option>
- <option value="未生成">未生成</option>
- <option value="已失效">已失效</option>
- </select>
-
- <!-- 开始时间选择框,类型改为 date -->
- <input type="date" id="start-date" placeholder="开始时间" />
-
- <!-- 结束时间选择框,类型改为 date -->
- <input type="date" id="end-date" placeholder="结束时间" />
-
- <!-- 搜索框 -->
- <input type="text" id="search-bar" placeholder="搜索..." />
-
- <!-- 确定按钮 -->
- <button id="submit-button">确定</button>
- </div>
- <div class="license-info-container" id="license-info-restaurant-list"> </div>
- `;
-
- license_info_mainElement.innerHTML = licenseInfoHtml;
-
- LicApplicationData = [];
- initializeScrollListeners();
-
- (async function() {
- const data = await fetchLicenseData(1, 10);
- if (data.length > 0) {
- console.log('加载的数据:', data);
- renderLicenseCards(data, true);
-
- } else {
- console.error('未加载到数据');
- }
- })();
- });
- roleManagementLink.addEventListener('click', function(event) {
- event.preventDefault();
- removeScrollListeners();
-
- fetch('../role/role.html')
- .then(response => response.text())
- .then(data => {
-
- license_info_mainElement.innerHTML = data;
-
- const script = document.createElement('script');
- script.src = '../role/role.js';
- document.body.appendChild(script);
-
- })
- .catch(error => console.error('加载用户管理页面失败:', error));
- });
- async function fetchLicenseData(page, pageSize) {
- try {
- const response = await fetch(`http://127.0.0.1:8080/api/admin/GetAllLicenseInfo?page=${page}&pageSize=${pageSize}`, {
- method: 'GET',
- headers: {
- 'Authorization': `Bearer ${authToken}`,
- 'Content-Type': 'application/json'
- }
- });
-
- const result = await response.json();
-
-
- if (total === 0 && result.total) {
- total = result.total;
- }
-
-
- LicApplicationData = LicApplicationData.concat(result.data || []);
- console.log("LicApplicationData: ",LicApplicationData);
- return result.data || [];
- } catch (error) {
- console.error("加载数据失败", error);
- return [];
- }
- }
- function renderLicenseCards(data, clearContainer = false) {
- console.log("-----------渲染次数");
-
- const license_info_container = document.getElementById('license-info-restaurant-list');
-
- if (clearContainer) {
- license_info_container.innerHTML = '';
- isLoading = false;
- loadedItems = 0;
- page = 11;
- pageSize = 20;
- console.log("-----------渲染清除");
- }
- console.log("-----------data:",data);
-
- data.forEach(group => {
- const firstItem = group[0];
-
- const childRowCount = group.length;
- let statusClass = '';
- if (firstItem.LicenseFlage === '已生成') {
- statusClass = 'license-status-green';
- } else if (firstItem.LicenseFlage === '未生成') {
- statusClass = 'license-status-yellow';
- } else if (firstItem.LicenseFlage === '已失效') {
- statusClass = 'license-status-red';
- }
- const card = document.createElement('div');
- card.className = 'license-info-card';
-
- card.setAttribute('data-oa-request-id', firstItem.oa_request_id);
-
- card.innerHTML = `
- <div class="license-info-card-header">
- <h3 class="card-title">${firstItem.GlxmName}</h3>
- </div>
- <div class="license-info-card-content">
- <p class="card-text">${firstItem.ApplicationDate} ${firstItem.ApplicationTime}</p> <!-- 显示日期和时间 -->
- <p class="card-text">创建者:${firstItem.Creator}</p>
- <p class="card-text">公司:${firstItem.Company}</p>
- <p class="card-text">集群:${childRowCount} 套 共计:${firstItem.TotalNodes} 节点</p>
- <p class="card-text license-status ${statusClass}">许可证状态:${firstItem.LicenseFlage}</p>
- <p class="card-text">oa_request_id:${firstItem.oa_request_id}</p>
- </div>
- `;
-
- card.addEventListener('click', () => {
-
- const oaRequestId = card.getAttribute('data-oa-request-id');
- showModalForCard(group, oaRequestId);
-
- });
-
-
- license_info_container.appendChild(card);
- });
-
- }
- async function loadMoreData() {
- if (isLoading) return;
- isLoading = true;
- console.log('开始加载更多数据');
-
-
-
-
-
- const timeout = setTimeout(() => {
- license_info_loadingIndicator.innerText = '加载超时,请重试';
- isLoading = false;
- license_info_loadingIndicator.style.display = 'none';
- }, timeoutDuration);
-
- const data = await fetchLicenseData(page, pageSize);
- console.log(`加载的新数据 data`,data);
-
- clearTimeout(timeout);
- if (data.length > 0) {
-
-
- page += 10;
- pageSize += 10;
-
- loadedItems += data.length;
-
- renderLicenseCards(data);
- console.log('数据加载完成,更新页面');
- }
-
-
- isLoading = false;
-
-
- checkAndLoadMore();
- }
- function initializeScrollListeners() {
-
- license_info_mainElement.addEventListener('scroll', handleMainScroll);
-
- }
- function removeScrollListeners() {
-
- license_info_mainElement.removeEventListener('scroll', handleMainScroll);
- }
- function restartScrollListeners() {
-
- initializeScrollListeners();
- }
- function handleMainScroll() {
-
- checkAndLoadMore(license_info_mainElement.scrollHeight, license_info_mainElement.scrollTop, license_info_mainElement.clientHeight);
- }
- async function checkAndLoadMore(scrollHeight, scrollTop, clientHeight) {
- if (isLoading || loadedItems >= total) return;
-
- if (scrollTop + clientHeight >= scrollHeight - preLoadDistance) {
- console.log(`触发加载更多数据:page=${page}, pageSize=${pageSize}`);
- await loadMoreData();
- }
- }
- (async function() {
- const data = await fetchLicenseData(1, 10);
- if (data.length > 0) {
- renderLicenseCards(data);
- loadedItems += data.length;
- }
-
-
-
- checkAndLoadMore()
- })();
- initializeScrollListeners()
- function showModalForCard(item,oaRequestId) {
- const modal = document.getElementById('license-info-modal');
- const modalContent = document.querySelector('.license-info-modal-content');
- const modalBody = document.getElementById('license-info-modal-body');
- console.log(`当前点击的卡片 ID: ${oaRequestId}`);
-
-
- let currentPage = 1;
- const itemsPerPage = 3;
-
- const sortedItem = item.sort((a, b) => a.oa_id - b.oa_id);
- const totalPages = Math.ceil(sortedItem.length / itemsPerPage);
-
- const paginationContainer = document.querySelector('.license-info-modal-pagination');
-
- paginationContainer.innerHTML = '';
-
- const prevButton = document.createElement('button');
- prevButton.classList.add('prev-page');
- prevButton.innerText = '上一页';
- paginationContainer.appendChild(prevButton);
-
- const selectPageDropdown = document.createElement('select');
- paginationContainer.appendChild(selectPageDropdown);
-
- const nextButton = document.createElement('button');
- nextButton.classList.add('next-page');
- nextButton.innerText = '下一页';
- paginationContainer.appendChild(nextButton);
-
-
- function initializeHeaderContent(firstItem,sortedItem) {
- console.log("initializeHeaderContent");
-
- const modalHeader = document.querySelector('.license-info-modal-header');
- modalHeader.innerHTML = '';
- let statusClass = '';
- if (firstItem.LicenseFlage === '已生成') {
- statusClass = 'license-status-green';
- } else if (firstItem.LicenseFlage === '未生成') {
- statusClass = 'license-status-yellow';
- } else if (firstItem.LicenseFlage === '已失效') {
- statusClass = 'license-status-red';
- }
-
- const hasGeneratePermission = currentUserPermissions.includes('generate_license');
- const hasDispatchPermission = currentUserPermissions.includes('dispat_license');
- console.log(`当前用户是否有生成权限: ${hasGeneratePermission}, ${hasDispatchPermission}`);
-
- modalHeader.innerHTML = `
- <div class="license-info-card-header">
- <h3 class="card-title">${firstItem.GlxmName}</h3>
- </div>
- <div class="license-info-card-content">
- <p class="card-text">${firstItem.ApplicationDate} ${firstItem.ApplicationTime}</p> <!-- 显示日期和时间 -->
- <p class="card-text">公司:${firstItem.Company}</p>
- <p class="card-text">${firstItem.Project}</p>
- <p class="card-text">创建者:${firstItem.Creator}</p>
- <p class="card-text license-status ${statusClass}">许可证状态:${firstItem.LicenseFlage}</p>
- <div class="license-info-card-buttons">
- ${
- firstItem.LicenseFlage === '已生成' && hasDispatchPermission
- ? `<button class="license-info-modal-button" id="generateOrDistribute">分发</button>`
- : firstItem.LicenseFlage !== '已生成' && hasGeneratePermission
- ? `<button class="license-info-modal-button" id="generateOrDistribute">生成</button>`
- : ''
- }
- <button class="license-info-modal-button" id="downloadAllLicenses-button">打包下载所有license.dat</button>
- <button id="viewDistributionHistory-button">查看分发历史</button>
- </div>
- </div>
- `;
-
- const generateOrDistribute = modalHeader.querySelector('#generateOrDistribute');
- console.log("generateOrDistribute",generateOrDistribute);
- if (generateOrDistribute) {
- generateOrDistribute.addEventListener('click', () => {
- if (firstItem.LicenseFlage === '已生成') {
-
- showDistributeModal(firstItem);
-
- } else {
-
- const oaRequestID = parseInt(firstItem.oa_request_id, 10);
- generateLicense(oaRequestID, true);
- }
- console.log('Button 1 clicked');
- });
- }
- ;
-
-
-
- const downloadButton = modalHeader.querySelector('#downloadAllLicenses-button');
-
- if (firstItem.LicenseFlage === '未生成' || firstItem.LicenseFlage === '已失效') {
- downloadButton.disabled = true;
- downloadButton.style.backgroundColor = '#ccc';
- downloadButton.style.cursor = 'not-allowed';
- } else {
-
- downloadButton.addEventListener('click', () => {
- downloadAllLicenses(sortedItem);
- });
- }
-
- const viewDistributionHistoryButton = document.getElementById('viewDistributionHistory-button');
- if (viewDistributionHistoryButton) {
- viewDistributionHistoryButton.addEventListener('click', () => {
- showDistributionHistory(firstItem);
- });
- }
- }
-
- function initializeDropdown() {
- selectPageDropdown.innerHTML = '';
- for (let page = 1; page <= totalPages; page++) {
- const option = document.createElement('option');
- option.value = page;
- option.innerText = `第 ${page} 页`;
- selectPageDropdown.appendChild(option);
- }
- selectPageDropdown.value = currentPage;
- }
-
- function ModalForCardRenderPage(page) {
- modalBody.innerHTML = '';
-
- const startIndex = (page - 1) * itemsPerPage;
- const endIndex = Math.min(startIndex + itemsPerPage, sortedItem.length);
-
- const firstItem = sortedItem[0];
- initializeHeaderContent(firstItem,sortedItem);
-
- for (let i = startIndex; i < endIndex; i++) {
- const group = sortedItem[i];
- const groupBox = document.createElement('div');
- groupBox.classList.add('license-info-group-box');
-
- groupBox.innerHTML = `
- <div class="license-info-group-title">集群 ${i + 1} :</div>
- <p><strong>节点数:</strong> ${group.NodeCount}</p>
- <p><strong>数据库版本: </strong> ${group.ProductName}${group.ProductVersion}</p>
- <p><strong>CPU 型号:</strong> ${group.oa_cpu}</p>
- <p><strong>操作系统环境:</strong> ${group.oa_operating_system}</p>
- <p><strong>以下为测试显示:</strong> </p>
- <p><strong>oa_id:</strong> ${group.oa_id}</p>
- <p><strong>oa_request_id:</strong> ${group.oa_request_id}</p>
- `;
-
- modalBody.appendChild(groupBox);
- }
-
- selectPageDropdown.value = page;
-
- prevButton.disabled = (page === 1);
- nextButton.disabled = (page === totalPages);
- }
-
- selectPageDropdown.addEventListener('change', function() {
- currentPage = parseInt(this.value);
- ModalForCardRenderPage(currentPage);
- });
-
- prevButton.addEventListener('click', function() {
- if (currentPage > 1) {
- currentPage--;
- ModalForCardRenderPage(currentPage);
- }
- });
-
- nextButton.addEventListener('click', function() {
- if (currentPage < totalPages) {
- currentPage++;
- ModalForCardRenderPage(currentPage);
- }
- });
-
- function togglePaginationVisibility() {
- if (totalPages <= 1) {
-
- paginationContainer.style.display = 'none';
- } else {
-
- paginationContainer.style.display = 'flex';
- }
- }
-
- initializeDropdown();
-
- ModalForCardRenderPage(currentPage);
-
- togglePaginationVisibility();
-
- modal.style.display = 'flex';
- setTimeout(() => {
- modalContent.classList.add('show');
- }, 10);
-
- const closeModal = document.querySelector('.license-info-close');
- closeModal.addEventListener('click', () => {
- modalContent.classList.remove('show');
- setTimeout(() => {
- modal.style.display = 'none';
- }, 500);
- });
-
- window.addEventListener('click', (event) => {
- if (event.target === modal) {
- modalContent.classList.remove('show');
- setTimeout(() => {
- modal.style.display = 'none';
- }, 500);
- }
- });
- }
- function downloadAllLicenses(sortedApplicationArray) {
- const zip = new JSZip();
- console.log("传进来的 sortedApplicationArray:", sortedApplicationArray);
-
- let idCounter = 1;
- let Project = sortedApplicationArray[0].Project;
- console.log("Project", Project);
-
- sortedApplicationArray.forEach(row => {
- if (row.LicenseFlage === "已生成") {
-
- const mainMac = row.oa_main_mac.replace(/:/g, '.');
- const secondMac = row.oa_second_mac.replace(/:/g, '.');
-
- if (row.lic1) {
- const filename1 = `${idCounter}_license.dat_1_${mainMac}`;
- zip.file(filename1, row.lic1);
- }
- if (row.lic2) {
- const filename2 = `${idCounter}_license.dat_2_${secondMac}`;
- zip.file(filename2, row.lic2);
- }
-
- idCounter++;
- }
- });
-
- zip.generateAsync({ type: "blob" }).then(content => {
- const link = document.createElement('a');
- link.href = URL.createObjectURL(content);
- link.download = `${Project}_license.zip`;
- link.click();
- });
- }
- let userMap = {};
- function showDistributeModal(firstItem) {
- console.log("showDistributeModal firstItem", firstItem);
- const modal = document.getElementById('distribute-modal');
- const emailInputs = document.getElementById('emailInputs');
- const userInputs = document.getElementById('userInputs');
- let usedUsernames = [];
-
- emailInputs.innerHTML = '';
- userInputs.innerHTML = '';
-
- if (firstItem.SupportEmail) {
- emailInputs.innerHTML += `<div><input type="checkbox" id="supportEmail" value="${firstItem.SupportEmail}"> 运维邮箱: ${firstItem.SupportEmail}</div>`;
- }
- if (firstItem.SalesEmail) {
- emailInputs.innerHTML += `<div><input type="checkbox" id="salesEmail" value="${firstItem.SalesEmail}"> 销售邮箱: ${firstItem.SalesEmail}</div>`;
- }
-
- fetch('http://127.0.0.1:8080/api/admin/distributeLicenseByUserInfo', {
- method: 'GET',
- headers: {
- 'Authorization': `Bearer ${authToken}`,
- 'Content-Type': 'application/json'
- }
- })
- .then(response => response.json())
- .then(data => {
-
- userMap = {};
-
- const availableUsers = data.data
- .map(user => {
-
- userMap[user.Username] = {
- Account: user.Account,
- UniqueID: user.UniqueID,
- Username: user.Username,
- Email: user.Email,
- Role: user.Role,
- Telephone: user.Telephone
- };
- return user.Username;
- })
- .filter(user => user !== 'admin');
-
-
- const addButton = document.createElement('button');
- addButton.className = 'distribute-add-user-button';
- addButton.textContent = '添加用户';
- addButton.addEventListener('click', () => {
- createUserSelect(userInputs, availableUsers, usedUsernames);
- });
- userInputs.appendChild(addButton);
-
-
- const distributeButton = document.createElement('button');
- distributeButton.className = 'distribute-confirm-button';
- distributeButton.textContent = '确定分发';
- distributeButton.addEventListener('click', () => {
-
- if (confirm('确定要分发许可证吗?')) {
-
- const selectedUserInputs = Array.from(document.querySelectorAll('select.distribute-user-select'));
- const userIds = selectedUserInputs.map(select => userMap[select.value].UniqueID);
- const userAccounts = selectedUserInputs.map(select => userMap[select.value].Account);
- const userNames = selectedUserInputs.map(select => userMap[select.value].Username);
-
- distributeLicenseToUsers(firstItem, userIds, userAccounts, userNames);
- }
- });
- userInputs.appendChild(distributeButton);
- })
- .catch(error => console.error('获取用户信息失败:', error));
-
- modal.style.display = 'flex';
-
- const closeButton = document.querySelector('#distribute-modal .distribute-close');
- closeButton.addEventListener('click', () => {
- modal.style.display = 'none';
- });
-
- window.addEventListener('click', function(event) {
- if (event.target === modal) {
- modal.style.display = 'none';
- }
- });
- }
- function distributeLicenseToUsers(selectedRowData, userIds, userAccounts, userNames) {
- console.log('Distribute button clicked');
- console.log('userIds', userIds);
- console.log('userAccounts', userAccounts);
- console.log('userNames', userNames);
-
- showLoadingModal('正在分发 License...');
- const operatorUniqueID = userMap[currentUserName].UniqueID;
- if (userIds.length === 0) {
- alert('请至少选择一个用户。');
- hideLoadingModal();
- return;
- }
- const requestData = {
- LicenseUniqueID: selectedRowData.UniqueID,
- Oa_request_id: selectedRowData.oa_request_id,
- UserUniqueIDs: userIds,
- UserAccounts: userAccounts,
- UserNames: userNames,
- Emails: '',
- OperatorUniqueID: operatorUniqueID
- };
- console.log('requestData:', requestData);
-
- fetch('http://127.0.0.1:8080/api/admin/DistributeLicenseToUser', {
- method: 'POST',
- headers: {
- 'Authorization': `Bearer ${authToken}`,
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(requestData)
- })
- .then(response => response.json())
- .then(data => {
- hideLoadingModal();
- if (data.success) {
- alert('分发成功!');
- closeModal('distribute-modal');
- } else {
- const errorMessage = data.error || '分发失败。';
- alert(`分发失败: ${errorMessage}`);
- }
- })
- .catch(error => {
- hideLoadingModal();
- console.error('Error occurred during license distribution:', error);
- alert('分发失败,请检查网络或后端服务。');
- });
- }
- function createUserSelect(container, availableUsers, usedUsernames) {
-
- const userSelectContainer = document.createElement('div');
- userSelectContainer.className = 'distribute-modal-user-select-container';
-
- const userSelect = document.createElement('select');
- userSelect.className = 'distribute-modal-user-select';
-
- const filteredUsers = availableUsers.filter(user => !usedUsernames.includes(user));
-
- filteredUsers.forEach(user => {
- const option = document.createElement('option');
- option.value = user;
- option.textContent = user;
- userSelect.appendChild(option);
- });
-
- const closeButton = document.createElement('span');
- closeButton.textContent = 'X';
- closeButton.className = 'distribute-modal-close-select';
- closeButton.style.cursor = 'pointer';
- closeButton.style.marginLeft = '10px';
-
- closeButton.addEventListener('click', function() {
-
- const selectedValue = userSelect.value;
- const index = usedUsernames.indexOf(selectedValue);
- if (index > -1) {
- usedUsernames.splice(index, 1);
- }
- container.removeChild(userSelectContainer);
- });
-
- userSelectContainer.appendChild(userSelect);
- userSelectContainer.appendChild(closeButton);
-
- container.appendChild(userSelectContainer);
-
- userSelect.addEventListener('change', function() {
- const previousValue = usedUsernames.find(u => u === this.defaultValue);
- if (previousValue) {
-
- usedUsernames.splice(usedUsernames.indexOf(previousValue), 1);
- }
- usedUsernames.push(this.value);
- this.defaultValue = this.value;
- console.log('已选择的用户:', usedUsernames);
- });
- }
- function updateUserSelectOptions(availableUsers, usedUsernames, container) {
- const allSelects = container.querySelectorAll('.distribute-modal-user-select');
-
- allSelects.forEach(select => {
- const currentValue = select.value;
-
- select.innerHTML = '';
-
- availableUsers.forEach(user => {
- if (!usedUsernames.includes(user) || user === currentValue) {
- const option = document.createElement('option');
- option.value = user;
- option.textContent = user;
- if (user === currentValue) {
- option.selected = true;
- }
- select.appendChild(option);
- }
- });
- });
- }
- async function refreshLicenseDataAndScrollAndOpenModal(selfPage,selfPageSize, targetCardId) {
- const data = await fetchLicenseData(selfPage, selfPageSize);
- if (data.length > 0) {
- isLoading = true;
- console.log('加载的数据:', data);
- renderLicenseCards(data, true);
- page = selfPageSize+1;
- pageSize= selfPageSize +10;
-
- if (targetCardId) {
- const targetCard = document.querySelector(`[data-oa-request-id="${targetCardId}"]`);
- if (targetCard) {
- targetCard.scrollIntoView({ behavior: 'smooth', block: 'center' });
-
-
- setTimeout(() => {
- targetCard.click();
- }, 500);
- }
- }
-
- setTimeout(() => {
- isLoading = false;
- }, 2000);
-
- } else {
- console.error('未加载到数据');
- }
- }
- function generateLicense(id, isParentRow) {
-
- showLoadingModal('正在生成 License...');
-
- const payload = isParentRow
- ? { oa_request_id: parseInt(id, 10) }
- : { uniqueID: parseInt(id, 10) };
- console.log("generateLicense",payload ,id, isParentRow)
- fetch('http://127.0.0.1:8080/api/admin/GenerateLicense', {
- method: 'POST',
- headers: {
- 'Authorization': `Bearer ${authToken}`,
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(payload)
- })
- .then(response => response.json())
- .then(data => {
- if (data.success) {
-
- hideLoadingModal();
- alert('License 生成成功!');
-
-
-
-
- refreshLicenseDataAndScrollAndOpenModal(1,pageSize,id);
- } else {
-
- hideLoadingModal();
- alert('License 生成失败:' + data.error);
- }
-
- })
- .catch(error => {
- console.error('生成过程中出现错误Error:', error);
-
- hideLoadingModal();
- alert('生成过程中出现错误,请稍后再试。',error);
- });
- }
- function updateCardAndModalStatus(id, isParentRow) {
-
- const cardSelector = isParentRow ? `[data-oa-request-id="${id}"]` : `[data-unique-id="${id}"]`;
- const card = document.querySelector(cardSelector);
- console.log("generateLicense card", cardSelector, card);
-
- if (card) {
-
- const statusElement = card.querySelector('.license-status');
- console.log("statusElement:", statusElement);
-
- if (statusElement) {
-
- statusElement.innerHTML = '许可证状态:已生成';
-
-
- statusElement.classList.remove('license-status-yellow', 'license-status-red');
- statusElement.classList.add('license-status-green');
- } else {
- console.error('找不到 .license-status 元素');
- }
-
- const modalStatusElement = document.querySelector('.license-info-modal-header .license-status');
- console.log("modalStatusElement:", modalStatusElement);
-
- if (modalStatusElement) {
- modalStatusElement.textContent = '许可证状态:已生成';
- modalStatusElement.classList.remove('license-status-yellow', 'license-status-red');
- modalStatusElement.classList.add('license-status-green');
- } else {
- console.error('找不到 #license-info-modal-body .license-status 元素');
- }
-
- const generateButton = document.getElementById('button1');
- if (generateButton) {
- generateButton.textContent = '分发';
- generateButton.removeEventListener('click', generateLicense);
- generateButton.addEventListener('click', () => {
- distributeLicense(id);
- });
- }
-
- const downloadButton = document.getElementById('downloadAllLicenses-button');
- if (downloadButton) {
- downloadButton.disabled = false;
- downloadButton.style.backgroundColor = '#007aff';
- downloadButton.style.cursor = 'pointer';
- }
- } else {
- console.error(`找不到与 ID ${id} 对应的卡片`);
- }
- }
- async function fetchUsername() {
- try {
- const response = await fetch(`http://127.0.0.1:8080/api/admin/userInfo`, {
- method: 'GET',
- headers: {
- 'Authorization': `Bearer ${authToken}`,
- 'Content-Type': 'application/json'
- }
- });
-
- const data = await response.json();
- currentUserRole = data.data.Role;
- currentUserName = data.data.Username;
-
-
- await fetchPermissionsByRole(currentUserRole);
- return data.data;
-
- } catch (error) {
- console.error('Error fetching user info or permissions:', error);
- }
- }
- async function fetchPermissionsByRole(role) {
- try {
- const response = await fetch(`http://127.0.0.1:8080/api/admin/GetSelfRoles`, {
- method: 'POST',
- headers: {
- 'Authorization': `Bearer ${authToken}`,
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({ name: role })
- });
- const data = await response.json();
- currentUserPermissions = data.data.Permissions;
- console.log('currentUserPermissions:', currentUserPermissions);
-
-
-
-
-
-
-
-
-
-
- } catch (error) {
- console.error('Error fetching permissions:', error);
- }
- }
- function createLoadingModal() {
- const modalHTML = `
- <div id="loadingModal" class="loading-modal" style="display: none;">
- <div class="loading-modal-content">
- <div class="spinner"></div>
- <p id="loadingMessage">加载中...</p>
- </div>
- </div>
- `;
- document.body.insertAdjacentHTML('beforeend', modalHTML);
- }
- function showLoadingModal(message = "加载中...") {
- const loadingModal = document.getElementById('loadingModal');
- const loadingMessage = document.getElementById('loadingMessage');
-
- if (loadingModal && loadingMessage) {
- loadingMessage.textContent = message;
- loadingModal.style.display = 'flex';
- }
- }
- function hideLoadingModal() {
- const loadingModal = document.getElementById('loadingModal');
-
- if (loadingModal) {
- loadingModal.style.display = 'none';
- }
- }
- document.addEventListener('DOMContentLoaded', createLoadingModal);
- const searchBar = document.getElementById('search-bar');
- const statusFilter = document.getElementById('license-status-filter');
- const startDate = document.getElementById('start-date');
- const endDate = document.getElementById('end-date');
- const submitButton = document.getElementById('submit-button');
- const licenseInfoContainer = document.getElementById('license-info-restaurant-list');
- function filterContent() {
- console.log('过滤功能触发');
-
-
-
- const requestData = {
- license_flag: statusFilter.value || undefined,
- starting_date: startDate.value || undefined,
- end_date: endDate.value || undefined,
- any_search: searchBar.value || undefined,
- };
- console.log("requestData",requestData);
-
- fetch('http://127.0.0.1:8080/api/admin/GetConditionalSearch', {
- method: 'POST',
- headers: {
- 'Authorization': `Bearer ${authToken}`,
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(requestData),
- })
- .then(response => response.json())
- .then(data => {
- console.log('成功获取数据:', data);
-
- displayLicenseInfo(data.data);
- })
- .catch(error => {
- console.error('获取数据时发生错误:', error);
- });
- }
- function displayLicenseInfo(data) {
-
- licenseInfoContainer.innerHTML = '';
- LicApplicationData =[];
-
-
- renderLicenseCards(data, true);
-
- }
- submitButton.addEventListener('click', function() {
-
- filterContent();
-
- removeScrollListeners();
- });
- const resetButton = document.getElementById('reset-button');
- resetButton.addEventListener('click', function() {
-
- location.reload();
- });
- searchBar.addEventListener('input', function() {
- if (!searchBar.value && !statusFilter.value && !startDate.value && !endDate.value) {
- console.log("搜索条件清空,重新启动滚动监听");
- restartScrollListeners();
- }
- });
|