add submodule adn remote redirecto to login

This commit is contained in:
2025-03-22 13:33:32 +08:00
parent cf543c7f1d
commit 2ee8ec7a29
15 changed files with 217 additions and 813 deletions

View File

@@ -11,5 +11,5 @@ query.afterResponse = async (response) => {
noMsg: true,
};
}
return response;
return response as any;
};

View File

@@ -1,24 +1,42 @@
import { toast } from 'react-toastify';
import { useTranslation } from 'react-i18next';
// Custom message component
const LoginMessage = () => {
const LoginMessage = (props: ToastLoginProps) => {
const { t } = useTranslation();
const handleClick = () => {
const currentUrl = window.location.href;
console.log(currentUrl);
const redirect = encodeURIComponent(currentUrl);
console.log('redirect', redirect);
const newUrl = location.origin + '/user/login/?redirect=' + redirect;
const redirect = encodeURIComponent(props?.redirectUrl || currentUrl);
const loginUrl = props?.loginUrl || '/user/login/';
const newUrl = location.origin + loginUrl + '?redirect=' + redirect;
window.open(newUrl, '_self');
};
return (
<div className='msg-container' onClick={handleClick} style={{ cursor: 'pointer' }}>
<p className='msg-title'>Please login</p>
<p className='msg-description'>Click here to go to the login page.</p>
<p className='msg-title'>{t('Please login')}</p>
<p className='msg-description'>{t('Click here to go to the login page.')}</p>
</div>
);
};
export const toastLogin = () => {
toast.info(<LoginMessage />);
type ToastLoginProps = {
/**
* 登录页面地址, /user/login
*/
loginUrl?: string;
/**
* 登录成功后跳转的地址, 默认是当前页面
*/
redirectUrl?: string;
};
/**
* 登录提示
* @param props
* @example
* toastLogin({
* loginUrl: '/user/login/',
* redirectUrl: window.location.href,
* });
*/
export const toastLogin = (props: ToastLoginProps = {}) => {
toast.info(<LoginMessage {...props} />);
};