From 94e2c27f8b8a7191c25b1c6ea2b23348368cf8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B5=B7?= Date: Sat, 25 Apr 2020 17:09:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E9=87=8D=E5=A4=8D=EF=BC=8C?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=E8=AF=B7=E6=B1=82=E4=BC=9A=E5=B9=BF=E6=92=AD?= =?UTF-8?q?err=E5=AF=BC=E8=87=B4=E6=8E=A5=E6=94=B6=E5=88=B0null=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index/src/app/services/user.service.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index/src/app/services/user.service.ts b/index/src/app/services/user.service.ts index 9c1c484..5d35bfc 100644 --- a/index/src/app/services/user.service.ts +++ b/index/src/app/services/user.service.ts @@ -14,6 +14,8 @@ export class UserService { private localStorageService: LocalStorageService) { } + private lastRequestTime: number; + // 存储订阅者 private userObserverArray: Observer>[] = []; @@ -29,8 +31,16 @@ export class UserService { } } } + if (this.lastRequestTime && Date.now() - this.lastRequestTime < 1000) { + return { + unsubscribe() { + observer.complete(); + } + } + } // 不符合 请求网络数据并更新缓存 // 向订阅者传数据 + this.lastRequestTime = Date.now(); const subscription = this.apiService.userInfo().subscribe({ next: o => { this.localStorageService.setUser(o.result); @@ -38,6 +48,10 @@ export class UserService { }, error: err => { // console.debug('登录过期 token错误 等等'); + if (err.code === -1) { + // 请求重复 + return + } this.localStorageService.removeToken(); observer.next(new Response(null)); observer.error(err);