修复显示bug和项目回读bug
This commit is contained in:
@@ -36,7 +36,6 @@ interface ProjectData {
|
||||
aircrafts: Aircraft[];
|
||||
containers: Container[];
|
||||
configs: Config[];
|
||||
projectPaths: { [key: string]: string };
|
||||
}
|
||||
|
||||
export class ConfigPanel {
|
||||
@@ -105,66 +104,66 @@ export class ConfigPanel {
|
||||
}
|
||||
|
||||
private setupMessageListener() {
|
||||
this.panel.webview.onDidReceiveMessage(async (data) => {
|
||||
switch (data.type) {
|
||||
case 'openExistingProject':
|
||||
await this.openExistingProject();
|
||||
break;
|
||||
|
||||
case 'configureProject':
|
||||
const selectedPath = await this.selectProjectPath(data.projectId, data.projectName);
|
||||
if (selectedPath) {
|
||||
this.panel.webview.onDidReceiveMessage(async (data) => {
|
||||
switch (data.type) {
|
||||
case 'openExistingProject':
|
||||
await this.openExistingProject();
|
||||
break;
|
||||
|
||||
case 'configureProject':
|
||||
const selectedPath = await this.selectProjectPath(data.projectId, data.projectName);
|
||||
if (selectedPath) {
|
||||
this.currentView = 'aircrafts';
|
||||
this.currentProjectId = data.projectId;
|
||||
this.updateWebview();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'openProject':
|
||||
// 已配置的项目直接打开
|
||||
this.currentView = 'aircrafts';
|
||||
this.currentProjectId = data.projectId;
|
||||
this.updateWebview();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'openProject':
|
||||
// 已配置的项目直接打开
|
||||
this.currentView = 'aircrafts';
|
||||
this.currentProjectId = data.projectId;
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
case 'openAircraftConfig':
|
||||
this.currentView = 'containers';
|
||||
this.currentProjectId = data.projectId;
|
||||
this.currentAircraftId = data.aircraftId;
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
case 'openContainerConfig':
|
||||
this.currentView = 'configs';
|
||||
this.currentContainerId = data.containerId;
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
// 修复返回按钮的消息处理
|
||||
case 'goBackToProjects':
|
||||
this.currentView = 'projects';
|
||||
// 清空当前选择的ID
|
||||
this.currentProjectId = '';
|
||||
this.currentAircraftId = '';
|
||||
this.currentContainerId = '';
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
case 'goBackToAircrafts':
|
||||
this.currentView = 'aircrafts';
|
||||
// 保持 currentProjectId,清空其他ID
|
||||
this.currentAircraftId = '';
|
||||
this.currentContainerId = '';
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
case 'goBackToContainers':
|
||||
this.currentView = 'containers';
|
||||
// 保持 currentProjectId 和 currentAircraftId,清空 currentContainerId
|
||||
this.currentContainerId = '';
|
||||
this.updateWebview();
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'openAircraftConfig':
|
||||
this.currentView = 'containers';
|
||||
this.currentProjectId = data.projectId;
|
||||
this.currentAircraftId = data.aircraftId;
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
case 'openContainerConfig':
|
||||
this.currentView = 'configs';
|
||||
this.currentContainerId = data.containerId;
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
// 修复返回按钮的消息处理
|
||||
case 'goBackToProjects':
|
||||
this.currentView = 'projects';
|
||||
// 清空当前选择的ID
|
||||
this.currentProjectId = '';
|
||||
this.currentAircraftId = '';
|
||||
this.currentContainerId = '';
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
case 'goBackToAircrafts':
|
||||
this.currentView = 'aircrafts';
|
||||
// 保持 currentProjectId,清空其他ID
|
||||
this.currentAircraftId = '';
|
||||
this.currentContainerId = '';
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
case 'goBackToContainers':
|
||||
this.currentView = 'containers';
|
||||
// 保持 currentProjectId 和 currentAircraftId,清空 currentContainerId
|
||||
this.currentContainerId = '';
|
||||
this.updateWebview();
|
||||
break;
|
||||
|
||||
case 'updateProjectName':
|
||||
await this.updateProjectName(data.projectId, data.name);
|
||||
break;
|
||||
@@ -251,27 +250,20 @@ export class ConfigPanel {
|
||||
// === 数据持久化方法 ===
|
||||
|
||||
/**
|
||||
* 保存所有数据到项目路径
|
||||
* 保存当前项目数据到项目路径
|
||||
*/
|
||||
private async saveAllData(): Promise<void> {
|
||||
private async saveCurrentProjectData(): Promise<void> {
|
||||
try {
|
||||
console.log('开始保存数据...');
|
||||
console.log('开始保存当前项目数据...');
|
||||
console.log('当前项目ID:', this.currentProjectId);
|
||||
console.log('项目路径映射:', Array.from(this.projectPaths.entries()));
|
||||
|
||||
// 找到当前项目的路径
|
||||
let projectPath: string | undefined;
|
||||
|
||||
// 首先尝试使用当前项目ID
|
||||
if (this.currentProjectId) {
|
||||
projectPath = this.projectPaths.get(this.currentProjectId);
|
||||
if (!this.currentProjectId) {
|
||||
console.log('未找到当前项目ID,跳过保存数据');
|
||||
vscode.window.showWarningMessage('未找到当前项目,数据将不会保存');
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果没有找到,尝试使用第一个项目
|
||||
if (!projectPath && this.projects.length > 0) {
|
||||
projectPath = this.projectPaths.get(this.projects[0].id);
|
||||
}
|
||||
|
||||
|
||||
const projectPath = this.projectPaths.get(this.currentProjectId);
|
||||
if (!projectPath) {
|
||||
console.log('未找到项目路径,跳过保存数据');
|
||||
vscode.window.showWarningMessage('未找到项目存储路径,数据将不会保存');
|
||||
@@ -280,29 +272,33 @@ export class ConfigPanel {
|
||||
|
||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||
|
||||
// 只保存与当前项目相关的数据
|
||||
const currentProjectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
||||
const currentAircraftIds = currentProjectAircrafts.map(a => a.id);
|
||||
const currentProjectContainers = this.containers.filter(c => currentAircraftIds.includes(c.aircraftId));
|
||||
const currentContainerIds = currentProjectContainers.map(c => c.id);
|
||||
const currentProjectConfigs = this.configs.filter(cfg => currentContainerIds.includes(cfg.containerId));
|
||||
|
||||
const data: ProjectData = {
|
||||
projects: this.projects,
|
||||
aircrafts: this.aircrafts,
|
||||
containers: this.containers,
|
||||
configs: this.configs,
|
||||
projectPaths: Object.fromEntries(this.projectPaths)
|
||||
projects: this.projects.filter(p => p.id === this.currentProjectId), // 只保存当前项目
|
||||
aircrafts: currentProjectAircrafts,
|
||||
containers: currentProjectContainers,
|
||||
configs: currentProjectConfigs
|
||||
};
|
||||
|
||||
console.log('要保存的数据:', {
|
||||
projects: this.projects.length,
|
||||
aircrafts: this.aircrafts.length,
|
||||
containers: this.containers.length,
|
||||
configs: this.configs.length,
|
||||
projectPaths: this.projectPaths.size
|
||||
console.log('要保存的当前项目数据:', {
|
||||
projects: data.projects.length,
|
||||
aircrafts: data.aircrafts.length,
|
||||
containers: data.containers.length,
|
||||
configs: data.configs.length
|
||||
});
|
||||
|
||||
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
|
||||
await vscode.workspace.fs.writeFile(dataUri, uint8Array);
|
||||
|
||||
console.log('项目数据已保存到:', dataUri.fsPath);
|
||||
vscode.window.showInformationMessage('项目数据已保存');
|
||||
console.log('当前项目数据已保存到:', dataUri.fsPath);
|
||||
} catch (error) {
|
||||
console.error('保存项目数据时出错:', error);
|
||||
console.error('保存当前项目数据时出错:', error);
|
||||
vscode.window.showErrorMessage(`保存项目数据失败: ${error}`);
|
||||
}
|
||||
}
|
||||
@@ -334,7 +330,6 @@ export class ConfigPanel {
|
||||
this.aircrafts = [];
|
||||
this.containers = [];
|
||||
this.configs = [];
|
||||
this.projectPaths = new Map();
|
||||
|
||||
// 验证数据格式并加载
|
||||
if (data.projects && Array.isArray(data.projects)) {
|
||||
@@ -349,21 +344,18 @@ export class ConfigPanel {
|
||||
if (data.configs && Array.isArray(data.configs)) {
|
||||
this.configs = data.configs;
|
||||
}
|
||||
if (data.projectPaths && typeof data.projectPaths === 'object') {
|
||||
this.projectPaths = new Map(Object.entries(data.projectPaths));
|
||||
}
|
||||
|
||||
console.log('加载后的数据状态:', {
|
||||
projects: this.projects.length,
|
||||
aircrafts: this.aircrafts.length,
|
||||
containers: this.containers.length,
|
||||
configs: this.configs.length,
|
||||
projectPaths: this.projectPaths.size
|
||||
configs: this.configs.length
|
||||
});
|
||||
|
||||
// 设置当前项目为第一个项目(如果有的话)
|
||||
if (this.projects.length > 0) {
|
||||
this.currentProjectId = this.projects[0].id;
|
||||
this.projectPaths.set(this.currentProjectId, projectPath);
|
||||
this.currentView = 'aircrafts';
|
||||
}
|
||||
|
||||
@@ -458,7 +450,7 @@ export class ConfigPanel {
|
||||
vscode.window.showInformationMessage(`项目存储位置已设置: ${selectedPath}`);
|
||||
|
||||
// 保存初始数据
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
|
||||
return selectedPath;
|
||||
}
|
||||
@@ -485,7 +477,7 @@ export class ConfigPanel {
|
||||
vscode.window.showInformationMessage(`项目存储位置已创建: ${pathInput}`);
|
||||
|
||||
// 保存初始数据
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
|
||||
return pathInput;
|
||||
} catch (error) {
|
||||
@@ -508,7 +500,7 @@ export class ConfigPanel {
|
||||
if (project) {
|
||||
project.name = newName;
|
||||
vscode.window.showInformationMessage(`项目名称更新: ${newName}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
@@ -523,7 +515,6 @@ export class ConfigPanel {
|
||||
this.projects.push(newProject);
|
||||
|
||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||
await this.saveAllData();
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
@@ -546,7 +537,7 @@ export class ConfigPanel {
|
||||
this.projectPaths.delete(projectId);
|
||||
|
||||
vscode.window.showInformationMessage(`删除项目: ${project.name}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
@@ -556,7 +547,7 @@ export class ConfigPanel {
|
||||
if (aircraft) {
|
||||
aircraft.name = newName;
|
||||
vscode.window.showInformationMessage(`飞行器名称更新: ${newName}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
@@ -577,7 +568,7 @@ export class ConfigPanel {
|
||||
this.aircrafts.push(newAircraft);
|
||||
|
||||
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
@@ -594,7 +585,7 @@ export class ConfigPanel {
|
||||
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
||||
|
||||
vscode.window.showInformationMessage(`删除飞行器: ${aircraft.name}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
@@ -604,12 +595,12 @@ export class ConfigPanel {
|
||||
if (container) {
|
||||
container.name = newName;
|
||||
vscode.window.showInformationMessage(`容器名称更新: ${newName}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新容器 - 修复版本
|
||||
// 创建新容器
|
||||
private async createContainer(name: string) {
|
||||
console.log('创建容器,当前飞行器ID:', this.currentAircraftId);
|
||||
|
||||
@@ -654,7 +645,7 @@ export class ConfigPanel {
|
||||
});
|
||||
|
||||
vscode.window.showInformationMessage(`新建容器: ${name} (包含2个默认配置文件)`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
@@ -670,7 +661,7 @@ export class ConfigPanel {
|
||||
this.configs = this.configs.filter(cfg => cfg.containerId !== containerId);
|
||||
|
||||
vscode.window.showInformationMessage(`删除容器: ${container.name}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
@@ -680,7 +671,7 @@ export class ConfigPanel {
|
||||
if (config) {
|
||||
config.name = newName;
|
||||
vscode.window.showInformationMessage(`配置名称更新: ${newName}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
@@ -691,7 +682,7 @@ export class ConfigPanel {
|
||||
if (config) {
|
||||
config.fileName = fileName;
|
||||
vscode.window.showInformationMessage(`文件名更新: ${fileName}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
@@ -702,14 +693,14 @@ export class ConfigPanel {
|
||||
const newConfig: Config = {
|
||||
id: newId,
|
||||
name: name,
|
||||
fileName: name.toLowerCase().replace(/\s+/g, '_') + '.yaml',
|
||||
fileName: name.toLowerCase().replace(/\s+/g, '_'),
|
||||
content: `# ${name} 配置文件\n# 创建时间: ${new Date().toLocaleString()}\n# 您可以在此编辑配置内容\n\n`,
|
||||
containerId: this.currentContainerId
|
||||
};
|
||||
this.configs.push(newConfig);
|
||||
|
||||
vscode.window.showInformationMessage(`新建配置: ${name}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
|
||||
@@ -719,7 +710,7 @@ export class ConfigPanel {
|
||||
if (config) {
|
||||
this.configs = this.configs.filter(c => c.id !== configId);
|
||||
vscode.window.showInformationMessage(`删除配置: ${config.name}`);
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
this.updateWebview();
|
||||
}
|
||||
}
|
||||
@@ -786,7 +777,7 @@ export class ConfigPanel {
|
||||
vscode.window.showInformationMessage(`配置文件已保存: ${fileUri.fsPath}`);
|
||||
|
||||
// 保存数据到JSON文件
|
||||
await this.saveAllData();
|
||||
await this.saveCurrentProjectData();
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage(`保存文件时出错: ${error}`);
|
||||
}
|
||||
@@ -827,10 +818,12 @@ export class ConfigPanel {
|
||||
});
|
||||
case 'containers':
|
||||
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
||||
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
|
||||
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
||||
|
||||
return this.containerView.render({
|
||||
project: currentProject,
|
||||
aircraft: currentAircraft,
|
||||
containers: projectContainers
|
||||
});
|
||||
case 'configs':
|
||||
|
||||
@@ -24,13 +24,14 @@ export interface AircraftViewData {
|
||||
}
|
||||
|
||||
export interface ProjectListData {
|
||||
aircrafts?: AircraftViewData[];
|
||||
aircraft?: AircraftViewData[];
|
||||
projects: ProjectViewData[];
|
||||
|
||||
}
|
||||
|
||||
export interface AircraftConfigData {
|
||||
project?: ProjectViewData;
|
||||
aircraft?: AircraftViewData;
|
||||
containers: ContainerViewData[];
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export class AircraftView extends BaseView {
|
||||
const aircraftsHtml = aircrafts.map(aircraft => `
|
||||
<tr>
|
||||
<td>
|
||||
<span class="aircraft-name" data-aircraft-id="${aircraft.id}">✈️ ${aircraft.name}</span>
|
||||
<span class="aircraft-name" data-aircraft-id="${aircraft.id}">🛸 ${aircraft.name}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openAircraftConfig('${aircraft.id}', '${aircraft.projectId}')">配置容器</span>
|
||||
@@ -90,7 +90,7 @@ export class AircraftView extends BaseView {
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h2>飞行器配置</h2>
|
||||
<h2>🚀飞行器配置</h2>
|
||||
<button class="back-btn" onclick="goBackToProjects()">← 返回项目</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ export class ConfigView extends BaseView {
|
||||
const container = data?.container;
|
||||
const configs = data?.configs || [];
|
||||
|
||||
// 生成配置列表的 HTML - 添加文件名编辑功能
|
||||
// 生成配置列表的 HTML - 移除文件名编辑功能
|
||||
const configsHtml = configs.map((config: ConfigViewData) => `
|
||||
<tr>
|
||||
<td>
|
||||
<span class="editable" onclick="editConfigName('${config.id}', '${config.name}')">🔧 ${config.name}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="editable" onclick="editFileName('${config.id}', '${config.fileName}')">📄 ${config.fileName}</span>
|
||||
<span class="clickable" onclick="openConfigFile('${config.id}')">📄 ${config.fileName}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-delete" onclick="deleteConfig('${config.id}')">删除</button>
|
||||
@@ -85,23 +85,6 @@ export class ConfigView extends BaseView {
|
||||
);
|
||||
}
|
||||
|
||||
function editFileName(configId, currentFileName) {
|
||||
showPromptDialog(
|
||||
'修改文件名',
|
||||
'请输入新的文件名(包含扩展名):',
|
||||
currentFileName,
|
||||
function(newFileName) {
|
||||
if (newFileName && newFileName !== currentFileName) {
|
||||
vscode.postMessage({
|
||||
type: 'updateConfigFileName',
|
||||
configId: configId,
|
||||
fileName: newFileName
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function openConfigFile(configId) {
|
||||
currentConfigId = configId;
|
||||
document.getElementById('configEditor').style.display = 'block';
|
||||
@@ -250,19 +233,7 @@ export class ConfigView extends BaseView {
|
||||
}
|
||||
});
|
||||
|
||||
// 修改:点击文件名时打开编辑器
|
||||
document.addEventListener('click', function(event) {
|
||||
if (event.target.classList.contains('editable') && event.target.textContent.includes('📄')) {
|
||||
const row = event.target.closest('tr');
|
||||
if (row) {
|
||||
const configNameCell = row.querySelector('td:first-child .editable');
|
||||
if (configNameCell) {
|
||||
const configId = configNameCell.onclick.toString().match(/'([^']+)'/)[1];
|
||||
openConfigFile(configId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// 移除原来的复杂点击事件处理,现在文件名直接调用 openConfigFile
|
||||
</script>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
@@ -5,6 +5,7 @@ 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 || [];
|
||||
|
||||
// 生成容器列表的 HTML
|
||||
@@ -32,7 +33,7 @@ export class ContainerView extends BaseView {
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h2>📋 容器管理 - <span style="color: var(--vscode-textLink-foreground);">${project?.name || '未知项目'}</span></h2>
|
||||
<h2>📋 容器管理 - <span style="color: var(--vscode-textLink-foreground);">${aircraft?.name || '未知飞行器'}</span></h2>
|
||||
<button class="back-btn" onclick="goBackToAircrafts()">← 返回飞行器管理</button>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user