0
0
Files
dscp/src/panels/views/ContainerView.ts

123 lines
3.9 KiB
TypeScript
Raw Normal View History

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-12-03 16:08:14 +08:00
const aircraft = data?.aircraft;
2025-11-18 09:10:47 +08:00
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">
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() {
// 用户取消删除
}
);
}
</script>
</body>
</html>`;
}
}