Sfoglia il codice sorgente

feat(邀请好友): 活动状态

曾志翔 2 anni fa
parent
commit
e5f734e160

+ 23 - 0
modules/vee-validate/plugin.js

@@ -7,3 +7,26 @@ localize('zhCN', zhCN);
 Object.entries(rules).forEach(([name, value]) => {
   extend(name, value);
 });
+
+extend('phone', {
+  computesRequired: true,
+  validate(value) {
+    if (/1\d{10}/.test(value)) {
+      return true;
+    }
+    return '{_field_}不正确,请重新输入!';
+    // return {
+    //   valid: false,
+    //   required: true,
+    // };
+  },
+});
+extend('code', {
+  computesRequired: true,
+  validate(value) {
+    if (/\d{6}/.test(value)) {
+      return true;
+    }
+    return '{_field_}不正确,请重新输入';
+  },
+});

+ 1 - 0
nuxt.config.js

@@ -214,6 +214,7 @@ export default {
 
   // Build Configuration: https://go.nuxtjs.dev/config-build
   build: {
+    transpile: ['vee-validate/dist/rules'],
     // extend(config, { isClient, loaders: { less } }) {
     //   // console.log('🚀 ~ file: nuxt.config.js ~ line 197 ~ extend ~ less', less);
     //   less.lessOptions = {

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

@@ -12,7 +12,9 @@
           <div class="cybz-content-text-item">邀请购买云机</div>
           <div class="cybz-content-text-item">返星币换现金</div>
         </div>
-        <v-btn class="share-button" rounded @click="share()">分享好友赚星币</v-btn>
+        <v-btn class="share-button" rounded @click="share()"
+          >分享好友赚星币</v-btn
+        >
         <!-- <button @click="share()">邀请</button> -->
       </div>
       <!-- <div class="h-40">13</div> -->
@@ -101,12 +103,17 @@ export default {
         withdrawStarCoinNum: 0,
         inviteUserName: null,
         activityId: null,
+        status: 0,
       },
     };
   },
   async fetch() {
     //
-    this.data = (await getStarCoinOverview(this)).data;
+    try {
+      this.data = (await getStarCoinOverview(this)).data;
+    } catch (error) {
+      this.$toast.error(error.message);
+    }
   },
   head: {
     title: '邀请好友',
@@ -140,8 +147,10 @@ export default {
   methods: {
     async share() {
       // console.log(this);
+      if (this.data.status !== 1) {
+        throw new Error('当前活动已失效');
+      }
       this.$tongji.trackEvent('活动', '分享', '', 0);
-
       const url =
         location.origin +
         this.$router.resolve({
@@ -254,7 +263,7 @@ export default {
     background-size: 100% 100%;
     margin-top: 24px;
     // margin-bottom: 24px;
-    color: #DD1B0D;
+    color: #dd1b0d;
     font-size: 22px;
     font-weight: bold;
   }

+ 7 - 2
pages/activity/invite-user/register.vue

@@ -9,7 +9,7 @@
               v-slot="{ errors }"
               ref="providerPhome"
               name="手机号码"
-              rules="required|min:11|max:11"
+              rules="phone"
               slim
             >
               <v-text-field
@@ -29,7 +29,7 @@
             <validation-provider
               v-slot="{ errors }"
               name="验证码"
-              rules="required|min:6|max:6"
+              rules="code"
               slim
             >
               <v-text-field
@@ -114,6 +114,10 @@ export default {
       try {
         this.submitting = true;
         const valid = await this.$refs.observer.validate();
+        console.log(
+          '🚀 ~ file: register.vue ~ line 117 ~ submit ~ valid',
+          valid,
+        );
         if (valid) {
           this.$tongji.trackEvent('活动', '注册', '', 0);
           const res = await registerForInvite(this, this.form);
@@ -131,6 +135,7 @@ export default {
       try {
         this.codeSending = true;
         const validationResult = await this.$refs.providerPhome.validate();
+
         if (validationResult.valid) {
           this.$tongji.trackEvent('活动', '发送短信', '', 0);
           const res = await sendSmsCode(this, {