mirror of
https://gitee.com/fantastic-admin/basic.git
synced 2024-11-30 02:57:46 +08:00
refactor: 修改登录相关数据
This commit is contained in:
parent
fc44d941d0
commit
c9d25a0e8d
@ -12,8 +12,7 @@ export default defineFakeRoute([
|
|||||||
data: Mock.mock({
|
data: Mock.mock({
|
||||||
account: body.account,
|
account: body.account,
|
||||||
token: `${body.account}_@string`,
|
token: `${body.account}_@string`,
|
||||||
failure_time: Math.ceil(new Date().getTime() / 1000) + 24 * 60 * 60,
|
avatar: 'https://fantastic-admin.github.io/logo.png',
|
||||||
avatar: '',
|
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -12,19 +12,15 @@ const useUserStore = defineStore(
|
|||||||
const routeStore = useRouteStore()
|
const routeStore = useRouteStore()
|
||||||
const menuStore = useMenuStore()
|
const menuStore = useMenuStore()
|
||||||
|
|
||||||
const account = ref(localStorage.account ?? '')
|
const account = ref(sessionStorage.account ?? '')
|
||||||
const token = ref(localStorage.token ?? '')
|
const token = ref(sessionStorage.token ?? '')
|
||||||
const failure_time = ref(localStorage.failure_time ?? '')
|
const avatar = ref(sessionStorage.avatar ?? '')
|
||||||
const avatar = ref(localStorage.avatar ?? '')
|
|
||||||
const permissions = ref<string[]>([])
|
const permissions = ref<string[]>([])
|
||||||
const isLogin = computed(() => {
|
const isLogin = computed(() => {
|
||||||
let retn = false
|
|
||||||
if (token.value) {
|
if (token.value) {
|
||||||
if (new Date().getTime() < Number.parseInt(failure_time.value) * 1000) {
|
return true
|
||||||
retn = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return retn
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
// 登录
|
// 登录
|
||||||
@ -33,24 +29,20 @@ const useUserStore = defineStore(
|
|||||||
password: string
|
password: string
|
||||||
}) {
|
}) {
|
||||||
const res = await apiUser.login(data)
|
const res = await apiUser.login(data)
|
||||||
localStorage.setItem('account', res.data.account)
|
sessionStorage.setItem('account', res.data.account)
|
||||||
localStorage.setItem('token', res.data.token)
|
sessionStorage.setItem('token', res.data.token)
|
||||||
localStorage.setItem('failure_time', res.data.failure_time)
|
sessionStorage.setItem('avatar', res.data.avatar)
|
||||||
localStorage.setItem('avatar', res.data.avatar)
|
|
||||||
account.value = res.data.account
|
account.value = res.data.account
|
||||||
token.value = res.data.token
|
token.value = res.data.token
|
||||||
failure_time.value = res.data.failure_time
|
|
||||||
avatar.value = res.data.avatar
|
avatar.value = res.data.avatar
|
||||||
}
|
}
|
||||||
// 登出
|
// 登出
|
||||||
async function logout(redirect = router.currentRoute.value.fullPath) {
|
async function logout(redirect = router.currentRoute.value.fullPath) {
|
||||||
localStorage.removeItem('account')
|
sessionStorage.removeItem('account')
|
||||||
localStorage.removeItem('token')
|
sessionStorage.removeItem('token')
|
||||||
localStorage.removeItem('failure_time')
|
sessionStorage.removeItem('avatar')
|
||||||
localStorage.removeItem('avatar')
|
|
||||||
account.value = ''
|
account.value = ''
|
||||||
token.value = ''
|
token.value = ''
|
||||||
failure_time.value = ''
|
|
||||||
avatar.value = ''
|
avatar.value = ''
|
||||||
permissions.value = []
|
permissions.value = []
|
||||||
routeStore.removeRoutes()
|
routeStore.removeRoutes()
|
||||||
|
Loading…
Reference in New Issue
Block a user