0
0

修复显示bug和项目回读bug

This commit is contained in:
xubing
2025-11-21 16:07:48 +08:00
parent 6d3d020f8a
commit 925024bce1
17 changed files with 193 additions and 243 deletions

16
.vscodeignore Normal file
View File

@@ -0,0 +1,16 @@
.vscode/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/*.map
**/*.ts
node_modules/**/*.ts
node_modules/.bin
node_modules/**/test
node_modules/**/tests
node_modules/**/*.md
node_modules/**/LICENSE
node_modules/**/CHANGELOG.md
node_modules/**/README.md

Binary file not shown.

BIN
dsc-platform-1.1.0.vsix Normal file

Binary file not shown.

BIN
dsc-platform-1.1.1.vsix Normal file

Binary file not shown.

View File

@@ -168,50 +168,48 @@ class ConfigPanel {
}
// === 数据持久化方法 ===
/**
* 保存所有数据到项目路径
* 保存当前项目数据到项目路径
*/
async saveAllData() {
async saveCurrentProjectData() {
try {
console.log('开始保存数据...');
console.log('开始保存当前项目数据...');
console.log('当前项目ID:', this.currentProjectId);
console.log('项目路径映射:', Array.from(this.projectPaths.entries()));
// 找到当前项目的路径
let projectPath;
// 首先尝试使用当前项目ID
if (this.currentProjectId) {
projectPath = this.projectPaths.get(this.currentProjectId);
}
// 如果没有找到,尝试使用第一个项目
if (!projectPath && this.projects.length > 0) {
projectPath = this.projectPaths.get(this.projects[0].id);
if (!this.currentProjectId) {
console.log('未找到当前项目ID跳过保存数据');
vscode.window.showWarningMessage('未找到当前项目,数据将不会保存');
return;
}
const projectPath = this.projectPaths.get(this.currentProjectId);
if (!projectPath) {
console.log('未找到项目路径,跳过保存数据');
vscode.window.showWarningMessage('未找到项目存储路径,数据将不会保存');
return;
}
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 = {
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}`);
}
}
@@ -239,7 +237,6 @@ class ConfigPanel {
this.aircrafts = [];
this.containers = [];
this.configs = [];
this.projectPaths = new Map();
// 验证数据格式并加载
if (data.projects && Array.isArray(data.projects)) {
this.projects = data.projects;
@@ -253,19 +250,16 @@ 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';
}
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载`);
@@ -344,7 +338,7 @@ class ConfigPanel {
this.projectPaths.set(projectId, selectedPath);
vscode.window.showInformationMessage(`项目存储位置已设置: ${selectedPath}`);
// 保存初始数据
await this.saveAllData();
await this.saveCurrentProjectData();
return selectedPath;
}
}
@@ -368,7 +362,7 @@ class ConfigPanel {
this.projectPaths.set(projectId, pathInput);
vscode.window.showInformationMessage(`项目存储位置已创建: ${pathInput}`);
// 保存初始数据
await this.saveAllData();
await this.saveCurrentProjectData();
return pathInput;
}
catch (error) {
@@ -390,7 +384,7 @@ class ConfigPanel {
if (project) {
project.name = newName;
vscode.window.showInformationMessage(`项目名称更新: ${newName}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
}
@@ -403,7 +397,6 @@ class ConfigPanel {
};
this.projects.push(newProject);
vscode.window.showInformationMessage(`新建项目: ${name}`);
await this.saveAllData();
this.updateWebview();
}
// 删除项目
@@ -424,7 +417,7 @@ class ConfigPanel {
// 删除项目路径映射
this.projectPaths.delete(projectId);
vscode.window.showInformationMessage(`删除项目: ${project.name}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
// 更新飞行器名
@@ -433,7 +426,7 @@ class ConfigPanel {
if (aircraft) {
aircraft.name = newName;
vscode.window.showInformationMessage(`飞行器名称更新: ${newName}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
}
@@ -451,7 +444,7 @@ class ConfigPanel {
};
this.aircrafts.push(newAircraft);
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
// 删除飞行器
@@ -466,7 +459,7 @@ class ConfigPanel {
const containerIds = this.containers.filter(c => c.aircraftId === aircraftId).map(c => c.id);
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
vscode.window.showInformationMessage(`删除飞行器: ${aircraft.name}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
// 更新容器名
@@ -475,11 +468,11 @@ class ConfigPanel {
if (container) {
container.name = newName;
vscode.window.showInformationMessage(`容器名称更新: ${newName}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
}
// 创建新容器 - 修复版本
// 创建新容器
async createContainer(name) {
console.log('创建容器当前飞行器ID:', this.currentAircraftId);
if (!this.currentAircraftId) {
@@ -516,7 +509,7 @@ class ConfigPanel {
configs: this.configs.length
});
vscode.window.showInformationMessage(`新建容器: ${name} (包含2个默认配置文件)`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
// 删除容器
@@ -529,7 +522,7 @@ class ConfigPanel {
// 删除相关的配置
this.configs = this.configs.filter(cfg => cfg.containerId !== containerId);
vscode.window.showInformationMessage(`删除容器: ${container.name}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
// 更新配置名
@@ -538,7 +531,7 @@ class ConfigPanel {
if (config) {
config.name = newName;
vscode.window.showInformationMessage(`配置名称更新: ${newName}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
}
@@ -548,7 +541,7 @@ class ConfigPanel {
if (config) {
config.fileName = fileName;
vscode.window.showInformationMessage(`文件名更新: ${fileName}`);
await this.saveAllData();
await this.saveCurrentProjectData();
this.updateWebview();
}
}
@@ -558,13 +551,13 @@ class ConfigPanel {
const newConfig = {
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();
}
// 删除配置文件
@@ -573,7 +566,7 @@ 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();
}
}
@@ -630,7 +623,7 @@ class ConfigPanel {
config.content = content;
vscode.window.showInformationMessage(`配置文件已保存: ${fileUri.fsPath}`);
// 保存数据到JSON文件
await this.saveAllData();
await this.saveCurrentProjectData();
}
catch (error) {
vscode.window.showErrorMessage(`保存文件时出错: ${error}`);
@@ -670,9 +663,11 @@ 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':

File diff suppressed because one or more lines are too long

View File

@@ -10,7 +10,7 @@ class AircraftView extends BaseView_1.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>
@@ -83,7 +83,7 @@ class AircraftView extends BaseView_1.BaseView {
</head>
<body>
<div class="header">
<h2>飞行器配置</h2>
<h2>🚀飞行器配置</h2>
<button class="back-btn" onclick="goBackToProjects()">← 返回项目</button>
</div>

View File

@@ -7,14 +7,14 @@ class ConfigView extends BaseView_1.BaseView {
render(data) {
const container = data?.container;
const configs = data?.configs || [];
// 生成配置列表的 HTML - 添加文件名编辑功能
// 生成配置列表的 HTML - 移除文件名编辑功能
const configsHtml = configs.map((config) => `
<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>
@@ -84,23 +84,6 @@ class ConfigView extends BaseView_1.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';
@@ -249,19 +232,7 @@ class ConfigView extends BaseView_1.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>`;

View File

@@ -1 +1 @@
{"version":3,"file":"ConfigView.js","sourceRoot":"","sources":["../../../src/panels/views/ConfigView.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,yCAAsC;AAGtC,MAAa,UAAW,SAAQ,mBAAQ;IACpC,MAAM,CAAC,IAA0B;QAC7B,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,CAAC;QAClC,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC;QAEpC,2BAA2B;QAC3B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAsB,EAAE,EAAE,CAAC;;;sEAGE,MAAM,CAAC,EAAE,OAAO,MAAM,CAAC,IAAI,UAAU,MAAM,CAAC,IAAI;;;oEAGlD,MAAM,CAAC,EAAE,OAAO,MAAM,CAAC,QAAQ,UAAU,MAAM,CAAC,QAAQ;;;wEAGpD,MAAM,CAAC,EAAE;;;SAGxE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA+LjB,CAAC;IACL,CAAC;CACJ;AA5OD,gCA4OC"}

View File

@@ -6,6 +6,7 @@ const BaseView_1 = require("./BaseView");
class ContainerView extends BaseView_1.BaseView {
render(data) {
const project = data?.project;
const aircraft = data?.aircraft; // 新增:获取飞行器数据
const containers = data?.containers || [];
// 生成容器列表的 HTML
const containersHtml = containers.map((container) => `
@@ -31,7 +32,7 @@ class ContainerView extends BaseView_1.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>

View File

@@ -1 +1 @@
{"version":3,"file":"ContainerView.js","sourceRoot":"","sources":["../../../src/panels/views/ContainerView.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,yCAAsC;AAGtC,MAAa,aAAc,SAAQ,mBAAQ;IACvC,MAAM,CAAC,IAAyB;QAC5B,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC;QAC9B,MAAM,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC;QAE1C,eAAe;QACf,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAA4B,EAAE,EAAE,CAAC;;;yEAGP,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC,IAAI,UAAU,SAAS,CAAC,IAAI;;;4EAGtD,SAAS,CAAC,EAAE;;;2EAGb,SAAS,CAAC,EAAE;;;SAG9E,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,OAAO;;;;;;MAMT,IAAI,CAAC,SAAS,EAAE;;;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IACL,CAAC;CACJ;AAvMD,sCAuMC"}

View File

@@ -1,12 +1,12 @@
{
"name": "dsc_platform",
"name": "dsc-platform",
"displayName": "数字卫星构建平台",
"version": "1.0.0",
"publisher": "njust_Micro-Nano Satellite Laboratory",
"version": "1.1.1",
"publisher": "njust-micro-nano-lab",
"description": "一个用于快速构建数字卫星的平台",
"repository": {
"type": "git",
"url": "https://github.com/your-username/DSCP.git"
"url": "http://117.72.162.127:3000/xb/vs-p.git"
},
"engines": {
"vscode": "^1.67.0"
@@ -15,7 +15,7 @@
"Other"
],
"activationEvents": [
"DSCP"
"onCommand:open_DSCP"
],
"main": "./out/extension.js",
"contributes": {
@@ -30,7 +30,8 @@
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./"
"watch": "tsc -watch -p ./",
"package": "vsce package"
},
"devDependencies": {
"@types/vscode": "^1.67.0",

View File

@@ -36,7 +36,6 @@ interface ProjectData {
aircrafts: Aircraft[];
containers: Container[];
configs: Config[];
projectPaths: { [key: string]: string };
}
export class ConfigPanel {
@@ -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 (!projectPath && this.projects.length > 0) {
projectPath = this.projectPaths.get(this.projects[0].id);
if (!this.currentProjectId) {
console.log('未找到当前项目ID跳过保存数据');
vscode.window.showWarningMessage('未找到当前项目,数据将不会保存');
return;
}
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':

View File

@@ -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[];
}

View File

@@ -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>

View File

@@ -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>`;

View File

@@ -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>