mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-06 07:21:24 +08:00
Added login expiration reminder. Add logout reminder.
This commit is contained in:
@@ -1,33 +1,19 @@
|
||||
import type { Captcha } from './common'
|
||||
import {
|
||||
getCaptcha,
|
||||
getLocalStorage,
|
||||
getToken,
|
||||
removeLocalStorage,
|
||||
setLocalStorage,
|
||||
setToken
|
||||
} from './common'
|
||||
import { clearLocalStorage, getCaptcha, getLocalStorage, setLocalStorage } from './common'
|
||||
import { TOKEN_NAME } from '@/constants/Common.constants'
|
||||
import _ from 'lodash'
|
||||
import request from '@/services'
|
||||
|
||||
let captcha: Captcha
|
||||
|
||||
async function login(username: string, passwd: string): Promise<boolean> {
|
||||
removeLocalStorage('username')
|
||||
await request.post('/login', { username, passwd }).then((res: any) => {
|
||||
const response = res.data
|
||||
if (response.code === 20010) {
|
||||
setToken(response.data.token)
|
||||
}
|
||||
})
|
||||
|
||||
return !_.isEmpty(getToken())
|
||||
async function login<T = any>(username: string, passwd: string): Promise<T> {
|
||||
return await request.post('/login', { username, passwd })
|
||||
}
|
||||
|
||||
function logout(): void {
|
||||
removeLocalStorage(TOKEN_NAME)
|
||||
removeLocalStorage('username')
|
||||
void request.get('/logout').finally(() => {
|
||||
clearLocalStorage()
|
||||
})
|
||||
}
|
||||
|
||||
function getLoginStatus(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user