0
0
Files
vs-p/out/panels/views/ProjectListView.js
2025-11-18 14:03:22 +08:00

202 lines
7.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProjectListView = void 0;
// src/panels/views/ProjectListView.ts
const BaseView_1 = require("./BaseView");
class ProjectListView extends BaseView_1.BaseView {
render(data) {
const projects = data?.projects || [];
// 生成项目列表的 HTML
const projectsHtml = projects.map((project) => `
<tr>
<td>
<span class="editable" onclick="editProjectName('${project.id}', '${project.name}')">🛸 ${project.name}</span>
</td>
<td>
<span class="clickable" onclick="openAircraftConfig('${project.id}')">配置</span>
</td>
<td>
<button class="btn-delete" onclick="deleteProject('${project.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>🚀 飞行器项目管理</h2>
<button class="back-btn" onclick="goBackToManagement()">← 返回项目管理</button>
</div>
<table class="table">
<thead>
<tr>
<th width="40%">项目</th>
<th width="40%">配置</th>
<th width="20%">操作</th>
</tr>
</thead>
<tbody>
${projectsHtml}
<tr>
<td colspan="3" style="text-align: center; padding: 20px;">
<button class="btn-new" onclick="createNewProject()">+ 新建项目</button>
</td>
</tr>
</tbody>
</table>
<script>
const vscode = acquireVsCodeApi();
function editProjectName(projectId, currentName) {
showPromptDialog(
'修改项目名称',
'请输入新的项目名称:',
currentName,
function(newName) {
if (newName && newName !== currentName) {
vscode.postMessage({
type: 'updateProjectName',
projectId: projectId,
name: newName
});
}
}
);
}
function openAircraftConfig(projectId) {
vscode.postMessage({
type: 'openAircraftConfig',
projectId: projectId
});
}
function createNewProject() {
showPromptDialog(
'新建项目',
'请输入项目名称:',
'',
function(name) {
if (name) {
vscode.postMessage({
type: 'createProject',
name: name
});
}
}
);
}
function deleteProject(projectId) {
showConfirmDialog(
'确认删除',
'确定删除这个项目吗?',
function() {
vscode.postMessage({
type: 'deleteProject',
projectId: projectId
});
},
function() {
// 用户取消删除
}
);
}
function goBackToManagement() {
vscode.postMessage({ type: 'goBackToManagement' });
}
// 对话框函数(与之前相同)
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.ProjectListView = ProjectListView;
//# sourceMappingURL=ProjectListView.js.map