This commit is contained in:
2024-01-15 23:44:28 +08:00
parent 0281ce9dd6
commit 7b68496aa1
8 changed files with 58 additions and 20 deletions

View File

@@ -79,17 +79,17 @@ function openFNotification() {
* 获取服务端异步菜单
* @param handler 执行回调
*/
function fetchSmenu(handler: any) {
const setAlitaMenu = (menus: any) => {
handler(menus);
// this.props.setAlitaState({ stateName: 'smenus', data: menus });
};
setAlitaMenu(umbrella.getLocalStorage('smenus') || []);
fetchMenu().then((smenus) => {
setAlitaMenu(smenus);
umbrella.setLocalStorage('smenus', smenus);
});
}
// function fetchSmenu(handler: any) {
// const setAlitaMenu = (menus: any) => {
// handler(menus);
// // this.props.setAlitaState({ stateName: 'smenus', data: menus });
// };
// setAlitaMenu(umbrella.getLocalStorage('smenus') || []);
// fetchMenu().then((smenus) => {
// setAlitaMenu(smenus);
// umbrella.setLocalStorage('smenus', smenus);
// });
// }
const App = (props: AppProps) => {
const [collapsed, setCollapsed] = useState<boolean>(false);
@@ -106,7 +106,7 @@ const App = (props: AppProps) => {
handleResize((isMobile: boolean) => setAlita('responsive', { isMobile }));
openFNotification();
fetchSmenu((smenus: any[]) => setAlita('smenus', smenus));
// fetchSmenu((smenus: any[]) => setAlita('smenus', smenus));
}, [setAlita]);
function toggle() {

View File

@@ -26,7 +26,7 @@ const SiderCustom = (props: SiderCustomProps) => {
const [firstHide, tFirstHide] = useSwitch();
const [menu, setMenu] = useState<IMenu>({ openKeys: [''], selectedKey: '' });
// 异步菜单
const [smenus] = useAlita({ smenus: [] }, { light: true });
// const [smenus] = useAlita({ smenus: [] }, { light: true });
const { location, collapsed: pCollapsed } = props;
const prePathname = usePrevious(props.location.pathname);
@@ -81,7 +81,8 @@ const SiderCustom = (props: SiderCustomProps) => {
>
<div className="logo" />
<SiderMenu
menus={[...routes.menus, ...smenus]}
// menus={[...routes.menus, ...smenus]}
menus={[...routes.menus]}
onClick={menuClick}
mode="inline"
selectedKeys={[menu.selectedKey]}

View File

@@ -34,6 +34,7 @@ import Env from './env';
import Home from './visualize/Home';
import UserManage from './management/UserManage';
import BlankPage from './management/BlankPage';
import StationInfo from './station/StationInfo';
const WysiwygBundle = Loadable({
// 按需加载富文本配置
@@ -73,4 +74,5 @@ export default {
Home,
UserManage,
BlankPage,
StationInfo,
} as any;

View File

@@ -36,10 +36,18 @@ const Login = (props: LoginProps) => {
}, [history, auth]);
const handleSubmit = async (values: any) => {
console.log(await checkUser(values));
if (await checkUser(values)) {
setAlita({ funcName: values.userName, stateName: 'auth' });
}
trailwayLogin({ username: values.userName, password: values.password }).then((res) => {
if (res.data.success) {
let user = {
uid: res.data.id,
role: res.data.role === 1 ? '系统管理员' : '访客',
roleType: res.data.role,
username: values.userName,
permissions: res.data.role === 1 ? ['auth/admin'] : [],
};
setAlita('auth', user);
}
});
};
const checkUser = async (values: any) => {
let success = await trailwayLogin({

View File

@@ -0,0 +1,19 @@
import { Card } from 'antd';
import React from 'react';
type StationInfoProps = {
query: any;
};
const StationInfo = (props: StationInfoProps) => {
console.log(props.query.param1);
return (
<div>
<Card title="站点信息">
<p>{props.query.t}</p>
</Card>
</div>
);
};
export default StationInfo;

View File

@@ -8,6 +8,7 @@ export interface IFMenuBase {
route?: string;
/** 是否登录校验true不进行校验访客 */
login?: boolean;
showAuth?: string;
}
export interface IFMenu extends IFMenuBase {
@@ -150,6 +151,12 @@ const menus: {
// },
// ],
// },
{
key: '/app/station',
title: '站点信息',
icon: 'bars',
component: 'StationInfo',
},
{
key: '/app/manage',
title: '管理',
@@ -159,6 +166,7 @@ const menus: {
key: '/app/manage/user',
title: '用户管理',
component: 'UserManage',
requireAuth: 'auth/admin',
},
// {
// key: '/app/extension/visitor',

View File

@@ -16,7 +16,7 @@ type CRouterProps = {
const CRouter = (props: CRouterProps) => {
const { auth } = props;
const [smenus] = useAlita({ smenus: null }, { light: true });
// const [smenus] = useAlita({ smenus: null }, { light: true });
const getPermits = (): any[] | null => {
return auth ? auth.permissions : null;

View File

@@ -19,4 +19,4 @@ export const GIT_USER = 'https://api.github.com/user';
export const NEWS_BBC =
'https://newsapi.org/v2/top-headlines?sources=bbc-news&apiKey=429904aa01f54a39a278a406acf50070';
export const TRAILWAY_API = 'http://localhost:8000';
export const TRAILWAY_API = 'http://127.0.0.1:8000';