feat(功能强化): 新增附件下载,优化附件展示与目录间距
build.yaml / build (push) Successful in 38s

This commit is contained in:
xiaoqidun committed 2026-09-12 19:26:33 +08:00
1 parent c2899deff1
commit 299c2cbfdc
6 files changed
+178 -18

No files matched your search

+15
View File
@@ -37,6 +37,7 @@ func RunWASM() {
registerCallback("ofdgoOpen", openDocument)
registerCallback("ofdgoConfigure", configureDocument)
registerCallback("ofdgoDocumentInfo", documentInfo)
registerCallback("ofdgoAttachmentData", attachmentData)
registerCallback("ofdgoRenderPage", renderPage)
registerCallback("ofdgoExportFormats", exportFormats)
registerCallback("ofdgoExportPage", exportPage)
@@ -131,6 +132,20 @@ func documentInfo(args []js.Value) (any, error) {
return currentSession.Info(), nil
}
// attachmentData 读取附件数据
// 入参: args 浏览器参数
// 返回: any 附件数据, error 错误信息
func attachmentData(args []js.Value) (any, error) {
if currentSession == nil {
return nil, fmt.Errorf("ofd document is not opened")
}
data, err := currentSession.Reader.AttachmentData(args[0].String())
if err != nil {
return nil, err
}
return successResult(map[string]any{"bytes": bytesToJS(data)}), nil
}
// renderPage 渲染OFD页面
// 入参: args 浏览器参数
// 返回: any 页面SVG结果, error 错误信息
+43 -16
View File
@@ -22,6 +22,7 @@ import (
"image/draw"
"image/jpeg"
"image/png"
"path"
"strings"
"time"
@@ -113,27 +114,38 @@ type Session struct {
// DocumentInfo 文档信息
type DocumentInfo struct {
Version string `json:"version"`
DocType string `json:"docType"`
Title string `json:"title"`
Author string `json:"author"`
Subject string `json:"subject"`
CreationDate string `json:"creationDate"`
ModDate string `json:"modDate"`
PageCount int `json:"pageCount"`
FontCount int `json:"fontCount"`
SignatureCount int `json:"signatureCount"`
SignatureError string `json:"signatureError,omitempty"`
Fonts []FontInfo `json:"fonts"`
Signatures []SignatureInfo `json:"signatures"`
Pages []PageInfo `json:"pages"`
Outlines []OutlineInfo `json:"outlines,omitempty"`
DetailsPending bool `json:"detailsPending,omitempty"`
Version string `json:"version"`
DocType string `json:"docType"`
Title string `json:"title"`
Author string `json:"author"`
Subject string `json:"subject"`
CreationDate string `json:"creationDate"`
ModDate string `json:"modDate"`
PageCount int `json:"pageCount"`
FontCount int `json:"fontCount"`
SignatureCount int `json:"signatureCount"`
SignatureError string `json:"signatureError,omitempty"`
AttachmentError string `json:"attachmentError,omitempty"`
Attachments []AttachmentInfo `json:"attachments,omitempty"`
Fonts []FontInfo `json:"fonts"`
Signatures []SignatureInfo `json:"signatures"`
Pages []PageInfo `json:"pages"`
Outlines []OutlineInfo `json:"outlines,omitempty"`
DetailsPending bool `json:"detailsPending,omitempty"`
}
// OutlineInfo 目录节点信息
type OutlineInfo = ofdgo.OutlineInfo
// AttachmentInfo 可见附件信息,Size单位为KB
type AttachmentInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Format string `json:"format,omitempty"`
Size *float64 `json:"size,omitempty"`
FileName string `json:"fileName"`
}
// PageInfo 页面信息
type PageInfo struct {
Index int `json:"index"`
@@ -307,6 +319,21 @@ func (s *Session) Info() DocumentInfo {
Pages: make([]PageInfo, 0, len(s.doc.Pages.Page)),
Outlines: s.doc.OutlineInfos(),
}
if attachments, err := s.Reader.Attachments(); err == nil {
for _, attachment := range attachments {
if attachment.Visible {
info.Attachments = append(info.Attachments, AttachmentInfo{
ID: attachment.ID,
Name: attachment.Name,
Format: attachment.Format,
Size: attachment.Size,
FileName: path.Base(s.Reader.ResPath(attachment.FileLoc)),
})
}
}
} else {
info.AttachmentError = err.Error()
}
if signatures, err := s.signatureInfos(); err == nil {
info.Signatures = signatures
} else {