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

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

parent a596cc75
......@@ -15,6 +15,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';
@NgModule({
declarations: [AppComponent],
......@@ -28,7 +29,8 @@ import { TransferService } from './service/transfer.service';
HttpService,
AuthService,
TransferService,
LocalNotifications
LocalNotifications,
BackgroundMode
],
bootstrap: [AppComponent]
})
......
......@@ -3,4 +3,5 @@
<img class="imgPart" src="../../../assets/icon/favicon.png">
<div class="topRight">1111111</div>
</div>
<ion-button mode="ios" color="primary" expand="full" class="loginBtn" (click)="getSelfInfo()">getSelfInfo</ion-button>
</div>
import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../service/api.service';
@Component({
selector: 'app-page-four',
......@@ -7,8 +8,21 @@ import { Component, OnInit } from '@angular/core';
})
export class PageFourComponent implements OnInit {
constructor() { }
req: any = {};
constructor(private api: ApiService) { }
ngOnInit() {}
getSelfInfo() {
const req = {
userName: this.req.name,
password: this.req.ps
};
this.api.user.getSelfInfo([req, (data) => {
if (data) {
console.log(data);
}
}]);
}
}
......@@ -16,6 +16,17 @@ export class ApiService {
logout: (data) => this.trans('get', '/login/logout', data),
};
public user = {
addUser: (data) => this.trans('post', '/user/addUser', data),
deleteUser: (data) => this.trans('post', '/user/deleteUser', data),
getAll: (data) => this.trans('get', '/user/getAll', data),
getByUserNameForLike: (data) => this.trans('post', '/user/getByUserNameForLike', data),
getSelfInfo: (data) => this.trans('get', '/user/getSelfInfo', data),
updateSelfPassword: (data) => this.trans('post', '/user/updateSelfPassword', data),
updateSelfUser: (data) => this.trans('post', '/user/updateSelfUser', data),
updateUser: (data) => this.trans('post', '/user/updateUser', data),
};
private trans(type, addr, data) {
this.sendHttpReq(type, addr, data[0], data[1], data[2], data[3]);
}
......
import { Injectable, OnInit } from '@angular/core';
import { HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
@Injectable()
export class AuthInterceptor implements HttpInterceptor, OnInit {
constructor() {
}
token: string;
ngOnInit() {
}
intercept(req: HttpRequest<any>, next: HttpHandler) {
// 这里的拦截了所有的请求,并且加上了token
// 每次都获取最新的token
this.token = window.sessionStorage.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