中化加油站项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class BuildingBasicInfosService {
//获取单位信息的api
baseUrl = 'api/v2/BuildingBasicInfos';
/**
* ()api
*/
markUrl = "api/v2/Sandboxie";
constructor(
private http: HttpClient
) { }
/**
*
*/
getBuildingBasicInfos(name: string): Observable<string> {
return this.http.get<string>(this.baseUrl + '?name=' + name);
}
/**
*
* @param name
* @param data
*/
postBuildingBasicInfos(name: string, data: any): Observable<any> {
return this.http.post<any>(this.baseUrl + '?name=' + name, data)
.pipe(
catchError((err) => this.handleError(err))
);
}
/**
*
* @param name
*/
getMarkData(name: string): Observable<string> {
// name = "bb";
let id = { "name": name };
return this.http.get<string>(this.markUrl, { params: id }).pipe( //'?name='
catchError((err) => this.handleError(err))
);
}
/**
*
* @param name
* @param data
*/
postMarkData(name: string, data: any): Observable<any> {
return this.http.post<any>(this.markUrl + '?name=' + name, data)
.pipe(
catchError((err) => this.handleError(err))
);
}
private handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong.
if (error.status == 404) {
console.log("404===" + error.error);
}
else {
console.error(
error + `Backend returned code ${error.status}, ` +
`body was: ${error.error}`);
}
}
// Return an observable with a user-facing error message.
return throwError(
error);
}
}