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

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

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