@rjgf/http-client
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -1,2 +0,2 @@ | ||
import { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import { AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios'; | ||
import EventEmitter from 'eventemitter3'; | ||
@@ -50,3 +50,3 @@ export interface ApiResult<T = unknown> { | ||
export declare class HTTPClient extends EventEmitter<HTTPEventTypes> implements IHTTPClient { | ||
client: import("axios").AxiosInstance; | ||
client: AxiosInstance; | ||
private static instances; | ||
@@ -53,0 +53,0 @@ /** |
@@ -34,38 +34,2 @@ "use strict"; | ||
exports.HTTPError = HTTPError; | ||
const client = axios_1.default.create(); | ||
// @ts-expect-error 如果是 uni-app 的话,加上对应的适配器 | ||
if (typeof uni === 'object') { | ||
client.defaults.adapter = function (config) { | ||
// 自己定义个适配器,用来适配 uniapp 的语法 | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const settle = require('axios/lib/core/settle'); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const buildURL = require('axios/lib/helpers/buildURL'); | ||
// @ts-expect-error ignore | ||
uni.request({ | ||
method: (_a = config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(), | ||
url: config.baseURL + buildURL(config.url, config.params, config.paramsSerializer), | ||
header: config.headers, | ||
data: config.data, | ||
// @ts-expect-error ignore | ||
dataType: config.dataType, | ||
responseType: config.responseType, | ||
// @ts-expect-error ignore | ||
sslVerify: config.sslVerify, | ||
complete: function complete(response) { | ||
const res = { | ||
data: response.data, | ||
status: response.statusCode, | ||
errMsg: response.errMsg, | ||
header: response.header, | ||
config: config, | ||
}; | ||
settle(resolve, reject, res); | ||
}, | ||
}); | ||
}); | ||
}; | ||
} | ||
// eslint-disable-next-line import/no-unused-modules | ||
@@ -83,6 +47,40 @@ class HTTPClient extends eventemitter3_1.default { | ||
} | ||
// test | ||
constructor(baseURL) { | ||
super(); | ||
this.client = client; | ||
this.client = axios_1.default.create(); | ||
// @ts-expect-error 如果是 uni-app 的话,加上对应的适配器 | ||
if (typeof uni === 'object') { | ||
this.client.defaults.adapter = function (config) { | ||
// 自己定义个适配器,用来适配 uniapp 的语法 | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const settle = require('axios/lib/core/settle'); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const buildURL = require('axios/lib/helpers/buildURL'); | ||
// @ts-expect-error ignore | ||
uni.request({ | ||
method: (_a = config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(), | ||
url: config.baseURL + buildURL(config.url, config.params, config.paramsSerializer), | ||
header: config.headers, | ||
data: config.data, | ||
// @ts-expect-error ignore | ||
dataType: config.dataType, | ||
responseType: config.responseType, | ||
// @ts-expect-error ignore | ||
sslVerify: config.sslVerify, | ||
complete: function complete(response) { | ||
const res = { | ||
data: response.data, | ||
status: response.statusCode, | ||
errMsg: response.errMsg, | ||
header: response.header, | ||
config: config, | ||
}; | ||
settle(resolve, reject, res); | ||
}, | ||
}); | ||
}); | ||
}; | ||
} | ||
this.client.defaults.baseURL = baseURL; | ||
@@ -89,0 +87,0 @@ this.client.defaults.headers.common.Pragma = 'no-cache'; |
@@ -35,3 +35,3 @@ { | ||
}, | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"scripts": { | ||
@@ -38,0 +38,0 @@ "build": "pnpm tsc", |
Sorry, the diff of this file is not supported yet
33095
343