lijj 2 роки тому
батько
коміт
f8ff039420
2 змінених файлів з 173 додано та 91 видалено
  1. 83 8
      admin_ui/src/option/user/info.js
  2. 90 83
      admin_ui/src/views/system/userinfo.vue

+ 83 - 8
admin_ui/src/option/user/info.js

@@ -1,12 +1,88 @@
-export default {
+export const checkPwdValid = (that, pwd) => {
+  // 1、最少8位;
+  // 2、含三种字符或以上(大写字母、小写字母、数字、特殊字符);
+  // 3、不能包含用户名;
+  // 4、不能三个同样或连续字符;
+  // let reg1 = /^(?=.{8})(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d).*$/;
+  if(!(pwd && pwd.length >= 8)) {
+    that.$message({
+      type: "error",
+      message: "密码长度最少为8位!"
+    });
+    return false;
+  }
+  let count = 0;
+  // 包含数字
+  let reg1 = /^(?=.*?[a-z]).*$/;
+  if(reg1.test(pwd)) {
+    count++;
+  }
+  // 包含小写
+  let reg2 = /^(?=.*?[A-Z]).*$/;
+  if(reg2.test(pwd)) {
+    count++;
+  }
+  // 包含大写
+  let reg3 = /^(?=.*?\d).*$/;
+  if(reg3.test(pwd)) {
+    count++;
+  }
+  // 特殊符号正则
+  let reg4 = /^(?=.*?\W).*$/;
+  if(reg4.test(pwd)) {
+    count++;
+  }
+  if(count < 3) {
+    /** 至少包含数字,大写,小写,特殊符号其中三种字符 */
+    that.$message({
+      type: "error",
+      message: "密码中需要包含三种字符或以上(大写字母、小写字母、数字、特殊字符)!"
+    });
+    return false;
+  }
+  // 不能包含三个同样的字符,也不能出现连续字符
+  let coutObj = {};
+  // 用于判断是否出现连续字符串的
+  let cc = '';
+  let wList = pwd.split("");
+  for(let i = 0; i < wList.length; i++) {
+    let e = wList[i];
+    if(cc && cc === e) {
+      // 不能出现连续字符串
+      that.$message({
+        type: "error",
+        message: "密码中不能出现连续的字符!"
+      });
+      return false;
+    } else {
+      cc = e;
+    }
+    if(coutObj[e]) {
+      coutObj[e] += 1;
+    } else {
+      coutObj[e] = 1;
+    }
+  }
+  for(let k in coutObj) {
+    let e = coutObj[k];
+    if(e >= 3) {
+      that.$message({
+        type: "error",
+        message: "密码中相同的字符不能出现3次以上"
+      });
+      return false;
+    }
+  }
+  return true;
+}
+
+export const option = {
   tabs: true,
   tabsActive: 1,
-  group: [
-    {
+  group: [{
       label: '个人信息',
       prop: 'info',
-      column: [
-        {
+      column: [{
           label: '头像',
           type: 'upload',
           listType: 'picture-img',
@@ -53,8 +129,7 @@ export default {
     {
       label: '修改密码',
       prop: 'password',
-      column: [
-        {
+      column: [{
           label: '原密码',
           span: 12,
           row: true,
@@ -78,4 +153,4 @@ export default {
       ],
     },
   ],
-};
+};

+ 90 - 83
admin_ui/src/views/system/userinfo.vue

@@ -1,100 +1,107 @@
 <template>
   <div>
     <basic-container>
-      <avue-form
-        :option="option"
-        v-model="form"
-        @tab-click="handleTabClick"
-        @submit="handleSubmit"
-      ></avue-form>
+      <avue-form :option="option" v-model="form" @tab-click="handleTabClick" @submit="handleSubmit"></avue-form>
     </basic-container>
   </div>
 </template>
 
 <script>
-import option from '@/option/user/info';
-import { getUserInfo, updateInfo, updatePassword } from '@/api/system/user';
-import md5 from 'js-md5';
-import func from '@/utils/func';
+  import { checkPwdValid, option } from '@/option/user/info';
+  import { getUserInfo, updateInfo, updatePassword } from '@/api/system/user';
+  import md5 from 'js-md5';
+  import func from '@/utils/func';
 
-export default {
-  data() {
-    return {
-      index: 0,
-      option: option,
-      form: {},
-    };
-  },
-  created() {
-    this.handleWitch();
-  },
-  methods: {
-    handleSubmit(form, done) {
-      if (this.index === 0) {
-        updateInfo(form).then(
-          res => {
-            if (res.data.success) {
-              this.$message({
-                type: 'success',
-                message: '修改信息成功!',
-              });
-            } else {
-              this.$message({
-                type: 'error',
-                message: res.data.msg,
-              });
+  export default {
+    data() {
+      return {
+        index: 0,
+        option: option,
+        form: {},
+      };
+    },
+    created() {
+      this.handleWitch();
+    },
+    methods: {
+      handleSubmit(form, done) {
+        if(this.index === 0) {
+          updateInfo(form).then(
+            res => {
+              if(res.data.success) {
+                this.$message({
+                  type: 'success',
+                  message: '修改信息成功!',
+                });
+              } else {
+                this.$message({
+                  type: 'error',
+                  message: res.data.msg,
+                });
+              }
+              done();
+            },
+            error => {
+              window.console.log(error);
+              done();
             }
+          );
+        } else {
+          if(this.form.newPassword != this.form.newPassword1) {
+            this.$message({
+              type: "error",
+              message: "两次输入密码不一致!"
+            });
             done();
-          },
-          error => {
-            window.console.log(error);
-            done();
+            return;
           }
-        );
-      } else {
-        updatePassword(md5(form.oldPassword), md5(form.newPassword), md5(form.newPassword1)).then(
-          res => {
-            if (res.data.success) {
-              this.$message({
-                type: 'success',
-                message: '修改密码成功!',
-              });
-            } else {
-              this.$message({
-                type: 'error',
-                message: res.data.msg,
-              });
-            }
-            done();
-          },
-          error => {
-            window.console.log(error);
+          if(!checkPwdValid(this, this.form.newPassword)) {
             done();
+            return;
           }
-        );
-      }
-    },
-    handleWitch() {
-      if (this.index === 0) {
-        getUserInfo().then(res => {
-          const user = res.data.data;
-          this.form = {
-            id: user.id,
-            avatar: user.avatar,
-            name: user.name,
-            realName: user.realName,
-            phone: user.phone,
-            email: user.email,
-          };
-        });
-      }
-    },
-    handleTabClick(tabs) {
-      this.index = func.toInt(tabs.index);
-      this.handleWitch();
+          updatePassword(md5(form.oldPassword), md5(form.newPassword), md5(form.newPassword1)).then(
+            res => {
+              if(res.data.success) {
+                this.$message({
+                  type: 'success',
+                  message: '修改密码成功!',
+                });
+              } else {
+                this.$message({
+                  type: 'error',
+                  message: res.data.msg,
+                });
+              }
+              done();
+            },
+            error => {
+              window.console.log(error);
+              done();
+            }
+          );
+        }
+      },
+      handleWitch() {
+        if(this.index === 0) {
+          getUserInfo().then(res => {
+            const user = res.data.data;
+            this.form = {
+              id: user.id,
+              avatar: user.avatar,
+              name: user.name,
+              realName: user.realName,
+              phone: user.phone,
+              email: user.email,
+            };
+          });
+        }
+      },
+      handleTabClick(tabs) {
+        this.index = func.toInt(tabs.index);
+        this.handleWitch();
+      },
     },
-  },
-};
+  };
 </script>
 
-<style></style>
+<style></style>