Explorar el Código

fix: 增加用户帐号(中文)登录限制

zh hace 2 años
padre
commit
dae09fe951
Se han modificado 1 ficheros con 34 adiciones y 32 borrados
  1. 34 32
      src/views/login/index.vue

+ 34 - 32
src/views/login/index.vue

@@ -14,11 +14,11 @@
           <div class="flex">
             <div class="image-container">
               <div class="empty-height">
-                <img class="logo" src="@/assets/login/logo.png" alt="" />
+                <img class="logo" src="@/assets/login/logo.png" alt="">
               </div>
               <el-carousel :interval="5000" arrow="always" height="440px" class="carousel">
                 <el-carousel-item v-for="item in banner" :key="item.id">
-                  <el-image :z-index="1" :src="imageURL + item.imgCarouselUrl"></el-image>
+                  <el-image :z-index="1" :src="imageURL + item.imgCarouselUrl" />
                 </el-carousel-item>
               </el-carousel>
             </div>
@@ -42,7 +42,7 @@
                           style="width: 20px; height: 20px"
                           :src="require('@/assets/login/icon_001.png')"
                           fit="contain "
-                        ></el-image>
+                        />
                       </span>
                       <el-input
                         ref="username"
@@ -61,7 +61,7 @@
                           style="width: 20px; height: 20px"
                           :src="require('@/assets/login/icon_002.png')"
                           fit="contain "
-                        ></el-image>
+                        />
                       </span>
                       <el-input
                         :key="passwordType"
@@ -86,7 +86,7 @@
                             style="width: 20px; height: 20px"
                             :src="require('@/assets/login/icon_003.png')"
                             fit="contain "
-                          ></el-image>
+                          />
                         </span>
                         <el-input
                           ref="codeValue"
@@ -100,7 +100,7 @@
                         />
                       </el-form-item>
                       <div class="code" @click.stop="getCode">
-                        <img :src="'data:image/jpeg;base64,' + codeImage" alt="" />
+                        <img :src="'data:image/jpeg;base64,' + codeImage" alt="">
                       </div>
                     </div>
 
@@ -110,14 +110,14 @@
                           style="width: 16px; height: 16px"
                           :src="require('@/assets/login/icon_004.png')"
                           fit="contain "
-                        ></el-image>
+                        />
                         <el-image
                           v-if="isRemenberPw"
                           class="yes"
                           style="width: 11px; height: 11px"
                           :src="require('@/assets/login/icon_005.png')"
                           fit="contain "
-                        ></el-image>
+                        />
                       </div>
                       <el-checkbox v-model="isRemenberPw">记住账号密码</el-checkbox>
                     </div>
@@ -134,7 +134,7 @@
                           style="width: 20px; height: 20px"
                           :src="require('@/assets/login/icon_001.png')"
                           fit="contain "
-                        ></el-image>
+                        />
                       </span>
                       <el-input
                         ref="username"
@@ -153,7 +153,7 @@
                             style="width: 20px; height: 20px"
                             :src="require('@/assets/login/icon_003.png')"
                             fit="contain "
-                          ></el-image>
+                          />
                         </span>
                         <el-input
                           ref="codeValue"
@@ -167,7 +167,7 @@
                         />
                       </el-form-item>
                       <div class="code" @click.stop="getCode">
-                        <img :src="'data:image/jpeg;base64,' + codeImage" alt="" />
+                        <img :src="'data:image/jpeg;base64,' + codeImage" alt="">
                       </div>
                     </div>
                     <div class="input-box">
@@ -177,7 +177,7 @@
                             style="width: 20px; height: 20px"
                             :src="require('@/assets/login/icon_003.png')"
                             fit="contain "
-                          ></el-image>
+                          />
                         </span>
                         <el-input
                           ref="smsCode"
@@ -210,9 +210,9 @@
           <el-link :href="companyList[0].icpRecordLink" :underline="false" target="_blank">{{
             companyList[0].icpRecord
           }}</el-link>
-          <div style="margin: 0 20px" v-if="companyList[0].companyName && companyList[0].icpRecordLink">|</div>
+          <div v-if="companyList[0].companyName && companyList[0].icpRecordLink" style="margin: 0 20px">|</div>
           <el-link :href="companyList[0].pubSecurityRecordLink" :underline="false" target="_blank">
-            <el-image style="width: 14px; height: 16px" :src="require('@/assets/login/icon_0001.png')"></el-image>
+            <el-image style="width: 14px; height: 16px" :src="require('@/assets/login/icon_0001.png')" />
             {{ companyList[0].pubSecurityRecord }}
           </el-link>
         </div>
@@ -229,9 +229,11 @@ export default {
   name: 'Login',
   data() {
     const validateUsername = (rule, value, callback) => {
-      console.log(this.loginForm.loginType)
+      const accountRules = /[\u4e00-\u9fa5|\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/
       if (value.length <= 0 && this.loginForm.loginType == 'account') {
         callback(new Error('请输入用户名'))
+      } else if (accountRules.test(value) && this.loginForm.loginType == 'account') {
+        callback(new Error('请输入正确用户名'))
       } else if (value.length <= 0 && this.loginForm.loginType == 'mobile') {
         callback(new Error('请输入手机号'))
       } else {
@@ -290,7 +292,7 @@ export default {
   },
   watch: {
     $route: {
-      handler: function (route) {
+      handler: function(route) {
         this.redirect = route.query && route.query.redirect
       },
       immediate: true
@@ -299,7 +301,7 @@ export default {
   created() {
     // 获取缓存信息
     if (localStorage.getItem('supply_login')) {
-      let storageData = JSON.parse(localStorage.getItem('supply_login'))
+      const storageData = JSON.parse(localStorage.getItem('supply_login'))
       this.loginForm.username = storageData.username
       this.isRemenberPw = storageData.isRemenberPw
     }
@@ -312,7 +314,7 @@ export default {
     this.getCompanyList()
   },
   methods: {
-    //获取短信验证码
+    // 获取短信验证码
     async getSmsCode() {
       await getAdminUserSmsCode({
         mobile: this.loginForm.username,
@@ -400,7 +402,7 @@ export default {
 
     // 处理账号密码的储存
     saveUnAndPw() {
-      let storageData = {
+      const storageData = {
         username: this.loginForm.username,
         isRemenberPw: this.isRemenberPw
       }
@@ -411,24 +413,24 @@ export default {
       }
     },
 
-    //设置cookie
+    // 设置cookie
     setCookie(c_name, c_pwd, exdays) {
-      var exdate = new Date() //获取时间
-      exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays) //保存的天数
-      //字符串拼接cookie
+      var exdate = new Date() // 获取时间
+      exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays) // 保存的天数
+      // 字符串拼接cookie
       window.document.cookie = 'supply_username' + '=' + c_name + ';path=/;expires=' + exdate.toGMTString()
       window.document.cookie = 'supply_password' + '=' + c_pwd + ';path=/;expires=' + exdate.toGMTString()
     },
 
-    //读取cookie
-    getCookie: function () {
+    // 读取cookie
+    getCookie: function() {
       if (document.cookie.length > 0) {
-        var arr = document.cookie.split('; ') //这里显示的格式需要切割一下自己可输出看下
+        var arr = document.cookie.split('; ') // 这里显示的格式需要切割一下自己可输出看下
         for (var i = 0; i < arr.length; i++) {
-          var arr2 = arr[i].split('=') //再次切割
-          //判断查找相对应的值
+          var arr2 = arr[i].split('=') // 再次切割
+          // 判断查找相对应的值
           if (arr2[0] == 'supply_username') {
-            this.loginForm.username = arr2[1] //保存到保存数据的地方
+            this.loginForm.username = arr2[1] // 保存到保存数据的地方
           } else if (arr2[0] == 'supply_password') {
             this.loginForm.password = arr2[1]
           }
@@ -436,9 +438,9 @@ export default {
       }
     },
 
-    //清除cookie
-    clearCookie: function () {
-      this.setCookie('', '', -1) //修改2值都为空,天数为负1天就好了
+    // 清除cookie
+    clearCookie: function() {
+      this.setCookie('', '', -1) // 修改2值都为空,天数为负1天就好了
     }
   }
 }