JS代码优化重构

This commit is contained in:
藏柏 2024-04-13 00:29:31 +08:00
parent 447ec9dcc5
commit e1831c9eee
3 changed files with 70 additions and 82 deletions

View File

@ -78,7 +78,7 @@ public class CertificateContextHolder {
return CertificateContextHolder.crtFile;
}
private static void generateCertificate() {
public static void generateCertificate() {
KeyPair keyPair = SecureUtil.generateKeyPair("RSA", 4096);
PrivateKey privateKey = keyPair.getPrivate();
PublicKey publicKey = keyPair.getPublic();

View File

@ -1,83 +1,71 @@
$(document).ready(function() {
// Set default headers for AJAX requests
$.ajaxSetup({
headers: {
'Content-Type': 'application/json'
}
});
// Function to handle submission of license information
window.submitLicenseInfo = function () {
let licenseeName = document.getElementById('licenseeName').value
let assigneeName = document.getElementById('assigneeName').value
let expiryDate = document.getElementById('expiryDate').value
let licenseInfo = {
licenseeName: licenseeName,
assigneeName: assigneeName,
expiryDate: expiryDate
}
localStorage.setItem('licenseInfo', JSON.stringify(licenseInfo))
document.getElementById('mask').style.display = 'none'
document.getElementById('form').style.display = 'none'
}
document.getElementById('search').oninput = function (e) {
$("#product-list").load('/search?search=' + e.target.value)
}
licenseeName: $('#licenseeName').val(),
assigneeName: $('#assigneeName').val(),
expiryDate: $('#expiryDate').val()
};
localStorage.setItem('licenseInfo', JSON.stringify(licenseInfo));
$('#mask, #form').hide();
};
// Function to handle search input
$('#search').on('input', function(e) {
$("#product-list").load('/search?search=' + e.target.value);
});
// Function to show license form
window.showLicenseForm = function () {
let licenseInfo = localStorage.getItem('licenseInfo');
if (licenseInfo !== null) {
licenseInfo = JSON.parse(licenseInfo)
document.getElementById('licenseeName').value = licenseInfo.licenseeName
document.getElementById('assigneeName').value = licenseInfo.assigneeName
document.getElementById('expiryDate').value = licenseInfo.expiryDate
} else {
document.getElementById('licenseeName').value = '光云'
document.getElementById('assigneeName').value = '藏柏'
document.getElementById('expiryDate').value = '2111-11-11'
}
document.getElementById('mask').style.display = 'block'
document.getElementById('form').style.display = 'block'
}
let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo'));
$('#licenseeName').val(licenseInfo?.licenseeName || '光云');
$('#assigneeName').val(licenseInfo?.assigneeName || '藏柏');
$('#expiryDate').val(licenseInfo?.expiryDate || '2111-11-11');
$('#mask, #form').show();
};
// Function to show VM options
window.showVmoptins = function () {
alert("-javaagent:/(Your Path)/ja-netfilter/ja-netfilter.jar\n" +
"--add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED\n" +
"--add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED")
}
//@see https://zhuanlan.zhihu.com/p/597944027
const copyText = async (val) => {
if (navigator.clipboard && navigator.permissions) {
await navigator.clipboard.writeText(val)
} else {
const textArea = document.createElement('textArea')
textArea.value = val
textArea.style.width = 0
textArea.style.position = 'fixed'
textArea.style.left = '-999px'
textArea.style.top = '10px'
textArea.setAttribute('readonly', 'readonly')
document.body.appendChild(textArea)
"--add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED");
};
textArea.select()
document.execCommand('copy')
document.body.removeChild(textArea)
}
}
// Function to copy license
window.copyLicense = async function (e) {
while (localStorage.getItem('licenseInfo') === null) {
document.getElementById('mask').style.display = 'block'
document.getElementById('form').style.display = 'block'
$('#mask, #form').show();
await new Promise(r => setTimeout(r, 1000));
}
let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo'))
let productCode = e.closest('.card').dataset.productCodes;
let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo'));
let productCode = $(e).closest('.card').data('productCodes');
let data = {
"licenseName": licenseInfo.licenseeName,
"assigneeName": licenseInfo.assigneeName,
"expiryDate": licenseInfo.expiryDate,
"productCode": productCode,
}
let resp = await fetch('/generateLicense', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => response.text())
copyText(resp)
};
$.post('/generateLicense', JSON.stringify(data))
.then(response => {
copyText(response)
.then(() => {
alert("The activation code has been copied");
})
});
});
};
// Function to copy text to clipboard
const copyText = async (val) => {
if (navigator.clipboard && navigator.permissions) {
await navigator.clipboard.writeText(val);
}
};
});

View File

@ -101,6 +101,6 @@
</div>
</div>
</body>
<script type="text/javascript" src="/js/index.js"></script>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/index.js"></script>
</html>