diff --git a/ruoyi-ui/src/components/Password/CheckList.vue b/ruoyi-ui/src/components/Password/CheckList.vue new file mode 100644 index 00000000..07545878 --- /dev/null +++ b/ruoyi-ui/src/components/Password/CheckList.vue @@ -0,0 +1,127 @@ + + + + + + diff --git a/ruoyi-ui/src/components/Password/index.js b/ruoyi-ui/src/components/Password/index.js new file mode 100644 index 00000000..b9cd50c6 --- /dev/null +++ b/ruoyi-ui/src/components/Password/index.js @@ -0,0 +1,6 @@ +import Password from "./index.vue"; +import {usePassword} from "./utils"; + +export {usePassword}; + +export default Password; diff --git a/ruoyi-ui/src/components/Password/index.vue b/ruoyi-ui/src/components/Password/index.vue new file mode 100644 index 00000000..aea3c34d --- /dev/null +++ b/ruoyi-ui/src/components/Password/index.vue @@ -0,0 +1,91 @@ + + + + + diff --git a/ruoyi-ui/src/components/Password/utils.js b/ruoyi-ui/src/components/Password/utils.js new file mode 100644 index 00000000..102f2590 --- /dev/null +++ b/ruoyi-ui/src/components/Password/utils.js @@ -0,0 +1,63 @@ +export const usePassword = (options) => { + const defaultRules = [ + { + key: "length", + label: "长度在6到20个字符", + regExp: /^.{10,20}$/ + }, + { + key: "lowercase", + label: "使用小写字母", + regExp: /[a-z]+/ + }, + { + key: "capital", + label: "用大写字母", + regExp: /[A-Z]+/ + }, + { + key: "number", + label: "使用数字", + regExp: /\d{1,}/ + } + ]; + const ruleItems = options + ? options.reduce((res, item) => { + if (typeof item === "string") { + const rule = defaultRules.find(i => item === i.key); + if (rule) { + res.push(rule); + } else { + throw new Error("无效的规则"); + } + } else { + res.push(item); + } + return res; + }, []) + : [...defaultRules]; + // 返回默认的匹配规则map 和 校验结果mapList + return { + checkList: ruleItems.map(({key, label}) => ({key, label})), + validate: (value) => { + // 过滤出符合正则的rule[], map返回key[] + const validList = ruleItems + .filter(({regExp, validator}) => { + if (validator) { + return validator(value); + } else if (regExp) { + return regExp.test(value); + } else { + return false; + } + }) + .map(({key}) => { + return key; + }); + return { + validList, + valid: validList.length === ruleItems.length + }; + } + }; +}; diff --git a/ruoyi-ui/src/views/system/user/index.vue b/ruoyi-ui/src/views/system/user/index.vue index fc8e3850..de6b9c70 100644 --- a/ruoyi-ui/src/views/system/user/index.vue +++ b/ruoyi-ui/src/views/system/user/index.vue @@ -238,7 +238,13 @@ - + + @@ -342,16 +348,18 @@ \ No newline at end of file + + diff --git a/ruoyi-ui/src/views/system/user/profile/resetPwd.vue b/ruoyi-ui/src/views/system/user/profile/resetPwd.vue index fcea6799..56f277d0 100644 --- a/ruoyi-ui/src/views/system/user/profile/resetPwd.vue +++ b/ruoyi-ui/src/views/system/user/profile/resetPwd.vue @@ -4,7 +4,13 @@ - + + @@ -18,8 +24,14 @@