i更新
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
<template>
|
||||
<section class="esign-panel" aria-label="处方电子签署" v-loading="busy">
|
||||
<div class="esign-panel__heading">
|
||||
<strong>医师电子签署</strong>
|
||||
<el-tag v-if="state && confirmed" :type="state.status === 'signed' ? 'success' : 'info'" size="small">
|
||||
{{ state.status_label }}
|
||||
</el-tag>
|
||||
<el-tag v-if="state?.environment === 'sandbox' && state?.status !== 'legacy'" type="warning" size="small">
|
||||
沙箱测试
|
||||
</el-tag>
|
||||
</div>
|
||||
<p v-if="state?.message" class="esign-panel__message">{{ state.message }}</p>
|
||||
<p v-if="state?.environment === 'sandbox' && state?.status !== 'legacy'" class="esign-panel__message">
|
||||
当前为沙箱测试签署,仅用于接入验证。
|
||||
</p>
|
||||
<p v-if="error" class="esign-panel__error" role="alert">{{ error }}</p>
|
||||
<div class="esign-panel__actions">
|
||||
<el-button
|
||||
v-if="state?.can_sign"
|
||||
type="primary"
|
||||
size="small"
|
||||
:disabled="busy || !confirmed"
|
||||
@click="start"
|
||||
>{{ state.status === 'failed' ? '重试核身签署' : authUrl ? '重新获取核身链接' : '发起核身签署' }}</el-button>
|
||||
<el-link v-if="authUrl && state?.can_sign && confirmed" :href="authUrl" target="_blank" rel="noopener noreferrer" type="primary">
|
||||
打开核身页面
|
||||
</el-link>
|
||||
<el-button
|
||||
v-if="state?.can_sign && (state.status === 'authenticating' || authUrl)"
|
||||
size="small"
|
||||
:disabled="busy || !confirmed"
|
||||
@click="complete"
|
||||
>已完成核身,继续签署</el-button>
|
||||
<el-button size="small" :disabled="busy" @click="refresh">刷新签署状态</el-button>
|
||||
<el-button v-if="state?.can_download" size="small" :disabled="busy || !confirmed" @click="download">
|
||||
下载已签原始 PDF
|
||||
</el-button>
|
||||
</div>
|
||||
<p v-if="authUrl && state?.can_sign" class="esign-panel__message">
|
||||
请在新页面完成核身,然后返回继续签署;关闭页面后可从处方详情继续。
|
||||
</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
prescriptionEsignComplete,
|
||||
prescriptionEsignStart,
|
||||
prescriptionEsignStatus,
|
||||
type PrescriptionEsignStatus
|
||||
} from '@/api/tcm'
|
||||
import { downloadPrescriptionPdfIfRequired, safeEsignAuthUrl, validateEsignStatus } from '@/utils/prescription-esign'
|
||||
|
||||
const props = defineProps<{ prescriptionId: number; initialState?: PrescriptionEsignStatus }>()
|
||||
const emit = defineEmits<{ (e: 'status-change', state: PrescriptionEsignStatus): void }>()
|
||||
function initialStatus(): PrescriptionEsignStatus | null {
|
||||
try {
|
||||
return validateEsignStatus(props.initialState)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
const state = ref<PrescriptionEsignStatus | null>(initialStatus())
|
||||
const busy = ref(false)
|
||||
const confirmed = ref(false)
|
||||
const error = ref('')
|
||||
const authUrl = computed(() => safeEsignAuthUrl(state.value?.auth_url))
|
||||
let generation = 0
|
||||
|
||||
async function run(action: 'refresh' | 'start' | 'complete') {
|
||||
if (busy.value || !props.prescriptionId) return
|
||||
if (action !== 'refresh' && (!confirmed.value || state.value?.can_sign !== true)) return
|
||||
const id = props.prescriptionId
|
||||
const current = generation
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const api = action === 'start' ? prescriptionEsignStart : action === 'complete' ? prescriptionEsignComplete : prescriptionEsignStatus
|
||||
const result = validateEsignStatus(await api({ id }))
|
||||
if (id !== props.prescriptionId || current !== generation) return
|
||||
state.value = result
|
||||
confirmed.value = true
|
||||
emit('status-change', result)
|
||||
// A browser visit is never evidence of authentication or signing.
|
||||
if (result.auth_url && !safeEsignAuthUrl(result.auth_url)) {
|
||||
error.value = '核身链接无效,请重新获取或联系管理员'
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (id === props.prescriptionId && current === generation) {
|
||||
confirmed.value = false
|
||||
error.value = e?.msg || e?.message || '签署服务暂时不可用,请刷新状态后重试'
|
||||
}
|
||||
} finally {
|
||||
if (current === generation) busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const refresh = () => run('refresh')
|
||||
const start = () => run('start')
|
||||
const complete = () => run('complete')
|
||||
|
||||
async function download() {
|
||||
if (busy.value || !confirmed.value || state.value?.can_download !== true) return
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
await downloadPrescriptionPdfIfRequired(props.prescriptionId)
|
||||
} catch (e: any) {
|
||||
confirmed.value = false
|
||||
error.value = e?.msg || e?.message || '下载签署文件失败,请重试'
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.prescriptionId, () => {
|
||||
generation++
|
||||
busy.value = false
|
||||
confirmed.value = false
|
||||
error.value = ''
|
||||
state.value = initialStatus()
|
||||
void refresh()
|
||||
}, { immediate: true })
|
||||
|
||||
watch(() => props.initialState, (value) => {
|
||||
if (value) {
|
||||
state.value = initialStatus()
|
||||
if (!state.value) confirmed.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.esign-panel { margin: 12px 0; padding: 14px 16px; border: 1px solid var(--el-border-color-light); border-radius: 6px; background: var(--el-fill-color-light); }
|
||||
.esign-panel__heading, .esign-panel__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||||
.esign-panel__message { margin: 8px 0; color: var(--el-text-color-secondary); font-size: 13px; }
|
||||
.esign-panel__error { color: var(--el-color-danger); font-size: 13px; }
|
||||
@media print { .esign-panel { display: none; } }
|
||||
</style>
|
||||
@@ -510,7 +510,12 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="医师签名" prop="doctor_signature" required>
|
||||
<el-alert v-if="esignError" type="error" :closable="false" class="mb-3">
|
||||
{{ esignError }} <el-button link type="primary" @click="loadEsignConfig">重试</el-button>
|
||||
</el-alert>
|
||||
<el-alert v-else-if="esignEnabled" type="info" :closable="false" class="mb-3"
|
||||
:title="esignConfig?.environment === 'sandbox' ? '沙箱测试:保存处方后,请完成医师核身与电子签署' : '保存处方后,请完成医师核身与电子签署'" />
|
||||
<el-form-item v-else-if="esignReady" label="医师签名" prop="doctor_signature" required>
|
||||
<div class="signature-pad-wrap">
|
||||
<canvas
|
||||
ref="signatureCanvasRef"
|
||||
@@ -534,6 +539,12 @@
|
||||
</div>
|
||||
|
||||
<div v-else class="rx-wrap">
|
||||
<EsignPrescriptionPanel
|
||||
:key="savedPrescription.id"
|
||||
:prescription-id="Number(savedPrescription.id)"
|
||||
:initial-state="savedPrescription.esign"
|
||||
@status-change="onEsignStatusChange"
|
||||
/>
|
||||
<div class="rx-toolbar">
|
||||
<el-tag v-if="savedPrescription.void_status === 1" type="danger" size="small">已作废</el-tag>
|
||||
<el-tag v-else-if="approvedPreviewOnly" type="success" size="small">已通过</el-tag>
|
||||
@@ -679,13 +690,14 @@
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-2 mt-4">
|
||||
<el-button @click="handleDownloadImage">
|
||||
<el-button v-if="!requiresOriginalEsignPdf(savedPrescription.esign)" @click="handleDownloadImage">
|
||||
<el-icon><Download /></el-icon>
|
||||
下载图片
|
||||
</el-button>
|
||||
<el-button type="primary" @click="handleDownloadPdf">
|
||||
<el-button type="primary" @click="handleDownloadPdf"
|
||||
:disabled="requiresOriginalEsignPdf(savedPrescription.esign) && !savedPrescription.esign?.can_download">
|
||||
<el-icon><Document /></el-icon>
|
||||
下载PDF
|
||||
{{ requiresOriginalEsignPdf(savedPrescription.esign) ? '下载已签原始 PDF' : '下载PDF' }}
|
||||
</el-button>
|
||||
<el-tooltip
|
||||
v-if="savedPrescription.void_status !== 1 && !approvedPreviewOnly"
|
||||
@@ -713,7 +725,9 @@
|
||||
<template v-if="!savedPrescription" #footer>
|
||||
<div class="flex justify-end gap-2">
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" @click="handleSave" :loading="saving">保存处方</el-button>
|
||||
<el-button type="primary" @click="handleSave" :loading="saving || esignLoading" :disabled="!esignReady">
|
||||
{{ esignEnabled ? '保存后核身签署' : '保存处方' }}
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-drawer>
|
||||
@@ -860,6 +874,10 @@ import { prescriptionAdd, prescriptionDetail, prescriptionGetByAppointment, pres
|
||||
import { medicineLists } from '@/api/medicine'
|
||||
import { getDictData } from '@/api/app'
|
||||
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
|
||||
import EsignPrescriptionPanel from '@/components/EsignPrescriptionPanel.vue'
|
||||
import { usePrescriptionEsignConfig } from '@/hooks/usePrescriptionEsignConfig'
|
||||
import { downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf } from '@/utils/prescription-esign'
|
||||
import type { PrescriptionEsignStatus } from '@/api/tcm'
|
||||
import html2canvas from 'html2canvas'
|
||||
import { jsPDF } from 'jspdf'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
@@ -1043,6 +1061,12 @@ const signatureActivePointerId = ref<number | null>(null)
|
||||
const SIGNATURE_CSS_W = 560
|
||||
const SIGNATURE_CSS_H = 168
|
||||
const savedPrescription = ref<any>(null)
|
||||
const { config: esignConfig, enabled: esignEnabled, ready: esignReady, loading: esignLoading, error: esignError, load: loadEsignConfig } = usePrescriptionEsignConfig()
|
||||
|
||||
const onEsignStatusChange = (state: PrescriptionEsignStatus) => {
|
||||
if (savedPrescription.value) savedPrescription.value.esign = state
|
||||
emit('success')
|
||||
}
|
||||
/** 预览联次:药房联 / 处方联(与消费者处方查看一致) */
|
||||
const prescriptionTabType = ref<'internal' | 'user'>('internal') // 保留兼容 openPreview options.slipType
|
||||
/** 诊单列表「查看」仅展示处方联,不展示详细病历 A3 */
|
||||
@@ -1661,6 +1685,7 @@ const open = async (data: any, options?: { templateId?: number; stationName?: st
|
||||
}
|
||||
|
||||
await loadDictOptions()
|
||||
await loadEsignConfig()
|
||||
|
||||
const appointmentId = Number(data.id ?? data.appointment_id ?? 0)
|
||||
if (appointmentId) {
|
||||
@@ -2032,6 +2057,9 @@ watch(() => formData.prescription_type, (newType) => {
|
||||
})
|
||||
|
||||
const handleSave = async () => {
|
||||
if (saving.value) return
|
||||
if (!esignReady.value && !(await loadEsignConfig())) return
|
||||
if (saving.value) return
|
||||
if (!formData.clinical_diagnosis?.trim()) {
|
||||
feedback.msgWarning('请输入临床诊断')
|
||||
return
|
||||
@@ -2056,7 +2084,7 @@ const handleSave = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
if (!formData.doctor_signature?.trim()) {
|
||||
if (!esignEnabled.value && !formData.doctor_signature?.trim()) {
|
||||
feedback.msgWarning('请使用电子签名板手写医师签名')
|
||||
return
|
||||
}
|
||||
@@ -2103,8 +2131,14 @@ const handleSave = async () => {
|
||||
})
|
||||
const id = res?.id
|
||||
if (id) {
|
||||
const detail = await prescriptionDetail({ id })
|
||||
savedPrescription.value = detail
|
||||
// Keep the saved id even if the follow-up detail request fails; retrying must not add twice.
|
||||
savedPrescription.value = { ...formData, id, audit_status: 0, esign: res.esign }
|
||||
feedback.msgSuccess(res.esign?.required ? '处方已保存,请继续完成核身签署' : '处方已保存')
|
||||
try {
|
||||
savedPrescription.value = await prescriptionDetail({ id })
|
||||
} catch {
|
||||
feedback.msgWarning('处方已保存,详情暂未加载,可从已开处方继续签署')
|
||||
}
|
||||
emit('success')
|
||||
} else {
|
||||
feedback.msgError('保存失败')
|
||||
@@ -2156,6 +2190,7 @@ const fetchCaseRecord = async (diagnosisId: number) => {
|
||||
}
|
||||
|
||||
const handleNewPrescription = async () => {
|
||||
await loadEsignConfig()
|
||||
const saved = savedPrescription.value
|
||||
if (saved) {
|
||||
// 将患者信息、诊断信息填入表单,新建处方时保留
|
||||
@@ -2273,6 +2308,7 @@ const handleDownloadImage = async () => {
|
||||
|
||||
const handleDownloadPdf = async () => {
|
||||
try {
|
||||
if (await downloadPrescriptionPdfIfRequired(Number(savedPrescription.value?.id))) return
|
||||
const canvas = await captureElement()
|
||||
const imgData = canvas.toDataURL('image/png')
|
||||
const pdf = new jsPDF({
|
||||
@@ -2301,8 +2337,8 @@ const handleDownloadPdf = async () => {
|
||||
|
||||
pdf.save(`处方_${savedPrescription.value?.patient_name || '未命名'}_${Date.now()}.pdf`)
|
||||
feedback.msgSuccess('PDF已下载')
|
||||
} catch (e) {
|
||||
feedback.msgError('下载PDF失败')
|
||||
} catch (e: any) {
|
||||
feedback.msgError(e?.message || '下载PDF失败')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user