jialin 2 years ago
commit 72a53424fa

@ -0,0 +1 @@
PORT=9000

@ -0,0 +1,4 @@
module.exports = {
extends: require.resolve('@umijs/max/eslint'),
};

14
.gitignore vendored

@ -0,0 +1,14 @@
/node_modules
/.env.local
/.umirc.local.ts
/config/config.local.ts
/src/.umi
/src/.umi-production
/src/.umi-test
/.umi
/.umi-production
/.umi-test
/dist
/.mfsu
.swc
.DS_Store

@ -0,0 +1 @@
npx --no-install max verify-commit $1

@ -0,0 +1 @@
npx --no-install lint-staged --quiet

@ -0,0 +1,17 @@
{
"*.{md,json}": [
"prettier --cache --write"
],
"*.{js,jsx}": [
"max lint --fix --eslint-only",
"prettier --cache --write"
],
"*.{css,less}": [
"max lint --fix --stylelint-only",
"prettier --cache --write"
],
"*.ts?(x)": [
"max lint --fix --eslint-only",
"prettier --cache --parser=typescript --write"
]
}

@ -0,0 +1,2 @@
registry=https://registry.npmjs.com/

@ -0,0 +1,3 @@
node_modules
.umi
.umi-production

@ -0,0 +1,12 @@
{
"printWidth": 80,
"singleQuote": true,
"trailingComma": "all",
"proseWrap": "never",
"overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }],
"plugins": ["prettier-plugin-organize-imports", "prettier-plugin-packagejson","unused-imports"],
"rules": {
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports-ts": "off"
}
}

@ -0,0 +1,3 @@
module.exports = {
extends: require.resolve('@umijs/max/stylelint'),
};

@ -0,0 +1,3 @@
# README
gpustack ui

@ -0,0 +1,32 @@
import { defineConfig } from '@umijs/max';
import routes from './routes';
export default defineConfig({
clickToComponent: {},
antd: {
style: 'less',
configProvider: {
theme:{
'root-entry-name': 'variable',
cssVar: true,
hashed: false,
token: {
colorPrimary: '#2fbf85',
motion: true,
}
},
}
},
access: {},
model: {},
initialState: {},
request: {},
// locale: {
// // 默认使用 src/locales/zh-CN.ts 作为多语言文件
// default: 'zh-CN',
// baseSeparator: '-',
// },
layout: false,
routes,
npmClient: 'pnpm',
});

@ -0,0 +1,69 @@
export default [
{
path: '/',
key: 'dashboard',
layout: false,
icon: 'home',
redirect: '/dashboard',
},
{
name: 'Dashboard',
path: '/dashboard',
key: 'dashboard',
icon: 'home',
component: './dashboard',
},
{
name: 'Playground',
path: '/playground',
key: 'playground',
icon: 'Comment',
component: './playground',
},
{
name: 'Models',
path: '/models',
key: 'models',
icon: 'Block',
component: './models',
},
{
name: 'Nodes',
path: '/nodes',
key: 'nodes',
icon: 'CloudServer',
component: './nodes',
},
{
name: 'Users',
path: '/users',
key: 'users',
icon: 'Team',
component: './users',
},
// {
// name: '首页',
// path: '/home',
// key: 'homes',
// component: './Home',
// },
// {
// name: '权限演示',
// path: '/access',
// key: 'access',
// component: './Access',
// },
// {
// name: ' CRUD 示例',
// path: '/table',
// key: 'table',
// component: './Table',
// },
{
name: '404',
path: '*',
key: '404',
layout: false,
component: './404',
},
];

@ -0,0 +1,20 @@
const users = [
{ id: 0, name: 'Umi', nickName: 'U', gender: 'MALE' },
{ id: 1, name: 'Fish', nickName: 'B', gender: 'FEMALE' },
];
export default {
'GET /api/v1/queryUserList': (req: any, res: any) => {
res.json({
success: true,
data: { list: users },
errorCode: 0,
});
},
'PUT /api/v1/user/': (req: any, res: any) => {
res.json({
success: true,
errorCode: 0,
});
},
};

@ -0,0 +1 @@
// only for third party libraries styles

@ -0,0 +1,29 @@
{
"private": true,
"author": "jialin <jialinkuang@126.com>",
"scripts": {
"dev": "max dev",
"build": "max build",
"format": "prettier --cache --write .",
"prepare": "husky",
"postinstall": "max setup",
"setup": "max setup",
"start": "npm run dev"
},
"dependencies": {
"@ant-design/icons": "^5.3.7",
"@ant-design/pro-components": "^2.7.1",
"@umijs/max": "^4.2.1",
"antd": "^5.17.0"
},
"devDependencies": {
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"prettier-plugin-packagejson": "^2.5.0",
"typescript": "^5.4.5"
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,11 @@
export default (initialState: API.UserInfo) => {
console.log('initialState==========', initialState)
// 在这里按照初始化数据定义项目中的权限,统一管理
// 参考文档 https://umijs.org/docs/max/access
const canSeeAdmin = !!(
initialState && initialState.name !== 'dontHaveAccess'
);
return {
canSeeAdmin,
};
};

@ -0,0 +1,20 @@
// import { RunTimeLayoutConfig } from '@umijs/max';
// 运行时配置
// 全局初始化数据配置,用于 Layout 用户信息和权限初始化
// 更多信息见文档https://umijs.org/docs/api/runtime-config#getinitialstate
export async function getInitialState(): Promise<{ name: string }> {
return { name: 'admin' };
}
// export const layout: RunTimeLayoutConfig = () => {
// return {
// title: '',
// logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
// menu: {
// locale: true,
// },
// };
// };

@ -0,0 +1,15 @@
.ant-pro-layout {
.ant-pro-sider {
padding: 10px;
&.ant-layout-sider {
background: var(--color-white-1);
}
.ant-layout-sider-children {
background-color: var(--color-fill-1);
border-inline: none;
border-radius: 32px;
padding-inline: 16px;
padding-block-end: 12px;
}
}
}

@ -0,0 +1,4 @@
.title {
margin: 0 auto;
font-weight: 200;
}

@ -0,0 +1,23 @@
import { Layout, Row, Typography } from 'antd';
import React from 'react';
import styles from './Guide.less';
interface Props {
name: string;
}
// 脚手架示例组件
const Guide: React.FC<Props> = (props) => {
const { name } = props;
return (
<Layout>
<Row>
<Typography.Title level={3} className={styles.title}>
使 <strong>{name}</strong>
</Typography.Title>
</Row>
</Layout>
);
};
export default Guide;

@ -0,0 +1,2 @@
import Guide from './Guide';
export default Guide;

@ -0,0 +1,28 @@
import { ProLayoutProps } from '@ant-design/pro-components';
/**
* @name
*/
const Settings: ProLayoutProps & {
pwa?: boolean;
logo?: string;
} = {
navTheme: 'light',
// 拂晓蓝
colorPrimary: '#2fbf85',
layout: 'mix',
contentWidth: 'Fluid',
fixedHeader: false,
fixSiderbar: true,
colorWeak: false,
title: 'seal',
pwa: false,
logo: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg',
iconfontUrl: '',
token: {
// 参见ts声明demo 见文档通过token 修改样式
//https://procomponents.ant.design/components/layout#%E9%80%9A%E8%BF%87-token-%E4%BF%AE%E6%94%B9%E6%A0%B7%E5%BC%8F
},
};
export default Settings;

@ -0,0 +1 @@
export const DEFAULT_NAME = 'Umi Max';

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@ -0,0 +1,61 @@
html{
--color-fill-1: #f3f6fa;
--color-fill-2: #fff;
--menu-border-radius-base: 32px;
--color-white-1: #fff;
--font-weight-normal: 500;
--font-weight-bold: 700;
--color-text-1: #1d2129;
.css-var-rf {
--ant-font-size: 12px;
}
.css-var-rf.ant-menu-css-var {
--ant-menu-item-height: 46px;
--ant-menu-item-selected-bg: var(--color-white-1);
--ant-menu-item-border-radius: 24px;
--ant-menu-item-selected-color: var(--ant-color-primary);
--ant-menu-item-hover-bg: var(--color-white-1);
--ant-menu-item-color: var(--color-text-1);
--ant-menu-item-active-bg: var(--color-white-1);
}
}
body {
font-weight: var(--font-weight-normal);
}
// ======== basic layout style start============
.ant-pro-layout {
height: 100vh;
.ant-pro-sider-logo {
border-block-end: none;
}
.ant-layout {
min-height: 100vh;
}
.ant-pro-layout-container {
background-color: var(--color-fill-2);
}
}
// ======== basic layout style end ============
// ======== menu style start ============
.ant-pro-sider-collapsed-button {
display: none;
}
.ant-pro-layout {
.ant-pro-sider {
.ant-menu {
.ant-menu-item:hover {
color: inherit;
}
}
}
}
// ======== menu style end ============
@import url('src/assets/menu.less');

@ -0,0 +1 @@
// 应用前置、全局运行的逻辑时 会在这里执行

@ -0,0 +1,21 @@
import { PageContainer } from '@ant-design/pro-components';
import { Access, useAccess } from '@umijs/max';
import { Button } from 'antd';
const Dashboard: React.FC = () => {
const access = useAccess();
return (
<PageContainer
ghost
header={{
title: 'Dashboard',
}}
>
<Access accessible={access.canSeeAdmin}>
<Button type="primary">==================</Button>
</Access>
</PageContainer>
);
};
export default Dashboard;

@ -0,0 +1,38 @@
// @ts-nocheck
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
import React from 'react';
import { history, type IRoute } from '@umijs/max';
import { Result, Button } from 'antd';
const Exception: React.FC<{
children: React.ReactNode;
route?: IRoute;
notFound?: React.ReactNode;
noAccessible?: React.ReactNode;
unAccessible?: React.ReactNode;
noFound?: React.ReactNode;
}> = (props) => (
console.log('Exception========', props),
// render custom 404
(!props.route && (props.noFound || props.notFound)) ||
// render custom 403
(props.route?.unaccessible && (props.unAccessible || props.noAccessible)) ||
// render default exception
((!props.route || props.route?.unaccessible) && (
<Result
status={props.route ? '403' : '404'}
title={props.route ? '403' : '404'}
subTitle={props.route ? '抱歉,你无权访问该页面' : '抱歉,你访问的页面不存在'}
extra={
<Button type="primary" onClick={() => history.push('/')}>
</Button>
}
/>
)) ||
// normal render
props.children
);
export default Exception;

@ -0,0 +1,50 @@
@media screen and (max-width: 480px) {
/* 在小屏幕的时候可以有更好的体验 */
.umi-plugin-layout-container {
width: 100% !important;
}
.umi-plugin-layout-container > * {
border-radius: 0 !important;
}
}
.umi-plugin-layout-menu .anticon {
margin-right: 8px;
}
.umi-plugin-layout-menu .ant-dropdown-menu-item {
min-width: 160px;
}
.umi-plugin-layout-right {
display: flex !important;
height: 100%;
overflow: hidden;
}
.umi-plugin-layout-right .umi-plugin-layout-action {
display: flex;
align-items: center;
height: 100%;
padding: 0 12px;
cursor: pointer;
transition: all 0.3s;
}
.umi-plugin-layout-right .umi-plugin-layout-action > i {
color: rgba(255, 255, 255, 0.85);
vertical-align: middle;
}
.umi-plugin-layout-right .umi-plugin-layout-action:hover {
background: rgba(0, 0, 0, 0.025);
}
.umi-plugin-layout-right .umi-plugin-layout-action.opened {
background: rgba(0, 0, 0, 0.025);
}
.umi-plugin-layout-right .umi-plugin-layout-search {
padding: 0 12px;
}
.umi-plugin-layout-right .umi-plugin-layout-search:hover {
background: transparent;
}
.umi-plugin-layout-name {
margin-left: 8px;
}
.umi-plugin-layout-name.umi-plugin-layout-hide-avatar-img {
margin-left: 0;
}

@ -0,0 +1,16 @@
// @ts-nocheck
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
import React from 'react';
const LogoIcon: React.FC = () => {
return (
<img
src="https://www.seal.io/Public/Uploads/uploadfile/images/20230825/a1logo1244.svg"
alt="logo"
style={{ height: 24 }}
/>
);
};
export default LogoIcon;

@ -0,0 +1,3 @@
// @ts-nocheck
import * as icons from '@ant-design/icons';
export default icons

@ -0,0 +1,4 @@
// @ts-nocheck
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
export type TempType = string

@ -0,0 +1,224 @@
// @ts-nocheck
/// <reference types="@ant-design/pro-components" />
import { useAccessMarkedRoutes } from '@@/plugin-access';
import { useModel } from '@@/plugin-model';
import { ProLayout } from '@ant-design/pro-components';
import {
Link,
Outlet,
matchRoutes,
useAppData,
useLocation,
useNavigate,
type IRoute,
} from '@umijs/max';
import { useMemo } from 'react';
import Exception from './Exception';
import './Layout.css';
import Logo from './Logo';
import { getRightRenderContent } from './rightRender';
import { renderMenuIcon,patchRoutes } from './runtime';
// 过滤出需要显示的路由, 这里的filterFn 指 不希望显示的层级
const filterRoutes = (
routes: IRoute[],
filterFn: (route: IRoute) => boolean,
) => {
if (routes.length === 0) {
return [];
}
let newRoutes = [];
for (const route of routes) {
const newRoute = { ...route };
if (filterFn(route)) {
if (Array.isArray(newRoute.routes)) {
newRoutes.push(...filterRoutes(newRoute.routes, filterFn));
}
} else {
if (Array.isArray(newRoute.children)) {
newRoute.children = filterRoutes(newRoute.children, filterFn);
newRoute.routes = newRoute.children;
}
newRoutes.push(newRoute);
}
}
return newRoutes;
};
// 格式化路由 处理因 wrapper 导致的 菜单 path 不一致
const mapRoutes = (routes: IRoute[]) => {
if (routes.length === 0) {
return [];
}
return routes.map((route) => {
// 需要 copy 一份, 否则会污染原始数据
const newRoute = { ...route };
if (route.originPath) {
newRoute.path = route.originPath;
}
if (Array.isArray(route.routes)) {
newRoute.routes = mapRoutes(route.routes);
}
if (Array.isArray(route.children)) {
newRoute.children = mapRoutes(route.children);
}
return newRoute;
});
};
export default (props: any) => {
const location = useLocation();
const navigate = useNavigate();
const { clientRoutes, pluginManager } = useAppData();
console.log('pluginManager===========', pluginManager);
const initialInfo = (useModel && useModel('@@initialState')) || {
initialState: undefined,
loading: false,
setInitialState: null,
};
const { initialState, loading, setInitialState } = initialInfo;
const userConfig = {
title: '',
layout: 'mix',
};
const formatMessage = undefined;
const runtimeConfig = pluginManager.applyPlugins({
key: 'layout',
type: 'modify',
initialValue: {
...initialInfo,
notFound: <div>not found</div>
},
});
console.log(
'clientRoute===========',
clientRoutes,
runtimeConfig,
initialInfo,
);
// 现在的 layout 及 wrapper 实现是通过父路由的形式实现的, 会导致路由数据多了冗余层级, proLayout 消费时, 无法正确展示菜单, 这里对冗余数据进行过滤操作
const newRoutes = filterRoutes(
clientRoutes.filter((route) => route.id === '@@/global-layout'),
(route) => {
return (
(!!route.isLayout && route.id !== '@@/global-layout') ||
!!route.isWrapper
);
},
);
console.log('clientRoutes===========', clientRoutes, newRoutes)
const [route] = useAccessMarkedRoutes(mapRoutes(newRoutes));
patchRoutes({ routes: route?.children || [] });
const matchedRoute = useMemo(
() => matchRoutes(route?.children || [], location.pathname)?.pop?.()?.route,
[location.pathname],
);
console.log('route===========', route)
return (
<ProLayout
route={route}
location={location}
title={userConfig.title}
navTheme="light"
siderWidth={270}
onMenuHeaderClick={(e) => {
e.stopPropagation();
e.preventDefault();
navigate('/');
}}
onPageChange={(route) => {
console.log('onRouteChange', route);
}}
formatMessage={userConfig.formatMessage || formatMessage}
menu={{ locale: userConfig.locale }}
logo={Logo}
menuItemRender={(menuItemProps, defaultDom) => {
console.log('meurender=========',{ defaultDom})
if (menuItemProps.isUrl || menuItemProps.children) {
return defaultDom;
}
if (menuItemProps.path && location.pathname !== menuItemProps.path) {
return (
// handle wildcard route path, for example /slave/* from qiankun
<Link
to={menuItemProps.path.replace('/*', '')}
target={menuItemProps.target}
>
{defaultDom}
</Link>
);
}
return (
<>
{defaultDom}
</>
);
}}
itemRender={(route, _, routes) => {
const { breadcrumbName, title, path } = route;
const label = title || breadcrumbName;
const last = routes[routes.length - 1];
if (last) {
if (last.path === path || last.linkPath === path) {
return <span>{label}</span>;
}
}
return <Link to={path}>{label}</Link>;
}}
disableContentMargin
fixSiderbar
fixedHeader
{...runtimeConfig}
rightContentRender={
runtimeConfig.rightContentRender !== false &&
((layoutProps) => {
const dom = getRightRenderContent({
runtimeConfig,
loading,
initialState,
setInitialState,
});
if (runtimeConfig.rightContentRender) {
return runtimeConfig.rightContentRender(layoutProps, dom, {
// BREAK CHANGE userConfig > runtimeConfig
userConfig,
runtimeConfig,
loading,
initialState,
setInitialState,
});
}
return dom;
})
}
>
<Exception
route={matchedRoute}
noFound={runtimeConfig?.noFound}
notFound={runtimeConfig?.notFound}
unAccessible={runtimeConfig?.unAccessible}
noAccessible={runtimeConfig?.noAccessible}
>
{runtimeConfig.childrenRender ? (
runtimeConfig.childrenRender(<Outlet />, props)
) : (
<Outlet />
)}
</Exception>
</ProLayout>
);
};

@ -0,0 +1,110 @@
// @ts-nocheck
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
import { LogoutOutlined } from '@ant-design/icons';
import { Avatar, Dropdown, Menu, Spin, version } from 'antd';
export function getRightRenderContent(opts: {
runtimeConfig: any;
loading: boolean;
initialState: any;
setInitialState: any;
}) {
if (opts.runtimeConfig.rightRender) {
return opts.runtimeConfig.rightRender(
opts.initialState,
opts.setInitialState,
opts.runtimeConfig,
);
}
const showAvatar =
opts.initialState?.avatar ||
opts.initialState?.name ||
opts.runtimeConfig.logout;
const disableAvatarImg = opts.initialState?.avatar === false;
const nameClassName = disableAvatarImg
? 'umi-plugin-layout-name umi-plugin-layout-hide-avatar-img'
: 'umi-plugin-layout-name';
const avatar = showAvatar ? (
<span className="umi-plugin-layout-action">
{!disableAvatarImg ? (
<Avatar
size="small"
className="umi-plugin-layout-avatar"
src={
opts.initialState?.avatar ||
'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
}
alt="avatar"
/>
) : null}
<span className={nameClassName}>{opts.initialState?.name}</span>
</span>
) : null;
if (opts.loading) {
return (
<div className="umi-plugin-layout-right">
<Spin size="small" style={{ marginLeft: 8, marginRight: 8 }} />
</div>
);
}
// 如果没有打开Locale并且头像为空就取消掉这个返回的内容
if (!avatar) return null;
const langMenu = {
className: 'umi-plugin-layout-menu',
selectedKeys: [],
items: [
{
key: 'logout',
label: (
<>
<LogoutOutlined />
退
</>
),
onClick: () => {
opts?.runtimeConfig?.logout?.(opts.initialState);
},
},
],
};
// antd@5 和 4.24 之后推荐使用 menu性能更好
let dropdownProps;
if (version.startsWith('5.') || version.startsWith('4.24.')) {
dropdownProps = { menu: langMenu };
} else if (version.startsWith('3.')) {
dropdownProps = {
overlay: (
<Menu>
{langMenu.items.map((item) => (
<Menu.Item key={item.key} onClick={item.onClick}>
{item.label}
</Menu.Item>
))}
</Menu>
),
};
} else {
// 需要 antd 4.20.0 以上版本
dropdownProps = { overlay: <Menu {...langMenu} /> };
}
return (
<div className="umi-plugin-layout-right anticon">
{opts.runtimeConfig.logout ? (
<Dropdown
{...dropdownProps}
overlayClassName="umi-plugin-layout-container"
>
{avatar}
</Dropdown>
) : (
avatar
)}
</div>
);
}

@ -0,0 +1,36 @@
// @ts-nocheck
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
import React from 'react';
import icons from './icons';
function formatIcon(name: string) {
return name
.replace(name[0], name[0].toUpperCase())
.replace(/-(w)/g, function(all, letter) {
return letter.toUpperCase();
});
}
export function patchRoutes({ routes }) {
console.log('patchRoutes====',routes)
Object.keys(routes).forEach(key => {
const { icon } = routes[key];
if (icon && typeof icon === 'string') {
const upperIcon = formatIcon(icon);
if (icons[upperIcon] || icons[upperIcon + 'Outlined']) {
routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
}
}
});
}
export function renderMenuIcon (icon: string){
const upperIcon = formatIcon(icon);
console.log('upperIcon',upperIcon)
if (icons[upperIcon] || icons[upperIcon + 'Outlined']) {
return React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
}
return null;
};

@ -0,0 +1,6 @@
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
import type { RunTimeLayoutConfig } from './types';
export interface IRuntimeConfig {
layout?: RunTimeLayoutConfig;
}

@ -0,0 +1,37 @@
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
/// <reference types="@ant-design/pro-components" />
import type InitialStateType from '@@/plugin-initialState/@@initialState';
import type { HeaderProps, ProLayoutProps } from '@ant-design/pro-components';
type InitDataType = ReturnType<typeof InitialStateType>;
import type { IConfigFromPlugins } from '@@/core/pluginConfig';
export type RunTimeLayoutConfig = (initData: InitDataType) => Omit<
ProLayoutProps,
'rightContentRender'
> & {
childrenRender?: (dom: JSX.Element, props: ProLayoutProps) => React.ReactNode;
unAccessible?: JSX.Element;
noFound?: JSX.Element;
logout?: (initialState: InitDataType['initialState']) => Promise<void> | void;
rightContentRender?:
| ((
headerProps: HeaderProps,
dom: JSX.Element,
props: {
userConfig: IConfigFromPlugins['layout'];
runtimeConfig: RunTimeLayoutConfig;
loading: InitDataType['loading'];
initialState: InitDataType['initialState'];
setInitialState: InitDataType['setInitialState'];
},
) => JSX.Element)
| false;
rightRender?: (
initialState: InitDataType['initialState'],
setInitialState: InitDataType['setInitialState'],
runtimeConfig: RunTimeLayoutConfig,
) => JSX.Element;
};

@ -0,0 +1,13 @@
// 全局共享数据示例
import { DEFAULT_NAME } from '@/constants';
import { useState } from 'react';
const useUser = () => {
const [name, setName] = useState<string>(DEFAULT_NAME);
return {
name,
setName,
};
};
export default useUser;

@ -0,0 +1,18 @@
import { history } from '@umijs/max';
import { Button, Result } from 'antd';
import React from 'react';
const NoFoundPage: React.FC = () => (
<Result
status="404"
title="404"
subTitle="Sorry, the page you visited does not exist."
extra={
<Button type="primary" onClick={() => history.push('/')}>
Back Home
</Button>
}
/>
);
export default NoFoundPage;

@ -0,0 +1,21 @@
import { PageContainer } from '@ant-design/pro-components';
import { Access, useAccess } from '@umijs/max';
import { Button } from 'antd';
const AccessPage: React.FC = () => {
const access = useAccess();
return (
<PageContainer
ghost
header={{
title: '权限示例',
}}
>
<Access accessible={access.canSeeAdmin}>
<Button> Admin </Button>
</Access>
</PageContainer>
);
};
export default AccessPage;

@ -0,0 +1,3 @@
.container {
padding-top: 80px;
}

@ -0,0 +1,18 @@
import Guide from '@/components/Guide';
import { trim } from '@/utils/format';
import { PageContainer } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import styles from './index.less';
const HomePage: React.FC = () => {
const { name } = useModel('global');
return (
<PageContainer ghost>
<div className={styles.container}>
<Guide name={trim(name)} />
</div>
</PageContainer>
);
};
export default HomePage;

@ -0,0 +1,26 @@
import { Modal } from 'antd';
import React, { PropsWithChildren } from 'react';
interface CreateFormProps {
modalVisible: boolean;
onCancel: () => void;
}
const CreateForm: React.FC<PropsWithChildren<CreateFormProps>> = (props) => {
const { modalVisible, onCancel } = props;
return (
<Modal
destroyOnClose
title="新建"
width={420}
open={modalVisible}
onCancel={() => onCancel()}
footer={null}
>
{props.children}
</Modal>
);
};
export default CreateForm;

@ -0,0 +1,138 @@
import {
ProFormDateTimePicker,
ProFormRadio,
ProFormSelect,
ProFormText,
ProFormTextArea,
StepsForm,
} from '@ant-design/pro-components';
import { Modal } from 'antd';
import React from 'react';
export interface FormValueType extends Partial<API.UserInfo> {
target?: string;
template?: string;
type?: string;
time?: string;
frequency?: string;
}
export interface UpdateFormProps {
onCancel: (flag?: boolean, formVals?: FormValueType) => void;
onSubmit: (values: FormValueType) => Promise<void>;
updateModalVisible: boolean;
values: Partial<API.UserInfo>;
}
const UpdateForm: React.FC<UpdateFormProps> = (props) => (
<StepsForm
stepsProps={{
size: 'small',
}}
stepsFormRender={(dom, submitter) => {
return (
<Modal
width={640}
bodyStyle={{ padding: '32px 40px 48px' }}
destroyOnClose
title="规则配置"
open={props.updateModalVisible}
footer={submitter}
onCancel={() => props.onCancel()}
>
{dom}
</Modal>
);
}}
onFinish={props.onSubmit}
>
<StepsForm.StepForm
initialValues={{
name: props.values.name,
nickName: props.values.nickName,
}}
title="基本信息"
>
<ProFormText
width="md"
name="name"
label="规则名称"
rules={[{ required: true, message: '请输入规则名称!' }]}
/>
<ProFormTextArea
name="desc"
width="md"
label="规则描述"
placeholder="请输入至少五个字符"
rules={[
{ required: true, message: '请输入至少五个字符的规则描述!', min: 5 },
]}
/>
</StepsForm.StepForm>
<StepsForm.StepForm
initialValues={{
target: '0',
template: '0',
}}
title="配置规则属性"
>
<ProFormSelect
width="md"
name="target"
label="监控对象"
valueEnum={{
0: '表一',
1: '表二',
}}
/>
<ProFormSelect
width="md"
name="template"
label="规则模板"
valueEnum={{
0: '规则模板一',
1: '规则模板二',
}}
/>
<ProFormRadio.Group
name="type"
width="md"
label="规则类型"
options={[
{
value: '0',
label: '强',
},
{
value: '1',
label: '弱',
},
]}
/>
</StepsForm.StepForm>
<StepsForm.StepForm
initialValues={{
type: '1',
frequency: 'month',
}}
title="设定调度周期"
>
<ProFormDateTimePicker
name="time"
label="开始时间"
rules={[{ required: true, message: '请选择开始时间!' }]}
/>
<ProFormSelect
name="frequency"
label="监控对象"
width="xs"
valueEnum={{
month: '月',
week: '周',
}}
/>
</StepsForm.StepForm>
</StepsForm>
);
export default UpdateForm;

@ -0,0 +1,270 @@
import services from '@/services/demo';
import {
ActionType,
FooterToolbar,
PageContainer,
ProDescriptions,
ProDescriptionsItemProps,
ProTable,
} from '@ant-design/pro-components';
import { Button, Divider, Drawer, message } from 'antd';
import React, { useRef, useState } from 'react';
import CreateForm from './components/CreateForm';
import UpdateForm, { FormValueType } from './components/UpdateForm';
const { addUser, queryUserList, deleteUser, modifyUser } =
services.UserController;
/**
*
* @param fields
*/
const handleAdd = async (fields: API.UserInfo) => {
const hide = message.loading('正在添加');
try {
await addUser({ ...fields });
hide();
message.success('添加成功');
return true;
} catch (error) {
hide();
message.error('添加失败请重试!');
return false;
}
};
/**
*
* @param fields
*/
const handleUpdate = async (fields: FormValueType) => {
const hide = message.loading('正在配置');
try {
await modifyUser(
{
userId: fields.id || '',
},
{
name: fields.name || '',
nickName: fields.nickName || '',
email: fields.email || '',
},
);
hide();
message.success('配置成功');
return true;
} catch (error) {
hide();
message.error('配置失败请重试!');
return false;
}
};
/**
*
* @param selectedRows
*/
const handleRemove = async (selectedRows: API.UserInfo[]) => {
const hide = message.loading('正在删除');
if (!selectedRows) return true;
try {
await deleteUser({
userId: selectedRows.find((row) => row.id)?.id || '',
});
hide();
message.success('删除成功,即将刷新');
return true;
} catch (error) {
hide();
message.error('删除失败,请重试');
return false;
}
};
const TableList: React.FC<unknown> = () => {
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] =
useState<boolean>(false);
const [stepFormValues, setStepFormValues] = useState({});
const actionRef = useRef<ActionType>();
const [row, setRow] = useState<API.UserInfo>();
const [selectedRowsState, setSelectedRows] = useState<API.UserInfo[]>([]);
const columns: ProDescriptionsItemProps<API.UserInfo>[] = [
{
title: '名称',
dataIndex: 'name',
tip: '名称是唯一的 key',
formItemProps: {
rules: [
{
required: true,
message: '名称为必填项',
},
],
},
},
{
title: '昵称',
dataIndex: 'nickName',
valueType: 'text',
},
{
title: '性别',
dataIndex: 'gender',
hideInForm: true,
valueEnum: {
0: { text: '男', status: 'MALE' },
1: { text: '女', status: 'FEMALE' },
},
},
{
title: '操作',
dataIndex: 'option',
valueType: 'option',
render: (_, record) => (
<>
<a
onClick={() => {
handleUpdateModalVisible(true);
setStepFormValues(record);
}}
>
</a>
<Divider type="vertical" />
<a href=""></a>
</>
),
},
];
return (
<PageContainer
header={{
title: 'CRUD 示例',
}}
>
<ProTable<API.UserInfo>
headerTitle="查询表格"
actionRef={actionRef}
rowKey="id"
search={{
labelWidth: 120,
}}
toolBarRender={() => [
<Button
key="1"
type="primary"
onClick={() => handleModalVisible(true)}
>
</Button>,
]}
request={async (params, sorter, filter) => {
const { data, success } = await queryUserList({
...params,
// FIXME: remove @ts-ignore
// @ts-ignore
sorter,
filter,
});
return {
data: data?.list || [],
success,
};
}}
columns={columns}
rowSelection={{
onChange: (_, selectedRows) => setSelectedRows(selectedRows),
}}
/>
{selectedRowsState?.length > 0 && (
<FooterToolbar
extra={
<div>
{' '}
<a style={{ fontWeight: 600 }}>{selectedRowsState.length}</a>{' '}
&nbsp;&nbsp;
</div>
}
>
<Button
onClick={async () => {
await handleRemove(selectedRowsState);
setSelectedRows([]);
actionRef.current?.reloadAndRest?.();
}}
>
</Button>
<Button type="primary"></Button>
</FooterToolbar>
)}
<CreateForm
onCancel={() => handleModalVisible(false)}
modalVisible={createModalVisible}
>
<ProTable<API.UserInfo, API.UserInfo>
onSubmit={async (value) => {
const success = await handleAdd(value);
if (success) {
handleModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
rowKey="id"
type="form"
columns={columns}
/>
</CreateForm>
{stepFormValues && Object.keys(stepFormValues).length ? (
<UpdateForm
onSubmit={async (value) => {
const success = await handleUpdate(value);
if (success) {
handleUpdateModalVisible(false);
setStepFormValues({});
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
onCancel={() => {
handleUpdateModalVisible(false);
setStepFormValues({});
}}
updateModalVisible={updateModalVisible}
values={stepFormValues}
/>
) : null}
<Drawer
width={600}
open={!!row}
onClose={() => {
setRow(undefined);
}}
closable={false}
>
{row?.name && (
<ProDescriptions<API.UserInfo>
column={2}
title={row?.name}
request={async () => ({
data: row || {},
})}
params={{
id: row?.name,
}}
columns={columns}
/>
)}
</Drawer>
</PageContainer>
);
};
export default TableList;

@ -0,0 +1,21 @@
import { PageContainer } from '@ant-design/pro-components';
import { Access, useAccess } from '@umijs/max';
import { Button } from 'antd';
const Dashboard: React.FC = () => {
const access = useAccess();
return (
<PageContainer
ghost
header={{
title: 'Dashboard',
}}
>
<Access accessible={access.canSeeAdmin}>
<Button type="primary"> Admin </Button>
</Access>
</PageContainer>
);
};
export default Dashboard;

@ -0,0 +1,16 @@
import { PageContainer } from '@ant-design/pro-components';
const Dashboard: React.FC = () => {
return (
<PageContainer
ghost
header={{
title: 'Dashboard',
}}
>
<div>Models</div>
</PageContainer>
);
};
export default Dashboard;

@ -0,0 +1,16 @@
import { PageContainer } from '@ant-design/pro-components';
const Dashboard: React.FC = () => {
return (
<PageContainer
ghost
header={{
title: 'Dashboard',
}}
>
<div>Nodes</div>
</PageContainer>
);
};
export default Dashboard;

@ -0,0 +1,16 @@
import { PageContainer } from '@ant-design/pro-components';
const Dashboard: React.FC = () => {
return (
<PageContainer
ghost
header={{
title: 'Dashboard',
}}
>
<div>Playground</div>
</PageContainer>
);
};
export default Dashboard;

@ -0,0 +1,16 @@
import { PageContainer } from '@ant-design/pro-components';
const Dashboard: React.FC = () => {
return (
<PageContainer
ghost
header={{
title: 'Dashboard',
}}
>
<div>Users</div>
</PageContainer>
);
};
export default Dashboard;

@ -0,0 +1,96 @@
/* eslint-disable */
// 该文件由 OneAPI 自动生成,请勿手动修改!
import { request } from '@umijs/max';
/** 此处后端没有提供注释 GET /api/v1/queryUserList */
export async function queryUserList(
params: {
// query
/** keyword */
keyword?: string;
/** current */
current?: number;
/** pageSize */
pageSize?: number;
},
options?: { [key: string]: any },
) {
return request<API.Result_PageInfo_UserInfo__>('/api/v1/queryUserList', {
method: 'GET',
params: {
...params,
},
...(options || {}),
});
}
/** 此处后端没有提供注释 POST /api/v1/user */
export async function addUser(
body?: API.UserInfoVO,
options?: { [key: string]: any },
) {
return request<API.Result_UserInfo_>('/api/v1/user', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
data: body,
...(options || {}),
});
}
/** 此处后端没有提供注释 GET /api/v1/user/${param0} */
export async function getUserDetail(
params: {
// path
/** userId */
userId?: string;
},
options?: { [key: string]: any },
) {
const { userId: param0 } = params;
return request<API.Result_UserInfo_>(`/api/v1/user/${param0}`, {
method: 'GET',
params: { ...params },
...(options || {}),
});
}
/** 此处后端没有提供注释 PUT /api/v1/user/${param0} */
export async function modifyUser(
params: {
// path
/** userId */
userId?: string;
},
body?: API.UserInfoVO,
options?: { [key: string]: any },
) {
const { userId: param0 } = params;
return request<API.Result_UserInfo_>(`/api/v1/user/${param0}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
params: { ...params },
data: body,
...(options || {}),
});
}
/** 此处后端没有提供注释 DELETE /api/v1/user/${param0} */
export async function deleteUser(
params: {
// path
/** userId */
userId?: string;
},
options?: { [key: string]: any },
) {
const { userId: param0 } = params;
return request<API.Result_string_>(`/api/v1/user/${param0}`, {
method: 'DELETE',
params: { ...params },
...(options || {}),
});
}

@ -0,0 +1,7 @@
/* eslint-disable */
// 该文件由 OneAPI 自动生成,请勿手动修改!
import * as UserController from './UserController';
export default {
UserController,
};

@ -0,0 +1,68 @@
/* eslint-disable */
// 该文件由 OneAPI 自动生成,请勿手动修改!
declare namespace API {
interface PageInfo {
/**
1 */
current?: number;
pageSize?: number;
total?: number;
list?: Array<Record<string, any>>;
}
interface PageInfo_UserInfo_ {
/**
1 */
current?: number;
pageSize?: number;
total?: number;
list?: Array<UserInfo>;
}
interface Result {
success?: boolean;
errorMessage?: string;
data?: Record<string, any>;
}
interface Result_PageInfo_UserInfo__ {
success?: boolean;
errorMessage?: string;
data?: PageInfo_UserInfo_;
}
interface Result_UserInfo_ {
success?: boolean;
errorMessage?: string;
data?: UserInfo;
}
interface Result_string_ {
success?: boolean;
errorMessage?: string;
data?: string;
}
type UserGenderEnum = 'MALE' | 'FEMALE';
interface UserInfo {
id?: string;
name?: string;
/** nick */
nickName?: string;
/** email */
email?: string;
gender?: UserGenderEnum;
}
interface UserInfoVO {
name?: string;
/** nick */
nickName?: string;
/** email */
email?: string;
}
type definitions_0 = null;
}

@ -0,0 +1,4 @@
// 示例方法,没有实际意义
export function trim(str: string) {
return str.trim();
}

@ -0,0 +1,3 @@
{
"extends": "./src/.umi/tsconfig.json"
}

1
typings.d.ts vendored

@ -0,0 +1 @@
import '@umijs/max/typings';
Loading…
Cancel
Save