feat: 提交
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { request } from '@/utils/request'
|
||||
import { unwrapApiResponse } from '@/utils/api-response'
|
||||
import type { ApiResponseOf, SigningFieldDef } from '@/api/workbench/types'
|
||||
|
||||
export type SignaturePosition = NonNullable<SigningFieldDef['pdfPosition']>
|
||||
export interface SignaturePreview {
|
||||
pages: { page: number; width: number; height: number; image: string }[]
|
||||
candidates: (SignaturePosition & { id: string })[]
|
||||
}
|
||||
export async function getSignaturePreview(
|
||||
templateId: string,
|
||||
contentHtml: string,
|
||||
): Promise<SignaturePreview> {
|
||||
const response = await request.post<ApiResponseOf<SignaturePreview>>(
|
||||
`/v1/templates/${encodeURIComponent(templateId)}/signature-preview`,
|
||||
{ contentHtml },
|
||||
{ timeout: 60000 },
|
||||
)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
@@ -3,7 +3,10 @@ import { request } from '@/utils/request'
|
||||
|
||||
import type {
|
||||
ApiResponseOf,
|
||||
SigningContextRequest,
|
||||
SigningContextResponseDto,
|
||||
PadBindingRequest,
|
||||
PatientSignerAssertionInput,
|
||||
PadSessionUploadInput,
|
||||
SendSmsDeliveryRequest,
|
||||
SignDeliveryResponseDto,
|
||||
@@ -77,6 +80,14 @@ export function consumeSigningToken(
|
||||
.then(unwrapApiResponse)
|
||||
}
|
||||
|
||||
export function getSigningContext(
|
||||
payload: SigningContextRequest,
|
||||
): Promise<SigningContextResponseDto> {
|
||||
return request
|
||||
.post<ApiResponseOf<SigningContextResponseDto>>('/v1/sign-deliveries/token/context', payload)
|
||||
.then(unwrapApiResponse)
|
||||
}
|
||||
|
||||
function createSignatureFormData(file: File | Blob, metadata: string) {
|
||||
const formData = new FormData()
|
||||
const fileName =
|
||||
@@ -86,20 +97,31 @@ function createSignatureFormData(file: File | Blob, metadata: string) {
|
||||
return formData
|
||||
}
|
||||
|
||||
function appendJsonPart(formData: FormData, name: string, value: unknown) {
|
||||
formData.append(
|
||||
name,
|
||||
new Blob([JSON.stringify(value)], { type: 'application/json' }),
|
||||
`${name}.json`,
|
||||
)
|
||||
}
|
||||
|
||||
function appendSigner(formData: FormData, signer: PatientSignerAssertionInput) {
|
||||
appendJsonPart(formData, 'signer', signer)
|
||||
}
|
||||
|
||||
export function uploadSigningSignature(
|
||||
payload: SigningTokenUploadInput,
|
||||
): Promise<SignatureUploadResponse> {
|
||||
const formData = createSignatureFormData(payload.file, payload.metadata)
|
||||
appendJsonPart(formData, 'deliveryId', payload.deliveryId)
|
||||
formData.append('uploadToken', payload.uploadToken)
|
||||
appendSigner(formData, payload.signer)
|
||||
|
||||
return request
|
||||
.post<ApiResponseOf<SignatureUploadResponse>>(
|
||||
`/v1/sign-deliveries/${encodeURIComponent(payload.taskId)}/signature`,
|
||||
formData,
|
||||
{
|
||||
params: {
|
||||
deliveryId: payload.deliveryId,
|
||||
uploadToken: payload.uploadToken,
|
||||
},
|
||||
headers: idempotencyHeaders(payload.idempotencyKey),
|
||||
},
|
||||
)
|
||||
@@ -140,14 +162,13 @@ export function uploadSigningSignatureByProof(
|
||||
payload: SigningTokenUploadInput,
|
||||
): Promise<SignatureUploadResponse> {
|
||||
const formData = createSignatureFormData(payload.file, payload.metadata)
|
||||
appendJsonPart(formData, 'taskId', payload.taskId)
|
||||
appendJsonPart(formData, 'deliveryId', payload.deliveryId)
|
||||
formData.append('uploadToken', payload.uploadToken)
|
||||
appendSigner(formData, payload.signer)
|
||||
|
||||
return request
|
||||
.post<ApiResponseOf<SignatureUploadResponse>>('/v1/sign-deliveries/token/signature', formData, {
|
||||
params: {
|
||||
taskId: payload.taskId,
|
||||
deliveryId: payload.deliveryId,
|
||||
uploadToken: payload.uploadToken,
|
||||
},
|
||||
headers: idempotencyHeaders(payload.idempotencyKey),
|
||||
})
|
||||
.then(unwrapApiResponse)
|
||||
|
||||
@@ -633,6 +633,43 @@ export interface TokenConsumeResponse {
|
||||
timestamp?: string | null
|
||||
}
|
||||
|
||||
export interface SigningContextRequest {
|
||||
taskId: string
|
||||
deliveryId: string
|
||||
uploadToken: string
|
||||
}
|
||||
|
||||
export interface SigningContextSignatureFieldDto {
|
||||
id: string
|
||||
page: number
|
||||
x: number
|
||||
y: number
|
||||
width: number
|
||||
height: number
|
||||
coordinateSystem: 'TOP_LEFT' | 'PDF_BOTTOM_LEFT'
|
||||
}
|
||||
|
||||
export interface SigningContextResponseDto {
|
||||
taskId: string
|
||||
deliveryId: string
|
||||
channel: SignDeliveryChannel
|
||||
status: BackendSigningTaskStatus
|
||||
signer: {
|
||||
type: string | null
|
||||
name: string | null
|
||||
relation: string | null
|
||||
}
|
||||
signatureFields: SigningContextSignatureFieldDto[]
|
||||
}
|
||||
|
||||
export interface PatientSignerAssertionInput {
|
||||
type: 'SELF' | 'FAMILY'
|
||||
name: string
|
||||
relation: string
|
||||
consentAccepted: true
|
||||
observedSignedAt: string
|
||||
}
|
||||
|
||||
export type SignatureUploadStatus = BackendSigningTaskStatus
|
||||
|
||||
export interface SignatureUploadResponse {
|
||||
@@ -661,6 +698,7 @@ export interface SignatureUploadInput {
|
||||
|
||||
export interface SigningTokenUploadInput extends Omit<SignatureUploadInput, 'pad'> {
|
||||
taskId: string
|
||||
signer: PatientSignerAssertionInput
|
||||
}
|
||||
|
||||
export interface PadSessionUploadInput extends SignatureUploadInput {
|
||||
|
||||
Reference in New Issue
Block a user