Commit a848d451 authored by van.chen's avatar van.chen

init----对于更新新的之后的凉凉之后的项目重构

parent f4a4d0ef
......@@ -5,9 +5,11 @@ import { HttpClientModule } from '@angular/common/http';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
import { BackgroundMode } from '@ionic-native/background-mode/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
......@@ -15,7 +17,7 @@ import { ApiService } from './service/api.service';
import { AuthService } from './service/auth.service';
import { HttpService } from './service/http.service';
import { TransferService } from './service/transfer.service';
import { BackgroundMode } from '@ionic-native/background-mode/ngx';
import { AuthInterceptor } from './service/token.service';
@NgModule({
declarations: [AppComponent],
......@@ -25,6 +27,11 @@ import { BackgroundMode } from '@ionic-native/background-mode/ngx';
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
{
provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptor,
multi: true,
},
ApiService,
HttpService,
AuthService,
......
......@@ -4,4 +4,5 @@
<div class="topRight">1111111</div>
</div>
<ion-button mode="ios" color="primary" expand="full" class="loginBtn" (click)="getSelfInfo()">getSelfInfo</ion-button>
{{resp}}
</div>
......@@ -9,6 +9,7 @@ import { ApiService } from '../../service/api.service';
export class PageFourComponent implements OnInit {
req: any = {};
resp: any = {};
constructor(private api: ApiService) { }
ngOnInit() {}
......@@ -21,6 +22,7 @@ export class PageFourComponent implements OnInit {
this.api.user.getSelfInfo([req, (data) => {
if (data) {
console.log(data);
this.resp = JSON.stringify(data);
}
}]);
}
......
......@@ -15,7 +15,7 @@ export class AuthInterceptor implements HttpInterceptor, OnInit {
intercept(req: HttpRequest<any>, next: HttpHandler) {
// 这里的拦截了所有的请求,并且加上了token
// 每次都获取最新的token
this.token = window.sessionStorage.getItem('token') || '';
this.token = window.localStorage.getItem('token') || '';
const authReq = req.clone({headers: req.headers.set('AccountToken', this.token)});
return next.handle(authReq);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment