0
0
Files
vs-p/out/panels/views/AircraftView.js

204 lines
7.0 KiB
JavaScript
Raw Normal View History

2025-11-18 18:45:30 +08:00
"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 || [];
// 生成飞行器列表的 HTML
const aircraftsHtml = aircrafts.map((aircraft) => {
return `
2025-11-18 09:10:47 +08:00
<tr>
<td>
2025-11-18 18:45:30 +08:00
<span class="editable" onclick="editAircraftName('${aircraft.id}', '${aircraft.name}')">🛸 ${aircraft.name}</span>
2025-11-18 09:10:47 +08:00
</td>
<td>
2025-11-18 18:45:30 +08:00
<span class="clickable" onclick="openAircraftConfig('${aircraft.id}')">配置</span>
2025-11-18 09:10:47 +08:00
</td>
<td>
2025-11-18 18:45:30 +08:00
<button class="btn-delete" onclick="deleteAircraft('${aircraft.id}')">删除</button>
2025-11-18 09:10:47 +08:00
</td>
</tr>
2025-11-18 18:45:30 +08:00
`;
}).join('');
2025-11-18 09:10:47 +08:00
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>
2025-11-18 14:03:22 +08:00
<div class="header">
2025-11-18 18:45:30 +08:00
<h2>🚀 飞行器管理</h2>
<button class="back-btn" onclick="goBackToProjects()"> 返回项目管理</button>
2025-11-18 14:03:22 +08:00
</div>
2025-11-18 09:10:47 +08:00
<table class="table">
<thead>
<tr>
2025-11-18 18:45:30 +08:00
<th width="40%">飞行器</th>
2025-11-18 09:10:47 +08:00
<th width="40%">配置</th>
<th width="20%">操作</th>
</tr>
</thead>
<tbody>
2025-11-18 18:45:30 +08:00
${aircraftsHtml}
2025-11-18 09:10:47 +08:00
<tr>
<td colspan="3" style="text-align: center; padding: 20px;">
2025-11-18 18:45:30 +08:00
<button class="btn-new" onclick="createNewAircraft()">+ 新建飞行器</button>
2025-11-18 09:10:47 +08:00
</td>
</tr>
</tbody>
</table>
<script>
const vscode = acquireVsCodeApi();
2025-11-18 18:45:30 +08:00
function editAircraftName(aircraftId, currentName) {
2025-11-18 09:10:47 +08:00
showPromptDialog(
2025-11-18 18:45:30 +08:00
'修改飞行器名称',
'请输入新的飞行器名称:',
2025-11-18 09:10:47 +08:00
currentName,
function(newName) {
if (newName && newName !== currentName) {
vscode.postMessage({
2025-11-18 18:45:30 +08:00
type: 'updateAircraftName',
aircraftId: aircraftId,
2025-11-18 09:10:47 +08:00
name: newName
});
}
}
);
}
2025-11-18 18:45:30 +08:00
function openAircraftConfig(aircraftId) {
2025-11-18 09:10:47 +08:00
vscode.postMessage({
type: 'openAircraftConfig',
2025-11-18 18:45:30 +08:00
aircraftId: aircraftId
2025-11-18 09:10:47 +08:00
});
}
2025-11-18 18:45:30 +08:00
function createNewAircraft() {
2025-11-18 09:10:47 +08:00
showPromptDialog(
2025-11-18 18:45:30 +08:00
'新建飞行器',
'请输入飞行器名称:',
2025-11-18 09:10:47 +08:00
'',
function(name) {
if (name) {
vscode.postMessage({
2025-11-18 18:45:30 +08:00
type: 'createAircraft',
2025-11-18 09:10:47 +08:00
name: name
});
}
}
);
}
2025-11-18 18:45:30 +08:00
function deleteAircraft(aircraftId) {
2025-11-18 09:10:47 +08:00
showConfirmDialog(
'确认删除',
2025-11-18 18:45:30 +08:00
'确定删除这个飞行器吗?',
2025-11-18 09:10:47 +08:00
function() {
vscode.postMessage({
2025-11-18 18:45:30 +08:00
type: 'deleteAircraft',
aircraftId: aircraftId
2025-11-18 09:10:47 +08:00
});
},
function() {
// 用户取消删除
}
);
}
2025-11-18 18:45:30 +08:00
function goBackToProjects() {
vscode.postMessage({ type: 'goBackToProjects' });
2025-11-18 14:03:22 +08:00
}
2025-11-18 18:45:30 +08:00
// 对话框函数
2025-11-18 09:10:47 +08:00
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>`;
}
2025-11-18 18:45:30 +08:00
}
exports.AircraftView = AircraftView;
//# sourceMappingURL=AircraftView.js.map