12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /**
- * 一切http辅助类的基类,用于调用axios
- * nh 2021.12.23
- */
- import { axiosUtils } from "./axiosUtils"
- import { toolUtils } from "../toolUtils";
- export class httpUtils extends axiosUtils {
- protected constructor(baseUrl: string) {
- super();
- this.baseUrl = baseUrl;
- };
- //根域名地址
- private _baseUrl = '';
- private set baseUrl(val: string) {
- this._baseUrl = val;
- }
- private get baseUrl() {
- return this._baseUrl;
- }
- private async send(url: string, data: any, superFnName: string) {
- var newUrl = toolUtils.getBaseHttpUrl(this.baseUrl, url);
- return await super[superFnName](newUrl, data);
- };
- /**
- * get请求
- * @param url
- * @param data
- * @returns
- */
- public async getRequest(url: string, data: any) {
- return await this.send(url, data, 'getRequest');
- };
- /**
- * post请求
- * @param url
- * @param data
- * @returns
- */
- public async postRequest(url: string, data: any) {
- return await this.send(url, data, 'postRequest');
- };
- /**
- * 自定义请求
- * @param url
- * @param headers
- * @param data
- * @param method get | post 默认post
- * @returns
- */
- protected async customRequest(url: string, headers: any, data: any, method: string) {
- return await super.customRequest(url, headers, data, method);
- }
- }
|