-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
204 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client'; | ||
|
||
import dynamic from 'next/dynamic'; | ||
|
||
export default dynamic(() => import('@/components/Error')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use client'; | ||
|
||
import Error from 'next/error'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function GlobalError({ | ||
error, | ||
}: { | ||
error: Error & { digest?: string }; | ||
reset: () => void; | ||
}) { | ||
useEffect(() => { | ||
console.log('error', error); | ||
}, [error]); | ||
return ( | ||
<html> | ||
<body> | ||
<Error statusCode={undefined as any} /> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use client'; | ||
|
||
import { FluentEmoji } from '@lobehub/ui'; | ||
import { Button } from 'antd'; | ||
import Link from 'next/link'; | ||
import { memo, useEffect } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import { MAX_WIDTH } from '@/constants/common'; | ||
import ResetConfig from '@/features/Actions/ClearSession'; | ||
import ClearChat from '@/features/Actions/ResetConfig'; | ||
|
||
interface ErrorCaptureProps { | ||
error: Error & { digest?: string }; | ||
reset: () => void; | ||
} | ||
|
||
const ErrorCapture = memo<ErrorCaptureProps>(({ reset, error }) => { | ||
useEffect(() => { | ||
// Log the error to an error reporting service | ||
console.error(error); | ||
}, [error]); | ||
|
||
return ( | ||
<Flexbox align={'center'} justify={'center'} style={{ minHeight: '100%', width: '100%' }}> | ||
<h1 | ||
style={{ | ||
filter: 'blur(8px)', | ||
fontSize: `min(${MAX_WIDTH / 6}px, 25vw)`, | ||
fontWeight: 900, | ||
margin: 0, | ||
opacity: 0.12, | ||
position: 'absolute', | ||
zIndex: 0, | ||
}} | ||
> | ||
ERROR | ||
</h1> | ||
<FluentEmoji emoji={'🤧'} size={64} /> | ||
<h2 style={{ fontWeight: 'bold', marginTop: '1em', textAlign: 'center' }}> | ||
页面遇到一点问题... | ||
</h2> | ||
<p style={{ marginBottom: '2em' }}> | ||
项目当前正在施工中,不保证数据稳定性,如果遇到问题可以尝试 | ||
<ClearChat text="清除会话消息" type={'link'} /> | ||
或 <ResetConfig text="重置系统设置" type={'link'} /> | ||
,造成地不便敬请谅解 | ||
</p> | ||
<Flexbox gap={12} horizontal style={{ marginBottom: '1em' }}> | ||
<Button onClick={() => reset()}>重新加载</Button> | ||
<Link href="/"> | ||
<Button type={'primary'}>返回首页</Button> | ||
</Link> | ||
</Flexbox> | ||
</Flexbox> | ||
); | ||
}); | ||
|
||
ErrorCapture.displayName = 'ErrorCapture'; | ||
|
||
export default ErrorCapture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { App, Button } from 'antd'; | ||
import { ButtonType } from 'antd/es/button'; | ||
import React from 'react'; | ||
|
||
import { useAgentStore } from '@/store/agent'; | ||
import { useSessionStore } from '@/store/session'; | ||
|
||
interface Props { | ||
text?: string; | ||
type?: ButtonType; | ||
} | ||
export default (props: Props) => { | ||
const { text = '立即清除', type = 'primary' } = props; | ||
const clearAgentStorage = useAgentStore((s) => s.clearAgentStorage); | ||
const clearSessions = useSessionStore((s) => s.clearSessions); | ||
const { message, modal } = App.useApp(); | ||
|
||
const handleClear = () => { | ||
modal.confirm({ | ||
cancelText: '取消', | ||
centered: true, | ||
content: '操作无法撤销,清除后数据将无法恢复,请慎重操作', | ||
okButtonProps: { | ||
danger: true, | ||
}, | ||
okText: '确定', | ||
onOk: () => { | ||
clearSessions(); | ||
clearAgentStorage(); | ||
message.success('清除成功'); | ||
}, | ||
title: '确认清除所有会话消息?', | ||
}); | ||
}; | ||
|
||
return ( | ||
<Button danger onClick={handleClear} type={type}> | ||
{text} | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { App, Button } from 'antd'; | ||
import { ButtonType } from 'antd/es/button'; | ||
import React from 'react'; | ||
|
||
import { useSettingStore } from '@/store/setting'; | ||
|
||
interface Props { | ||
text?: string; | ||
type?: ButtonType; | ||
} | ||
export default (props: Props) => { | ||
const { text = '立即重置', type = 'primary' } = props; | ||
const resetConfig = useSettingStore((s) => s.resetConfig); | ||
const { message, modal } = App.useApp(); | ||
|
||
const handleReset = () => { | ||
modal.confirm({ | ||
cancelText: '取消', | ||
centered: true, | ||
content: '操作无法撤销,重置后数据将无法恢复,请慎重操作', | ||
okButtonProps: { | ||
danger: true, | ||
}, | ||
okText: '确定', | ||
onOk: () => { | ||
resetConfig(); | ||
message.success('重置成功'); | ||
}, | ||
title: '确认重置所有系统设置?', | ||
}); | ||
}; | ||
|
||
return ( | ||
<Button danger onClick={handleReset} type={type}> | ||
{text} | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use client'; | ||
|
||
import { Icon } from '@lobehub/ui'; | ||
import { FloatButton } from 'antd'; | ||
import { LucideBugPlay } from 'lucide-react'; | ||
import { memo } from 'react'; | ||
|
||
const DebugUI = memo(() => { | ||
return ( | ||
<FloatButton | ||
icon={<Icon icon={LucideBugPlay} />} | ||
onClick={async () => { | ||
throw new Error('触发错误'); | ||
}} | ||
tooltip={'触发错误'} | ||
/> | ||
); | ||
}); | ||
|
||
export default DebugUI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters