Skip to content

Commit

Permalink
fix: 密码过期情况下,标记用户选择是否修改密码
Browse files Browse the repository at this point in the history
  • Loading branch information
jskils authored and Charles7c committed May 9, 2024
1 parent 395a564 commit c64cf9d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
26 changes: 26 additions & 0 deletions src/layout/components/HeaderRightBar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 4 additions & 1 deletion src/stores/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]>([]) // 当前角色权限标识集合

Expand Down Expand Up @@ -90,6 +91,7 @@ const storeSetup = () => {
const logoutCallBack = async () => {
roles.value = []
permissions.value = []
passwordExpiredShow.value = true
resetToken()
resetRouter()
}
Expand All @@ -112,6 +114,7 @@ const storeSetup = () => {
token,
roles,
permissions,
passwordExpiredShow,
accountLogin,
emailLogin,
phoneLogin,
Expand All @@ -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 }
})
21 changes: 0 additions & 21 deletions src/views/login/components/account/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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 = () => {
Expand Down

0 comments on commit c64cf9d

Please sign in to comment.