From 7b68496aa1f9cca5c7f3cd093144b6e1b9558432 Mon Sep 17 00:00:00 2001 From: Rain&Bus Date: Mon, 15 Jan 2024 23:44:28 +0800 Subject: [PATCH] temp --- src/App.tsx | 24 ++++++++++++------------ src/components/SiderCustom.tsx | 5 +++-- src/components/index.tsx | 2 ++ src/components/pages/Login.tsx | 16 ++++++++++++---- src/components/station/StationInfo.tsx | 19 +++++++++++++++++++ src/routes/config.ts | 8 ++++++++ src/routes/index.tsx | 2 +- src/service/config.ts | 2 +- 8 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 src/components/station/StationInfo.tsx diff --git a/src/App.tsx b/src/App.tsx index a686a6f..bbdffd6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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(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() { diff --git a/src/components/SiderCustom.tsx b/src/components/SiderCustom.tsx index 78e2f11..873617e 100644 --- a/src/components/SiderCustom.tsx +++ b/src/components/SiderCustom.tsx @@ -26,7 +26,7 @@ const SiderCustom = (props: SiderCustomProps) => { const [firstHide, tFirstHide] = useSwitch(); const [menu, setMenu] = useState({ 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) => { >
{ }, [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({ diff --git a/src/components/station/StationInfo.tsx b/src/components/station/StationInfo.tsx new file mode 100644 index 0000000..9ad4dcf --- /dev/null +++ b/src/components/station/StationInfo.tsx @@ -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 ( +
+ +

参数:{props.query.t}

+
+
+ ); +}; + +export default StationInfo; diff --git a/src/routes/config.ts b/src/routes/config.ts index b3118c6..9b33c8f 100644 --- a/src/routes/config.ts +++ b/src/routes/config.ts @@ -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', diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 2b0a46e..c91f5e6 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -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; diff --git a/src/service/config.ts b/src/service/config.ts index 7b7c818..b6ad8cb 100644 --- a/src/service/config.ts +++ b/src/service/config.ts @@ -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';