From f2c71c5acfba39386e18285a4570071cc85eda46 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Tue, 27 Oct 2026 20:26:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=96=E8=BE=91=E8=83=BD=E5=8A=9B):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AD=BE=E5=90=8D=E4=BE=9D=E8=B5=96=E4=B8=8E?= =?UTF-8?q?=E5=A4=9A=E6=96=87=E6=A1=A3=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/webui/ofdgo.js | 13 ++++++++++--- ofdgo_sign_write.go | 23 ++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/assets/webui/ofdgo.js b/assets/webui/ofdgo.js index 2be4858..058fb5d 100644 --- a/assets/webui/ofdgo.js +++ b/assets/webui/ofdgo.js @@ -9194,8 +9194,15 @@ function renderSecurity() { el.signButton.disabled = el.encryptSaveButton.disabled; el.signatureClear.hidden = !state.editing; el.signatureClear.disabled = el.encryptSaveButton.disabled || !state.editing || !!state.doc?.detailsPending || !state.doc?.signatures?.length; - if (!state.doc?.detailsPending) renderMetaContent(el.signatureList, [documentTab().id, documentContentKey(state), state.doc?.signatures, state.doc?.signatureError, state.editing], renderSignatures); - for (const button of el.signatureList.querySelectorAll(".signature-remove")) button.disabled = el.signatureClear.disabled; + const scope = JSON.stringify([documentTab().id, documentContentKey(state)]); + if (!state.doc?.detailsPending || metaContents.get(el.signaturePanel) !== scope) { + renderMetaContent(el.signatureList, [scope, state.doc?.signatures, state.doc?.signatureError, state.editing], renderSignatures); + metaContents.set(el.signaturePanel, scope); + } + for (const button of el.signatureList.querySelectorAll(".signature-remove")) { + button.hidden = !state.editing; + button.disabled = el.signatureClear.disabled; + } } function cancelSigning() { @@ -11930,7 +11937,7 @@ function signatureSummary(signatures) { } function signatureNameNode(signature) { - const stamps = signature.docIndex ? [] : signature.stamps || []; + const stamps = (signature.docIndex || 0) === (state.doc?.documentIndex || 0) ? signature.stamps || [] : []; const name = document.createElement("div"); name.className = "signature-name"; if (!stamps.length) { diff --git a/ofdgo_sign_write.go b/ofdgo_sign_write.go index ea8f4ee..0ce9004 100644 --- a/ofdgo_sign_write.go +++ b/ofdgo_sign_write.go @@ -131,7 +131,7 @@ func (e *Editor) removeSignatures(ctx context.Context, id string) error { if id != "" && !removed[id] { return fmt.Errorf("signature not found: %s", id) } - protected, references, err := reader.signatureRemovalProtected(ctx, name, removed) + protected, dependencies, err := reader.signatureRemovalProtected(ctx, name, removed) if err != nil { return err } @@ -157,8 +157,11 @@ func (e *Editor) removeSignatures(ctx context.Context, id string) error { return err } } else { + if dependencies[name] { + return fmt.Errorf("%w: retained signature protects %s", ErrSignatureDependency, name) + } for file := range candidates { - if references[file] { + if dependencies[file] { return fmt.Errorf("%w: retained signature protects %s", ErrSignatureDependency, file) } } @@ -186,9 +189,6 @@ func (e *Editor) removeSignatures(ctx context.Context, id string) error { parts["OFD.xml"] = editorPatchXML(entry, []editorXMLPatch{{start: node.start, end: node.end}}) candidates[name] = true } else { - if references[name] { - return fmt.Errorf("%w: retained signature protects %s", ErrSignatureDependency, name) - } target := name shared := false for index, body := range reader.OFD.DocBody { @@ -255,10 +255,11 @@ func (r *Reader) signatureRemovalFiles(ctx context.Context, name string) (map[st // signatureRemovalProtected 汇总保留签名的原文及其他文档的签名入口,不要求证书或私钥 // 入参: ctx 取消上下文, selected 当前签名列表, removed 待移除标识 -// 返回: map[string]bool 保留路径, map[string]bool 摘要保护路径, error 读取、结构或取消错误 +// 返回: map[string]bool 保留路径, map[string]bool 非共享的摘要保护路径, error 读取、结构或取消错误 func (r *Reader) signatureRemovalProtected(ctx context.Context, selected string, removed map[string]bool) (map[string]bool, map[string]bool, error) { protected := make(map[string]bool) - references := make(map[string]bool) + dependencies := make(map[string]bool) + retained := make(map[string]bool) for index, body := range r.OFD.DocBody { if body.Signatures == "" { continue @@ -285,11 +286,15 @@ func (r *Reader) signatureRemovalProtected(ctx context.Context, selected string, return nil, nil, err } maps.Copy(protected, owned) + maps.Copy(retained, owned) maps.Copy(protected, refs) - maps.Copy(references, refs) + maps.Copy(dependencies, refs) } } - return protected, references, ctx.Err() + for name := range retained { + delete(dependencies, name) + } + return protected, dependencies, ctx.Err() } // SignatureWriteOptions 最终包签署选项,不修改Editor或调用方的原件