From 7d8ff462eeec79e59655a35da56a8607de5b0a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Wed, 20 Apr 2022 13:42:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=88=B0=E5=89=AA=E5=88=87?= =?UTF-8?q?=E6=9D=BF=E5=8A=9F=E8=83=BD=E5=85=BC=E5=AE=B9=E6=97=A7=E7=89=88?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/assets/javascripts/cssUtils.js | 47 +++++++++++++++---- bookshelfplus-frontend/routes/index.js | 2 +- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/bookshelfplus-frontend/public/assets/javascripts/cssUtils.js b/bookshelfplus-frontend/public/assets/javascripts/cssUtils.js index d62b923..aedc065 100644 --- a/bookshelfplus-frontend/public/assets/javascripts/cssUtils.js +++ b/bookshelfplus-frontend/public/assets/javascripts/cssUtils.js @@ -1,11 +1,42 @@ function copyToClipboard(content) { - var aux = document.createElement('input'); - aux.setAttribute('value', content); - aux.style.display = "none"; - document.body.appendChild(aux); - aux.select(); - document.execCommand('copy'); - document.body.removeChild(aux); + + // firefox 下必须为用户同步调用,不可以使用异步调用隔开 + // refer: http://www.caotama.com/43769.html + + function oldMethod() { + var aux = document.createElement('input'); + aux.setAttribute('value', content); + // 在 firefox for windows 93.0 版本下测试,添加这一行会无法复制到剪切板 + // aux.style.display = "none"; + document.body.appendChild(aux); + aux.select(); + aux.focus(); + document.execCommand('copy'); + document.body.removeChild(aux); + + console.log("isSuccess", isSuccess); + } + if (navigator.clipboard) { + navigator.permissions.query({ name: "clipboard-write" }).then(result => { + if (result.state == "granted") { + navigator.clipboard.writeText(content) + .then(function () { + // 复制成功 + console.log("API复制成功"); + }, function () { + // 使用API复制失败 + console.log("API复制失败"); + oldMethod(); + }) + } else { + console.log("支持API,但没有权限,使用旧方法复制"); + oldMethod(); + } + }); + } else { + console.log("不支持API,使用旧方法复制"); + oldMethod(); + } } function showTip(e, text) { var $i = $("").text(text); @@ -25,7 +56,7 @@ function showTip(e, text) { "top": y - 60, "left": x, "opacity": "0" - }, 600, function() { + }, 600, function () { $i.remove(); }); e.stopPropagation(); diff --git a/bookshelfplus-frontend/routes/index.js b/bookshelfplus-frontend/routes/index.js index 879884a..1cbc724 100644 --- a/bookshelfplus-frontend/routes/index.js +++ b/bookshelfplus-frontend/routes/index.js @@ -100,7 +100,7 @@ router.get('/dashboard/:group/:page/:subpage?', function (req, res) { }, "category-manage": { title: "分类管理", - baseTemplate: "form", + baseTemplate: "table", pageTemplate: "CategoryManage", }, "book-manage": {