Sfoglia il codice sorgente

fix(clipboard): https写入剪贴板报错

zengzhixiang 2 anni fa
parent
commit
24100b85f9
3 ha cambiato i file con 20 aggiunte e 2 eliminazioni
  1. 1 0
      package.json
  2. 7 2
      plugins/native.js
  3. 12 0
      pnpm-lock.yaml

+ 1 - 0
package.json

@@ -28,6 +28,7 @@
     "clipboard": "^2.0.11",
     "clipboard-polyfill": "^4.0.0-rc1",
     "clipboardy": "^3.0.0",
+    "copy-to-clipboard": "^3.3.2",
     "core-js": "^3.19.3",
     "dayjs": "^1.11.3",
     "format-number": "^3.0.0",

+ 7 - 2
plugins/native.js

@@ -1,4 +1,6 @@
-import * as clipboard from 'clipboard-polyfill/text';
+// import * as clipboard from 'clipboard-polyfill/text';
+import copy from 'copy-to-clipboard';
+console.log("🚀 ~ file: native.js ~ line 3 ~ copy", copy)
 export default function ({ $userAgent, $wx }, i) {
   // const before = () => {
   //   if ($userAgent.isApp) {
@@ -75,7 +77,10 @@ export default function ({ $userAgent, $wx }, i) {
         if ($userAgent.isSzx && $userAgent.isAndroid) {
           return await window.native.copyToClipboard(text);
         }
-        return await clipboard.writeText(text);
+        return await copy(text, {
+          format: 'text/plain',
+        });
+        // return await clipboard.writeText(text);
       },
     },
   });

+ 12 - 0
pnpm-lock.yaml

@@ -22,6 +22,7 @@ specifiers:
   clipboard: ^2.0.11
   clipboard-polyfill: ^4.0.0-rc1
   clipboardy: ^3.0.0
+  copy-to-clipboard: ^3.3.2
   core-js: ^3.19.3
   dayjs: ^1.11.3
   eslint: ^8.4.1
@@ -68,6 +69,7 @@ dependencies:
   clipboard: 2.0.11
   clipboard-polyfill: 4.0.0-rc1
   clipboardy: 3.0.0
+  copy-to-clipboard: 3.3.2
   core-js: 3.22.7
   dayjs: 1.11.4
   format-number: 3.0.0
@@ -4586,6 +4588,12 @@ packages:
     engines: {node: '>=12'}
     dev: false
 
+  /copy-to-clipboard/3.3.2:
+    resolution: {integrity: sha512-Vme1Z6RUDzrb6xAI7EZlVZ5uvOk2F//GaxKUxajDqm9LhOVM1inxNAD2vy+UZDYsd0uyA9s7b3/FVZPSxqrCfg==}
+    dependencies:
+      toggle-selection: 1.0.6
+    dev: false
+
   /core-js-compat/3.22.7:
     resolution: {integrity: sha512-uI9DAQKKiiE/mclIC5g4AjRpio27g+VMRhe6rQoz+q4Wm4L6A/fJhiLtBw+sfOpDG9wZ3O0pxIw7GbfOlBgjOA==}
     dependencies:
@@ -11087,6 +11095,10 @@ packages:
       regex-not: 1.0.2
       safe-regex: 1.1.0
 
+  /toggle-selection/1.0.6:
+    resolution: {integrity: sha512-BiZS+C1OS8g/q2RRbJmy59xpyghNBqrr6k5L/uKBGRsTfxmu3ffiRnd8mlGPUVayg8pvfi5urfnu8TU7DVOkLQ==}
+    dev: false
+
   /toidentifier/1.0.1:
     resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==}
     engines: {node: '>=0.6'}