chore: 删死代码 —— OpenReport/ReadLocalFile/isDesktop/openReport + admin Soon (P2)
完成度审计确认全链零生产调用: - app.go OpenReport(仅被死包装引用)、ReadLocalFile(仅测试引用); desktop.ts openReport 包装、isDesktop 导出(实际用 isMacDesktop)——全删。 绑定重新生成(OpenReport/ReadLocalFile 归零,PrintReportPage/SaveReportAs/ Notify 保留)。删对应的 app_test TestReadLocalFile。 - admin Soon.tsx(规划中占位组件)已成未引用死组件——routes.tsx 9 条路由全 ready:true,import 未用。删组件+import。 openInSystem/filepath/os 仍被 PrintReportPage/download 使用,不孤立。 desktop go test + tsc + 68 vitest、admin tsc + 41 vitest 全绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
// 规划中页面占位(路由目标,后续替换为真实页面即可)。
|
||||
export function Soon({ title, desc }: { title: string; desc: string }) {
|
||||
return (
|
||||
<div className="rounded-lg border border-dashed bg-gray-50 p-6">
|
||||
<div className="mb-1 text-sm font-semibold text-gray-600">{title}</div>
|
||||
<p className="text-xs leading-relaxed text-gray-400">{desc}</p>
|
||||
<span className="mt-3 inline-block rounded bg-gray-200 px-2 py-0.5 text-[10px] text-gray-500">规划中</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { lazy, type ReactNode } from "react";
|
||||
import { Soon } from "./components/Soon";
|
||||
|
||||
// 路由注册表 —— 控制台的单一事实源:导航 + 内容都从这里派生。
|
||||
// 新增页面 = 在此加一条;real 页面用 lazy 懒加载(代码分割)。
|
||||
|
||||
@@ -22,15 +22,6 @@ type App struct{}
|
||||
// Ping 供前端探活 Go 桥是否就绪。
|
||||
func (a *App) Ping() string { return "sundynix-desktop ok" }
|
||||
|
||||
// ReadLocalFile 读取本地文件内容(本地文件系统 I/O)。
|
||||
func (a *App) ReadLocalFile(path string) (string, error) {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
// SaveReportAs 弹原生"另存为"对话框,把 url 指向的报告(.docx)下载到用户选定路径。
|
||||
// 返回保存路径;用户取消则返回空串。
|
||||
func (a *App) SaveReportAs(url, filename string) (string, error) {
|
||||
@@ -50,18 +41,6 @@ func (a *App) SaveReportAs(url, filename string) (string, error) {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
// OpenReport 把报告下载到临时目录,并用系统默认应用(Word/Pages/WPS)打开。
|
||||
func (a *App) OpenReport(url, filename string) error {
|
||||
if filename == "" {
|
||||
filename = "report.docx"
|
||||
}
|
||||
dst := filepath.Join(os.TempDir(), "sundynix-open-"+filename)
|
||||
if err := download(url, dst); err != nil {
|
||||
return err
|
||||
}
|
||||
return openInSystem(dst)
|
||||
}
|
||||
|
||||
// PrintReportPage 把报告打印视图 HTML 落到临时文件,交系统默认浏览器打开(在那里 ⌘P →
|
||||
// 存储为 PDF)。Wails 的 WKWebView 会把 window.open 拦成 null,前端弹打印窗那条路在壳内
|
||||
// 走不通;转交系统浏览器后「前端打印出 PDF、CJK 零字体依赖」的原有优势不变。返回落盘路径。
|
||||
|
||||
@@ -70,18 +70,6 @@ func TestDownloadTruncatedLeavesNoFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadLocalFile(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "a.txt")
|
||||
_ = os.WriteFile(p, []byte("你好"), 0o600)
|
||||
got, err := (&App{}).ReadLocalFile(p)
|
||||
if err != nil || got != "你好" {
|
||||
t.Fatalf("读文件: got=%q err=%v", got, err)
|
||||
}
|
||||
if _, err := (&App{}).ReadLocalFile(filepath.Join(t.TempDir(), "nope")); err == nil {
|
||||
t.Error("读不存在的文件应报错")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
if (&App{}).Ping() == "" {
|
||||
t.Error("Ping 是前端探活 Go 桥的唯一手段,不能返回空")
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import { Call as $Call, CancellablePromise as $CancellablePromise } from "@wailsio/runtime";
|
||||
import { Call as $Call, CancellablePromise as $CancellablePromise, Create as $Create } from "@wailsio/runtime";
|
||||
|
||||
/**
|
||||
* Notify 弹一条系统通知(best-effort:macOS 用 osascript,其它平台暂静默)。
|
||||
@@ -19,13 +19,6 @@ export function Notify(title: string, body: string): $CancellablePromise<void> {
|
||||
return $Call.ByID(2739682372, title, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* OpenReport 把报告下载到临时目录,并用系统默认应用(Word/Pages/WPS)打开。
|
||||
*/
|
||||
export function OpenReport(url: string, filename: string): $CancellablePromise<void> {
|
||||
return $Call.ByID(802670751, url, filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ping 供前端探活 Go 桥是否就绪。
|
||||
*/
|
||||
@@ -42,13 +35,6 @@ export function PrintReportPage(filename: string, html: string): $CancellablePro
|
||||
return $Call.ByID(3564528865, filename, html);
|
||||
}
|
||||
|
||||
/**
|
||||
* ReadLocalFile 读取本地文件内容(本地文件系统 I/O)。
|
||||
*/
|
||||
export function ReadLocalFile(path: string): $CancellablePromise<string> {
|
||||
return $Call.ByID(4016121990, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* SaveReportAs 弹原生"另存为"对话框,把 url 指向的报告(.docx)下载到用户选定路径。
|
||||
* 返回保存路径;用户取消则返回空串。
|
||||
|
||||
@@ -8,11 +8,6 @@ function inWails(): boolean {
|
||||
return !!(window as unknown as { _wails?: { environment?: unknown } })._wails?.environment;
|
||||
}
|
||||
|
||||
// isDesktop 是否运行在真实 Wails 桌面窗口(而非浏览器预览)。
|
||||
export function isDesktop(): boolean {
|
||||
return inWails();
|
||||
}
|
||||
|
||||
// isMacDesktop 用于交通灯让位等 macOS 专属适配。
|
||||
export function isMacDesktop(): boolean {
|
||||
return inWails() && System.IsMac();
|
||||
@@ -27,15 +22,6 @@ export async function saveReportAs(url: string, filename: string): Promise<strin
|
||||
return App.SaveReportAs(url, filename);
|
||||
}
|
||||
|
||||
// openReport:桌面端下载到临时目录并用系统默认应用打开;浏览器降级为新标签打开。
|
||||
export async function openReport(url: string, filename: string): Promise<void> {
|
||||
if (!inWails()) {
|
||||
window.open(url, "_blank");
|
||||
return;
|
||||
}
|
||||
await App.OpenReport(url, filename);
|
||||
}
|
||||
|
||||
// notify:桌面端弹系统通知;浏览器为空操作(由应用内 Toast 兜底)。
|
||||
export function notify(title: string, body: string): void {
|
||||
if (inWails()) void App.Notify(title, body);
|
||||
|
||||
Reference in New Issue
Block a user