chore: add modal
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
import * as icons from '@ant-design/icons';
|
||||||
|
import { Button, Dropdown, Space } from 'antd';
|
||||||
|
import type { MenuProps } from 'antd/es/menu';
|
||||||
|
import react from 'react';
|
||||||
|
|
||||||
|
type DropdownProps = {
|
||||||
|
trigger?: Array<'click' | 'hover' | 'contextMenu'>;
|
||||||
|
items: MenuProps['items'];
|
||||||
|
onClick: (e: any) => void;
|
||||||
|
};
|
||||||
|
const renderIcon = (icon: string) => {
|
||||||
|
if (!icon) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
const Icon = icons[icon] as React.FC;
|
||||||
|
return react.createElement(Icon);
|
||||||
|
};
|
||||||
|
const DropDownActions: React.FC<DropdownProps> = (props) => {
|
||||||
|
const { trigger, items, onClick } = props;
|
||||||
|
return (
|
||||||
|
<Space>
|
||||||
|
<Dropdown menu={{ items, onClick }} trigger={trigger}>
|
||||||
|
<Button
|
||||||
|
onClick={(e) => e.preventDefault()}
|
||||||
|
style={{ fontSize: '14px' }}
|
||||||
|
type="text"
|
||||||
|
icon={renderIcon('MoreOutlined')}
|
||||||
|
></Button>
|
||||||
|
</Dropdown>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DropDownActions;
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { Button, Space } from 'antd';
|
||||||
|
|
||||||
|
type ModalFooterProps = {
|
||||||
|
onOk: () => void;
|
||||||
|
onCancel: () => void;
|
||||||
|
};
|
||||||
|
const ModalFooter: React.FC<ModalFooterProps> = ({ onOk, onCancel }) => {
|
||||||
|
return (
|
||||||
|
<Space size={20}>
|
||||||
|
<Button onClick={onCancel} style={{ width: '88px' }}>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" onClick={onOk} style={{ width: '88px' }}>
|
||||||
|
确定
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ModalFooter;
|
||||||
@@ -39,6 +39,7 @@ const SealSelect: React.FC<SelectProps & SealFormItemProps> = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleOnBlur = (e: any) => {
|
const handleOnBlur = (e: any) => {
|
||||||
|
setIsFocus(false);
|
||||||
props.onBlur?.(e);
|
props.onBlur?.(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ const SealSelect: React.FC<SelectProps & SealFormItemProps> = (props) => {
|
|||||||
onBlur={handleOnBlur}
|
onBlur={handleOnBlur}
|
||||||
onSearch={handleOnSearch}
|
onSearch={handleOnSearch}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
notFoundContent={null}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { PageActionType } from './types';
|
||||||
|
|
||||||
|
export const PageAction: Record<string, PageActionType> = {
|
||||||
|
CREATE: 'create',
|
||||||
|
UPDATE: 'update',
|
||||||
|
VIEW: 'view'
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
export interface DropDownItem {
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
disabled?: boolean;
|
||||||
|
iconfont?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PageActionType = 'create' | 'update' | 'view';
|
||||||
@@ -50,6 +50,16 @@ html {
|
|||||||
&.ant-table-css-var {
|
&.ant-table-css-var {
|
||||||
--ant-table-row-hover-bg: #e6e6e6;
|
--ant-table-row-hover-bg: #e6e6e6;
|
||||||
}
|
}
|
||||||
|
&.ant-modal-css-var {
|
||||||
|
--ant-modal-title-font-size: 14px;
|
||||||
|
--ant-modal-header-margin-bottom: 26px;
|
||||||
|
--ant-modal-footer-margin-top: 30px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.css-var-ru.ant-btn {
|
||||||
|
--ant-button-content-font-size-lg: 13px;
|
||||||
|
--ant-button-content-font-size: 12px;
|
||||||
|
--ant-button-content-font-size-sm: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.css-var-rf.ant-menu-css-var {
|
.css-var-rf.ant-menu-css-var {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import type { SortOrder } from 'antd/es/table/interface';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
export default function useTableSort({
|
||||||
|
defaultSortOrder = 'descend'
|
||||||
|
}: {
|
||||||
|
defaultSortOrder?: SortOrder;
|
||||||
|
}) {
|
||||||
|
const [sortOrder, setSortOrder] = useState<SortOrder>(defaultSortOrder);
|
||||||
|
|
||||||
|
const handleSortChange = (order: SortOrder) => {
|
||||||
|
if (order) {
|
||||||
|
setSortOrder(order);
|
||||||
|
} else if (defaultSortOrder === 'descend') {
|
||||||
|
setSortOrder('ascend');
|
||||||
|
} else if (defaultSortOrder === 'ascend') {
|
||||||
|
setSortOrder('descend');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
sortOrder,
|
||||||
|
setSortOrder: handleSortChange
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import ModalFooter from '@/components/modal-footer';
|
||||||
|
import SealInput from '@/components/seal-form/seal-input';
|
||||||
|
import SealSelect from '@/components/seal-form/seal-select';
|
||||||
|
import { PageActionType } from '@/config/types';
|
||||||
|
import { Form, Modal } from 'antd';
|
||||||
|
|
||||||
|
type AddModalProps = {
|
||||||
|
title: string;
|
||||||
|
action: PageActionType;
|
||||||
|
open: boolean;
|
||||||
|
onOk: () => void;
|
||||||
|
onCancel: () => void;
|
||||||
|
};
|
||||||
|
const AddModal: React.FC<AddModalProps> = ({
|
||||||
|
title,
|
||||||
|
action,
|
||||||
|
open,
|
||||||
|
onOk,
|
||||||
|
onCancel
|
||||||
|
}) => {
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title={title}
|
||||||
|
open={open}
|
||||||
|
onOk={onOk}
|
||||||
|
onCancel={onCancel}
|
||||||
|
destroyOnClose={true}
|
||||||
|
closeIcon={false}
|
||||||
|
maskClosable={false}
|
||||||
|
keyboard={false}
|
||||||
|
width={600}
|
||||||
|
styles={{}}
|
||||||
|
footer={<ModalFooter onOk={onOk} onCancel={onCancel}></ModalFooter>}
|
||||||
|
>
|
||||||
|
<Form name="addModalForm" form={form} onFinish={onOk}>
|
||||||
|
<Form.Item name="displayName" rules={[{ required: true }]}>
|
||||||
|
<SealInput.Input label="Display Name"></SealInput.Input>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="catagory" rules={[{ required: true }]}>
|
||||||
|
<SealSelect label="Catagory"></SealSelect>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="name" rules={[{ required: true }]}>
|
||||||
|
<SealInput.Input label="Model Name"></SealInput.Input>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddModal;
|
||||||
+201
-80
@@ -1,8 +1,22 @@
|
|||||||
import PageTools from '@/components/page-tools';
|
import PageTools from '@/components/page-tools';
|
||||||
|
import { PageAction } from '@/config';
|
||||||
|
import type { PageActionType } from '@/config/types';
|
||||||
import useTableRowSelection from '@/hooks/use-table-row-selection';
|
import useTableRowSelection from '@/hooks/use-table-row-selection';
|
||||||
import { PlusOutlined, SyncOutlined } from '@ant-design/icons';
|
import useTableSort from '@/hooks/use-table-sort';
|
||||||
|
import { DeleteOutlined, PlusOutlined, SyncOutlined } from '@ant-design/icons';
|
||||||
import { PageContainer } from '@ant-design/pro-components';
|
import { PageContainer } from '@ant-design/pro-components';
|
||||||
import { Button, Input, Progress, Space, Table } from 'antd';
|
import {
|
||||||
|
Button,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Progress,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tooltip,
|
||||||
|
message
|
||||||
|
} from 'antd';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import AddModal from './components/add-modal';
|
||||||
const { Column } = Table;
|
const { Column } = Table;
|
||||||
|
|
||||||
const dataSource = [
|
const dataSource = [
|
||||||
@@ -13,7 +27,7 @@ const dataSource = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: '2',
|
key: '2',
|
||||||
name: 'meta-llama/Meta-Llama-3-8B',
|
name: 'meta-llama/Meta-Llama-3-8B-nksrlsl-esLscs-1:latest',
|
||||||
createTime: '2021-09-01 12:00:00'
|
createTime: '2021-09-01 12:00:00'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -23,86 +37,193 @@ const dataSource = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const columns = [
|
const Models: React.FC = () => {
|
||||||
{
|
|
||||||
title: '姓名',
|
|
||||||
dataIndex: 'name',
|
|
||||||
key: 'name'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '年龄',
|
|
||||||
dataIndex: 'age',
|
|
||||||
key: 'age'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '住址',
|
|
||||||
dataIndex: 'address',
|
|
||||||
key: 'address'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const Dashboard: React.FC = () => {
|
|
||||||
const rowSelection = useTableRowSelection();
|
const rowSelection = useTableRowSelection();
|
||||||
|
const { sortOrder, setSortOrder } = useTableSort({
|
||||||
|
defaultSortOrder: 'descend'
|
||||||
|
});
|
||||||
|
const [total, setTotal] = useState(100);
|
||||||
|
const [openAddModal, setOpenAddModal] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [action, setAction] = useState<PageActionType>(PageAction.CREATE);
|
||||||
|
const [title, setTitle] = useState<string>('');
|
||||||
|
const [queryParams, setQueryParams] = useState({
|
||||||
|
current: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
name: ''
|
||||||
|
});
|
||||||
|
const handleShowSizeChange = (current: number, size: number) => {
|
||||||
|
console.log(current, size);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageChange = (page: number, pageSize: number | undefined) => {
|
||||||
|
console.log(page, pageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTableChange = (pagination: any, filters: any, sorter: any) => {
|
||||||
|
console.log('handleTableChange=======', pagination, filters, sorter);
|
||||||
|
setSortOrder(sorter.order);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchData = async () => {
|
||||||
|
console.log('fetchData');
|
||||||
|
};
|
||||||
|
const handleSearch = (e: any) => {
|
||||||
|
fetchData();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNameChange = (e: any) => {
|
||||||
|
setQueryParams({
|
||||||
|
...queryParams,
|
||||||
|
name: e.target.value
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAddModal = () => {
|
||||||
|
setOpenAddModal(true);
|
||||||
|
setAction(PageAction.CREATE);
|
||||||
|
setTitle('Import Module');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClickMenu = (e: any) => {
|
||||||
|
console.log('click', e);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalOk = () => {
|
||||||
|
console.log('handleModalOk');
|
||||||
|
setOpenAddModal(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalCancel = () => {
|
||||||
|
console.log('handleModalCancel');
|
||||||
|
setOpenAddModal(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '',
|
||||||
|
content: 'Are you sure you want to delete the selected models?',
|
||||||
|
onOk() {
|
||||||
|
console.log('OK');
|
||||||
|
message.success('successfully!');
|
||||||
|
},
|
||||||
|
onCancel() {
|
||||||
|
console.log('Cancel');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<>
|
||||||
ghost
|
<PageContainer
|
||||||
header={{
|
ghost
|
||||||
title: 'Dashboard'
|
header={{
|
||||||
}}
|
title: 'Models'
|
||||||
extra={[]}
|
}}
|
||||||
>
|
extra={[]}
|
||||||
<PageTools
|
>
|
||||||
marginBottom={22}
|
<PageTools
|
||||||
left={
|
marginBottom={22}
|
||||||
<Space>
|
left={
|
||||||
<Input placeholder="按名称查询" style={{ width: 300 }}></Input>
|
<Space>
|
||||||
<Button
|
<Input
|
||||||
type="text"
|
placeholder="按名称查询"
|
||||||
style={{ color: 'var(--ant-color-primary)' }}
|
style={{ width: 300 }}
|
||||||
icon={<SyncOutlined></SyncOutlined>}
|
onChange={handleNameChange}
|
||||||
></Button>
|
></Input>
|
||||||
</Space>
|
<Button
|
||||||
}
|
type="text"
|
||||||
right={
|
style={{ color: 'var(--ant-color-primary)' }}
|
||||||
<div>
|
onClick={handleSearch}
|
||||||
<Button icon={<PlusOutlined></PlusOutlined>} type="primary">
|
icon={<SyncOutlined></SyncOutlined>}
|
||||||
Import Module
|
></Button>
|
||||||
</Button>
|
</Space>
|
||||||
</div>
|
}
|
||||||
}
|
right={
|
||||||
></PageTools>
|
<Space size={20}>
|
||||||
<Table dataSource={dataSource} rowSelection={rowSelection}>
|
<Button
|
||||||
<Column
|
icon={<PlusOutlined></PlusOutlined>}
|
||||||
title="Model Name"
|
type="primary"
|
||||||
dataIndex="name"
|
onClick={handleAddModal}
|
||||||
key="name"
|
>
|
||||||
render={(text, record) => {
|
Import Module
|
||||||
return (
|
</Button>
|
||||||
<>
|
<Button
|
||||||
<span>{text}</span>
|
icon={<DeleteOutlined />}
|
||||||
<Progress percent={30} strokeColor="var(--ant-color-primary)" />
|
danger
|
||||||
</>
|
onClick={handleDelete}
|
||||||
);
|
disabled={!rowSelection.selectedRowKeys.length}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
></PageTools>
|
||||||
|
<Table
|
||||||
|
dataSource={dataSource}
|
||||||
|
rowSelection={rowSelection}
|
||||||
|
loading={loading}
|
||||||
|
onChange={handleTableChange}
|
||||||
|
pagination={{
|
||||||
|
showSizeChanger: true,
|
||||||
|
pageSize: 10,
|
||||||
|
current: 2,
|
||||||
|
total: total,
|
||||||
|
hideOnSinglePage: true,
|
||||||
|
onShowSizeChange: handleShowSizeChange,
|
||||||
|
onChange: handlePageChange
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
<Column
|
<Column
|
||||||
title="Create Time"
|
title="Model Name"
|
||||||
dataIndex="createTime"
|
dataIndex="name"
|
||||||
key="createTime"
|
key="name"
|
||||||
defaultSortOrder="descend"
|
width={400}
|
||||||
sortOrder="descend"
|
render={(text, record) => {
|
||||||
sorter={(a, b) => a.createTime - b.createTime}
|
return (
|
||||||
/>
|
<>
|
||||||
<Column
|
<Tooltip>{text}</Tooltip>
|
||||||
title="Operation"
|
<Progress
|
||||||
key="operation"
|
percent={30}
|
||||||
render={(text, record) => {
|
strokeColor="var(--ant-color-primary)"
|
||||||
return <Button size="middle">Open in PlayGround</Button>;
|
/>
|
||||||
}}
|
</>
|
||||||
/>
|
);
|
||||||
</Table>
|
}}
|
||||||
</PageContainer>
|
/>
|
||||||
|
<Column
|
||||||
|
title="Create Time"
|
||||||
|
dataIndex="createTime"
|
||||||
|
key="createTime"
|
||||||
|
defaultSortOrder="descend"
|
||||||
|
sortOrder={sortOrder}
|
||||||
|
showSorterTooltip={false}
|
||||||
|
sorter={true}
|
||||||
|
/>
|
||||||
|
<Column
|
||||||
|
title="Operation"
|
||||||
|
key="operation"
|
||||||
|
render={(text, record) => {
|
||||||
|
return (
|
||||||
|
<Space>
|
||||||
|
<Button size="middle">Open in PlayGround</Button>
|
||||||
|
<Button size="middle" danger>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Table>
|
||||||
|
</PageContainer>
|
||||||
|
<AddModal
|
||||||
|
open={openAddModal}
|
||||||
|
action={action}
|
||||||
|
title={title}
|
||||||
|
onCancel={handleModalCancel}
|
||||||
|
onOk={handleModalOk}
|
||||||
|
></AddModal>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dashboard;
|
export default Models;
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ const ParamsSettings: React.FC<{ onClose: () => void }> = ({ onClose }) => {
|
|||||||
>
|
>
|
||||||
<SealInput.Input
|
<SealInput.Input
|
||||||
label="Seed"
|
label="Seed"
|
||||||
disabled={true}
|
|
||||||
style={{ width: INPUT_WIDTH.default }}
|
style={{ width: INPUT_WIDTH.default }}
|
||||||
></SealInput.Input>
|
></SealInput.Input>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -72,11 +71,7 @@ const ParamsSettings: React.FC<{ onClose: () => void }> = ({ onClose }) => {
|
|||||||
name="select"
|
name="select"
|
||||||
rules={[{ required: true }]}
|
rules={[{ required: true }]}
|
||||||
>
|
>
|
||||||
<SealSelect
|
<SealSelect label="Select" style={{ width: INPUT_WIDTH.default }}>
|
||||||
label="Select"
|
|
||||||
disabled={true}
|
|
||||||
style={{ width: INPUT_WIDTH.default }}
|
|
||||||
>
|
|
||||||
<Select.Option value={1}>1</Select.Option>
|
<Select.Option value={1}>1</Select.Option>
|
||||||
<Select.Option value={2}>2</Select.Option>
|
<Select.Option value={2}>2</Select.Option>
|
||||||
<Select.Option value={3}>3</Select.Option>
|
<Select.Option value={3}>3</Select.Option>
|
||||||
|
|||||||
Reference in New Issue
Block a user