import { getLeafNodes } from '@/utils/utils'; import { PlusOutlined } from '@ant-design/icons'; import { Button, Input, message, Popconfirm, Select, Table, Tag } from 'antd'; import moment from 'moment'; import { useEffect, useState } from 'react'; import { PLUGIN_TYPE_MAP } from './constants'; import DetailModal from './DetailModal'; import { deletePlugin, getModelList, getPluginList } from './service'; import styles from './style.less'; import { ModelType, PluginType, PluginTypeEnum } from './type'; const { Search } = Input; const PluginManage = () => { const [name, setName] = useState(); const [type, setType] = useState(); const [pattern, setPattern] = useState(); const [model, setModel] = useState(); const [data, setData] = useState([]); const [modelList, setModelList] = useState([]); const [loading, setLoading] = useState(false); const [currentPluginDetail, setCurrentPluginDetail] = useState(); const [detailModalVisible, setDetailModalVisible] = useState(false); const initModelList = async () => { const res = await getModelList(); setModelList(getLeafNodes(res.data)); }; const updateData = async (filters?: any) => { setLoading(true); const res = await getPluginList({ name, type, pattern, model, ...(filters || {}) }); setLoading(false); setData(res.data?.map((item) => ({ ...item, config: JSON.parse(item.config || '{}') })) || []); }; useEffect(() => { initModelList(); updateData(); }, []); const onCheckPluginDetail = (record: PluginType) => { setCurrentPluginDetail(record); setDetailModalVisible(true); }; const onDeletePlugin = async (record: PluginType) => { await deletePlugin(record.id); message.success('插件删除成功'); updateData(); }; const columns: any[] = [ { title: '插件名称', dataIndex: 'name', key: 'name', }, { title: '数据集', dataIndex: 'dataSetList', key: 'dataSetList', width: 200, render: (value: number[]) => { if (value?.includes(-1)) { return '默认'; } return value ? (
{value.map((id) => { const name = modelList.find((model) => model.id === id)?.name; return name ? {name} : null; })}
) : ( '-' ); }, }, { title: '插件类型', dataIndex: 'type', key: 'type', render: (value: string) => { return ( {PLUGIN_TYPE_MAP[value]} ); }, }, { title: '函数描述', dataIndex: 'pattern', key: 'pattern', width: 450, }, { title: '更新人', dataIndex: 'updatedBy', key: 'updatedBy', render: (value: string) => { return value || '-'; }, }, { title: '更新时间', dataIndex: 'updatedAt', key: 'updatedAt', render: (value: string) => { return value ? moment(value).format('YYYY-MM-DD HH:mm') : '-'; }, }, { title: '操作', dataIndex: 'x', key: 'x', render: (_: any, record: any) => { return ( ); }, }, ]; const onModelChange = (value: string) => { setModel(value); updateData({ model: value }); }; const onTypeChange = (value: PluginTypeEnum) => { setType(value); updateData({ type: value }); }; const onSearch = () => { updateData(); }; const onCreatePlugin = () => { setCurrentPluginDetail(undefined); setDetailModalVisible(true); }; const onSavePlugin = () => { setDetailModalVisible(false); updateData(); }; return (
主题域
({ label: PLUGIN_TYPE_MAP[key], value: key, }))} value={type} allowClear onChange={onTypeChange} />
插件列表
{detailModalVisible && ( { setDetailModalVisible(false); }} /> )} ); }; export default PluginManage;