feat: 模型管理
This commit is contained in:
@@ -15,8 +15,9 @@ export default {
|
|||||||
// localhost:8000/api/** -> https://preview.pro.ant.design/api/**
|
// localhost:8000/api/** -> https://preview.pro.ant.design/api/**
|
||||||
'/admin-api/': {
|
'/admin-api/': {
|
||||||
// http://192.168.1.231:48080 伟强
|
// http://192.168.1.231:48080 伟强
|
||||||
|
// http://192.168.1.89:48086 子杰
|
||||||
// https://petshy.tashowz.com/
|
// https://petshy.tashowz.com/
|
||||||
target: 'https://petshy.tashowz.com/ ',
|
target: 'http://192.168.1.89:48086',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
126
src/pages/ai/model/config.tsx
Normal file
126
src/pages/ai/model/config.tsx
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
import type {
|
||||||
|
ProColumns,
|
||||||
|
ProCoreActionType,
|
||||||
|
ProFormColumnsType,
|
||||||
|
} from '@ant-design/pro-components';
|
||||||
|
import { Modal, message, Switch } from 'antd';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { type AiModelRespVO, updateModelStatus } from '@/services/ai/model';
|
||||||
|
|
||||||
|
export const baseDeptColumns: ProColumns<AiModelRespVO>[] = [
|
||||||
|
{
|
||||||
|
title: '模型名称',
|
||||||
|
dataIndex: 'modelName',
|
||||||
|
hideInSearch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '版本号',
|
||||||
|
dataIndex: 'version',
|
||||||
|
hideInSearch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '负载',
|
||||||
|
dataIndex: 'loadPercentage',
|
||||||
|
hideInSearch: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
valueType: 'switch',
|
||||||
|
hideInSearch: true,
|
||||||
|
render: (
|
||||||
|
_,
|
||||||
|
record: AiModelRespVO,
|
||||||
|
_index: number,
|
||||||
|
action: ProCoreActionType | undefined,
|
||||||
|
) => (
|
||||||
|
<Switch
|
||||||
|
checked={record.status === 1}
|
||||||
|
checkedChildren="禁用"
|
||||||
|
unCheckedChildren="启用"
|
||||||
|
onChange={(checked) => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认操作',
|
||||||
|
content: `确认要"${checked ? '启用' : '禁用'}${
|
||||||
|
record.modelName
|
||||||
|
}"类目吗?`,
|
||||||
|
onOk: async () => {
|
||||||
|
console.log(checked);
|
||||||
|
await updateModelStatus({
|
||||||
|
status: checked ? 1 : 0,
|
||||||
|
id: record.id,
|
||||||
|
});
|
||||||
|
message.success('修改成功');
|
||||||
|
action?.reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
valueType: 'dateRange',
|
||||||
|
hideInSearch: true,
|
||||||
|
render: (_, record: AiModelRespVO) =>
|
||||||
|
dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const formColumns = (_type: string): ProFormColumnsType[] => [
|
||||||
|
{
|
||||||
|
title: '模型名称',
|
||||||
|
dataIndex: 'modelName',
|
||||||
|
formItemProps: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入模型名称',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '版本号',
|
||||||
|
dataIndex: 'version',
|
||||||
|
valueType: 'text',
|
||||||
|
formItemProps: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入部门名称',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '负载',
|
||||||
|
dataIndex: 'loadPercentage',
|
||||||
|
valueType: 'digit',
|
||||||
|
fieldProps: {
|
||||||
|
min: 0,
|
||||||
|
},
|
||||||
|
formItemProps: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入显示顺序',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
valueType: 'switch',
|
||||||
|
fieldProps: {
|
||||||
|
checkedChildren: '禁用',
|
||||||
|
unCheckedChildren: '启用',
|
||||||
|
defaultChecked: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
131
src/pages/ai/model/index.tsx
Normal file
131
src/pages/ai/model/index.tsx
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
|
import { message, Popconfirm } from 'antd';
|
||||||
|
import React, { useCallback, useRef, useState } from 'react';
|
||||||
|
import ConfigurableDrawerForm, {
|
||||||
|
type ConfigurableDrawerFormRef,
|
||||||
|
} from '@/components/DrawerForm';
|
||||||
|
import EnhancedProTable from '@/components/EnhancedProTable';
|
||||||
|
import type { ToolbarAction } from '@/components/EnhancedProTable/types';
|
||||||
|
import { formStatusType } from '@/constants';
|
||||||
|
import {
|
||||||
|
type AiModelRespVO,
|
||||||
|
createModel,
|
||||||
|
delModel,
|
||||||
|
getModelList,
|
||||||
|
updateModel,
|
||||||
|
updateModelStatus,
|
||||||
|
} from '@/services/ai/model';
|
||||||
|
import { baseDeptColumns, formColumns } from './config';
|
||||||
|
|
||||||
|
const ModelPage = () => {
|
||||||
|
const configurableDrawerRef = useRef<ConfigurableDrawerFormRef>(null);
|
||||||
|
const tableRef = useRef<ActionType>(null);
|
||||||
|
|
||||||
|
const [type, setType] = useState<'create' | 'update'>('create');
|
||||||
|
const [id, setId] = useState<number>(0);
|
||||||
|
|
||||||
|
const handleEdit = (record: AiModelRespVO) => {
|
||||||
|
setType('update');
|
||||||
|
setId(record.id as number);
|
||||||
|
configurableDrawerRef.current?.open(record);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onFetch = async (params: { pageSize?: number; current?: number }) => {
|
||||||
|
const data = await getModelList(params);
|
||||||
|
return {
|
||||||
|
data: data.list,
|
||||||
|
success: true,
|
||||||
|
total: data.total,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
setType('create');
|
||||||
|
configurableDrawerRef.current?.open({ status: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = useCallback(
|
||||||
|
async (values: AiModelRespVO) => {
|
||||||
|
if (type === 'create') {
|
||||||
|
console.log('values', values);
|
||||||
|
await createModel({ ...values, status: values.status ? 1 : 0 });
|
||||||
|
} else {
|
||||||
|
await updateModel({
|
||||||
|
...values,
|
||||||
|
status: values.status ? 1 : 0,
|
||||||
|
id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
tableRef.current?.reload();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
[type, id],
|
||||||
|
);
|
||||||
|
|
||||||
|
const toolbarActions: ToolbarAction[] = [
|
||||||
|
{
|
||||||
|
key: 'add',
|
||||||
|
label: '新建',
|
||||||
|
type: 'primary',
|
||||||
|
icon: <PlusOutlined />,
|
||||||
|
onClick: handleAdd,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const actionColumns: ProColumns<AiModelRespVO> = {
|
||||||
|
title: '操作',
|
||||||
|
dataIndex: 'option',
|
||||||
|
valueType: 'option',
|
||||||
|
fixed: 'right',
|
||||||
|
width: 120,
|
||||||
|
render: (
|
||||||
|
_text: React.ReactNode,
|
||||||
|
record: AiModelRespVO,
|
||||||
|
_: any,
|
||||||
|
action: any,
|
||||||
|
) => [
|
||||||
|
<a key="editable" onClick={() => handleEdit(record)}>
|
||||||
|
编辑
|
||||||
|
</a>,
|
||||||
|
<Popconfirm
|
||||||
|
title="是否删除?"
|
||||||
|
key="delete"
|
||||||
|
onConfirm={async () => {
|
||||||
|
await delModel(record.id as number);
|
||||||
|
message.success('删除成功');
|
||||||
|
action?.reload();
|
||||||
|
}}
|
||||||
|
okText="是"
|
||||||
|
cancelText="否"
|
||||||
|
>
|
||||||
|
<a>删除</a>
|
||||||
|
</Popconfirm>,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns = [...baseDeptColumns, actionColumns];
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<EnhancedProTable<AiModelRespVO>
|
||||||
|
ref={tableRef}
|
||||||
|
columns={columns}
|
||||||
|
request={onFetch}
|
||||||
|
toolbarActions={toolbarActions}
|
||||||
|
headerTitle="租户列表"
|
||||||
|
showIndex={false}
|
||||||
|
showSelection={false}
|
||||||
|
search={false}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ConfigurableDrawerForm
|
||||||
|
ref={configurableDrawerRef}
|
||||||
|
title={formStatusType[type]}
|
||||||
|
columns={formColumns(type)}
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ModelPage;
|
||||||
74
src/services/ai/model/index.tsx
Normal file
74
src/services/ai/model/index.tsx
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* 返回数据
|
||||||
|
*
|
||||||
|
* AiModelRespVO
|
||||||
|
*/
|
||||||
|
export interface AiModelRespVO {
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
createTime?: string;
|
||||||
|
/**
|
||||||
|
* 版本描述
|
||||||
|
*/
|
||||||
|
description?: string;
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
id?: number;
|
||||||
|
/**
|
||||||
|
* 负载
|
||||||
|
*/
|
||||||
|
loadPercentage?: number;
|
||||||
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
|
modelName?: string;
|
||||||
|
/**
|
||||||
|
* 状态(0-禁用 1-启用 2-测试中 3-已废弃)
|
||||||
|
*/
|
||||||
|
status?: number;
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
updateTime?: string;
|
||||||
|
/**
|
||||||
|
* 版本号
|
||||||
|
*/
|
||||||
|
version?: string;
|
||||||
|
}
|
||||||
|
import { request } from "@umijs/max";
|
||||||
|
export const getModelList = async (params: PageParam) => {
|
||||||
|
return request("/ai/model/page", {
|
||||||
|
method: "GET",
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createModel = async (params: AiModelRespVO) => {
|
||||||
|
return request("/ai/model/create", {
|
||||||
|
method: "POST",
|
||||||
|
data: params,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateModel = async (params: AiModelRespVO) => {
|
||||||
|
return request("/ai/model/update", {
|
||||||
|
method: "PUT",
|
||||||
|
data: params,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const delModel = async (id: number) => {
|
||||||
|
return request("/ai/model/delete", {
|
||||||
|
method: "DELETE",
|
||||||
|
params: { id },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateModelStatus = async (params: AiModelRespVO) => {
|
||||||
|
return request("/ai/model/update-status", {
|
||||||
|
method: "PUT",
|
||||||
|
params: params,
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user