diff --git a/src/api/componentInstance.ts b/src/api/componentInstance.ts index 097672a..d9f7d74 100644 --- a/src/api/componentInstance.ts +++ b/src/api/componentInstance.ts @@ -36,4 +36,14 @@ export function getInstanceLog(params) { // 组件实例列表 export function getInstanceList(params, identifier) { return axios.get(`${urlPrefix}/componentInstance/list/${identifier}`, { params }); +} + +// 获取组件环境配置 +export function getComponentEnvConfig(instanceId) { + return axios.get(`${urlPrefix}/componentInstance/config/${instanceId}`); +} + +// 保存组件环境配置 +export function saveComponentEnvConfig(instanceId, params) { + return axios.post(`${urlPrefix}/componentInstance/config/${instanceId}`, params); } \ No newline at end of file diff --git a/src/pages/componentDevelopment/componentDeployment/envConfigModal.tsx b/src/pages/componentDevelopment/componentDeployment/envConfigModal.tsx new file mode 100644 index 0000000..dbbd7e6 --- /dev/null +++ b/src/pages/componentDevelopment/componentDeployment/envConfigModal.tsx @@ -0,0 +1,250 @@ +import React, { useState, useEffect } from 'react'; +import { Modal, Button, Input, Message, Tooltip } from '@arco-design/web-react'; +import { IconQuestionCircle, IconCopy, IconDelete, IconPlus } from '@arco-design/web-react/icon'; +import styles from './style/envConfigModal.module.less'; +import { getComponentEnvConfig, saveComponentEnvConfig } from '@/api/componentInstance'; + +interface EnvConfigModalProps { + language: string; + visible: boolean; + instanceId: string; + onCancel: () => void; + onSuccess?: () => void; +} + +interface ConfigItem { + name: string; + key: string; + value: string; + desc: string; + unmodifiable?: boolean; + isCustom?: boolean; // 标记是否为用户自定义添加的 +} + +const EnvConfigModal: React.FC = ({ + language, + visible, + instanceId, + onCancel, + onSuccess + }) => { + const [loading, setLoading] = useState(false); + const [saveLoading, setSaveLoading] = useState(false); + const [configData, setConfigData] = useState(null); + const [configList, setConfigList] = useState([]); + + useEffect(() => { + if (visible && instanceId) { + fetchEnvConfig(); + } + }, [visible, instanceId]); + + const fetchEnvConfig = async () => { + try { + setLoading(true); + const res: any = await getComponentEnvConfig(instanceId); + if (res.code === 200) { + setConfigData(res.data); + setConfigList(res.data.config || []); + } + else { + Message.error(res.msg || '获取环境配置失败'); + } + } catch (error) { + console.error('获取环境配置失败:', error); + Message.error('获取环境配置失败'); + } finally { + setLoading(false); + } + }; + + const handleConfigChange = (index: number, field: keyof ConfigItem, value: string) => { + const newConfigList = [...configList]; + newConfigList[index][field] = value; + setConfigList(newConfigList); + }; + + // 添加新配置行 + const handleAddConfig = () => { + const newConfig: ConfigItem = { + name: '', + key: '', + value: '', + desc: '', + isCustom: true + }; + setConfigList([...configList, newConfig]); + }; + + // 删除配置行 + const handleDeleteConfig = (index: number) => { + const newConfigList = configList.filter((_, i) => i !== index); + setConfigList(newConfigList); + }; + + const handleCopyCommand = () => { + if (configData?.javaCommand) { + navigator.clipboard.writeText(configData.javaCommand); + Message.success('复制成功'); + } + }; + + const handleSave = async () => { + try { + setSaveLoading(true); + const params = { + ...configData, + config: configList + }; + const res: any = await saveComponentEnvConfig(instanceId, params); + if (res.code === 200) { + Message.success('保存成功'); + onSuccess?.(); + onCancel(); + } + else { + Message.error(res.msg || '保存失败'); + } + } catch (error) { + console.error('保存失败:', error); + Message.error('保存失败'); + } finally { + setSaveLoading(false); + } + }; + + return ( + + + + + } + > +
+ {loading ? ( +
+
+

正在加载配置信息...

+
+ ) : ( + <> + {/* 命令展示 */} + {configData?.javaCommand && ( +
+
+ +
+
+ {language.includes('Python') ? configData.pythonCommand : configData.javaCommand} +
+
+ 本地点击"复制命令"按钮可以复制上方命令 +
+
+ )} + + {/* 配置表格 */} +
+
+
#
+
+ * + 启动名称 +
+
+ * + 参数名(key) +
+
配置值
+
描述说明
+
操作
+
+ +
+ {configList.map((item, index) => ( +
+
{index + 1}
+
+ handleConfigChange(index, 'name', value)} + placeholder="请输入启动名称" + size="small" + /> +
+
+ handleConfigChange(index, 'key', value)} + placeholder="请输入参数名" + size="small" + /> +
+
+ handleConfigChange(index, 'value', value)} + placeholder="请输入配置值" + size="small" + /> +
+
+ handleConfigChange(index, 'desc', value)} + placeholder="请输入描述说明" + size="small" + /> +
+
+ {item.isCustom && ( + + )} +
+
+ ))} +
+ + {/* 添加新配置按钮 */} +
+ +
+
+ + )} +
+
+ ); +}; + +export default EnvConfigModal; diff --git a/src/pages/componentDevelopment/componentDeployment/listNode.tsx b/src/pages/componentDevelopment/componentDeployment/listNode.tsx index 38dcf3d..62d0f2c 100644 --- a/src/pages/componentDevelopment/componentDeployment/listNode.tsx +++ b/src/pages/componentDevelopment/componentDeployment/listNode.tsx @@ -24,6 +24,7 @@ import { import { runStatusConstant, runStatusDic, runTypeConstant, runTypeDic } from '@/const/isdp/componentDeploy'; import dayjs from 'dayjs'; import EditInstanceModal from './editInstanceModal'; +import EnvConfigModal from './envConfigModal'; const { RangePicker } = DatePicker; const { TextArea } = Input; @@ -52,8 +53,13 @@ const ListNode: React.FC = ({ componentData }) => { const [editModalVisible, setEditModalVisible] = useState(false); const [editingInstance, setEditingInstance] = useState(null); + // 环境配置 Modal 相关状态 + const [envModalVisible, setEnvModalVisible] = useState(false); + const [envInstanceId, setEnvInstanceId] = useState(''); + // 获取实例列表 const fetchInstanceList = async () => { + console.log("componentData:",componentData); if (!componentData?.identifier) return; setLoading(true); @@ -276,6 +282,23 @@ const ListNode: React.FC = ({ componentData }) => { setEditingInstance(null); }; + // 打开环境配置 Modal + const handleOpenEnvConfig = (record: any) => { + setEnvInstanceId(record.id); + setEnvModalVisible(true); + }; + + // 关闭环境配置 Modal + const handleEnvConfigCancel = () => { + setEnvModalVisible(false); + setEnvInstanceId(''); + }; + + // 环境配置保存成功回调 + const handleEnvConfigSuccess = () => { + fetchInstanceList(); // 刷新列表 + }; + const columns: TableColumnProps[] = [ { title: '#', @@ -340,7 +363,9 @@ const ListNode: React.FC = ({ componentData }) => { 刷新依赖 - + {!isRunning && ( + + )}