2025-11-18 18:45:30 +08:00
|
|
|
// src/panels/views/ContainerView.ts
|
2025-11-18 09:10:47 +08:00
|
|
|
import { BaseView } from './BaseView';
|
|
|
|
|
import { AircraftConfigData, ContainerViewData } from '../types/ViewTypes';
|
|
|
|
|
|
2025-11-18 18:45:30 +08:00
|
|
|
export class ContainerView extends BaseView {
|
2025-11-18 09:10:47 +08:00
|
|
|
render(data?: AircraftConfigData): string {
|
|
|
|
|
const project = data?.project;
|
2025-11-21 16:07:48 +08:00
|
|
|
const aircraft = data?.aircraft; // 新增:获取飞行器数据
|
2025-11-18 09:10:47 +08:00
|
|
|
const containers = data?.containers || [];
|
|
|
|
|
|
|
|
|
|
// 生成容器列表的 HTML
|
|
|
|
|
const containersHtml = containers.map((container: ContainerViewData) => `
|
|
|
|
|
<tr>
|
|
|
|
|
<td>
|
|
|
|
|
<span class="editable" onclick="editContainerName('${container.id}', '${container.name}')">📦 ${container.name}</span>
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<span class="clickable" onclick="openContainerConfig('${container.id}')">配置文件</span>
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<button class="btn-delete" onclick="deleteContainer('${container.id}')">删除</button>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
`).join('');
|
|
|
|
|
|
|
|
|
|
return `<!DOCTYPE html>
|
|
|
|
|
<html lang="zh-CN">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2025-11-18 18:45:30 +08:00
|
|
|
<title>容器管理</title>
|
2025-11-18 09:10:47 +08:00
|
|
|
${this.getStyles()}
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="header">
|
2025-11-21 16:07:48 +08:00
|
|
|
<h2>📋 容器管理 - <span style="color: var(--vscode-textLink-foreground);">${aircraft?.name || '未知飞行器'}</span></h2>
|
2025-11-18 18:45:30 +08:00
|
|
|
<button class="back-btn" onclick="goBackToAircrafts()">← 返回飞行器管理</button>
|
2025-11-18 09:10:47 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<table class="table">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th width="40%">容器</th>
|
|
|
|
|
<th width="40%">配置文件</th>
|
|
|
|
|
<th width="20%">操作</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
${containersHtml}
|
|
|
|
|
<tr>
|
|
|
|
|
<td colspan="3" style="text-align: center; padding: 20px;">
|
|
|
|
|
<button class="btn-new" onclick="createNewContainer()">+ 新建容器</button>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
const vscode = acquireVsCodeApi();
|
|
|
|
|
|
|
|
|
|
function editContainerName(containerId, currentName) {
|
|
|
|
|
showPromptDialog(
|
|
|
|
|
'修改容器名称',
|
|
|
|
|
'请输入新的容器名称:',
|
|
|
|
|
currentName,
|
|
|
|
|
function(newName) {
|
|
|
|
|
if (newName && newName !== currentName) {
|
|
|
|
|
vscode.postMessage({
|
|
|
|
|
type: 'updateContainerName',
|
|
|
|
|
containerId: containerId,
|
|
|
|
|
name: newName
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openContainerConfig(containerId) {
|
|
|
|
|
vscode.postMessage({
|
|
|
|
|
type: 'openContainerConfig',
|
|
|
|
|
containerId: containerId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createNewContainer() {
|
|
|
|
|
showPromptDialog(
|
|
|
|
|
'新建容器',
|
|
|
|
|
'请输入容器名称:',
|
|
|
|
|
'',
|
|
|
|
|
function(name) {
|
|
|
|
|
if (name) {
|
|
|
|
|
vscode.postMessage({
|
|
|
|
|
type: 'createContainer',
|
|
|
|
|
name: name
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-18 18:45:30 +08:00
|
|
|
function goBackToAircrafts() {
|
|
|
|
|
vscode.postMessage({ type: 'goBackToAircrafts' });
|
2025-11-18 09:10:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteContainer(containerId) {
|
|
|
|
|
showConfirmDialog(
|
|
|
|
|
'确认删除',
|
|
|
|
|
'确定删除这个容器吗?',
|
|
|
|
|
function() {
|
|
|
|
|
vscode.postMessage({
|
|
|
|
|
type: 'deleteContainer',
|
|
|
|
|
containerId: containerId
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function() {
|
|
|
|
|
// 用户取消删除
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 对话框函数(与之前相同)
|
|
|
|
|
function showConfirmDialog(title, message, onConfirm, onCancel) {
|
|
|
|
|
const overlay = document.createElement('div');
|
|
|
|
|
overlay.className = 'modal-overlay';
|
|
|
|
|
overlay.id = 'confirmModal';
|
|
|
|
|
|
|
|
|
|
overlay.innerHTML = \`
|
|
|
|
|
<div class="modal-dialog">
|
|
|
|
|
<div class="modal-title">\${title}</div>
|
|
|
|
|
<div>\${message}</div>
|
|
|
|
|
<div class="modal-buttons">
|
|
|
|
|
<button class="modal-btn modal-btn-secondary" onclick="closeConfirmDialog(false)">取消</button>
|
|
|
|
|
<button class="modal-btn modal-btn-primary" onclick="closeConfirmDialog(true)">确定</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
\`;
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(overlay);
|
|
|
|
|
|
|
|
|
|
window.confirmCallback = function(result) {
|
|
|
|
|
if (result && onConfirm) {
|
|
|
|
|
onConfirm();
|
|
|
|
|
} else if (!result && onCancel) {
|
|
|
|
|
onCancel();
|
|
|
|
|
}
|
|
|
|
|
delete window.confirmCallback;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeConfirmDialog(result) {
|
|
|
|
|
const modal = document.getElementById('confirmModal');
|
|
|
|
|
if (modal) {
|
|
|
|
|
modal.remove();
|
|
|
|
|
}
|
|
|
|
|
if (window.confirmCallback) {
|
|
|
|
|
window.confirmCallback(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showPromptDialog(title, message, defaultValue, onConfirm) {
|
|
|
|
|
const overlay = document.createElement('div');
|
|
|
|
|
overlay.className = 'modal-overlay';
|
|
|
|
|
overlay.id = 'promptModal';
|
|
|
|
|
|
|
|
|
|
overlay.innerHTML = \`
|
|
|
|
|
<div class="modal-dialog">
|
|
|
|
|
<div class="modal-title">\${title}</div>
|
|
|
|
|
<div>\${message}</div>
|
|
|
|
|
<input type="text" id="promptInput" value="\${defaultValue}" style="width: 100%; margin: 10px 0; padding: 6px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border: 1px solid var(--vscode-input-border);">
|
|
|
|
|
<div class="modal-buttons">
|
|
|
|
|
<button class="modal-btn modal-btn-secondary" onclick="closePromptDialog(null)">取消</button>
|
|
|
|
|
<button class="modal-btn modal-btn-primary" onclick="closePromptDialog(document.getElementById('promptInput').value)">确定</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
\`;
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(overlay);
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
const input = document.getElementById('promptInput');
|
|
|
|
|
if (input) {
|
|
|
|
|
input.focus();
|
|
|
|
|
input.select();
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
|
|
window.promptCallback = onConfirm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closePromptDialog(result) {
|
|
|
|
|
const modal = document.getElementById('promptModal');
|
|
|
|
|
if (modal) {
|
|
|
|
|
modal.remove();
|
|
|
|
|
}
|
|
|
|
|
if (window.promptCallback) {
|
|
|
|
|
window.promptCallback(result);
|
|
|
|
|
}
|
|
|
|
|
delete window.promptCallback;
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>`;
|
|
|
|
|
}
|
|
|
|
|
}
|