Skip to content

Commit

Permalink
首页布局修改,新增页面:镜像列表,用户列表管理
Browse files Browse the repository at this point in the history
  • Loading branch information
7911-hx committed Dec 27, 2024
1 parent 585b50f commit 47d58ff
Show file tree
Hide file tree
Showing 3 changed files with 428 additions and 41 deletions.
100 changes: 59 additions & 41 deletions frontend/providers/applaunchpad/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import List from '@/components/ImageHub/list';
import { theme } from '@/constants/theme';
import { useConfirm } from '@/hooks/useConfirm';
import { useLoading } from '@/hooks/useLoading';
import { useGlobalStore } from '@/store/global';
import { DESKTOP_DOMAIN, loadInitData } from '@/store/static';
import { SEALOS_DOMAIN, loadInitData } from '@/store/static';
import { useUserStore } from '@/store/user';
import '@/styles/reset.scss';
import { getLangStore, setLangStore } from '@/utils/cookieUtils';
import { ChakraProvider } from '@chakra-ui/react';
import { getUserIsLogin } from '@/utils/user';
import { Box, ChakraProvider, Flex, Heading, ListItem, Text, Link, useDisclosure, background } from '@chakra-ui/react';
import '@sealos/driver/src/driver.css';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import throttle from 'lodash/throttle';
import { appWithTranslation, useTranslation } from 'next-i18next';
import type { AppProps } from 'next/app';
import Head from 'next/head';
import Router, { useRouter } from 'next/router';
import NProgress from 'nprogress'; //nprogress module
import 'nprogress/nprogress.css';
import { useEffect, useState } from 'react';
import { EVENT_NAME } from 'sealos-desktop-sdk';
import { createSealosApp, sealosApp } from 'sealos-desktop-sdk/app';
import '@/styles/reset.scss';
import 'nprogress/nprogress.css';
import '@sealos/driver/src/driver.css';
import { AppEditSyncedFields } from '@/types/app';
import Script from 'next/script';

//Binding events.
Router.events.on('routeChangeStart', () => NProgress.start());
Expand Down Expand Up @@ -50,10 +50,17 @@ const App = ({ Component, pageProps }: AppProps) => {
content: 'jump_message'
});

const myStyles = {
cursor: 'pointer',
};

useEffect(() => {
if (!getUserIsLogin()) {
router.push('/login');
}
const response = createSealosApp();
(async () => {
const { FORM_SLIDER_LIST_CONFIG, DESKTOP_DOMAIN } = await (() => loadInitData())();
const { SEALOS_DOMAIN, FORM_SLIDER_LIST_CONFIG } = await (() => loadInitData())();
initFormSliderList(FORM_SLIDER_LIST_CONFIG);
loadUserSourcePrice();

Expand All @@ -67,12 +74,12 @@ const App = ({ Component, pageProps }: AppProps) => {
console.log('app init success');
} catch (err) {
console.log('App is not running in desktop');
if (!process.env.NEXT_PUBLIC_MOCK_USER) {
localStorage.removeItem('session');
openConfirm(() => {
window.open(`https://${DESKTOP_DOMAIN}`, '_self');
})();
}
// if (!process.env.NEXT_PUBLIC_MOCK_USER) {
// localStorage.removeItem('session');
// openConfirm(() => {
// window.open(`https://${SEALOS_DOMAIN}`, '_self');
// })();
// }
}
})();
return response;
Expand Down Expand Up @@ -122,12 +129,9 @@ const App = ({ Component, pageProps }: AppProps) => {
// record route
useEffect(() => {
return () => {
const currentPath = router.asPath;
if (router.isReady && !currentPath.includes('/redirect')) {
setLastRoute(currentPath);
}
setLastRoute(router.asPath);
};
}, [router.pathname, router.isReady, setLastRoute]);
}, [router.pathname]);

useEffect(() => {
const lang = getLangStore() || 'zh';
Expand All @@ -137,31 +141,19 @@ const App = ({ Component, pageProps }: AppProps) => {
useEffect(() => {
const setupInternalAppCallListener = async () => {
try {
const event = async (
e: MessageEvent<{
type?: string;
name?: string;
formData?: string;
}>
) => {
const whitelist = [`https://${DESKTOP_DOMAIN}`];
const event = async (e: MessageEvent) => {
const whitelist = [`https://${SEALOS_DOMAIN}`];
if (!whitelist.includes(e.origin)) {
return;
}
try {
if (e.data?.type === 'InternalAppCall') {
const { name, formData } = e.data;
if (formData) {
router.replace({
pathname: '/redirect',
query: { formData }
});
} else if (name) {
router.replace({
pathname: '/app/detail',
query: { name }
});
}
if (e.data?.type === 'InternalAppCall' && e.data?.name) {
router.push({
pathname: '/app/detail',
query: {
name: e.data.name
}
});
}
} catch (error) {
console.log(error, 'error');
Expand Down Expand Up @@ -197,7 +189,33 @@ const App = ({ Component, pageProps }: AppProps) => {
>
changeLanguage
</button> */}
<Component {...pageProps} />

{/* <Route path="/login" component={Login} /> */}
<Flex minH="100vh" direction="column">

<Box bg="#001529" color="white" px={4} py={5}>

<Heading size="md">储存云</Heading>

</Box>

<Flex flex={1}>

<Box w="200px" bg="#001529" color="white" p={4} borderRight="1px" borderColor="gray.300">
<Text fontSize="lg" p={4} className="menu" onClick={()=>router.push('/imagehub')}>镜像管理</Text>
<Text fontSize="lg" p={4} className="menu" onClick={()=>router.push('/apps')}>应用管理</Text>
<Text fontSize="lg" p={4} className="menu" onClick={()=>router.push('/tenantManage')}>租户管理</Text>
<Text fontSize="lg" p={4} className="menu" onClick={()=>router.push('/nodeManage')}>节点管理</Text>
</Box>

<Box flex={1}>

<Component {...pageProps} />

</Box>

</Flex>
</Flex>
<ConfirmChild />
<Loading loading={loading} />
</ChakraProvider>
Expand Down
192 changes: 192 additions & 0 deletions frontend/providers/applaunchpad/src/pages/nodeManage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { deleteImageHub, uploadImageHub } from '@/api/app';
import FileSelect from '@/components/FileSelect';
import MyIcon from '@/components/Icon';
import { ImageHubItem } from '@/pages/api/imagehub/get';
import { formatPodTime } from '@/utils/tools';
import {
Box,
Button,
Center,
Flex,
FormControl,
FormHelperText,
FormLabel,
Grid,
HStack,
Icon,
Input,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Radio,
RadioGroup,
useDisclosure,
useTheme,
Table,
Thead,
Tbody,
Tfoot,
Tr,
Th,
Td,
TableCaption,
TableContainer,
Select,
} from '@chakra-ui/react';
import type { ThemeType } from '@sealos/ui';
import { useMessage } from '@sealos/ui';
import dayjs from 'dayjs';
import { debounce } from 'lodash';
import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
import React, { useCallback, useMemo, useState } from 'react';

const AppList = ({
apps = [],
namespaces,
refetchApps,
onSearch
}: {
namespaces: string[];
apps: ImageHubItem[];
refetchApps: () => void;
onSearch: (value: string) => void;
}) => {

const Title = "节点管理"

const Label = ({
children,
w = 120,
...props
}: {
children: string;
w?: number | 'auto';
[key: string]: any;
}) => (
<Box
flex={`0 0 ${w === 'auto' ? 'auto' : `${w}px`}`}
color={'grayModern.900'}
fontWeight={'bold'}
userSelect={'none'}
{...props}
>
{children}
</Box>
);


const columns = [
{ title: 'ip', field: 'nickname' },
{ title: '主机名', field: 'email' },
{ title: '节点类型', field: 'phone' },
{ title: '系统', field: 'tokenLink' },
{ title: '内核版本', field: 'details' },
{ title: 'cpu', field: 'details' },
{ title: '内存', field: 'details' },
{ title: '磁盘', field: 'details' },
{ title: '操作', field: 'details' },
];

const data = [
// 这里添加你的数据
// 每个对象应该有和columns中field属性对应的键值对
];

const { isOpen, onOpen, onClose } = useDisclosure();


return (
<Box backgroundColor={'grayModern.100'} px={'32px'} pb={5} minH={'100%'}>
<Flex h={'88px'} alignItems={'center'} justifyContent={'space-between'} >
<Flex alignItems={'center'}>
<Center
w="46px"
h={'46px'}
mr={4}
backgroundColor={'#FEFEFE'}
borderRadius={'md'}
>
<MyIcon name="logo" w={'24px'} h={'24px'} />
</Center>
<Box fontSize={'xl'} color={'grayModern.900'} fontWeight={'bold'}>
{Title}
</Box>
</Flex>
<Button onClick={onOpen}>添加节点</Button>
</Flex>


<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalHeader>新增节点</ModalHeader>
<ModalCloseButton />
<ModalBody>
<FormControl mb={7} w={'100%'}>
<Flex alignItems={'center'} mb={5}>
<Label>{"ip"}</Label>
<Input
width={'60%'}
autoFocus={true}
maxLength={60}
/>
</Flex>
<Flex alignItems={'center'}>
<Label>{"节点类型"}</Label>
<Select
width={'60%'}
autoFocus={true}
/>
</Flex>
</FormControl>
<FormControl mb={7} w={'100%'}>
<Flex alignItems={'center'} mb={5}>
<Label>{"密码"}</Label>
<Input
width={'60%'}
autoFocus={true}
maxLength={60}
/>
</Flex>
</FormControl>
</ModalBody>
<ModalFooter>
<Button colorScheme="blue" mr={3} onClick={onClose}>
关闭
</Button>
</ModalFooter>
</ModalContent>
</Modal>

<TableContainer>
<Table variant="simple" backgroundColor={'white'} color={'black'}>
<Thead>
<Tr>
{columns.map((column, index) => (
<Th key={index}>{column.title}</Th>
))}
</Tr>
</Thead>
<Tbody>
{data.map((row, rowIndex) => (
<Tr key={rowIndex}>
{columns.map((column, colIndex) => (
<Td key={`${rowIndex}-${colIndex}`}>
{row[column.field]}
</Td>
))}
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
</Box>
);
};

export default React.memo(AppList);
Loading

0 comments on commit 47d58ff

Please sign in to comment.