feat: 添加双屏控制功能,更新相关逻辑以支持双屏窗口全屏展示;新增全局错误边界组件以处理渲染错误
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { Component } from 'react';
|
||||
|
||||
/* 全局错误边界:渲染崩溃时不白屏,显示具体错误 + 重载按钮,便于双屏/异常定位 */
|
||||
export default class ErrorBoundary extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { err: null };
|
||||
}
|
||||
static getDerivedStateFromError(err) {
|
||||
return { err };
|
||||
}
|
||||
componentDidCatch(err, info) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('[AppError]', err, info);
|
||||
}
|
||||
render() {
|
||||
if (this.state.err) {
|
||||
return (
|
||||
<div style={{ padding: 40, fontFamily: 'sans-serif', color: '#333' }}>
|
||||
<h3>页面加载出错</h3>
|
||||
<pre style={{ whiteSpace: 'pre-wrap', fontSize: 12, background: '#f5f5f5', padding: 12, borderRadius: 8 }}>
|
||||
{String(this.state.err && (this.state.err.message || this.state.err))}
|
||||
</pre>
|
||||
<button
|
||||
style={{ marginTop: 12, padding: '8px 16px', cursor: 'pointer' }}
|
||||
onClick={() => { this.setState({ err: null }); window.location.reload(); }}
|
||||
>
|
||||
重载
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
+6
-3
@@ -1,6 +1,7 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import ErrorBoundary from "./components/ErrorBoundary";
|
||||
import { ThemeProvider } from "@appica/ui-react/providers/theme-provider";
|
||||
import { getApiBase } from "./config";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
@@ -60,9 +61,11 @@ async function bootstrapRuntimeConfig() {
|
||||
bootstrapRuntimeConfig().then(() => {
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(
|
||||
<React.StrictMode>
|
||||
<ThemeProvider>
|
||||
<App />
|
||||
</ThemeProvider>
|
||||
<ErrorBoundary>
|
||||
<ThemeProvider>
|
||||
<App />
|
||||
</ThemeProvider>
|
||||
</ErrorBoundary>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user