feat(patient-h5): 接入签署令牌与签名上传
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios'
|
||||
|
||||
const DEFAULT_API_BASE_URL = '/api'
|
||||
const DEFAULT_TIMEOUT = 15_000
|
||||
|
||||
class Request {
|
||||
private readonly instance: AxiosInstance
|
||||
|
||||
constructor(
|
||||
baseURL = import.meta.env.VITE_API_BASE_URL || DEFAULT_API_BASE_URL,
|
||||
timeout = DEFAULT_TIMEOUT,
|
||||
) {
|
||||
this.instance = axios.create({
|
||||
baseURL,
|
||||
timeout,
|
||||
withCredentials: false,
|
||||
})
|
||||
}
|
||||
|
||||
request<T = unknown>(config: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.request<T, AxiosResponse<T>>(config).then((response) => response.data)
|
||||
}
|
||||
|
||||
get<T = unknown>(url: string, config: AxiosRequestConfig = {}): Promise<T> {
|
||||
return this.request<T>({ ...config, url, method: 'GET' })
|
||||
}
|
||||
|
||||
post<T = unknown>(url: string, data?: unknown, config: AxiosRequestConfig = {}): Promise<T> {
|
||||
return this.request<T>({ ...config, url, data, method: 'POST' })
|
||||
}
|
||||
}
|
||||
|
||||
export const request = new Request()
|
||||
|
||||
export default request
|
||||
Reference in New Issue
Block a user