fix(signing): align workbench with MEDISIGN contract

This commit is contained in:
yelan
2026-09-01 14:50:07 +08:00
parent 8b4b9d031d
commit 5b2cc33038
10 changed files with 155 additions and 51 deletions

View File

@@ -46,21 +46,23 @@ function getCollectionRecords(collection: ArtifactCollection) {
} }
function normalizeArtifact(dto: SignArtifactResponseDto): SigningArtifact { function normalizeArtifact(dto: SignArtifactResponseDto): SigningArtifact {
const artifactType: SignArtifactType = dto.artifactType ?? dto.type ?? 'UNKNOWN' const artifactType: SignArtifactType = dto.artifactType
const label = artifactLabels[artifactType] ?? '签署文件' const label = artifactLabels[artifactType] ?? '签署文件'
const mimeType = dto.mimeType ?? dto.contentType ?? 'application/octet-stream' const mimeType = dto.mimeType || 'application/octet-stream'
const extension = const extension =
mimeType === 'application/pdf' ? 'pdf' : mimeType === 'image/png' ? 'png' : 'bin' mimeType === 'application/pdf' ? 'pdf' : mimeType === 'image/png' ? 'png' : 'bin'
return { return {
id: dto.id, id: dto.id,
taskId: dto.taskId, taskId: dto.taskId,
pipelineId: dto.pipelineId,
artifactType, artifactType,
label, label,
fileName: dto.fileName || `${label}.${extension}`, fileName: `${label}.${extension}`,
mimeType, mimeType,
size: dto.size ?? dto.byteSize ?? dto.fileSize ?? 0, sizeBytes: dto.sizeBytes,
sha256: dto.sha256 ?? dto.contentSha256 ?? '', sha256: dto.sha256,
metadata: dto.metadata ?? {},
createdAt: formatDateTime(dto.createdAt), createdAt: formatDateTime(dto.createdAt),
} }
} }

View File

@@ -41,15 +41,12 @@ export function sendSigningSms(
export function resendSigningSms( export function resendSigningSms(
taskId: string, taskId: string,
expectedRowVersion?: number,
idempotencyKey?: string, idempotencyKey?: string,
): Promise<SignDeliveryResponseDto | null> { ): Promise<SignDeliveryResponseDto | null> {
const data = expectedRowVersion === undefined ? undefined : { expectedRowVersion }
return request return request
.post<ApiResponseOf<SignDeliveryResponseDto | null>>( .post<ApiResponseOf<SignDeliveryResponseDto | null>>(
`/v1/sign-deliveries/${encodeURIComponent(taskId)}/sms/resend`, `/v1/sign-deliveries/${encodeURIComponent(taskId)}/sms/resend`,
data, undefined,
{ headers: idempotencyHeaders(idempotencyKey) }, { headers: idempotencyHeaders(idempotencyKey) },
) )
.then(unwrapNullableApiResponse) .then(unwrapNullableApiResponse)
@@ -69,9 +66,14 @@ export function createPadSigningSession(
.then(unwrapApiResponse) .then(unwrapApiResponse)
} }
export function consumeSigningToken(payload: TokenConsumeRequest): Promise<TokenConsumeResponse> { export function consumeSigningToken(
payload: TokenConsumeRequest,
idempotencyKey?: string,
): Promise<TokenConsumeResponse> {
return request return request
.post<ApiResponseOf<TokenConsumeResponse>>('/v1/sign-deliveries/token/consume', payload) .post<ApiResponseOf<TokenConsumeResponse>>('/v1/sign-deliveries/token/consume', payload, {
headers: idempotencyHeaders(idempotencyKey),
})
.then(unwrapApiResponse) .then(unwrapApiResponse)
} }

View File

@@ -10,6 +10,7 @@ import type {
AvailableTemplateVersionResponseDto, AvailableTemplateVersionResponseDto,
BackendSigningMethod, BackendSigningMethod,
BackendSigningTaskStatus, BackendSigningTaskStatus,
BackendVisitType,
CreateSigningTaskInput, CreateSigningTaskInput,
CreateSigningTaskRequest, CreateSigningTaskRequest,
PatientProfile, PatientProfile,
@@ -563,7 +564,6 @@ function toBackendTaskQuery(query: SigningTaskQuery, options: SigningApiOptions
pending: 'WAITING_SIGN', pending: 'WAITING_SIGN',
signing: 'GENERATING', signing: 'GENERATING',
signed: 'SIGNED', signed: 'SIGNED',
rejected: 'FAILED',
expired: 'EXPIRED', expired: 'EXPIRED',
void: 'VOIDED', void: 'VOIDED',
failed: 'FAILED', failed: 'FAILED',
@@ -579,6 +579,19 @@ function toBackendTaskQuery(query: SigningTaskQuery, options: SigningApiOptions
params.signMethod = query.method === 'sms' ? 'SMS' : 'PAD' params.signMethod = query.method === 'sms' ? 'SMS' : 'PAD'
} }
if (query.visitType && query.visitType !== 'all') {
const visitTypeMap: Partial<Record<VisitType, BackendVisitType>> = {
: 'OUTPATIENT',
: 'INPATIENT',
: 'CHECKUP',
}
const visitType = visitTypeMap[query.visitType]
if (visitType) {
params.visitType = visitType
}
}
if (query.documentId) { if (query.documentId) {
params.templateVersionId = params.templateVersionId =
findTemplate(options.templates, query.documentId)?.versionId ?? query.documentId findTemplate(options.templates, query.documentId)?.versionId ?? query.documentId
@@ -604,8 +617,12 @@ function toBackendTaskQuery(query: SigningTaskQuery, options: SigningApiOptions
params.createdTo = end.toISOString() params.createdTo = end.toISOString()
} }
if (query.campus && query.campus !== 'all' && options.campusId) { if (query.campus && query.campus !== 'all') {
params.campusId = options.campusId const campusId = options.campusIds?.[query.campus] ?? options.campusId
if (campusId) {
params.campusId = campusId
}
} }
if (query.department && options.departmentIds?.[query.department]) { if (query.department && options.departmentIds?.[query.department]) {
@@ -1031,7 +1048,7 @@ export async function resendSigningSms(
options: SigningTaskActionOptions = {}, options: SigningTaskActionOptions = {},
): Promise<SigningTaskRecord | null> { ): Promise<SigningTaskRecord | null> {
if (!useMockData) { if (!useMockData) {
await resendSigningSmsDelivery(id, options.expectedRowVersion) await resendSigningSmsDelivery(id)
return getSigningTaskDetail(id, options) return getSigningTaskDetail(id, options)
} }
@@ -1107,7 +1124,6 @@ export function getSigningStatusLabel(status: SigningTaskStatus) {
pending: '待签署', pending: '待签署',
signing: '签署中', signing: '签署中',
signed: '已签署', signed: '已签署',
rejected: '已拒签',
expired: '已超时', expired: '已超时',
void: '已作废', void: '已作废',
failed: '处理失败', failed: '处理失败',

View File

@@ -9,8 +9,7 @@ export interface WorkbenchOverviewQuery {
rankingPeriod: HomeRankingPeriod rankingPeriod: HomeRankingPeriod
} }
export type SigningTaskStatus = export type SigningTaskStatus = 'pending' | 'signing' | 'signed' | 'expired' | 'void' | 'failed'
'pending' | 'signing' | 'signed' | 'rejected' | 'expired' | 'void' | 'failed'
export type PatientSex = '男' | '女' | '未知' export type PatientSex = '男' | '女' | '未知'
@@ -171,6 +170,7 @@ export interface SigningApiOptions {
templates?: SigningTemplate[] templates?: SigningTemplate[]
campus?: WorkbenchCampus campus?: WorkbenchCampus
campusId?: string campusId?: string
campusIds?: Record<string, string>
campusNames?: Record<string, WorkbenchCampus> campusNames?: Record<string, WorkbenchCampus>
departmentIds?: Record<string, string> departmentIds?: Record<string, string>
} }
@@ -438,32 +438,29 @@ export interface SignTaskEventResponseDto {
export type SignArtifactType = 'ORIGINAL_PDF' | 'SIGNATURE_IMAGE' | 'SIGNED_PDF' | string export type SignArtifactType = 'ORIGINAL_PDF' | 'SIGNATURE_IMAGE' | 'SIGNED_PDF' | string
/** MEDISIGN 签署产物 DTO。部分文件元数据由不同版本的服务端返回字段保持可选并在 API 边界归一化。 */
export interface SignArtifactResponseDto { export interface SignArtifactResponseDto {
id: string id: string
taskId: string taskId: string
artifactType?: SignArtifactType pipelineId: string
type?: SignArtifactType artifactType: SignArtifactType
fileName?: string | null sizeBytes: number
mimeType?: string | null mimeType: string
contentType?: string | null sha256: string
size?: number | null metadata: Record<string, unknown>
byteSize?: number | null createdAt: string
fileSize?: number | null
sha256?: string | null
contentSha256?: string | null
createdAt?: string | null
} }
export interface SigningArtifact { export interface SigningArtifact {
id: string id: string
taskId: string taskId: string
pipelineId: string
artifactType: SignArtifactType artifactType: SignArtifactType
label: string label: string
fileName: string fileName: string
mimeType: string mimeType: string
size: number sizeBytes: number
sha256: string sha256: string
metadata: Record<string, unknown>
createdAt: string createdAt: string
} }

View File

@@ -226,7 +226,7 @@ function mapReportTask(task: SigningTaskRecord, templates: SigningTemplate[]): R
? 'signed' ? 'signed'
: task.status === 'expired' : task.status === 'expired'
? 'expired' ? 'expired'
: task.status === 'void' || task.status === 'failed' || task.status === 'rejected' : task.status === 'void' || task.status === 'failed'
? 'void' ? 'void'
: 'pending' : 'pending'

View File

@@ -48,7 +48,7 @@ function formatFileSize(size: number) {
</div> </div>
<div class="artifact-info"> <div class="artifact-info">
<strong>{{ artifact.label }}</strong> <strong>{{ artifact.label }}</strong>
<span>{{ artifact.fileName }} · {{ formatFileSize(artifact.size) }}</span> <span>{{ artifact.fileName }} · {{ formatFileSize(artifact.sizeBytes) }}</span>
<small v-if="artifact.createdAt">生成于 {{ artifact.createdAt }}</small> <small v-if="artifact.createdAt">生成于 {{ artifact.createdAt }}</small>
</div> </div>
<button type="button" class="artifact-download" @click="emit('download', artifact)"> <button type="button" class="artifact-download" @click="emit('download', artifact)">

View File

@@ -93,7 +93,7 @@ const emit = defineEmits<{
</button> </button>
</template> </template>
<template v-else-if="task.status === 'expired' || task.status === 'failed'"> <template v-else-if="task.status === 'expired'">
<button type="button" class="action-button" @click="emit('action', 'reopen')"> <button type="button" class="action-button" @click="emit('action', 'reopen')">
重新发起 重新发起
</button> </button>
@@ -105,7 +105,7 @@ const emit = defineEmits<{
class="action-button action-button--ghost" class="action-button action-button--ghost"
@click="emit('action', 'download-pdf')" @click="emit('action', 'download-pdf')"
> >
下载 PDF 原件 下载签署后 PDF
</button> </button>
<button <button
type="button" type="button"

View File

@@ -1,22 +1,28 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'
import type { SigningTaskRecord } from '@/api/workbench/types' import type { SigningTaskRecord } from '@/api/workbench/types'
defineProps<{ const props = defineProps<{
tasks: SigningTaskRecord[] tasks: SigningTaskRecord[]
selectedId: string | null selectedId: string | null
total: number total: number
page: number
pageSize: number
loading: boolean loading: boolean
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
select: [id: string] select: [id: string]
pageChange: [page: number]
}>() }>()
const pageCount = computed(() => Math.max(Math.ceil(props.total / props.pageSize), 1))
const statusLabels: Record<SigningTaskRecord['status'], string> = { const statusLabels: Record<SigningTaskRecord['status'], string> = {
pending: '待签署', pending: '待签署',
signing: '签署中', signing: '签署中',
signed: '已签署', signed: '已签署',
rejected: '已拒签',
expired: '已超时', expired: '已超时',
void: '已作废', void: '已作废',
failed: '处理失败', failed: '处理失败',
@@ -100,6 +106,21 @@ function getVisitClass(type: SigningTaskRecord['visitType']) {
<span aria-hidden="true">🔍</span> <span aria-hidden="true">🔍</span>
<p>没有符合条件的任务</p> <p>没有符合条件的任务</p>
</div> </div>
<footer v-if="total > pageSize" class="task-pagination">
<span> {{ page }} / {{ pageCount }} </span>
<span class="task-pagination__total"> {{ total }} </span>
<button type="button" :disabled="page <= 1 || loading" @click="emit('pageChange', page - 1)">
上一页
</button>
<button
type="button"
:disabled="page >= pageCount || loading"
@click="emit('pageChange', page + 1)"
>
下一页
</button>
</footer>
</section> </section>
</template> </template>
@@ -212,7 +233,6 @@ function getVisitClass(type: SigningTaskRecord['visitType']) {
background: var(--ok-l); background: var(--ok-l);
} }
.task-status--rejected,
.task-status--expired { .task-status--expired {
color: var(--err); color: var(--err);
background: var(--err-l); background: var(--err-l);
@@ -292,6 +312,42 @@ function getVisitClass(type: SigningTaskRecord['visitType']) {
font-size: 13px; font-size: 13px;
} }
.task-pagination {
display: flex;
gap: 8px;
align-items: center;
padding: 9px 10px;
margin-top: 10px;
color: var(--mut);
font-size: 11.5px;
background: var(--card);
border-radius: var(--r);
box-shadow: var(--sh);
}
.task-pagination__total {
margin-right: auto;
}
.task-pagination button {
padding: 4px 8px;
color: var(--brand);
font-size: 11.5px;
background: #fff;
border: 1px solid var(--line);
border-radius: 5px;
}
.task-pagination button:hover:not(:disabled) {
border-color: var(--brand);
background: var(--brand-l);
}
.task-pagination button:disabled {
cursor: not-allowed;
opacity: 0.45;
}
.task-items--loading { .task-items--loading {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@@ -48,7 +48,6 @@ const STATUS_VALUES: SigningTaskStatus[] = [
'pending', 'pending',
'signing', 'signing',
'signed', 'signed',
'rejected',
'expired', 'expired',
'void', 'void',
'failed', 'failed',
@@ -59,7 +58,6 @@ const statusLabels: Record<SigningTaskStatus, string> = {
pending: '待签署', pending: '待签署',
signing: '签署中', signing: '签署中',
signed: '已签署', signed: '已签署',
rejected: '已拒签',
expired: '已超时', expired: '已超时',
void: '已作废', void: '已作废',
failed: '处理失败', failed: '处理失败',
@@ -78,6 +76,8 @@ const filter = reactive<SigningFilterForm>({
const tasks = ref<SigningTaskRecord[]>([]) const tasks = ref<SigningTaskRecord[]>([])
const total = ref(0) const total = ref(0)
const page = ref(1)
const pageSize = ref(20)
const selectedTaskId = ref<string | null>(null) const selectedTaskId = ref<string | null>(null)
const selectedTask = ref<SigningTaskRecord | null>(null) const selectedTask = ref<SigningTaskRecord | null>(null)
const taskEvents = ref<SigningTaskEvent[]>([]) const taskEvents = ref<SigningTaskEvent[]>([])
@@ -145,6 +145,7 @@ const documentOptions = computed<SigningFilterOption[]>(() => [
const signingApiOptions = computed(() => ({ const signingApiOptions = computed(() => ({
campus: appStore.selectedCampus, campus: appStore.selectedCampus,
campusId: campusIds.value[appStore.selectedCampus], campusId: campusIds.value[appStore.selectedCampus],
campusIds: campusIds.value,
campusNames: campusNames.value, campusNames: campusNames.value,
departmentIds: departmentIds.value, departmentIds: departmentIds.value,
templates: templates.value, templates: templates.value,
@@ -275,7 +276,11 @@ async function loadTaskDetail(id: string | null) {
} }
} }
async function loadTasks(preferredTaskId?: string) { async function loadTasks(preferredTaskId?: string, resetPage = false) {
if (resetPage) {
page.value = 1
}
const requestId = ++listRequestId const requestId = ++listRequestId
loading.value = true loading.value = true
@@ -283,8 +288,8 @@ async function loadTasks(preferredTaskId?: string) {
const response = await getSigningTasks( const response = await getSigningTasks(
{ {
...filter, ...filter,
page: 1, page: page.value,
pageSize: 50, pageSize: pageSize.value,
}, },
signingApiOptions.value, signingApiOptions.value,
) )
@@ -295,6 +300,8 @@ async function loadTasks(preferredTaskId?: string) {
tasks.value = response.records tasks.value = response.records
total.value = response.total total.value = response.total
page.value = response.page
pageSize.value = response.pageSize
const taskIds = new Set(response.records.map((task) => task.id)) const taskIds = new Set(response.records.map((task) => task.id))
const routeTaskId = getQueryString(route.query.taskId) const routeTaskId = getQueryString(route.query.taskId)
@@ -323,7 +330,7 @@ async function loadTasks(preferredTaskId?: string) {
function handleSearch(nextFilter: SigningFilterForm) { function handleSearch(nextFilter: SigningFilterForm) {
Object.assign(filter, nextFilter) Object.assign(filter, nextFilter)
selectedTaskId.value = null selectedTaskId.value = null
void loadTasks() void loadTasks(undefined, true)
} }
function selectTask(id: string) { function selectTask(id: string) {
@@ -331,13 +338,25 @@ function selectTask(id: string) {
void loadTaskDetail(id) void loadTaskDetail(id)
} }
function handlePageChange(nextPage: number) {
const pageCount = Math.max(Math.ceil(total.value / pageSize.value), 1)
if (nextPage < 1 || nextPage > pageCount || nextPage === page.value) {
return
}
page.value = nextPage
selectedTaskId.value = null
void loadTasks()
}
async function refreshTask(updatedTask: SigningTaskRecord | null, successMessage: string) { async function refreshTask(updatedTask: SigningTaskRecord | null, successMessage: string) {
if (!updatedTask) { if (!updatedTask) {
ElMessage.error('签署任务不存在或已被删除') ElMessage.error('签署任务不存在或已被删除')
return return
} }
await loadTasks(updatedTask.id) await loadTasks(updatedTask.id, true)
ElMessage.success(successMessage) ElMessage.success(successMessage)
} }
@@ -389,15 +408,18 @@ async function handleTaskAction(action: SigningTaskAction) {
return return
} }
if (action === 'reopen' && task.status !== 'expired') {
ElMessage.info('只有已超时任务可以重新发起')
return
}
if (action === 'download-pdf') { if (action === 'download-pdf') {
const artifact = const artifact = artifacts.value.find((item) => item.artifactType === 'SIGNED_PDF')
artifacts.value.find((item) => item.artifactType === 'SIGNED_PDF') ??
artifacts.value.find((item) => item.artifactType === 'ORIGINAL_PDF')
if (artifact) { if (artifact) {
await downloadArtifact(artifact) await downloadArtifact(artifact)
} else { } else {
ElMessage.info('当前任务暂无 PDF 文件') ElMessage.info('当前任务暂无签署后 PDF')
} }
return return
} }
@@ -535,13 +557,14 @@ async function initializePage() {
} }
async function handleTaskCreated(task: SigningTaskRecord) { async function handleTaskCreated(task: SigningTaskRecord) {
await loadTasks(task.id) await loadTasks(task.id, true)
} }
watch( watch(
() => [route.query.status, route.query.range, route.query.taskId], () => [route.query.status, route.query.range, route.query.taskId],
() => { () => {
syncFilterFromRoute() syncFilterFromRoute()
page.value = 1
selectedTaskId.value = null selectedTaskId.value = null
void loadTasks() void loadTasks()
}, },
@@ -553,6 +576,7 @@ watch(
if (filter.campus !== 'all') { if (filter.campus !== 'all') {
filter.campus = campus filter.campus = campus
} }
page.value = 1
void loadTasks() void loadTasks()
}, },
) )
@@ -593,8 +617,11 @@ onMounted(() => {
:tasks="tasks" :tasks="tasks"
:selected-id="selectedTaskId" :selected-id="selectedTaskId"
:total="total" :total="total"
:page="page"
:page-size="pageSize"
:loading="loading" :loading="loading"
@select="selectTask" @select="selectTask"
@page-change="handlePageChange"
/> />
<SigningTaskDetail <SigningTaskDetail
:task="selectedTask" :task="selectedTask"

View File

@@ -11,7 +11,11 @@ import type {
export function consumeSigningToken(payload: TokenConsumeRequest): Promise<TokenConsumeResponse> { export function consumeSigningToken(payload: TokenConsumeRequest): Promise<TokenConsumeResponse> {
return request return request
.post<ApiResponse<TokenConsumeResponse>>('/v1/sign-deliveries/token/consume', payload) .post<ApiResponse<TokenConsumeResponse>>('/v1/sign-deliveries/token/consume', payload, {
headers: {
'Idempotency-Key': createIdempotencyKey(),
},
})
.then(unwrapApiResponse) .then(unwrapApiResponse)
} }