feat(navbar): 添加跳转到课程平台的功能

master
钟良源 2 months ago
parent e8a3b8ddfa
commit 595551871d

@ -9,7 +9,8 @@ import {
IconSettings,
IconPoweroff,
IconLoading,
IconUser
IconUser,
IconLink
} from '@arco-design/web-react/icon';
import { useSelector, useDispatch } from 'react-redux';
import { GlobalContext } from '@/context';
@ -63,6 +64,22 @@ function Navbar({ show }: { show: boolean }) {
);
}
const toRouter = () => {
const token = localStorage.getItem('token');
if (window.location.href.includes('localhost')) {
window.open(` http://localhost:9797/pc/login?token=${encodeURIComponent(token)}`);
return;
}
const baseUrl = `${window.location.protocol}//${window.location.hostname}`;
const targetUrl = `${baseUrl}:9800/pc/login`;
if (token) {
window.open(`${targetUrl}?token=${encodeURIComponent(token)}`);
}
else {
window.open(targetUrl);
}
};
const handleChangeRole = () => {
const newRole = role === 'admin' ? 'user' : 'admin';
setRole(newRole);
@ -98,6 +115,10 @@ function Navbar({ show }: { show: boolean }) {
</div>
</div>
<ul className={styles.right}>
<Button style={{ marginRight: 20 }} onClick={toRouter}>
<IconLink />
</Button>
{userInfo && (
<>
<li>

Loading…
Cancel
Save