diff --git a/src/App.tsx b/src/App.tsx index ae95aee..23f563a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,6 +9,7 @@ import { App as PromptApp } from './pages/prompt'; import { App as AiAgentApp } from './pages/ai-agent'; import { App as UserApp } from './pages/user'; import { App as ChatApp } from './pages/chat-manager'; +import { App as GitHubApp } from './pages/github'; import '@abearxiong/container/dist/container.css'; @@ -31,6 +32,7 @@ export const App = () => { } /> } /> } /> + } /> 404} /> 404} /> diff --git a/src/modules/layout/Menu.tsx b/src/modules/layout/Menu.tsx new file mode 100644 index 0000000..c43f22d --- /dev/null +++ b/src/modules/layout/Menu.tsx @@ -0,0 +1,78 @@ +import { useShallow } from 'zustand/react/shallow'; +import { useMenuStore } from './store'; +import clsx from 'clsx'; +import { Button, message } from 'antd'; +import { CloseOutlined, CodeOutlined, DashboardOutlined, HomeOutlined, MessageOutlined, ReadOutlined, RocketOutlined, SmileOutlined } from '@ant-design/icons'; +import { useNavigate } from 'react-router'; +const meun = [ + { + title: 'Home', + icon: , + link: '/map', + }, + { + title: 'Panel', + icon: , + link: '/panel/edit/list', + }, + { + title: 'Prompt', + icon: , + link: '/prompt', + }, + { + title: 'Container', + icon: , + link: '/container/edit/list', + }, + { + title: 'Agent', + icon: , + link: '/agent/edit/list', + }, + { + title: 'Chat Prompt', + icon: , + link: '/chat/chat-prompt/list', + }, + { + title: 'About', + icon: , + }, +]; +export const LayoutMenu = () => { + const { open, setOpen } = useMenuStore(useShallow((state) => ({ open: state.open, setOpen: state.setOpen }))); + const navigate = useNavigate(); + return ( + + + + + Envision + + } onClick={() => setOpen(false)}> + + + + {meun.map((item, index) => { + return ( + { + if (item.link) navigate(`${item.link}`); + else { + message.info('About Envision'); + } + setOpen(false); + }}> + {item.icon} + {item.title} + + ); + })} + + + + ); +}; diff --git a/src/modules/layout/index.tsx b/src/modules/layout/index.tsx index 9e50a64..5675d75 100644 --- a/src/modules/layout/index.tsx +++ b/src/modules/layout/index.tsx @@ -1,14 +1,33 @@ import { AiMoudle } from '@/pages/ai-chat'; +import { MenuOutlined } from '@ant-design/icons'; +import { Button } from 'antd'; import { Outlet } from 'react-router-dom'; +import { LayoutMenu } from './Menu'; +import { useMenuStore } from './store'; +import { useShallow } from 'zustand/react/shallow'; type LayoutMainProps = { title?: React.ReactNode; children?: React.ReactNode; }; export const LayoutMain = (props: LayoutMainProps) => { + const menuStore = useMenuStore( + useShallow((state) => { + return { open: state.open, setOpen: state.setOpen }; + }), + ); return ( - - {props.title} + + + + { + menuStore.setOpen(true); + }} + icon={}> + {props.title} + void; +}; +export const useMenuStore = create((set) => ({ + open: false, + setOpen: (open) => set({ open }), +})); diff --git a/src/pages/ai-agent/layouts/index.tsx b/src/pages/ai-agent/layouts/index.tsx index b8b230d..66ece94 100644 --- a/src/pages/ai-agent/layouts/index.tsx +++ b/src/pages/ai-agent/layouts/index.tsx @@ -1,14 +1,5 @@ -import { Outlet } from 'react-router'; +import { LayoutMain } from '@/modules/layout'; export const Main = () => { - return ( - - Agent - - - - - - - ); + return ; }; diff --git a/src/pages/container/store/index.ts b/src/pages/container/store/index.ts index cd6ee87..e80931c 100644 --- a/src/pages/container/store/index.ts +++ b/src/pages/container/store/index.ts @@ -46,7 +46,7 @@ export const useContainerStore = create((set, get) => { }); if (res.code === 200) { message.success('Success'); - set({ showEdit: false, formData: [] }); + set({ showEdit: false, formData: res.data }); getList(); } else { message.error(res.message || 'Request failed'); diff --git a/src/pages/github/Callback.tsx b/src/pages/github/Callback.tsx new file mode 100644 index 0000000..ca4ac4c --- /dev/null +++ b/src/pages/github/Callback.tsx @@ -0,0 +1,28 @@ +import { useEffect, useState } from 'react'; +import { getCodeFromUrl, useGithubStore } from './store'; +import { useShallow } from 'zustand/react/shallow'; + +export const Callback = () => { + const [code, setCode] = useState(''); + const githubStore = useGithubStore( + useShallow((state) => { + return { + getToken: state.getToken, + githubToken: state.githubToken, + }; + }), + ); + useEffect(() => { + setCode(getCodeFromUrl()); + githubStore.getToken(); + }, []); + return ( + + + Callback + code: {code} + access_token: {githubStore.githubToken} + + + ); +}; diff --git a/src/pages/github/Login.tsx b/src/pages/github/Login.tsx new file mode 100644 index 0000000..8877500 --- /dev/null +++ b/src/pages/github/Login.tsx @@ -0,0 +1,21 @@ +import { nanoid } from 'nanoid'; +import { useEffect, useState } from 'react'; + +const getGithubAuth = () => { + const client_id = 'Ov23littcejmbA5iKrhK'; + const redirect_uri = 'https://envision.xiongxiao.me/github/callback'; + const scope = 'user'; + const state = 'abc123' && nanoid(6); + return `https://github.com/login/oauth/authorize?client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}`; +}; +export const Login = () => { + const [url, setUrl] = useState(''); + useEffect(() => { + setUrl(getGithubAuth()); + }, []); + return ( + + Github登录 + + ); +}; diff --git a/src/pages/github/index.tsx b/src/pages/github/index.tsx new file mode 100644 index 0000000..4d2f197 --- /dev/null +++ b/src/pages/github/index.tsx @@ -0,0 +1,16 @@ +import { LayoutMain } from '@/modules/layout'; +import { Navigate, Route, Routes } from 'react-router-dom'; +import { Login } from './Login'; +import { Callback } from './Callback'; + +export const App = () => { + return ( + + }> + }> + } /> + }> + + + ); +}; diff --git a/src/pages/github/store/index.ts b/src/pages/github/store/index.ts new file mode 100644 index 0000000..2fad5b0 --- /dev/null +++ b/src/pages/github/store/index.ts @@ -0,0 +1,32 @@ +import { query } from '@/modules'; +import { message } from 'antd'; +import { create } from 'zustand'; +export const getCodeFromUrl = () => { + const searchParams = new URLSearchParams(window.location.search); + return searchParams.get('code') || ''; +}; +type GithubStore = { + githubToken?: string; + getToken: () => Promise; +}; +export const useGithubStore = create((set) => ({ + githubToken: '', + getToken: async () => { + const code = getCodeFromUrl(); + if (!code) { + message.error('code不存在'); + } + const loaded = message.loading('获取token中', 0); + const res = await query.post({ + path: 'github', + key: 'token', + code, + }); + loaded(); + if (res.code === 200) { + const { githubToken } = res.data; + set({ githubToken: githubToken }); + localStorage.setItem('githubToken', githubToken); + } + }, +})); diff --git a/src/pages/prompt/layout/Main.tsx b/src/pages/prompt/layout/Main.tsx index 362bc7d..1058059 100644 --- a/src/pages/prompt/layout/Main.tsx +++ b/src/pages/prompt/layout/Main.tsx @@ -1,13 +1,4 @@ -import { AiMoudle } from '@/pages/ai-chat'; -import { Outlet } from 'react-router'; - +import { LayoutMain } from '@/modules/layout'; export const Main = () => { - return ( - - - - - - - ); + return ; };
code: {code}
access_token: {githubStore.githubToken}