1
0
Эх сурвалжийг харах

Merge remote-tracking branch 'origin/v_2.0' into v_2.0

穿云 9 сар өмнө
parent
commit
c75e52af04

+ 1 - 1
dbsyncer-web/src/main/java/org/dbsyncer/web/controller/license/LicenseController.java

@@ -44,7 +44,7 @@ public class LicenseController {
     public RestResult upload(MultipartFile[] files) {
         try {
             if (files != null && files[0] != null) {
-                String filename = files[0].getOriginalFilename();
+                String filename = "license";
                 File dest = new File(licenseService.getLicensePath() + filename);
                 FileUtils.deleteQuietly(dest);
                 FileUtils.copyInputStreamToFile(files[0].getInputStream(), dest);

+ 20 - 14
dbsyncer-web/src/main/resources/static/js/license/license.js

@@ -29,24 +29,30 @@ $(function () {
     }
 
     document.getElementById("copyBtn").addEventListener('click', async event => {
-        if (!navigator.clipboard) {
-            // Clipboard API not available
-            bootGrowl("非常抱歉,当前浏览器不支持复制机器码,请手动复制", "danger");
-            return;
-        }
+        //Get the copied text
+        const text = document.getElementById("licenseKey").value;
+        fallbackCopyTextToClipboard(text)
+    });
+
+
+    // 旧浏览器的回退方案
+    function fallbackCopyTextToClipboard(text) {
+        var textArea = document.createElement("textarea");
+        textArea.value = text;
+        textArea.style.height='0px';
+        document.body.appendChild(textArea);
+        textArea.focus();
+        textArea.select();
         try {
-            //Get the copied text
-            const text = document.getElementById("licenseKey").value;
-            if (isBlank(text)) {
-                bootGrowl("功能暂未开放.", "danger");
-                return;
+            var successful = document.execCommand('copy');
+            if (successful) {
+                bootGrowl("复制机器码成功!", "success");
             }
-            await navigator.clipboard.writeText(text);
-            bootGrowl("复制机器码成功!", "success");
         } catch (err) {
-            console.error('Failed to copy!', err);
+            console.error('复制失败', err);
         }
-    });
+        document.body.removeChild(textArea);
+    }
 
     $("#fileLicense").fileinput({
         theme: 'fas',