Pārlūkot izejas kodu

fix: 限制用户名长度

weijin 4 gadi atpakaļ
vecāks
revīzija
bb24fb818a
1 mainītis faili ar 13 papildinājumiem un 2 dzēšanām
  1. 13 2
      pages/register.vue

+ 13 - 2
pages/register.vue

@@ -3,7 +3,7 @@
     <el-card class="login-card">
       <h2 class="login-card__title login-card__item">注 册</h2>
       <el-input ref="name" v-model="name" placeholder="请输入昵称, 长度为1-20个字符" maxlength="20" class="login-card__item"  autofocus></el-input>
-      <el-input ref="username" v-model="username" placeholder="请输入用户名, 只允许英文数字字符, 长度为1-20个字符" maxlength="20" class="login-card__item"></el-input>
+      <el-input ref="username" v-model="username" placeholder="请输入用户名, 只允许英文数字字符, 长度为4-16个字符" maxlength="16" class="login-card__item"></el-input>
       <el-input ref="password" v-model="password" type="password" placeholder="请输入密码, 只允许英文和数字, 长度为8-30个字符" minlength="8" maxlength="30" class="login-card__item"></el-input>
       <el-input ref="passwordConfirm" v-model="passwordConfirm" type="password" placeholder="请再次输入密码" minlength="8" maxlength="30" class="login-card__item"></el-input>
       <el-input ref="email" v-model="email" placeholder="请输入邮箱" maxlength="320" class="login-card__item" autofocus></el-input>
@@ -118,7 +118,18 @@ export default {
         })
         return false
       }
-      if (this.username.length > 20) {
+
+      if (this.username.length < 4) {
+        this.$message({
+          showClose: true,
+          message: '用户名过短',
+          type: 'error'
+        })
+        this.$refs.username.focus()
+        return false
+      }
+
+      if (this.username.length > 16) {
         this.$message({
           showClose: true,
           message: '用户名过长',