igengx
This commit is contained in:
@@ -2,14 +2,19 @@
|
||||
<el-dialog
|
||||
:model-value="true"
|
||||
:title="reviewer ? '审核签署身份' : '医生电子签署身份'"
|
||||
:width="frameUrl ? 'min(760px, 94vw)' : 'min(520px, 94vw)'"
|
||||
width="min(760px, 94vw)"
|
||||
top="5vh"
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
:before-close="dismiss"
|
||||
>
|
||||
<p class="doctor-esign__message" role="status">{{ guidance }}</p>
|
||||
<dl v-if="state?.enabled && state.status === 'ready'" class="doctor-esign__expiry">
|
||||
<p v-if="statusNotice" class="doctor-esign__message" role="status">{{ statusNotice }}</p>
|
||||
<dl v-if="state && (certificateLabel || grantActive)" class="doctor-esign__expiry">
|
||||
<template v-if="certificateLabel">
|
||||
<dt>签署证书状态</dt>
|
||||
<dd>{{ certificateLabel }}</dd>
|
||||
</template>
|
||||
<template v-if="state.cert_expires_at">
|
||||
<dt>签署证书有效期至</dt>
|
||||
<dd>{{ formatExpiry(state.cert_expires_at) }}</dd>
|
||||
@@ -22,6 +27,17 @@
|
||||
</template>
|
||||
</dl>
|
||||
<p v-if="error" class="doctor-esign__error" role="alert">{{ error }}</p>
|
||||
<label v-if="needsSignerName" class="doctor-esign__field">
|
||||
证件姓名
|
||||
<el-input
|
||||
v-model="signerName"
|
||||
:disabled="!!pending"
|
||||
autocomplete="off"
|
||||
:spellcheck="false"
|
||||
required
|
||||
placeholder="请输入与本人有效证件一致的姓名"
|
||||
/>
|
||||
</label>
|
||||
<label v-if="needsMobile" class="doctor-esign__field">
|
||||
本人手机号码
|
||||
<el-input
|
||||
@@ -67,11 +83,18 @@
|
||||
{{ state?.quicksign_authorizing ? '确认快捷签授权' : '确认绑定签署身份' }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="canResume && !state?.quicksign_authorizing"
|
||||
v-if="canRestartWithSignerName"
|
||||
:disabled="!!pending"
|
||||
@click="enterSignerName"
|
||||
>修改证件姓名</el-button>
|
||||
<el-button
|
||||
v-if="canResume && !state?.quicksign_authorizing && !canRestartWithSignerName"
|
||||
:disabled="!!pending"
|
||||
@click="enterMobile"
|
||||
>重新输入手机号</el-button>
|
||||
<el-button :disabled="!!pending" @click="refresh">检查状态</el-button>
|
||||
<el-button :disabled="!!pending" @click="checkStatus">
|
||||
{{ checkingIdentity ? '检查认证状态' : '重新校验证书' }}
|
||||
</el-button>
|
||||
<el-button v-if="frameUrl" link @click="authenticationUnavailable">验证页面不可用</el-button>
|
||||
<el-button @click="dismiss">关闭</el-button>
|
||||
</div>
|
||||
@@ -112,21 +135,42 @@ const state = ref<ReturnType<typeof validateStatus> | null>(null)
|
||||
const pending = ref<DoctorRequest | null>(null)
|
||||
const frameUrl = ref('')
|
||||
const mobile = ref('')
|
||||
const signerName = ref('')
|
||||
const identityNumber = ref('')
|
||||
const editingMobile = ref(false)
|
||||
const error = ref('')
|
||||
const statusNotice = ref('')
|
||||
const now = ref(Date.now() + props.serverTimeOffsetMs)
|
||||
|
||||
const authUrl = computed(() => state.value?.auth_url ?? '')
|
||||
const authenticating = computed(() => state.value?.enabled === true && state.value.status === 'authenticating')
|
||||
const canResume = computed(() => authenticating.value && !!authUrl.value && !frameUrl.value && !editingMobile.value)
|
||||
const canEditSignerName = computed(() => props.reviewer === true && state.value?.enabled === true
|
||||
&& state.value.can_edit_signer_name === true && !state.value.quicksign_authorizing)
|
||||
const canRestartWithSignerName = computed(() => canEditSignerName.value && authenticating.value && !editingMobile.value)
|
||||
const needsSignerName = computed(() => canEditSignerName.value
|
||||
&& (state.value?.status === 'unbound' || state.value?.status === 'needs_mobile'
|
||||
|| (authenticating.value && editingMobile.value)))
|
||||
const canComplete = computed(() => state.value?.enabled === true && state.value.status === 'binding_required')
|
||||
const checkingIdentity = computed(() => authenticating.value || canComplete.value)
|
||||
const needsIdentityNumber = computed(() => canComplete.value && !state.value?.quicksign_authorizing
|
||||
&& state.value?.identity_details_required === true)
|
||||
const needsMobile = computed(() => state.value?.enabled === true
|
||||
&& (enrollmentStatuses.includes(state.value.status) || editingMobile.value))
|
||||
const certificateState = computed(() => {
|
||||
const current = state.value
|
||||
if (!current?.enabled) return ''
|
||||
if (current.status === 'unbound') return 'unbound'
|
||||
if (current.certificate_state === 'unconfirmed') return 'unconfirmed'
|
||||
if (current.status === 'renewal_required' || current.certificate_state === 'renewal_required') return 'renewal_required'
|
||||
if (current.status !== 'ready' && current.status !== 'needs_mobile') return ''
|
||||
return current.cert_expires_at * 1000 > now.value ? 'valid' : 'renewal_required'
|
||||
})
|
||||
const certificateLabel = computed(() => ({
|
||||
'': '', unbound: '未绑定', valid: '有效', renewal_required: '需要续期', unconfirmed: '暂无法确认'
|
||||
})[certificateState.value])
|
||||
const quickReady = computed(() => state.value?.enabled === true && state.value.status === 'ready'
|
||||
&& state.value.quicksign_enabled === true)
|
||||
&& certificateState.value === 'valid' && state.value.quicksign_enabled === true)
|
||||
const grantActive = computed(() => quickReady.value && !!state.value && !state.value.quicksign_unavailable_reason
|
||||
&& (state.value.quicksign_remaining_times ?? 0) > 0 && state.value.quicksign_expires_at * 1000 > now.value)
|
||||
const canAuthorizeQuick = computed(() => quickReady.value && !grantActive.value)
|
||||
@@ -137,15 +181,19 @@ const startLabel = computed(() => {
|
||||
})
|
||||
const guidance = computed(() => {
|
||||
const current = state.value
|
||||
if (!current) return pending.value === 'status' ? '正在查询医生签署身份…' : ''
|
||||
if (pending.value === 'status' && !checkingIdentity.value) return '正在向 e签宝校验证书…'
|
||||
if (!current) return ''
|
||||
if (!current.enabled) return '当前环境未启用医生电子签署身份。'
|
||||
if (needsSignerName.value) return '请填写与本人有效证件一致的姓名和本人手机号码,完成人脸认证。'
|
||||
switch (current.status) {
|
||||
case 'unbound':
|
||||
return '首次电子签署前,请验证本人身份并绑定签署证书。'
|
||||
case 'needs_mobile':
|
||||
return '请使用本人手机号码完成签署身份验证。'
|
||||
case 'renewal_required':
|
||||
return '签署证书需要续期,请使用本人手机号码完成人脸认证。'
|
||||
return certificateState.value === 'unconfirmed'
|
||||
? '暂无法确认证书状态,可重新校验,或使用本人手机号码发起续期认证。'
|
||||
: '签署证书需要续期,请使用本人手机号码完成人脸认证。'
|
||||
case 'authenticating':
|
||||
if (editingMobile.value) return '请使用本人手机号码完成人脸认证。'
|
||||
if (current.authUrlUnavailable) return '验证链接不可用,请检查状态后重试。'
|
||||
@@ -159,9 +207,11 @@ const guidance = computed(() => {
|
||||
if (needsIdentityNumber.value) return '人脸认证已通过。首次绑定证书需要补充与本次认证一致的身份证号码。'
|
||||
return '人脸认证已通过,请确认完成本人的签署身份认证。'
|
||||
case 'ready': {
|
||||
if (certificateState.value !== 'valid') return '请重新校验签署证书后继续。'
|
||||
if (!quickReady.value) return '医生签署身份已就绪。'
|
||||
if (grantActive.value) return props.reviewer ? '快捷签授权有效。每张处方由审核人本人确认签名。'
|
||||
: '快捷签授权有效。每张处方仍需开方医生本人确认签名。'
|
||||
if (grantActive.value) return props.reviewer
|
||||
? '快捷签授权有效。每张处方由药师本人确认签名。'
|
||||
: '快捷签授权有效。请回到处方中,由开方医生本人确认签名。'
|
||||
const reason = current.quicksign_unavailable_reason
|
||||
if (reason === 'expired' || (current.quicksign_expires_at > 0 && current.quicksign_expires_at * 1000 <= now.value)) {
|
||||
return '快捷签授权已过期,请重新授权。'
|
||||
@@ -190,11 +240,14 @@ function validTime(value: number) {
|
||||
|
||||
function validateStatus(result: PrescriptionEsignDoctorStatus) {
|
||||
const {
|
||||
enabled, status, cert_expires_at,
|
||||
enabled, status, cert_expires_at, certificate_state,
|
||||
can_edit_signer_name = false,
|
||||
identity_details_required = false, quicksign_enabled = false, quicksign_authorizing = false,
|
||||
quicksign_expires_at = 0, quicksign_remaining_times = 0, quicksign_unavailable_reason = ''
|
||||
} = result
|
||||
if (!statuses.includes(status) || typeof enabled !== 'boolean'
|
||||
|| typeof can_edit_signer_name !== 'boolean'
|
||||
|| (certificate_state !== undefined && !['valid', 'renewal_required', 'unconfirmed'].includes(certificate_state))
|
||||
|| typeof quicksign_enabled !== 'boolean' || typeof quicksign_authorizing !== 'boolean'
|
||||
|| !validTime(cert_expires_at) || !validTime(quicksign_expires_at)
|
||||
|| typeof identity_details_required !== 'boolean'
|
||||
@@ -207,7 +260,7 @@ function validateStatus(result: PrescriptionEsignDoctorStatus) {
|
||||
const providerUrl = enabled && status === 'authenticating' ? result.auth_url : undefined
|
||||
const auth_url = safeEsignAuthUrl(providerUrl)
|
||||
return {
|
||||
enabled, status, cert_expires_at, identity_details_required, quicksign_enabled, quicksign_authorizing,
|
||||
enabled, status, cert_expires_at, certificate_state, can_edit_signer_name, identity_details_required, quicksign_enabled, quicksign_authorizing,
|
||||
quicksign_expires_at, quicksign_remaining_times, quicksign_unavailable_reason, auth_url,
|
||||
authUrlUnavailable: Boolean(providerUrl && !auth_url)
|
||||
}
|
||||
@@ -215,6 +268,7 @@ function validateStatus(result: PrescriptionEsignDoctorStatus) {
|
||||
|
||||
function clearInputs() {
|
||||
mobile.value = ''
|
||||
signerName.value = ''
|
||||
identityNumber.value = ''
|
||||
}
|
||||
|
||||
@@ -239,6 +293,7 @@ function clearStatus() {
|
||||
state.value = null
|
||||
editingMobile.value = false
|
||||
error.value = ''
|
||||
statusNotice.value = ''
|
||||
}
|
||||
|
||||
function dismiss() {
|
||||
@@ -257,8 +312,9 @@ function accept(result: ReturnType<typeof validateStatus>) {
|
||||
editingMobile.value = false
|
||||
state.value = result
|
||||
if (!authenticating.value || (frameUrl.value && frameUrl.value !== authUrl.value)) stopAuthentication()
|
||||
if (grantActive.value) {
|
||||
const expiresIn = result.quicksign_expires_at * 1000 - now.value
|
||||
if (certificateState.value === 'valid') {
|
||||
const expiry = grantActive.value ? Math.min(result.cert_expires_at, result.quicksign_expires_at) : result.cert_expires_at
|
||||
const expiresIn = expiry * 1000 - now.value
|
||||
if (expiresIn <= 2147483647) {
|
||||
grantExpiryTimer = setTimeout(() => { now.value = Date.now() + props.serverTimeOffsetMs }, expiresIn)
|
||||
}
|
||||
@@ -292,6 +348,13 @@ function enterMobile() {
|
||||
error.value = ''
|
||||
}
|
||||
|
||||
function enterSignerName() {
|
||||
if (!canAct() || pending.value || !canRestartWithSignerName.value) return
|
||||
stopAuthentication()
|
||||
editingMobile.value = true
|
||||
error.value = ''
|
||||
}
|
||||
|
||||
async function submit(
|
||||
kind: DoctorRequest,
|
||||
request: () => Promise<PrescriptionEsignDoctorStatus>
|
||||
@@ -301,6 +364,7 @@ async function submit(
|
||||
clearInputs()
|
||||
clearTimeout(pollTimer)
|
||||
error.value = ''
|
||||
statusNotice.value = ''
|
||||
pending.value = kind
|
||||
try {
|
||||
const result = validateStatus(await request())
|
||||
@@ -309,7 +373,7 @@ async function submit(
|
||||
} catch {
|
||||
if (current !== generation || !canAct()) return
|
||||
clearStatus()
|
||||
error.value = '医生签署身份状态待确认,请检查状态后继续。'
|
||||
error.value = kind === 'status' ? '签署身份状态待确认,请重新校验证书或检查认证状态。' : '签署身份操作结果待确认,请检查状态后继续。'
|
||||
return
|
||||
} finally {
|
||||
if (current === generation) pending.value = null
|
||||
@@ -329,18 +393,35 @@ async function refresh() {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkStatus() {
|
||||
if (!canAct() || pending.value) return
|
||||
const checkingFlow = checkingIdentity.value
|
||||
await refresh()
|
||||
if (!canAct() || !state.value?.enabled || error.value) return
|
||||
if (checkingFlow) statusNotice.value = '认证状态已更新。'
|
||||
else if (certificateState.value === 'valid') statusNotice.value = '证书校验通过。'
|
||||
}
|
||||
|
||||
async function start() {
|
||||
if (!canAct() || pending.value) return
|
||||
if (canAuthorizeQuick.value) {
|
||||
await submit('start', () => prescriptionEsignDoctorStart({}))
|
||||
} else if (needsMobile.value) {
|
||||
const number = mobile.value.trim()
|
||||
clearInputs()
|
||||
const name = needsSignerName.value ? signerName.value.trim() : undefined
|
||||
if (!/^1[3-9]\d{9}$/.test(number)) {
|
||||
if (name === undefined) clearInputs()
|
||||
error.value = '请输入有效的大陆手机号码。'
|
||||
return
|
||||
}
|
||||
await submit('start', () => prescriptionEsignDoctorStart({ mobile: number }))
|
||||
if (name !== undefined && !/^[\p{Script=Han}A-Za-z][\p{Script=Han}A-Za-z·()\-]{1,49}$/u.test(name)) {
|
||||
error.value = '证件姓名须为 2 至 50 个字符,以汉字或英文字母开头,可包含间隔号(·)、半角括号和连字符。'
|
||||
return
|
||||
}
|
||||
await submit('start', () => prescriptionEsignDoctorStart({
|
||||
mobile: number,
|
||||
...(name !== undefined ? { signer_name: name } : {})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +442,10 @@ async function complete() {
|
||||
|
||||
function onVisibilityChange() {
|
||||
if (document.visibilityState === 'visible') void refresh()
|
||||
else clearStatus()
|
||||
else {
|
||||
clearStatus()
|
||||
statusNotice.value = '身份验证已暂停,返回此页后会重新检查。'
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -393,6 +477,7 @@ onBeforeUnmount(() => {
|
||||
.doctor-esign__expiry dt { color: var(--el-text-color-secondary); }
|
||||
.doctor-esign__expiry dd { margin: 0; }
|
||||
.doctor-esign__field { display: grid; gap: 6px; max-width: 350px; }
|
||||
.doctor-esign__field + .doctor-esign__field { margin-top: 12px; }
|
||||
.doctor-esign__frame {
|
||||
display: block;
|
||||
width: 100%;
|
||||
|
||||
Reference in New Issue
Block a user