123 lines
3.9 KiB
TypeScript
Executable File
123 lines
3.9 KiB
TypeScript
Executable File
// src/panels/views/ContainerView.ts
|
|
import { BaseView } from './BaseView';
|
|
import { AircraftConfigData, ContainerViewData } from '../types/ViewTypes';
|
|
|
|
export class ContainerView extends BaseView {
|
|
render(data?: AircraftConfigData): string {
|
|
const project = data?.project;
|
|
const aircraft = data?.aircraft;
|
|
const containers = data?.containers || [];
|
|
|
|
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">
|
|
<title>容器管理</title>
|
|
${this.getStyles()}
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h2>📋 容器管理 - <span style="color: var(--vscode-textLink-foreground);">${aircraft?.name || '未知飞行器'}</span></h2>
|
|
<button class="back-btn" onclick="goBackToAircrafts()">← 返回飞行器管理</button>
|
|
</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
|
|
});
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
function goBackToAircrafts() {
|
|
vscode.postMessage({ type: 'goBackToAircrafts' });
|
|
}
|
|
|
|
function deleteContainer(containerId) {
|
|
showConfirmDialog(
|
|
'确认删除',
|
|
'确定删除这个容器吗?',
|
|
function() {
|
|
vscode.postMessage({
|
|
type: 'deleteContainer',
|
|
containerId: containerId
|
|
});
|
|
},
|
|
function() {
|
|
// 用户取消删除
|
|
}
|
|
);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>`;
|
|
}
|
|
} |