123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473 |
- 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}`);
- let creatorUser = firstItem.Creator;
- if (creatorUser.includes('-')) {
- let firstDashIndex = creatorUser.indexOf('-');
- let secondDashIndex = creatorUser.indexOf('-', firstDashIndex + 1);
- creatorUser = creatorUser.substring(firstDashIndex + 1, secondDashIndex);
- }
- console.log("筛选名字",creatorUser)
-
- 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 date-time">${firstItem.ApplicationDate} ${firstItem.ApplicationTime}</p> <!-- 显示日期和时间 -->
- <p class="card-text">公司:${firstItem.Company}</p>
- <p class="card-text">项目信息:<div class="project-info">${firstItem.Project}</div></p>
- <p class="card-text">创建者:${creatorUser}</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="distributeButton">分发</button>`
- : `<button class="license-info-modal-button" id="distributeButton" disabled style="background-color:#ccc;cursor:not-allowed;">分发</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 class="license-info-modal-button" id="viewDistributionHistory-button">查看分发历史</button>
- </div>
- </div>
- `;
-
- const generateOrDistribute = modalHeader.querySelector('#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 distributeButton = modalHeader.querySelector('#distributeButton');
- if (distributeButton && !distributeButton.disabled) {
- distributeButton.addEventListener('click', () => {
- showDistributeModal(firstItem);
- });
- }
-
-
-
-
-
-
-
-
-
-
-
- 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>主IP/MAC地址:</strong>
- ${group.oa_main_mac ? group.oa_main_mac : '未填写'}
- </p>
- <p><strong>副IP/MAC地址:</strong>
- ${group.oa_second_mac ? group.oa_second_mac : '未填写'}
- </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].GlxmName;
- 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_1_${mainMac}.dat`;
- zip.file(filename1, row.lic1);
- }
- if (row.lic2) {
- const filename2 = `${idCounter}_license_2_${secondMac}.dat`;
- 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();
- });
- }
- 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://${serverIP}:${serverPort}/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 生成成功!');
-
-
- updateCardAndModalStatus(id, isParentRow);
-
- 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} 对应的卡片`);
- }
- }
|