feat(font): 新增字体设置并统一医护端与患者端文书字体

This commit is contained in:
xy
2026-09-30 08:35:02 +08:00
parent fe8cb01d4d
commit c2984bfd98
18 changed files with 511 additions and 5 deletions
+2
View File
@@ -1,3 +1,4 @@
import type { DocumentFont } from '../../../packages/document-fonts'
export interface ApiResponse<T> {
code: number | string
message: string
@@ -92,6 +93,7 @@ export interface SigningContextTemplate {
}
export interface SigningContextDocument {
font?: DocumentFont | null
contentHtml?: string | null
contentSha256?: string | null
}
+15 -1
View File
@@ -6,6 +6,7 @@ const props = withDefaults(
defineProps<{
/** 文书正文 HTML(含占位符),由 context 接口返回 */
contentHtml: string
fontFamily?: string
fields?: SigningFormField[]
patientAnswers?: Record<string, PatientAnswer>
interactive?: boolean
@@ -22,6 +23,7 @@ const props = withDefaults(
signedAt?: string | null
}>(),
{
fontFamily: '',
answers: () => ({}),
fields: () => [],
patientAnswers: () => ({}),
@@ -232,10 +234,22 @@ watch(
正文来自医院自己的文书模板(经后端存储下发),不是用户输入,因此这里用 v-html 渲染。
患者端不解析、不执行其中任何脚本 —— 后端下发前应已做清洗。
-->
<article ref="paperRef" class="patient-paper" v-html="contentHtml" />
<article
ref="paperRef"
class="patient-paper"
:class="{ 'managed-font': Boolean(fontFamily) }"
:style="{ '--document-font': fontFamily }"
v-html="contentHtml"
/>
</template>
<style scoped>
.managed-font,
.managed-font :deep(*) {
font-family: var(--document-font) !important;
font-synthesis: none;
}
.patient-paper {
padding: 18px 16px 22px;
color: #173b56;
+13 -1
View File
@@ -1,3 +1,4 @@
import { loadDocumentFont } from '../../../packages/document-fonts'
import { reactive } from 'vue'
import {
@@ -59,6 +60,8 @@ const initialState: SignFlowState = {
age: '',
visitNo: 'MZ20260827018',
department: '',
documentFontFamily: '',
documentFontReady: false,
documentTitle: '儿科急诊特殊检查知情同意书',
templateVersion: 'v1.0.0',
documentContentHtml: '',
@@ -447,6 +450,12 @@ async function loadSigningContext(): Promise<SigningContextResponse | null> {
try {
const context = await fetchSigningContext(proof)
applyContext(context)
signingState.documentFontReady = false
signingState.documentFontFamily = await loadDocumentFont(
context.document?.font ?? null,
import.meta.env.VITE_API_BASE_URL || '/api',
)
signingState.documentFontReady = true
persistSession()
return context
} catch (error) {
@@ -488,6 +497,7 @@ function applyDemoContext() {
signingState.fields = [
{ id: DEMO_PATIENT_FIELD_ID, label: '患者签名', kind: 'signature', required: true },
]
signingState.documentFontReady = true
signingState.documentLoaded = true
signingState.documentError = ''
signingState.taskStatus = 'WAITING_SIGN'
@@ -583,7 +593,9 @@ export async function submitRealSignature(input: {
!signingState.taskId ||
!signingState.deliveryId ||
!signingState.uploadToken ||
!input.consentAccepted
!input.consentAccepted ||
!signingState.documentLoaded ||
!signingState.documentFontReady
) {
throw new Error('签署凭证或知情确认状态无效,请重新打开签署链接。')
}
+2
View File
@@ -26,6 +26,8 @@ export interface SignFlowState {
visitNo: string
department: string
documentFontFamily: string
documentFontReady: boolean
documentTitle: string
templateVersion: string
/**
@@ -56,6 +56,7 @@ async function continueToSigner() {
</section>
<DocumentPaper
:font-family="signingState.documentFontFamily"
:content-html="signingState.documentContentHtml"
:answers="signingState.staffAnswers"
:fields="signingState.form?.fields"
@@ -117,6 +117,7 @@ async function submitSigning() {
<!-- 签完的字会实时回填到文书里的签名位,患者能立刻看到自己签在哪一格 -->
<DocumentPaper
:font-family="signingState.documentFontFamily"
:content-html="signingState.documentContentHtml"
:answers="signingState.staffAnswers"
:fields="signingState.form?.fields"