Explorar el Código

feat: 注册以及修改密码的校验

Lambert hace 1 semana
padre
commit
87f552c69c
Se han modificado 2 ficheros con 37 adiciones y 14 borrados
  1. 32 12
      src/view/register/index.vue
  2. 5 2
      src/view/user/password.vue

+ 32 - 12
src/view/register/index.vue

@@ -24,10 +24,10 @@
       </van-steps>
       <van-form ref="loginInfoRef" v-show="state.active == 0" required="auto">
         <van-cell-group inset>
-          <van-field v-model="state.form.userName" label="登录账号" placeholder="登录账号"
-            @blur="checkUserNamePhoneExists('userName')" :rules="[{ required: true, message: '请填写登录账号' }]" />
-          <van-field v-model="state.form.password" type="password" label="密码" placeholder="密码" @blur="checkPassword"
-            :rules="[{ required: true, message: '请输入密码'}]" />
+          <van-field v-model="state.form.userName" label="登录账号" placeholder="登录账号" :rules="[{ required: true, message: '请填写登录账号' },
+            {validator: checkUserNameExists, message: '账号不可用'}]" />
+          <van-field v-model="state.form.password" type="password" label="密码" placeholder="密码"
+            :rules="[{ required: true, message: '密码不能为空'}, {validator: checkPassword, message: '密码不合法'}]" />
           <van-field v-model="state.form.confirmPassword" type="password" label="确认密码" placeholder="确认密码"
             :rules="[{ required: true, validator: confirmPasswordSame, message: '两次输入的密码不一致' }]" />
         </van-cell-group>
@@ -351,6 +351,19 @@ const checkUserNamePhoneExists = async (type: 'userName' | 'phone') => {
   await to(resquest)
 }
 
+const checkUserNameExists = (value: string) => {
+  if (!value) {
+    return "请输入账号"
+  }
+  return loginApi.checkUserNamePhoneExists({ userName: value, phone: '' })
+    .then(res => {
+      return true
+    })
+    .catch(() => {
+      return "账号不合法"
+    })
+}
+
 const renderDeptData = () => {
   let daptTree = deptDataBackup.value
 
@@ -449,16 +462,23 @@ const nextStep = async () => {
 }
 
 // const checkPassword = (value: any) => {
-  // let checkResult = isPasswordValid(value)
-  // if (!checkResult.isPassed) {
-  //   return checkResult.errorMsg
-  // }
+//   let checkResult = isPasswordValid(value)
+//   if (!checkResult.isPassed) {
+//     return checkResult.errorMsg
+//   }
 // }
 
-const checkPassword = async() => {
-  let resquest = loginApi.validatePassword({ password: state.form.password })
-
-  await to(resquest)
+const checkPassword = (value: string) => {
+  if (!value) {
+    return "请输入密码"
+  }
+  return loginApi.validatePassword({ password: value })
+    .then(res => {
+      return true
+    })
+    .catch(() => {
+      return "密码不合法"
+    })
 }
 
 const confirmPasswordSame = (value: any) => {

+ 5 - 2
src/view/user/password.vue

@@ -14,7 +14,7 @@
           type="password"
           label="新密码"
           placeholder="新密码"
-          :rules="[{ required: true, message: '请输入新密码', validator: checkPassword }]"
+          :rules="[{ required: true, message: '请输入新密码' }, {validator: checkPassword, message: '密码不合法'}]"
         />
         <van-field
           v-model="state.form.newPassword2"
@@ -74,8 +74,11 @@
     // } else {
     //   return '密码必须包含大小写字母、数字和特殊字符,长度在6~18之间'
     // }
+    if (!value) {
+      return "请输入新密码"
+    }
 
-    loginApi.validatePassword({ password: value })
+    return loginApi.validatePassword({ password: value })
       .then(res => {
         return true
       })