Showing
1 changed file
with
4 additions
and
3 deletions
... | ... | @@ -79,14 +79,14 @@ export class VAxios { |
79 | 79 | */ |
80 | 80 | private refreshTokenBeforeReq(doRefreshTokenApi: () => Promise<unknown>): Promise<unknown> { |
81 | 81 | // 创建一个未完成的promise,把改变状态的resolve方法交给请求token结束后执行 |
82 | - const promise = new Promise((resolve) => { | |
82 | + const promise = new Promise((resolve) => { | |
83 | 83 | // 等待队列放的是一个回调函数,来延迟resolve的执行,以此控制promise状态的改变 |
84 | 84 | this.waitingQueue.push(() => resolve(null)); |
85 | 85 | }); |
86 | 86 | if (!this.refreshing) { |
87 | 87 | this.refreshing = true; |
88 | 88 | // 模拟请求刷新Token接口,当接口返回数据时执行then方法 TODO 添加catch捕获异常 |
89 | - doRefreshTokenApi().then(() => { | |
89 | + doRefreshTokenApi().then(() => { | |
90 | 90 | this.refreshing = false; |
91 | 91 | this.waitingQueue.forEach((cb) => cb()); |
92 | 92 | this.waitingQueue.length = 0; |
... | ... | @@ -118,7 +118,8 @@ export class VAxios { |
118 | 118 | if (userStore && userStore.jwtToken) { |
119 | 119 | try { |
120 | 120 | const res = jwt_decode(userStore.jwtToken) as JwtModel; |
121 | - const currentTime = new Date().getTime() / 1000; | |
121 | + console.log(res) | |
122 | + const currentTime = (new Date().getTime() - (config.timeout || 0)) / 1000; | |
122 | 123 | if (currentTime >= res.exp && this.isNeedTokenURL(config.url!)) { |
123 | 124 | await this.refreshTokenBeforeReq(userStore.doRefresh); |
124 | 125 | } | ... | ... |