feat: enable patient form interactions and revision-aware signing

This commit is contained in:
cnxianyi
2026-09-29 21:37:30 +08:00
parent dc94265703
commit 9173d623a1
17 changed files with 451 additions and 49 deletions
@@ -123,6 +123,28 @@ function syncFromDom() {
emit('selectionChange', [...selected])
}
/** Repeated occurrences of one field must share the same answer. */
function syncEditedField(target: EventTarget | null) {
const root = containerRef.value
const host = target instanceof Element ? target.closest<HTMLElement>('[data-sign-field]') : null
const id = host?.getAttribute('data-sign-field')
if (root && host && id) {
const wrapper = document.createElement('div')
wrapper.append(host.cloneNode(true))
const value = readAnswersFromRoot(wrapper)[id]
if (value !== undefined)
root.querySelectorAll<HTMLElement>('[data-sign-field]').forEach((other) => {
if (other !== host && other.getAttribute('data-sign-field') === id)
applyAnswerToFieldHost(other, value)
})
}
syncFromDom()
}
function handleInput(event: Event) {
if (props.interactive) syncEditedField(event.target)
}
/** 按已固化的取值还原 DOM 状态(存量勾选表 + 填写项都覆盖) */
function applyStoredValues() {
const container = containerRef.value
@@ -201,7 +223,7 @@ function handleDocumentClick(event: MouseEvent) {
const container = containerRef.value
if (option && container && toggleOptionAt(container, option)) {
syncFromDom()
syncEditedField(option)
return
}
}
@@ -219,6 +241,13 @@ function handleDocumentKeydown(event: KeyboardEvent) {
return
}
const option =
event.target instanceof Element ? event.target.closest<HTMLElement>(OPTION_TICK_SELECTOR) : null
if (option && containerRef.value && toggleOptionAt(containerRef.value, option)) {
event.preventDefault()
syncEditedField(option)
return
}
const host = resolveSignatureHost(event.target)
if (host) {
@@ -285,8 +314,8 @@ defineExpose({ getDocumentElement })
<div
ref="containerRef"
class="doc-paper__body"
@change="syncFromDom"
@input="syncFromDom"
@change="handleInput"
@input="handleInput"
@click="handleDocumentClick"
@keydown="handleDocumentKeydown"
v-html="processedHtml"