浏览代码

feat(活动-邀请用户): 修复http环境下clipboard不能使用的问题

曾志翔 3 年之前
父节点
当前提交
f79829f63c
共有 4 个文件被更改,包括 26 次插入16 次删除
  1. 12 0
      package-lock.json
  2. 1 0
      package.json
  3. 10 14
      pages/activity/invite-user.vue
  4. 3 2
      pages/register-for-invite.vue

+ 12 - 0
package-lock.json

@@ -12,6 +12,7 @@
         "@nuxtjs/axios": "^5.13.6",
         "axios": "^0.27.2",
         "clipboard": "^2.0.11",
+        "clipboard-polyfill": "^4.0.0-rc1",
         "clipboardy": "^3.0.0",
         "core-js": "^3.19.3",
         "dayjs": "^1.11.3",
@@ -5991,6 +5992,12 @@
         "tiny-emitter": "^2.0.0"
       }
     },
+    "node_modules/clipboard-polyfill": {
+      "version": "4.0.0-rc1",
+      "resolved": "https://registry.npmmirror.com/clipboard-polyfill/-/clipboard-polyfill-4.0.0-rc1.tgz",
+      "integrity": "sha512-Cel03Es9ZgP6pYA2JT9cZ2VgvOH2/EHgB7jji84FpINBJWqfMEwiI1Y3LstVL+E43cm3CnCrLL2vwb9DMbr28A==",
+      "deprecated": "Use the browser-native async clipboard API instead of this library: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard"
+    },
     "node_modules/clipboardy": {
       "version": "3.0.0",
       "resolved": "https://registry.npmmirror.com/clipboardy/-/clipboardy-3.0.0.tgz",
@@ -25206,6 +25213,11 @@
         "tiny-emitter": "^2.0.0"
       }
     },
+    "clipboard-polyfill": {
+      "version": "4.0.0-rc1",
+      "resolved": "https://registry.npmmirror.com/clipboard-polyfill/-/clipboard-polyfill-4.0.0-rc1.tgz",
+      "integrity": "sha512-Cel03Es9ZgP6pYA2JT9cZ2VgvOH2/EHgB7jji84FpINBJWqfMEwiI1Y3LstVL+E43cm3CnCrLL2vwb9DMbr28A=="
+    },
     "clipboardy": {
       "version": "3.0.0",
       "resolved": "https://registry.npmmirror.com/clipboardy/-/clipboardy-3.0.0.tgz",

+ 1 - 0
package.json

@@ -25,6 +25,7 @@
     "@nuxtjs/axios": "^5.13.6",
     "axios": "^0.27.2",
     "clipboard": "^2.0.11",
+    "clipboard-polyfill": "^4.0.0-rc1",
     "clipboardy": "^3.0.0",
     "core-js": "^3.19.3",
     "dayjs": "^1.11.3",

+ 10 - 14
pages/activity/invite-user.vue

@@ -80,8 +80,9 @@
 </template>
 
 <script>
-import qs from 'qs';
-import clipboard from 'clipboardy/browser';
+// import qs from 'qs';
+// import clipboard from 'clipboardy/browser';
+import * as clipboard from 'clipboard-polyfill/text';
 import { getStarCoinOverview } from '~/api/activity/invite-user.js';
 
 export default {
@@ -98,6 +99,7 @@ export default {
         todayBuyOrderSuccessCount: 0,
         totalBuyOrderSuccessCount: 0,
         withdrawStarCoinNum: 0,
+        inviteUserName: null,
       },
     };
   },
@@ -144,36 +146,30 @@ export default {
         this.$router.resolve({
           path: '/register-for-invite',
           query: {
-            invitationUserName: this.$auth.user?.phone,
-            activityId: 1,
+            invitationUserName: this.data.invitationUserName,
+            activityId: this.$route.query.activityId,
           },
         }).href;
 
       if (this.$userAgent.isMiniProgram) {
         // 小程序环境
-        await clipboard.write(url);
+        await clipboard.writeText(url);
         this.$toast.success('链接复制成功');
       } else if (this.$userAgent.isApp) {
         // app环境
         this.$native.share({
           title: '双子星APP',
           content: '分享好友购买云机套餐,返星币换现金',
-          gotoUrl: `${location.origin}${location.pathname}${qs.stringify(
-            { id: 666 },
-            { addQueryPrefix: true },
-          )}`,
-          shareImg: url,
+          gotoUrl: url,
+          shareImg: 'sdsa.png',
         });
       } else {
         // 浏览器环境
-        await clipboard.write(url);
+        await clipboard.writeText(url);
         // throw new Error('1231');
         this.$toast.success('链接复制成功');
       }
     },
-    share2() {
-      throw new Error('1231');
-    },
   },
 };
 </script>

+ 3 - 2
pages/register-for-invite.vue

@@ -1,6 +1,6 @@
 <template>
   <v-container class="register-for-invite" fluid>
-    <div class="">注册</div>
+    <div class="title">注册</div>
     <validation-observer ref="observer" v-slot="{ invalid }" slim>
       <v-form @submit.prevent="submit()">
         <validation-provider
@@ -91,7 +91,8 @@ export default {
         this.$tongji.trackEvent('活动', '注册', '', 0);
         const validationResult = await this.$refs.observer.validate();
         if (validationResult) {
-          await registerForInvite(this, this.form);
+          const res = await registerForInvite(this, this.form);
+          this.$toast.success(res.msg);
         }
       } finally {
         this.submitting = false;