1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import {getStorage, setStorage, delStorage} from "@/utils/storage";
- import {calcDate} from 'js-fast-way'
- //计算token是否过期
- export const getTokenTime = (tokenKey) => {
- const token = getStorage(tokenKey, true)
- if (token) {
- const date = calcDate(token.datetime, new Date().getTime())
- if (date.seconds > 2000) {
- removeToken()
- removeRefreshToken()
- }
- }
- }
- export const getToken = () => {
- getTokenTime('token')
- return getStorage('token')
- }
- export const setToken = (token) => {
- setStorage('token', token)
- }
- export const getRefreshToken = () => {
- getTokenTime('refreshToken')
- return getStorage('refreshToken')
- }
- export const setRefreshToken = (token) => {
- setStorage('refreshToken', token)
- }
- export const removeToken = () => {
- delStorage('token')
- }
- export const removeRefreshToken = () => {
- delStorage('refreshToken')
- }
|