From 1c94382ae017a9c97ee6501f6f74f2c616b8c501 Mon Sep 17 00:00:00 2001 From: binbin_pan Date: Thu, 23 May 2024 17:32:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=9D=E5=A7=8B=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E7=99=BB=E5=BD=95=E5=90=8E=E9=87=8D=E7=BD=AE=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=AF=86=E7=A0=81=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sgzb-ui/src/router/index.js | 9 +- sgzb-ui/src/store/modules/user.js | 1 + sgzb-ui/src/utils/validate.js | 11 + sgzb-ui/src/views/login.vue | 8 +- sgzb-ui/src/views/resetPassword.vue | 248 ++++++++++++++++++ sgzb-ui/src/views/system/user/index.vue | 20 +- .../views/system/user/profile/resetPwd.vue | 4 +- 7 files changed, 292 insertions(+), 9 deletions(-) create mode 100644 sgzb-ui/src/views/resetPassword.vue diff --git a/sgzb-ui/src/router/index.js b/sgzb-ui/src/router/index.js index 47487f73..9447e4b3 100644 --- a/sgzb-ui/src/router/index.js +++ b/sgzb-ui/src/router/index.js @@ -105,9 +105,12 @@ export const constantRoutes = [ path: '/qrCode/qrCodePage', component: () => import('@/views/qrCode/qrCode'), hidden: true - - - } + }, + { + path: '/resetPassword', + component: () => import('@/views/resetPassword'), + hidden: true + }, ] // 动态路由,基于用户权限动态去加载 diff --git a/sgzb-ui/src/store/modules/user.js b/sgzb-ui/src/store/modules/user.js index 2b191a82..a76ad179 100644 --- a/sgzb-ui/src/store/modules/user.js +++ b/sgzb-ui/src/store/modules/user.js @@ -72,6 +72,7 @@ const user = { return new Promise((resolve, reject) => { login(username, password, code, uuid).then(res => { let data = res.data + localStorage.setItem('isCode', res.data.code) setToken(data.access_token) commit('SET_TOKEN', data.access_token) localStorage.setItem('token', data.access_token) diff --git a/sgzb-ui/src/utils/validate.js b/sgzb-ui/src/utils/validate.js index adfa2542..9b5804fb 100644 --- a/sgzb-ui/src/utils/validate.js +++ b/sgzb-ui/src/utils/validate.js @@ -81,3 +81,14 @@ export function isArray(arg) { } return Array.isArray(arg) } + +/** + * @param {string} str + * @returns {Boolean} + */ + +// 密码规则:8-20位,必须包含字母、数字、特殊字符中的两种 +export function validPassword(str) { + const reg = /^((?=.*[A-Za-z])(?=.*\d)|(?=.*[A-Za-z])(?=.*[!@#$%^&*()_+\-\=])|(?=.*\d)(?=.*[!@#$%^&*()_+\-\=]))[A-Za-z\d!@#$%^&*()_+\-\=]{8,20}$/ + return reg.test(str) +} \ No newline at end of file diff --git a/sgzb-ui/src/views/login.vue b/sgzb-ui/src/views/login.vue index 1eb39eaa..93574109 100644 --- a/sgzb-ui/src/views/login.vue +++ b/sgzb-ui/src/views/login.vue @@ -299,8 +299,12 @@ export default { } this.$store .dispatch('Login', this.loginForm) - .then(() => { - this.$router.push({ path: '/' }).catch(() => {}) + .then((res) => { + if (localStorage.getItem('isCode') == 1) { + this.$router.push({ path: '/resetPassword' }).catch(() => {}) + } else { + this.$router.push({ path: '/' }).catch(() => {}) + } }) .catch(() => { this.loading = false diff --git a/sgzb-ui/src/views/resetPassword.vue b/sgzb-ui/src/views/resetPassword.vue new file mode 100644 index 00000000..d3a7f350 --- /dev/null +++ b/sgzb-ui/src/views/resetPassword.vue @@ -0,0 +1,248 @@ + + + + + diff --git a/sgzb-ui/src/views/system/user/index.vue b/sgzb-ui/src/views/system/user/index.vue index 3d8f9e13..751a0aa8 100644 --- a/sgzb-ui/src/views/system/user/index.vue +++ b/sgzb-ui/src/views/system/user/index.vue @@ -257,6 +257,7 @@ import { import { getToken } from '@/utils/auth' import Treeselect from '@riophae/vue-treeselect' import '@riophae/vue-treeselect/dist/vue-treeselect.css' +import { validPassword } from '@/utils/validate' export default { name: 'User', @@ -373,11 +374,26 @@ export default { trigger: 'blur', }, { - min: 5, + min: 8, max: 20, - message: '用户密码长度必须介于 5 和 20 之间', + message: '用户密码长度必须介于 8 和 20 之间', trigger: 'blur', }, + { + required: true, + validator: (rule, value, callback) => { + if (!validPassword(value)) { + callback( + new Error( + '密码须包含数字、字母、特殊符号中的两种以上', + ) + ) + } else { + callback() + } + }, + trigger: 'blur', + } ], email: [ { diff --git a/sgzb-ui/src/views/system/user/profile/resetPwd.vue b/sgzb-ui/src/views/system/user/profile/resetPwd.vue index 402b9d6e..e112a4fb 100644 --- a/sgzb-ui/src/views/system/user/profile/resetPwd.vue +++ b/sgzb-ui/src/views/system/user/profile/resetPwd.vue @@ -18,14 +18,14 @@