0
0
Files
vs-p/out/panels/views/AircraftView.js
2025-11-21 16:07:48 +08:00

275 lines
9.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AircraftView = void 0;
// src/panels/views/AircraftView.ts
const BaseView_1 = require("./BaseView");
class AircraftView extends BaseView_1.BaseView {
render(data) {
const aircrafts = data?.aircrafts || [];
console.log('AircraftView 渲染数据:', aircrafts);
const aircraftsHtml = aircrafts.map(aircraft => `
<tr>
<td>
<span class="aircraft-name" data-aircraft-id="${aircraft.id}">🛸 ${aircraft.name}</span>
</td>
<td>
<span class="clickable" onclick="openAircraftConfig('${aircraft.id}', '${aircraft.projectId}')">配置容器</span>
</td>
<td>
<button class="btn-delete" onclick="deleteAircraft('${aircraft.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()}
<style>
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.back-btn {
background: var(--vscode-input-background);
color: var(--vscode-input-foreground);
border: 1px solid var(--vscode-input-border);
padding: 5px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 13px;
display: flex;
align-items: center;
gap: 6px;
}
.back-btn:hover {
background: var(--vscode-inputOption-hoverBackground);
}
.btn-new {
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 13px;
display: flex;
align-items: center;
gap: 6px;
margin: 0 auto; /* 确保按钮在容器内居中 */
}
.btn-new:hover {
background: var(--vscode-button-hoverBackground);
}
.aircraft-name {
cursor: pointer;
padding: 4px 8px;
border-radius: 4px;
transition: background-color 0.2s;
}
.aircraft-name:hover {
background: var(--vscode-input-background);
}
/* 专门为新建按钮的容器添加样式 */
.new-button-container {
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<div class="header">
<h2>🚀飞行器配置</h2>
<button class="back-btn" onclick="goBackToProjects()">← 返回项目</button>
</div>
<table class="table">
<thead>
<tr>
<th width="40%">飞行器</th>
<th width="40%">配置</th>
<th width="20%">操作</th>
</tr>
</thead>
<tbody>
${aircraftsHtml}
<!-- 修复:使用专门的容器类确保居中 -->
<tr>
<td colspan="3" class="new-button-container">
<button class="btn-new" onclick="createNewAircraft()">+ 新建飞行器</button>
</td>
</tr>
</tbody>
</table>
<script>
const vscode = acquireVsCodeApi();
function openAircraftConfig(aircraftId, projectId) {
vscode.postMessage({
type: 'openAircraftConfig',
aircraftId: aircraftId,
projectId: projectId
});
}
function goBackToProjects() {
vscode.postMessage({
type: 'goBackToProjects'
});
}
function createNewAircraft() {
showPromptDialog(
'新建飞行器',
'请输入飞行器名称:',
'',
function(name) {
if (name) {
vscode.postMessage({
type: 'createAircraft',
name: name
});
}
}
);
}
function deleteAircraft(aircraftId) {
showConfirmDialog(
'确认删除',
'确定删除这个飞行器吗?',
function() {
vscode.postMessage({
type: 'deleteAircraft',
aircraftId: aircraftId
});
},
function() {
// 用户取消删除
}
);
}
// 飞行器名称编辑功能
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('click', function(event) {
if (event.target.classList.contains('aircraft-name')) {
const aircraftNameElement = event.target;
const aircraftId = aircraftNameElement.getAttribute('data-aircraft-id');
const currentName = aircraftNameElement.textContent.trim().split(' ').slice(1).join(' ');
if (aircraftId) {
editAircraftName(aircraftId, currentName);
}
}
});
});
function editAircraftName(aircraftId, currentName) {
showPromptDialog(
'修改飞行器名称',
'请输入新的飞行器名称:',
currentName,
function(newName) {
if (newName && newName !== currentName) {
vscode.postMessage({
type: 'updateAircraftName',
aircraftId: aircraftId,
name: newName
});
}
}
);
}
// 对话框函数
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>`;
}
}
exports.AircraftView = AircraftView;
//# sourceMappingURL=AircraftView.js.map