完善token获取机制

This commit is contained in:
lyswhut
2019-10-31 20:26:53 +08:00
parent 82843b14b4
commit b0d6181bd7
4 changed files with 11 additions and 14 deletions
+5 -1
View File
@@ -17,8 +17,12 @@ export const matchToken = headers => {
}
}
const wait = time => new Promise(resolve => setTimeout(() => resolve(), time))
export const getToken = () => new Promise((resolve, reject) => {
if (window.kw_token.isGetingToken) reject(new Error('正在获取token'))
if (window.kw_token.isGetingToken) return wait(1000).then(() => getToken().then(token => resolve(token)))
if (window.kw_token.token) return resolve(window.kw_token.token)
window.kw_token.isGetingToken = true
httpGet('http://www.kuwo.cn', (err, resp) => {
window.kw_token.isGetingToken = false