window.location.reload()}>
+ 刷新页面
+ ,
+ ,
+ isDev && (
+
+ ),
+ ]}
+ >
+ {isDev && this.state.error && (
+
+ {this.state.error.stack || this.state.error.message}
+
+ )}
+
+ )
+ }
+
+ return this.props.children
+ }
+}
diff --git a/src/lib/antd-global.ts b/src/lib/antd-global.ts
index 2af2e4b..f9fff42 100644
--- a/src/lib/antd-global.ts
+++ b/src/lib/antd-global.ts
@@ -1,6 +1,7 @@
import { App } from 'antd'
import type { MessageInstance } from 'antd/es/message/interface'
import type { NotificationInstance } from 'antd/es/notification/interface'
+import { setErrorMessageFn } from './error-handler'
let message: MessageInstance | null = null
let notification: NotificationInstance | null = null
@@ -10,6 +11,7 @@ export function StaticAntdProvider() {
const staticFunc = App.useApp()
message = staticFunc.message
notification = staticFunc.notification
+ setErrorMessageFn((msg: string) => staticFunc.message.error(msg))
return null
}
diff --git a/src/lib/error-handler.ts b/src/lib/error-handler.ts
new file mode 100644
index 0000000..5d46431
--- /dev/null
+++ b/src/lib/error-handler.ts
@@ -0,0 +1,32 @@
+/**
+ * 统一错误处理
+ *
+ * try { ... } catch (err) { toastError(err) }
+ */
+
+// ── 错误格式化 ──
+
+export function formatError(err: unknown, fallback = '操作失败'): string {
+ if (!err) return fallback
+ if (typeof err === 'string') return err
+ if (err instanceof Error) return err.message
+ if (typeof err === 'object' && err !== null) {
+ const e = err as Record