From d0975268a963a8e7b62cae4abe47b1247fdff022 Mon Sep 17 00:00:00 2001 From: HandSonic <8078023+HandSonic@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:48:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E6=BF=80=E6=B4=BB=E7=A0=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/js/index.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/resources/static/js/index.js b/src/main/resources/static/js/index.js index a35bbc3..5ef82a9 100644 --- a/src/main/resources/static/js/index.js +++ b/src/main/resources/static/js/index.js @@ -59,8 +59,11 @@ $(document).ready(function() { $.post('/generateLicense', JSON.stringify(data)) .then(response => { copyText(response) - .then((result) => { - alert(result); + .then(() => { + alert("已复制成功"); + }) + .catch(() => { + alert("系统不支持复制功能,或者当前非SSL访问,若为Local环境,请使用127.0.0.1或者localhost访问."); }); }); }; @@ -68,11 +71,19 @@ $(document).ready(function() { // Function to copy text to clipboard const copyText = async (val) => { if (navigator.clipboard && navigator.permissions) { - await navigator.clipboard.writeText(val); - return "已复制成功"; + return navigator.clipboard.writeText(val); } else { console.log(val); - return "系统不支持复制功能,或者当前非SSL访问,若为Local环境,请使用127.0.0.1或者localhost访问."; + const textArea = document.createElement('textarea') + textArea.value = val + // 使text area不在viewport,同时设置不可见 + document.body.appendChild(textArea) + textArea.focus() + textArea.select() + return new Promise((res, rej) => { + document.execCommand('copy') ? res() : rej() + textArea.remove() + }) } }; From 3be2046f9a447adff96b693cec81ab4c60b16116 Mon Sep 17 00:00:00 2001 From: HandSonic <8078023+HandSonic@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:17:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E6=A1=86=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 827ed1c..9d6469d 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -40,7 +40,7 @@ th:text="${product.getName()}">

- ********** + *********************************************************************************************************************************************************

@@ -64,7 +64,7 @@ th:text="${plugin.getName()}">

- ********** + *********************************************************************************************************************************************************