Pārlūkot izejas kodu

refactor:注册代码优化,但还未测试,后续版本可以测试下注册页面

liyangbin 1 gadu atpakaļ
vecāks
revīzija
7afad69fb9
1 mainītis faili ar 81 papildinājumiem un 105 dzēšanām
  1. 81 105
      src/views/Create.vue

+ 81 - 105
src/views/Create.vue

@@ -17,9 +17,9 @@ export default {
   data() {
     var validatePass2 = (rule, value, callback) => {
       if (value === '') {
-        callback(new Error('Please confirm password.'))
+        callback('Please confirm password.')
       } else if (value !== this.ruleForm.password) {
-        callback(new Error("Confirm password doesn't match password"))
+        callback("Confirm password doesn't match password")
       } else {
         callback()
       }
@@ -67,11 +67,10 @@ export default {
           { min: 6, max: 24, message: 'Password must between 6-24 characters', trigger: [''] }
         ],
         passwordConfirm: [
-          // { required: true, validator: validatePass2, trigger: 'change' },
-          // { min: 6, max: 24, message: 'Password must between 6-24 characters', trigger: ['blur'] }
-        ],
-      },
-      errorSureMsg: ''
+          { required: true, validator: validatePass2, trigger: 'blur' },
+          { min: 6, max: 24, message: 'Password must between 6-24 characters', trigger: ['blur'] }
+        ]
+      }
     }
   },
   watch: {
@@ -88,7 +87,6 @@ export default {
   methods: {
     createAccount() {
       this.verificationCodeError = false
-      //自定义验证规则不生效
       this.$refs['ruleForm'].validate((valid) => {
         if (!this.checked) {
           this.checkBox = true
@@ -97,95 +95,76 @@ export default {
             message: 'Please read and confirm PRIVACY POLICY and TERMS OF USE first'
           })
         }
-        if (valid) {
-          if (this.ruleForm.passwordConfirm === '') {
-            this.errorSureMsg = 'Confirm Password is required'
-          } else if (this.ruleForm.passwordConfirm.length < 6 || this.ruleForm.passwordConfirm.length > 24) {
-            this.errorSureMsg = "Password must between 6-24 characters"
-          } else if (this.ruleForm.passwordConfirm !== this.ruleForm.password) {
-            this.errorSureMsg = "Confirm password doesn't match password"
-          } else if (this.checked) {
-            this.errorSureMsg = ""
-            this.loading = true
-            if (this.$route.query.teamIds) {
-              this.teamIds = this.$route.query.teamIds.split(',')
-            }
-            let teamIds = this.teamIds || null
-            post('/pdf-tech/vppMember/create', {
-              email: this.ruleForm.email,
-              verifyCode: this.ruleForm.verificationCode,
-              username: this.ruleForm.userName,
-              password: this.ruleForm.password,
-              confirmPassword: this.ruleForm.passwordConfirm,
-              industry: this.ruleForm.industry,
-              company: this.ruleForm.company,
-              inviteEmailCode: this.$route.query.code,
-              teamIds: teamIds
-            }).then((res) => {
-              this.loading = false
-              if (
-                res.data.code === 700 &&
-                res.data.msg === 'False Code,please check again'
-              ) {
-                this.verificationCodeError = true
-                this.$message.error({
-                  duration: 5000,
-                  message: 'Verification Code Error'
-                })
-              } else if (
-                res.data.code === 700 &&
-                res.data.msg === 'The inviteEmailCode is error'
-              ) {
-                this.verificationCodeError = true
-                this.$message.error({
-                  duration: 5000,
-                  message: 'Invited users only'
-                })
-              } else if (
-                res.data.code === 700 &&
-                res.data.msg === 'Password must between 6-24 characters'
-              ) {
-                this.$message.error({
-                  duration: 5000,
-                  message: 'Password must be 6-24 characters'
-                })
-              } else if (
-                res.data.code === 700 &&
-                res.data.msg === 'Different Password'
-              ) {
-                this.$message.error({
-                  duration: 5000,
-                  message: "Confirm password doesn't match password"
-                })
-              } else if (
-                res.data.code === 700 &&
-                res.data.msg === 'Email has been created'
-              ) {
-                this.EmailCodeError = true
-                this.$message.error({
-                  duration: 5000,
-                  message: 'Account already exist, log in or change email?'
-                })
-              } else if (res.data.code === 200 && res.data.msg === '注册成功') {
-                this.$message({
-                  duration: 5000,
-                  message: 'Create Successfully',
-                  type: 'success'
-                })
-                this.$router.push('/login?freeEmail=' + this.ruleForm.email)
-              }
-            })
-          }
-        } else {
-          if (this.ruleForm.passwordConfirm === '') {
-            this.errorSureMsg = 'Confirm Password is required'
-          } else if (this.ruleForm.passwordConfirm.length < 6 || this.ruleForm.passwordConfirm.length > 24) {
-            this.errorSureMsg = "Password must between 6-24 characters"
-          } else if (this.ruleForm.passwordConfirm !== this.ruleForm.password) {
-            this.errorSureMsg = "Confirm password doesn't match password"
-          } else {
-            this.errorSureMsg = ""
+        if (valid && this.checked) {
+          this.loading = true
+          if (this.$route.query.teamIds) {
+            this.teamIds = this.$route.query.teamIds.split(',')
           }
+          let teamIds = this.teamIds || null
+          post('/pdf-tech/vppMember/create', {
+            email: this.ruleForm.email,
+            verifyCode: this.ruleForm.verificationCode,
+            username: this.ruleForm.userName,
+            password: this.ruleForm.password,
+            confirmPassword: this.ruleForm.passwordConfirm,
+            industry: this.ruleForm.industry,
+            company: this.ruleForm.company,
+            inviteEmailCode: this.$route.query.code,
+            teamIds: teamIds
+          }).then((res) => {
+            this.loading = false
+            if (
+              res.data.code === 700 &&
+              res.data.msg === 'False Code,please check again'
+            ) {
+              this.verificationCodeError = true
+              this.$message.error({
+                duration: 5000,
+                message: 'Verification Code Error'
+              })
+            } else if (
+              res.data.code === 700 &&
+              res.data.msg === 'The inviteEmailCode is error'
+            ) {
+              this.verificationCodeError = true
+              this.$message.error({
+                duration: 5000,
+                message: 'Invited users only'
+              })
+            } else if (
+              res.data.code === 700 &&
+              res.data.msg === 'Password must between 6-24 characters'
+            ) {
+              this.$message.error({
+                duration: 5000,
+                message: 'Password must be 6-24 characters'
+              })
+            } else if (
+              res.data.code === 700 &&
+              res.data.msg === 'Different Password'
+            ) {
+              this.$message.error({
+                duration: 5000,
+                message: "Confirm password doesn't match password"
+              })
+            } else if (
+              res.data.code === 700 &&
+              res.data.msg === 'Email has been created'
+            ) {
+              this.EmailCodeError = true
+              this.$message.error({
+                duration: 5000,
+                message: 'Account already exist, log in or change email?'
+              })
+            } else if (res.data.code === 200 && res.data.msg === '注册成功') {
+              this.$message({
+                duration: 5000,
+                message: 'Create Successfully',
+                type: 'success'
+              })
+              this.$router.push('/login?freeEmail=' + this.ruleForm.email)
+            }
+          })
         }
       })
 
@@ -249,13 +228,9 @@ export default {
       }
     },
     clear(val) {
-      if (val !== 'passwordConfirm') {
-        this.$refs["ruleForm"].clearValidate([val])
-        if (val === 'verificationCode') {
-          this.verificationCodeError = false
-        }
-      } else {
-        this.errorSureMsg = ""
+      this.$refs["ruleForm"].clearValidate([val])
+      if (val === 'verificationCode') {
+        this.verificationCodeError = false
       }
     },
   }
@@ -296,7 +271,8 @@ export default {
               <div class="flex items-center relative">
                 <el-input v-model.trim="ruleForm.email" placeholder="Please enter email address." @focus="clear('email')">
                 </el-input>
-                <button type="button" :class="isDisabled || ruleForm.email === '' ? 'bgColor' : ''" :disabled=isDisabled @click="sendEmail()"
+                <button type="button" :class="isDisabled || ruleForm.email === '' ? 'bgColor' : ''" :disabled=isDisabled
+                  @click="sendEmail()"
                   class="absolute top-0.5px right-0px w-80px h-39px bg-[#0773ED] text-center rounded-tr-4px rounded-br-4px font-500 text-[16px] text-[#fff] leading-32px hover:bg-[#3091FF] cursor-pointer">
                   {{ buttonName }}
                 </button>
@@ -342,7 +318,7 @@ export default {
                 </span>
               </div>
             </el-form-item>
-            <el-form-item prop="passwordConfirm" class="mt-4px" :error="errorSureMsg">
+            <el-form-item prop="passwordConfirm" class="mt-4px">
               <div class="text-[#404653] text-16px leading-24px mb-8px">
                 Password Comfirm
                 <span class="text-[#F04438]">*</span>