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; return CertificateContextHolder.crtFile;
} }
private static void generateCertificate() { public static void generateCertificate() {
KeyPair keyPair = SecureUtil.generateKeyPair("RSA", 4096); KeyPair keyPair = SecureUtil.generateKeyPair("RSA", 4096);
PrivateKey privateKey = keyPair.getPrivate(); PrivateKey privateKey = keyPair.getPrivate();
PublicKey publicKey = keyPair.getPublic(); 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 () { window.submitLicenseInfo = function () {
let licenseeName = document.getElementById('licenseeName').value
let assigneeName = document.getElementById('assigneeName').value
let expiryDate = document.getElementById('expiryDate').value
let licenseInfo = { let licenseInfo = {
licenseeName: licenseeName, licenseeName: $('#licenseeName').val(),
assigneeName: assigneeName, assigneeName: $('#assigneeName').val(),
expiryDate: expiryDate expiryDate: $('#expiryDate').val()
} };
localStorage.setItem('licenseInfo', JSON.stringify(licenseInfo)) localStorage.setItem('licenseInfo', JSON.stringify(licenseInfo));
document.getElementById('mask').style.display = 'none' $('#mask, #form').hide();
document.getElementById('form').style.display = 'none' };
}
document.getElementById('search').oninput = function (e) { // Function to handle search input
$("#product-list").load('/search?search=' + e.target.value) $('#search').on('input', function(e) {
} $("#product-list").load('/search?search=' + e.target.value);
});
// Function to show license form
window.showLicenseForm = function () { window.showLicenseForm = function () {
let licenseInfo = localStorage.getItem('licenseInfo'); let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo'));
if (licenseInfo !== null) { $('#licenseeName').val(licenseInfo?.licenseeName || '光云');
licenseInfo = JSON.parse(licenseInfo) $('#assigneeName').val(licenseInfo?.assigneeName || '藏柏');
document.getElementById('licenseeName').value = licenseInfo.licenseeName $('#expiryDate').val(licenseInfo?.expiryDate || '2111-11-11');
document.getElementById('assigneeName').value = licenseInfo.assigneeName $('#mask, #form').show();
document.getElementById('expiryDate').value = licenseInfo.expiryDate };
} else {
document.getElementById('licenseeName').value = '光云' // Function to show VM options
document.getElementById('assigneeName').value = '藏柏'
document.getElementById('expiryDate').value = '2111-11-11'
}
document.getElementById('mask').style.display = 'block'
document.getElementById('form').style.display = 'block'
}
window.showVmoptins = function () { window.showVmoptins = function () {
alert("-javaagent:/(Your Path)/ja-netfilter/ja-netfilter.jar\n" + 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=ALL-UNNAMED\n" +
"--add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED") "--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)
textArea.select() // Function to copy license
document.execCommand('copy')
document.body.removeChild(textArea)
}
}
window.copyLicense = async function (e) { window.copyLicense = async function (e) {
while (localStorage.getItem('licenseInfo') === null) { while (localStorage.getItem('licenseInfo') === null) {
document.getElementById('mask').style.display = 'block' $('#mask, #form').show();
document.getElementById('form').style.display = 'block'
await new Promise(r => setTimeout(r, 1000)); await new Promise(r => setTimeout(r, 1000));
} }
let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo')) let licenseInfo = JSON.parse(localStorage.getItem('licenseInfo'));
let productCode = e.closest('.card').dataset.productCodes; let productCode = $(e).closest('.card').data('productCodes');
let data = { let data = {
"licenseName": licenseInfo.licenseeName, "licenseName": licenseInfo.licenseeName,
"assigneeName": licenseInfo.assigneeName, "assigneeName": licenseInfo.assigneeName,
"expiryDate": licenseInfo.expiryDate, "expiryDate": licenseInfo.expiryDate,
"productCode": productCode, "productCode": productCode,
} };
let resp = await fetch('/generateLicense', { $.post('/generateLicense', JSON.stringify(data))
method: 'POST', .then(response => {
headers: { copyText(response)
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => response.text())
copyText(resp)
.then(() => { .then(() => {
alert("The activation code has been copied"); 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>
</div> </div>
</body> </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/jquery.js"></script>
<script type="text/javascript" src="/js/index.js"></script>
</html> </html>