fix: 密码过期情况下,标记用户选择是否修改密码

This commit is contained in:
kils
2024-05-09 18:05:53 +08:00
committed by Charles7c
parent 395a5642af
commit c64cf9da34
3 changed files with 30 additions and 22 deletions

View File

@@ -98,6 +98,32 @@ const logout = () => {
}
})
}
onMounted(() => {
checkPasswordExpired()
})
const checkPasswordExpired = () => {
if (!userStore.passwordExpiredShow || !userStore.userInfo.passwordExpired) {
return
}
Modal.confirm({
title: '提示',
content: '密码已过期,是否去修改?',
hideCancel: false,
closable: true,
onBeforeOk: async () => {
try {
await router.push({ path: '/setting/profile' })
return true
} catch (error) {
return false
}
},
onCancel: () => {
// 当前登录会话不再提示
userStore.passwordExpiredShow = false
}
})
}
</script>
<style lang="scss" scoped>

View File

@@ -37,6 +37,7 @@ const storeSetup = () => {
const avatar = computed(() => userInfo.avatar)
const token = ref(getToken() || '')
const passwordExpiredShow = ref<boolean>(true)
const roles = ref<string[]>([]) // 当前用户角色
const permissions = ref<string[]>([]) // 当前角色权限标识集合
@@ -90,6 +91,7 @@ const storeSetup = () => {
const logoutCallBack = async () => {
roles.value = []
permissions.value = []
passwordExpiredShow.value = true
resetToken()
resetRouter()
}
@@ -112,6 +114,7 @@ const storeSetup = () => {
token,
roles,
permissions,
passwordExpiredShow,
accountLogin,
emailLogin,
phoneLogin,
@@ -124,5 +127,5 @@ const storeSetup = () => {
}
export const useUserStore = defineStore('user', storeSetup, {
persist: { paths: ['token', 'roles', 'permissions'], storage: localStorage }
persist: { paths: ['token', 'roles', 'permissions', 'passwordExpiredShow'], storage: localStorage }
})

View File

@@ -94,7 +94,6 @@ const handleLogin = async () => {
const { rememberMe } = loginConfig.value
loginConfig.value.username = rememberMe ? form.username : ''
Message.success('欢迎使用')
checkPasswordExpired()
} catch (error) {
getCaptcha()
form.captcha = ''
@@ -103,26 +102,6 @@ const handleLogin = async () => {
}
}
const checkPasswordExpired = () => {
if (!userStore.userInfo.passwordExpired) {
return
}
Modal.confirm({
title: '提示',
content: '密码已过期,是否去修改?',
hideCancel: false,
closable: true,
onBeforeOk: async () => {
try {
await router.push({ path: '/setting/profile' })
return true
} catch (error) {
return false
}
}
})
}
const captchaImgBase64 = ref()
// 获取验证码
const getCaptcha = () => {