|
|
@@ -31,9 +31,6 @@ export default function DockerControl({
|
|
|
const [containers, setContainers] = useState<Record<string, ContainerStatus>>({});
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
- const [selectedContainer, setSelectedContainer] = useState<string | null>(null);
|
|
|
- const [logs, setLogs] = useState<string>('');
|
|
|
- const [logsLines, setLogsLines] = useState(100);
|
|
|
|
|
|
const fetchStatus = async () => {
|
|
|
setLoading(true);
|
|
|
@@ -101,29 +98,6 @@ export default function DockerControl({
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const fetchLogs = async (containerName: string) => {
|
|
|
- setLoading(true);
|
|
|
- setError(null);
|
|
|
- try {
|
|
|
- const url = serverId ? '/api/remote/server/docker/logs' : '/api/remote/docker/logs';
|
|
|
- const payload = serverId
|
|
|
- ? { server_id: serverId, container_name: containerName, lines: logsLines, follow: false, project_path: projectPath }
|
|
|
- : { ...serverConfig, container_name: containerName, lines: logsLines, follow: false, project_path: projectPath };
|
|
|
-
|
|
|
- const response = await api.post(url, payload);
|
|
|
- if (response.data.code === 0) {
|
|
|
- setLogs(response.data.data.logs || '');
|
|
|
- setSelectedContainer(containerName);
|
|
|
- } else {
|
|
|
- setError(response.data.message || '获取日志失败');
|
|
|
- }
|
|
|
- } catch (err: any) {
|
|
|
- setError(err.response?.data?.message || err.message || '获取日志失败');
|
|
|
- } finally {
|
|
|
- setLoading(false);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
return (
|
|
|
<div className="space-y-6">
|
|
|
{/* 操作栏 */}
|
|
|
@@ -228,14 +202,6 @@ export default function DockerControl({
|
|
|
>
|
|
|
<RotateCw size={16} />
|
|
|
</button>
|
|
|
- <button
|
|
|
- onClick={() => fetchLogs(name)}
|
|
|
- disabled={loading}
|
|
|
- className="p-1.5 text-slate-600 hover:bg-slate-100 rounded transition-colors disabled:opacity-50"
|
|
|
- title="查看日志"
|
|
|
- >
|
|
|
- <FileText size={16} />
|
|
|
- </button>
|
|
|
</div>
|
|
|
</td>
|
|
|
</tr>
|
|
|
@@ -297,49 +263,12 @@ export default function DockerControl({
|
|
|
<span className="text-[10px]">重启</span>
|
|
|
</button>
|
|
|
</div>
|
|
|
- <button
|
|
|
- onClick={() => fetchLogs(name)}
|
|
|
- disabled={loading}
|
|
|
- className="flex flex-col items-center gap-1 text-slate-600 disabled:opacity-30"
|
|
|
- >
|
|
|
- <FileText size={18} />
|
|
|
- <span className="text-[10px]">日志</span>
|
|
|
- </button>
|
|
|
</div>
|
|
|
</div>
|
|
|
))
|
|
|
)}
|
|
|
</div>
|
|
|
</div>
|
|
|
-
|
|
|
- {/* 日志查看 */}
|
|
|
- {selectedContainer && (
|
|
|
- <div className="bg-slate-900 rounded-lg border border-slate-200 p-4">
|
|
|
- <div className="flex items-center justify-between mb-3">
|
|
|
- <h4 className="text-sm font-semibold text-white">
|
|
|
- 容器日志: {selectedContainer}
|
|
|
- </h4>
|
|
|
- <div className="flex items-center gap-2">
|
|
|
- <input
|
|
|
- type="number"
|
|
|
- value={logsLines}
|
|
|
- onChange={(e) => setLogsLines(parseInt(e.target.value) || 100)}
|
|
|
- className="w-20 px-2 py-1 bg-slate-800 text-white text-sm rounded border border-slate-700"
|
|
|
- placeholder="行数"
|
|
|
- />
|
|
|
- <button
|
|
|
- onClick={() => fetchLogs(selectedContainer)}
|
|
|
- className="px-3 py-1 bg-blue-600 text-white text-sm rounded hover:bg-blue-700"
|
|
|
- >
|
|
|
- 刷新
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <pre className="text-xs text-green-400 font-mono overflow-x-auto max-h-96 overflow-y-auto whitespace-pre-wrap">
|
|
|
- {logs || '暂无日志'}
|
|
|
- </pre>
|
|
|
- </div>
|
|
|
- )}
|
|
|
</div>
|
|
|
);
|
|
|
}
|