diff --git a/config/proxy.ts b/config/proxy.ts index e51e48a..8110d09 100644 --- a/config/proxy.ts +++ b/config/proxy.ts @@ -15,8 +15,9 @@ export default { // localhost:8000/api/** -> https://preview.pro.ant.design/api/** '/admin-api/': { // http://192.168.1.231:48080 伟强 + // http://192.168.1.89:48086 子杰 // https://petshy.tashowz.com/ - target: 'https://petshy.tashowz.com/ ', + target: 'http://192.168.1.89:48086', changeOrigin: true, }, }, diff --git a/src/pages/ai/model/config.tsx b/src/pages/ai/model/config.tsx new file mode 100644 index 0000000..d23d32e --- /dev/null +++ b/src/pages/ai/model/config.tsx @@ -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[] = [ + { + 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, + ) => ( + { + 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, + }, + }, +]; diff --git a/src/pages/ai/model/index.tsx b/src/pages/ai/model/index.tsx new file mode 100644 index 0000000..0735379 --- /dev/null +++ b/src/pages/ai/model/index.tsx @@ -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(null); + const tableRef = useRef(null); + + const [type, setType] = useState<'create' | 'update'>('create'); + const [id, setId] = useState(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: , + onClick: handleAdd, + }, + ]; + + const actionColumns: ProColumns = { + title: '操作', + dataIndex: 'option', + valueType: 'option', + fixed: 'right', + width: 120, + render: ( + _text: React.ReactNode, + record: AiModelRespVO, + _: any, + action: any, + ) => [ + handleEdit(record)}> + 编辑 + , + { + await delModel(record.id as number); + message.success('删除成功'); + action?.reload(); + }} + okText="是" + cancelText="否" + > + 删除 + , + ], + }; + + const columns = [...baseDeptColumns, actionColumns]; + return ( + <> + + ref={tableRef} + columns={columns} + request={onFetch} + toolbarActions={toolbarActions} + headerTitle="租户列表" + showIndex={false} + showSelection={false} + search={false} + /> + + + + ); +}; + +export default ModelPage; diff --git a/src/services/ai/model/index.tsx b/src/services/ai/model/index.tsx new file mode 100644 index 0000000..6963f04 --- /dev/null +++ b/src/services/ai/model/index.tsx @@ -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, + }); +};