From be92f66f9cbb83ac2623a3b19f2f1522dd0ffd4b Mon Sep 17 00:00:00 2001 From: JayChou Date: Mon, 21 Apr 2025 14:36:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9copy=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=9C=A8http=E5=8D=8F=E8=AE=AE=E4=B8=8B=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/compiler/index.vue | 29 +++++++++++++++++++++++------ src/views/largeDataScreen/home.vue | 2 +- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/views/compiler/index.vue b/src/views/compiler/index.vue index 659cc1e..da5d71b 100644 --- a/src/views/compiler/index.vue +++ b/src/views/compiler/index.vue @@ -29,11 +29,11 @@ const useSettingStore = settingStore(); const isShowStrring = Boolean(localStorage.getItem("falg")) || false; const saveCode = () => { - if(!validateJavaCode(answer, code.value.innerText)){ - ElMessage({ + if (!validateJavaCode(answer, code.value.innerText)) { + return ElMessage({ message: "代码编写错误", type: "warning", - }) + }); } useSettingStore.setValue(true, "isRunCode"); localStorage.setItem("isRunCode", "true"); @@ -72,9 +72,26 @@ public String convert() throws IOException { } `; const copyCode = () => { - navigator.clipboard.writeText(answer).then(() => { - ElMessage.success("复制成功"); - }); + const textarea = document.createElement("textarea"); + textarea.value = answer; + textarea.style.position = "fixed"; // 避免页面滚动 + document.body.appendChild(textarea); + textarea.focus(); + textarea.select(); + + try { + const success = document.execCommand("copy"); + if (success) { + ElMessage.success("复制成功"); + } else { + ElMessage.error("复制失败"); + } + } catch (err) { + ElMessage.error("复制失败"); + console.error("复制异常", err); + } + + document.body.removeChild(textarea); }; diff --git a/src/views/largeDataScreen/home.vue b/src/views/largeDataScreen/home.vue index afaa758..be2107c 100644 --- a/src/views/largeDataScreen/home.vue +++ b/src/views/largeDataScreen/home.vue @@ -836,7 +836,7 @@ const isShowStrring = Boolean(localStorage.getItem("falg")) || false; // 前往labView const goToLabView = async () => { - console.log(isShowStrring); + console.log(isShowStrring,localStorage.getItem("falg")); if (isShowStrring) { await setStepEvent(1, formatDate(new Date()));