mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00

* perf: simple app save * fix: notify config i18n * perf: service side props render * perf: model selector * update doc
27 lines
748 B
TypeScript
27 lines
748 B
TypeScript
import { useTranslation } from 'next-i18next';
|
|
import { useEffect } from 'react';
|
|
import { isProduction } from '@fastgpt/global/common/system/constants';
|
|
|
|
export const useBeforeunload = (props?: { callback?: () => any; tip?: string }) => {
|
|
const { t } = useTranslation();
|
|
|
|
const { tip = t('common:common.Confirm to leave the page'), callback } = props || {};
|
|
|
|
useEffect(() => {
|
|
const listen = isProduction
|
|
? (e: any) => {
|
|
e.preventDefault();
|
|
e.returnValue = tip;
|
|
callback?.();
|
|
}
|
|
: () => {
|
|
callback?.();
|
|
};
|
|
window.addEventListener('beforeunload', listen);
|
|
|
|
return () => {
|
|
window.removeEventListener('beforeunload', listen);
|
|
};
|
|
}, [tip, callback]);
|
|
};
|