/* * @Author: donghao donghao@supervision.ltd * @Date: 2024-04-22 15:23:36 * @LastEditors: donghao donghao@supervision.ltd * @LastEditTime: 2024-06-19 11:42:02 * @FilePath: \general-ai-platform-web\src\pages\Business\DeviceGroup\components\deviceList.tsx * @Description: 设备节点设置 关键词 deviceGroup(dg) * @交互说明 * 1、设备列表:分页展示、新建、编辑、删除 * 2、基础模型配置:参数配置 * 3、设备分类:分类标记不可删除 * 待定: * 是否需要编辑 */ import InnerPageBack from '@/components/Back/innerPageBack'; import TableActionCard from '@/components/TableActionCard'; import { apiDeviceClassification, apiDeviceClassificationAdd, apiDeviceClassificationDelete, } from '@/services/business/device'; import { apiEntityNodesDeviceDelete, apiEntityNodesDeviceInfo, apiEntityNodesDeviceList, } from '@/services/business/entity'; import { isSuccessApi } from '@/utils/forApi'; import { ProTable } from '@ant-design/pro-components'; import { Access, FormattedMessage, history, useAccess, useIntl } from '@umijs/max'; import { Button, message } from 'antd'; import React, { useEffect, useRef, useState } from 'react'; import { proTablePaginationOptions } from '../../../../../config/defaultTable'; import CategorizeUpdate from '@/components/CategorizeUpdate'; import IsDelete from '@/components/TableActionCard/isDelete'; import CreateDeviceForm from './createDeviceForm'; import UpdateDeviceForm from './updateDeviceForm'; import ModelSetting from './modelSetting'; type DeviceListProps = { commInfo: Record; nodeInfo: Record; }; const DeviceList: React.FC = (props) => { /**state */ const access = useAccess(); // eslint-disable-next-line react-hooks/rules-of-hooks const intl = useIntl(); const actionRef = useRef(); const [createModalOpen, setCreateModalOpen] = useState(false); const [updateModalOpen, setUpdateModalOpen] = useState(false); // 编辑窗口是否打开 const [currentRow, setCurrentRow] = useState>({}); // 动态设置每页数量 const [currentPageSize, setCurrentPageSize] = useState(10); // 设置分类 const [deviceTypeOpen, setDeviceTypeOpen] = useState(false); // 设置行业类别 const handleSetDeviceType = () => { setDeviceTypeOpen(!deviceTypeOpen); }; // 基础模型设置 isSettingOpen const [isSettingOpen, setIsSettingOpen] = useState(false); /**新增 编辑 删除 */ // 新增 const handleCreateModal = () => { setCreateModalOpen(!createModalOpen); }; // 编辑 const handleUpdateModal = () => { setUpdateModalOpen(!updateModalOpen); }; // 设备节点信息 async function loadDetail(record) { const resp = await apiEntityNodesDeviceInfo({ device_id: record?.id }); if (isSuccessApi(resp) && resp?.data) { setCurrentRow({ ...resp?.data, device_id: record?.id }); } } function reloadList() { actionRef.current?.reload(); } // 筛选查询 useEffect(() => { if (actionRef && props?.nodeInfo) { reloadList(); setIsSettingOpen(false); } }, [actionRef, props.nodeInfo]); const columns: ProColumns>[] = [ { title: , dataIndex: 'name', hideInSearch: true, // width: 80, // key: 'fixedName', // fixed: 'left', }, { title: ( ), dataIndex: 'classification', hideInSearch: true, // width: 120, }, // TODO 待定模型部署使用什么字段 { title: ( ), dataIndex: 'isEnable', hideInSearch: true, // width: 80, render: (dom, record) => { return (
{record.isEnable ? ( ) : ( )}
); }, }, { title: , dataIndex: 'option', valueType: 'option', fixed: 'right', key: 'option', render: (_, record) => [ { setCurrentRow({ ...record, device_id: record.id }); setIsSettingOpen(true); }} > ), }, { key: 'updateDetail', renderDom: ( ), }, { key: 'destroy', renderDom: ( { console.log('删除成功'); apiEntityNodesDeviceDelete({ device_id: record.id }).then(() => { message.success( intl.formatMessage({ id: 'common.action.success', defaultMessage: '$$$', }), ); reloadList(); }); }} > ), }, ]} >, ], }, ]; /**设备分类 */ return (
[
, ]} search={false} // scroll={{ y: proTableCommonOptions.commscrollY, x: proTableCommonOptions.commscrollX }} options={{ fullScreen: false, setting: false, density: false, reload: false }} actionRef={actionRef} rowKey="id" onDataSourceChange={(data) => { console.log(data, 'onDataSourceChange_data'); }} pagination={{ ...proTablePaginationOptions, pageSize: currentPageSize, onChange: (pageNo, pageSize) => setCurrentPageSize(pageSize), }} columnsState={{ persistenceKey: 'algorithm_model_list', persistenceType: 'localStorage', }} request={async (params = {}) => { const { current, ...rest } = params; const reqParams = { pageNo: current, node_id: props.nodeInfo.id, ...rest, }; if (!reqParams.node_id) { return { data: [], success: true }; } let resp = await apiEntityNodesDeviceList({ ...reqParams }); console.log(resp, 'apiEntityNodesDeviceList_resp'); return { data: resp.data?.data, success: resp.success, total: resp.data.count, current: current, pageSize: currentPageSize, }; }} columns={columns} /> {isSettingOpen ? ( <> { setIsSettingOpen(false); }} size={16} title="模型列表" > ) : ( <> )} { let resp = await apiDeviceClassification(); return { data: resp.data, }; }} beforeCloseRequest={async (params, successRes) => { let resp = await apiDeviceClassificationDelete({ id: params.id }); if (isSuccessApi(resp)) { successRes(resp); } else { message.error(resp.meta.message); } }} beforeAddRequest={async (params, successRes) => { let resp = await apiDeviceClassificationAdd({ name: params }); if (isSuccessApi(resp)) { successRes(resp); } else { message.error(resp.meta.message); } }} modalFormProps={{ categorizeFormProps: { label: ( ), name: 'deviceType', }, categorizeModelProps: { title: intl.formatMessage({ id: 'device_group_list.table.list.action.setDeviceType', defaultMessage: '新建', }), }, }} />
); }; export default DeviceList;