1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import { Injectable } from '@angular/core';
- import { HttpClient, HttpHeaders } from '@angular/common/http';
- @Injectable({
- providedIn: 'root',
- })
- export class HttpService {
- constructor(public http: HttpClient) {}
- customSQL(sql: string) {
- return new Promise((resolve, reason) => {
- this.http
- .post('https://server.fmode.cn/api/novaql/select', {
- sql,
- })
- .subscribe((data) => {
- resolve(data);
- });
- });
- }
- // 定义请求方法
- httpPostRquest(url: string, params: any) : Promise<any> {
- return new Promise((resolve, reason) => {
- this.http
- .post(url, {
- params,
- })
- .subscribe((data) => {
- resolve(data);
- });
- });
- }
- postAuth(company: string, idCard: string, name: string) {
- return new Promise((resolve, reason) => {
- this.http
- .post('https://server.fmode.cn/api/apig/idcard', {
- company: company,
- cardNo: idCard,
- realName: name,
- })
- .subscribe((data) => {
- resolve(data);
- });
- });
- }
- // 定义jsonp的方法
- getJsonpMsg(url: string, cb: string) {
- return this.http.jsonp(url, cb);
- }
- async httpRequst(url: string, reqBody: any, method: string = 'GET') {
- let queryString = '';
- if (method === 'GET' && reqBody) {
- queryString = new URLSearchParams(reqBody).toString();
- url += `?${queryString}`;
- }
- let result = await fetch(url, {
- method: method,
- headers: {
- 'Content-Type': 'application/json',
- },
- body: method !== 'GET' ? JSON.stringify(reqBody) : undefined,
- });
- let data = await result.json();
- // console.log(data);
- return data;
- }
- }
|