feat(patient-h5): 接入签署令牌与签名上传

This commit is contained in:
yelan
2026-09-01 10:13:45 +08:00
parent e467f03f23
commit 40cd313786
11 changed files with 614 additions and 42 deletions
+29
View File
@@ -0,0 +1,29 @@
import type { ApiResponse } from '@/api/types'
export class ApiResponseError extends Error {
readonly code: number | string
readonly traceId?: string
constructor(response: ApiResponse<unknown>) {
super(response.message || '签署服务请求失败')
this.name = 'ApiResponseError'
this.code = response.code
this.traceId = response.traceId
}
}
export function isSuccessCode(code: number | string) {
return code === 0 || code === '0'
}
export function unwrapApiResponse<T>(response: ApiResponse<T>): T {
if (!isSuccessCode(response.code)) {
throw new ApiResponseError(response)
}
if (response.data === null) {
throw new Error(response.message || '签署服务未返回数据')
}
return response.data
}
+35
View File
@@ -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