公共组件 #18
@@ -23,6 +23,7 @@ export class HttpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Service<T>(request: RequestObj) {
|
Service<T>(request: RequestObj) {
|
||||||
|
request.url = null;
|
||||||
// 设置默认值
|
// 设置默认值
|
||||||
request.contentType = request.contentType == null ? 'application/x-www-form-urlencoded' : request.contentType;
|
request.contentType = request.contentType == null ? 'application/x-www-form-urlencoded' : request.contentType;
|
||||||
request.header = {
|
request.header = {
|
||||||
@@ -32,7 +33,7 @@ export class HttpService {
|
|||||||
if (token != null) {
|
if (token != null) {
|
||||||
request.header.Authorization = token;
|
request.header.Authorization = token;
|
||||||
}
|
}
|
||||||
request.path = this.checkUrl(request);
|
request.url = this.checkUrl(request);
|
||||||
|
|
||||||
let observable: Observable<HttpResponse<Response<T>>>;
|
let observable: Observable<HttpResponse<Response<T>>>;
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
@@ -73,7 +74,7 @@ export class HttpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get<T>(request: RequestObj) {
|
private get<T>(request: RequestObj) {
|
||||||
return this.httpClient.get<T>(request.path,
|
return this.httpClient.get<T>(request.url,
|
||||||
{
|
{
|
||||||
headers: request.header,
|
headers: request.header,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
@@ -82,7 +83,7 @@ export class HttpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private post<T>(request: RequestObj) {
|
private post<T>(request: RequestObj) {
|
||||||
return this.httpClient.post<T>(request.path, request.data,
|
return this.httpClient.post<T>(request.url, request.data,
|
||||||
{
|
{
|
||||||
headers: request.header,
|
headers: request.header,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
@@ -91,7 +92,7 @@ export class HttpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private put<T>(request: RequestObj) {
|
private put<T>(request: RequestObj) {
|
||||||
return this.httpClient.put<T>(request.path, request.data,
|
return this.httpClient.put<T>(request.url, request.data,
|
||||||
{
|
{
|
||||||
headers: request.header,
|
headers: request.header,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
@@ -100,7 +101,7 @@ export class HttpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private delete<T>(request: RequestObj) {
|
private delete<T>(request: RequestObj) {
|
||||||
return this.httpClient.delete<T>(request.path,
|
return this.httpClient.delete<T>(request.url,
|
||||||
{
|
{
|
||||||
headers: request.header,
|
headers: request.header,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {HttpHeaders} from '@angular/common/http';
|
|||||||
|
|
||||||
export class RequestObj {
|
export class RequestObj {
|
||||||
path: string;
|
path: string;
|
||||||
|
url?: string; // 仅在httpService里面进行使用
|
||||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||||
data?: {};
|
data?: {};
|
||||||
contentType?: 'application/json' | 'application/x-www-form-urlencoded';
|
contentType?: 'application/json' | 'application/x-www-form-urlencoded';
|
||||||
|
|||||||
Reference in New Issue
Block a user