diff --git a/wwwroot/api/workspace_open.dspy b/wwwroot/api/workspace_open.dspy index 28491db..1196606 100644 --- a/wwwroot/api/workspace_open.dspy +++ b/wwwroot/api/workspace_open.dspy @@ -116,15 +116,31 @@ if ext in image_exts: ] } -# 4. office 文档 → iframe 嵌入 univer-office 在线编辑 +# 4. office 文档 → iframe 嵌入 univer-office 在线编辑 + 顶部下载按钮 +# (2026-09-18 用户要求:查看和编辑都在线,另提供下载按钮) if ext in office_exts: univer_url = entire_url("/univer-office/") + "?file=" + quote(file_id) + _fq_s + download_url_e = file_url + "&download=1" + download_script_e = ( + "window.open(" + _json.dumps(download_url_e) + ",'_blank');" + ) return { "widgettype": "PopupWindow", "options": {"title": name + " (在线编辑)", "width": "85%", "height": "85%", "auto_open": True, "resizable": True}, - "subwidgets": [ - {"widgettype": "Iframe", "options": {"url": univer_url, "width": "100%", "height": "100%"}} - ] + "subwidgets": [{ + "widgettype": "VBox", + "options": {"css": "filler", "height": "100%", "width": "100%", "gap": "6px", "padding": "6px"}, + "subwidgets": [ + {"widgettype": "HBox", + "options": {"width": "100%", "gap": "8px", "alignItems": "center"}, + "subwidgets": [ + {"widgettype": "Button", "options": {"label": "⬇ 下载", "css": "small"}, + "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": download_script_e}]}, + {"widgettype": "Text", "options": {"text": "编辑后点右上角「💾 保存」写回工作空间", "cfontsize": 0.8, "color": "#94a3b8"}}, + ]}, + {"widgettype": "Iframe", "options": {"url": univer_url, "css": "filler", "width": "100%", "height": "100%"}}, + ] + }] } # 5. pdf 等 → 下载后用本地应用打开 diff --git a/wwwroot/api/workspace_view.dspy b/wwwroot/api/workspace_view.dspy index 78adf88..126af09 100644 --- a/wwwroot/api/workspace_view.dspy +++ b/wwwroot/api/workspace_view.dspy @@ -139,6 +139,34 @@ if ext in image_exts: }] } +# office 文档(docx)→ univer-office 在线查看(mode=view 只读,不显示保存按钮)+ 下载按钮 +# (2026-09-18 用户要求:查看和编辑都在线,另提供下载按钮) +office_exts = ['.docx'] +if ext in office_exts: + univer_url = entire_url("/univer-office/") + "?file=" + quote(file_id) + "&mode=view" + _fq_s + download_url_v = file_url + "&download=1" + download_script_v = ( + "window.open(" + _json.dumps(download_url_v) + ",'_blank');" + ) + return { + "widgettype": "PopupWindow", + "options": {"title": name + " (在线查看)", "width": "85%", "height": "85%", "auto_open": True, "resizable": True}, + "subwidgets": [{ + "widgettype": "VBox", + "options": {"css": "filler", "height": "100%", "width": "100%", "gap": "6px", "padding": "6px"}, + "subwidgets": [ + {"widgettype": "HBox", + "options": {"width": "100%", "gap": "8px", "alignItems": "center"}, + "subwidgets": [ + {"widgettype": "Button", "options": {"label": "⬇ 下载", "css": "small"}, + "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": download_script_v}]}, + {"widgettype": "Text", "options": {"text": "在线查看模式(只读);如需修改请用「编辑」", "cfontsize": 0.8, "color": "#94a3b8"}}, + ]}, + {"widgettype": "Iframe", "options": {"url": univer_url, "css": "filler", "width": "100%", "height": "100%"}}, + ] + }] + } + # 其他 → 下载查看 download_url = file_url + "&download=1" download_script = (