-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Octoveau/dev
Dev
- Loading branch information
Showing
7 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
# 限制git commit的命令 | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import authStorage from '@/utils/auth'; | ||
import { refreshTokenData } from '@/api/auth'; | ||
import { Message } from 'element-ui'; | ||
|
||
const refreshTokenFun = async () => { | ||
const tokenInfo = JSON.parse(authStorage.getTokenInfo() || 'null'); | ||
// token不存在,直接重新登录 | ||
if (!tokenInfo) { | ||
return false; | ||
} | ||
// token存在,需要判断是否刷新 | ||
// 1.判断是否超过刷新token的过期时间 | ||
if (new Date().getTime() > tokenInfo.refreshTokenExpires || new Date().getTime() > tokenInfo.expires) { | ||
Message.warning('登录过期,请重新登录'); | ||
return false; | ||
} | ||
// 2.判断是否需要续约token,30分支到60分钟续约 | ||
if (new Date().getTime() + 1000 * 60 * 30 >= tokenInfo.expires) { | ||
const { token, refreshToken } = tokenInfo; | ||
try { | ||
const result = await refreshTokenData({ token, refreshToken }); | ||
authStorage.setTokenInfo(result.data); | ||
return true; | ||
} catch (error) { | ||
console.error(error); | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
export default refreshTokenFun; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
<template> | ||
<div>This is Home</div> | ||
<section> | ||
<h1>这是一个home页面,发了一个请求</h1> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import { getUserInfoByToken } from '@/api/auth'; | ||
import authStorage from '@/utils/auth'; | ||
export default { | ||
data() { | ||
return {}; | ||
}, | ||
mounted() { | ||
const { token } = JSON.parse(authStorage.getTokenInfo()); | ||
getUserInfoByToken(token).then((res) => { | ||
console.log('res', res); | ||
}); | ||
}, | ||
}; | ||
</script> |