Selaa lähdekoodia

Merge branch 'hotfix/修复安卓app写入剪贴板' of Software/android-cloud-H5 into develop

zengzhixiang 2 vuotta sitten
vanhempi
commit
d150bd6703
2 muutettua tiedostoa jossa 23 lisäystä ja 4 poistoa
  1. 9 4
      pages/activity/invite-user/index.vue
  2. 14 0
      plugins/native.js

+ 9 - 4
pages/activity/invite-user/index.vue

@@ -172,7 +172,9 @@
 <script>
 // import qs from 'qs';
 // import clipboard from 'clipboardy/browser';
-import * as clipboard from 'clipboard-polyfill/text';
+
+// import * as clipboard from 'clipboard-polyfill/text';
+// console.log("🚀 ~ file: index.vue ~ line 176 ~ clipboard", clipboard)
 // import { getStarCoinOverview } from '~/api/activity/invite-user.js';
 // import { getContentByType } from '~/api/public/agreement.js';
 export default {
@@ -180,7 +182,7 @@ export default {
   name: 'InviteUser',
   filters: {
     activationCodeMask(value) {
-      // 微信环境不支持此正则
+      // 微信环境不支持零宽断言
       // return value.replace(/(?<=^.{4})(.*)(?=.{4}$)/, '***');
 
       return value.replace(/(.{4})(.*)(.{4}$)/, '$1***$3');
@@ -408,7 +410,10 @@ export default {
         this.$native.share(this.shareInfo);
       } else {
         // 浏览器环境
-        await clipboard.writeText(`${this.shareInfo.link} 唔即云手机`);
+
+        await this.$native.clipboard.writeText(
+          `${this.shareInfo.link} 唔即云手机`,
+        );
         // throw new Error('1231');
         this.$toast.success('链接复制成功');
       }
@@ -434,7 +439,7 @@ export default {
       }
     },
     async copyCode(item) {
-      await clipboard.writeText(item.activationCode);
+      await this.$native.clipboard.writeText(item.activationCode);
       this.$toast.success('复制成功');
     },
     codeLoadMoreIntersect(event) {

+ 14 - 0
plugins/native.js

@@ -1,3 +1,4 @@
+import * as clipboard from 'clipboard-polyfill/text';
 export default function ({ $userAgent, $wx }, i) {
   // const before = () => {
   //   if ($userAgent.isApp) {
@@ -64,5 +65,18 @@ export default function ({ $userAgent, $wx }, i) {
       //   window.native.setShareUrl(url);
       // }
     },
+    clipboard: {
+      /**
+       *
+       * @param {string} text
+       * @returns {Promise<any>}
+       */
+      async writeText(text) {
+        if ($userAgent.isSzx && $userAgent.isAndroid) {
+          return await window.native.copyToClipboard(text);
+        }
+        return await clipboard.writeText(text);
+      },
+    },
   });
 }