0
0

将git和配置文件合并,增加了配置文件永久删除的功能

This commit is contained in:
xubing
2025-11-25 14:30:54 +08:00
parent d3ef13de42
commit 056f98fd25
6 changed files with 1117 additions and 1258 deletions

View File

@@ -27,7 +27,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigPanel = void 0;
// src/panels/ConfigPanel.ts
const vscode = __importStar(require("vscode"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
@@ -62,29 +61,37 @@ class ConfigPanel {
this.aircrafts = [];
this.containers = [];
this.configs = [];
// Git 仓库存储
this.gitRepos = [];
this.gitRepos = []; // Git 仓库数据
// Git 文件树
this.currentRepoFileTree = [];
// 项目存储路径映射
this.projectPaths = new Map();
// Webview 状态跟踪
this.isWebviewDisposed = false;
this.panel = panel;
this.extensionUri = extensionUri;
this.isWebviewDisposed = false; // 初始化状态
// 初始化各个视图
this.projectView = new ProjectView_1.ProjectView(extensionUri);
this.aircraftView = new AircraftView_1.AircraftView(extensionUri);
this.containerView = new ContainerView_1.ContainerView(extensionUri);
this.configView = new ConfigView_1.ConfigView(extensionUri);
// 加载 Git 仓库数据
this.loadGitRepos();
this.updateWebview();
this.setupMessageListener();
this.panel.onDidDispose(() => {
this.isWebviewDisposed = true; // 标记为已销毁
ConfigPanel.currentPanel = undefined;
});
}
setupMessageListener() {
this.panel.webview.onDidReceiveMessage(async (data) => {
console.log('📨 收到Webview消息:', data);
// 检查 Webview 是否仍然有效
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,忽略消息');
return;
}
try {
switch (data.type) {
case 'openExistingProject':
await this.openExistingProject();
@@ -208,42 +215,95 @@ class ConfigPanel {
await this.importGitFile(data.filePath);
break;
}
}
catch (error) {
console.error('处理 Webview 消息时出错:', error);
if (!this.isWebviewDisposed) {
vscode.window.showErrorMessage(`处理操作时出错: ${error}`);
}
}
});
}
// === 目录创建方法 ===
/**
* 创建飞行器目录
*/
async createAircraftDirectory(aircraft) {
try {
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
console.warn('未找到项目路径,跳过创建飞行器目录');
return;
}
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
// 创建飞行器目录
await vscode.workspace.fs.createDirectory(aircraftDir);
console.log(`✅ 创建飞行器目录: ${aircraftDir.fsPath}`);
}
catch (error) {
console.error(`创建飞行器目录失败: ${error}`);
}
}
/**
* 创建容器目录
*/
async createContainerDirectory(container) {
try {
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft) {
console.warn('未找到对应的飞行器,跳过创建容器目录');
return;
}
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
console.warn('未找到项目路径,跳过创建容器目录');
return;
}
// 构建路径:项目路径/飞行器名/容器名
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
// 确保飞行器目录存在
try {
await vscode.workspace.fs.createDirectory(aircraftDir);
}
catch (error) {
// 目录可能已存在,忽略错误
}
// 创建容器目录
await vscode.workspace.fs.createDirectory(containerDir);
console.log(`✅ 创建容器目录: ${containerDir.fsPath}`);
}
catch (error) {
console.error(`创建容器目录失败: ${error}`);
}
}
/**
* 确保容器目录存在
*/
async ensureContainerDirectoryExists(containerId) {
try {
const container = this.containers.find(c => c.id === containerId);
if (!container)
return;
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft)
return;
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath)
return;
// 构建路径并创建目录
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
await vscode.workspace.fs.createDirectory(aircraftDir);
await vscode.workspace.fs.createDirectory(containerDir);
}
catch (error) {
console.error(`确保容器目录存在失败: ${error}`);
}
}
// === Git 仓库管理方法 ===
/**
* 加 Git 仓库数据
*/
async loadGitRepos() {
try {
const globalStoragePath = this.extensionUri.fsPath;
const reposFile = path.join(globalStoragePath, 'git-repos.json');
if (fs.existsSync(reposFile)) {
const data = await fs.promises.readFile(reposFile, 'utf8');
this.gitRepos = JSON.parse(data);
}
}
catch (error) {
vscode.window.showErrorMessage(`加载 Git 仓库数据失败: ${error}`);
}
}
/**
* 保存 Git 仓库数据
*/
async saveGitRepos() {
try {
const globalStoragePath = this.extensionUri.fsPath;
const reposFile = path.join(globalStoragePath, 'git-repos.json');
// 确保目录存在
await fs.promises.mkdir(path.dirname(reposFile), { recursive: true });
await fs.promises.writeFile(reposFile, JSON.stringify(this.gitRepos, null, 2));
}
catch (error) {
vscode.window.showErrorMessage(`保存 Git 仓库数据失败: ${error}`);
}
}
/**
* 添加 Git 仓库到配置目录
* 加 Git 仓库到容器目录
*/
async addGitRepo(url, name, branch) {
try {
@@ -252,41 +312,48 @@ class ConfigPanel {
vscode.window.showErrorMessage('请输入有效的 Git 仓库 URL');
return;
}
const repoId = 'git-' + Date.now();
// 构建本地路径
let localPath = '';
if (this.currentContainerId && this.currentProjectId) {
const projectPath = this.projectPaths.get(this.currentProjectId);
const container = this.containers.find(c => c.id === this.currentContainerId);
const aircraft = this.aircrafts.find(a => a.id === container?.aircraftId);
if (projectPath && container && aircraft) {
localPath = path.join(projectPath, aircraft.name, container.name, name);
console.log(`📁 Git仓库将保存到容器目录: ${localPath}`);
}
}
if (!localPath) {
localPath = path.join(this.extensionUri.fsPath, name);
console.log(`📁 Git仓库将保存到扩展目录: ${localPath}`);
}
// 修改:检查目标目录是否已存在
if (fs.existsSync(localPath)) {
vscode.window.showErrorMessage(`目标目录已存在: ${localPath},请选择不同的名称或删除现有目录`);
if (!this.currentContainerId) {
vscode.window.showErrorMessage('请先选择容器');
return;
}
// 修改:放宽重复检查,只检查完全相同的路径
const existingRepo = this.gitRepos.find(repo => repo.localPath === localPath // 只检查路径完全相同的情况
);
const repoId = 'git-' + Date.now();
// 构建本地路径 - 在容器目录下创建分支子目录
const container = this.containers.find(c => c.id === this.currentContainerId);
if (!container) {
vscode.window.showErrorMessage('未找到容器');
return;
}
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft) {
vscode.window.showErrorMessage('未找到飞行器');
return;
}
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
vscode.window.showErrorMessage('未找到项目路径');
return;
}
// 为每个分支创建独立的子目录
const branchName = branch || 'main';
const branchSafeName = branchName.replace(/[^a-zA-Z0-9-_]/g, '-');
const repoDirName = `${name}-${branchSafeName}`;
// 路径:项目路径/飞行器名/容器名/仓库名-分支名/
const localPath = path.join(projectPath, aircraft.name, container.name, repoDirName);
console.log(`📁 Git仓库将保存到: ${localPath}`);
// 检查是否已存在相同 URL 和分支的仓库
const existingRepo = this.gitRepos.find(repo => repo.url === url && repo.branch === branchName && repo.containerId === this.currentContainerId);
if (existingRepo) {
vscode.window.showWarningMessage('该路径已存在 Git 仓库');
vscode.window.showWarningMessage('该 Git 仓库和分支组合已存在');
return;
}
const newRepo = {
id: repoId,
name: name,
name: `${name} (${branchName})`,
url: url,
localPath: localPath,
branch: branch || 'main',
lastSync: new Date().toLocaleString()
branch: branchName,
lastSync: new Date().toLocaleString(),
containerId: this.currentContainerId
};
console.log(`📁 准备克隆仓库: ${name}, 分支: ${newRepo.branch}, 路径: ${localPath}`);
// 显示进度
@@ -298,7 +365,23 @@ class ConfigPanel {
progress.report({ increment: 0 });
try {
// 确保目录存在
await fs.promises.mkdir(path.dirname(localPath), { recursive: true });
await fs.promises.mkdir(localPath, { recursive: true });
// 检查目录是否为空
const dirContents = await fs.promises.readdir(localPath);
if (dirContents.length > 0) {
const confirm = await vscode.window.showWarningMessage(`目标目录不为空,确定要覆盖吗?`, { modal: true }, '确定覆盖', '取消');
if (confirm !== '确定覆盖') {
vscode.window.showInformationMessage('克隆操作已取消');
return;
}
// 清空目录(除了 .git 文件夹,如果存在的话)
for (const item of dirContents) {
const itemPath = path.join(localPath, item);
if (item !== '.git') {
await fs.promises.rm(itemPath, { recursive: true, force: true });
}
}
}
// 克隆仓库
await isomorphic_git_1.default.clone({
fs: fs,
@@ -307,7 +390,7 @@ class ConfigPanel {
url: url,
singleBranch: true,
depth: 1,
ref: branch || 'main',
ref: branchName,
onProgress: (event) => {
if (event.total) {
const percent = (event.loaded / event.total) * 100;
@@ -317,29 +400,24 @@ class ConfigPanel {
});
console.log('✅ Git克隆成功完成');
this.gitRepos.push(newRepo);
await this.saveGitRepos();
console.log('✅ 仓库数据保存成功');
await this.saveCurrentProjectData();
console.log('✅ Git仓库数据保存到项目文件');
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${name} (${newRepo.branch})`);
// 检查 Webview 状态后再加载文件树
if (!this.isWebviewDisposed) {
console.log('🌳 开始加载仓库文件树...');
// 自动加载仓库文件树
this.currentRepoId = repoId;
await this.loadGitRepoFileTree(repoId);
console.log('✅ 仓库文件树加载完成');
// 更新 Webview 显示
this.updateWebview();
}
else {
console.log('⚠️ Webview 已被销毁,跳过文件树加载');
}
}
catch (error) {
console.error('❌ 在克隆过程中捕获错误:', error);
vscode.window.showErrorMessage(`克隆仓库失败: ${error}`);
// 清理失败的克隆目录
try {
console.log('🧹 开始清理失败的克隆目录...');
await fs.promises.rm(localPath, { recursive: true, force: true });
console.log('✅ 失败目录清理完成');
}
catch (cleanupError) {
console.error('❌ 清理失败目录时出错:', cleanupError);
}
}
});
}
@@ -382,7 +460,7 @@ class ConfigPanel {
});
// 更新最后同步时间
repo.lastSync = new Date().toLocaleString();
await this.saveGitRepos();
await this.saveCurrentProjectData();
// 重新加载文件树
await this.loadGitRepoFileTree(repoId);
vscode.window.showInformationMessage(`Git 仓库同步成功: ${repo.name}`);
@@ -400,14 +478,14 @@ class ConfigPanel {
const repo = this.gitRepos.find(r => r.id === repoId);
if (!repo)
return;
const confirm = await vscode.window.showWarningMessage(`确定要删除 Git 仓库 "${repo.name}" 吗?这也会删除本地副本`, { modal: true }, '确定删除');
const confirm = await vscode.window.showWarningMessage(`确定要删除 Git 仓库 "${repo.name}" 吗?这删除本地文件`, { modal: true }, '确定删除', '取消');
if (confirm === '确定删除') {
try {
// 删除本地目录
// 删除整个仓库目录(因为是独立目录
await fs.promises.rm(repo.localPath, { recursive: true, force: true });
// 从列表中移除
this.gitRepos = this.gitRepos.filter(r => r.id !== repoId);
await this.saveGitRepos();
await this.saveCurrentProjectData();
// 如果删除的是当前仓库,清空状态
if (this.currentRepoId === repoId) {
this.currentRepoId = '';
@@ -425,32 +503,53 @@ class ConfigPanel {
* 加载 Git 仓库文件树
*/
async loadGitRepoFileTree(repoId) {
// 检查 Webview 是否仍然有效
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,跳过文件树加载');
return;
}
const repo = this.gitRepos.find(r => r.id === repoId);
if (!repo)
return;
// 通知前端开始加载
try {
this.panel.webview.postMessage({
type: 'gitRepoLoading',
loading: true
});
}
catch (error) {
console.log('⚠️ 无法发送加载消息Webview 可能已被销毁');
return;
}
try {
const fileTree = await this.buildFileTree(repo.localPath);
this.currentRepoFileTree = fileTree;
// 更新最后访问时间
repo.lastSync = new Date().toLocaleString();
await this.saveGitRepos();
await this.saveCurrentProjectData();
}
catch (error) {
vscode.window.showErrorMessage(`加载仓库文件树失败: ${error}`);
console.error('加载仓库文件树失败:', error);
this.currentRepoFileTree = [];
}
// 再次检查 Webview 状态
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,跳过完成通知');
return;
}
// 通知前端加载完成
try {
this.panel.webview.postMessage({
type: 'gitRepoLoading',
loading: false
});
this.updateWebview();
}
catch (error) {
console.log('⚠️ 无法发送完成消息Webview 可能已被销毁');
}
}
/**
* 构建文件树
*/
@@ -459,8 +558,10 @@ class ConfigPanel {
const files = await fs.promises.readdir(dir);
const tree = [];
for (const file of files) {
// 忽略 .git 文件夹和其他隐藏文件
if (file.startsWith('.'))
// 忽略 .git 文件夹和 .dcsp-data.json
if (file.startsWith('.') && file !== '.git')
continue;
if (file === '.dcsp-data.json')
continue;
const filePath = path.join(dir, file);
const stats = await fs.promises.stat(filePath);
@@ -556,12 +657,12 @@ class ConfigPanel {
async saveCurrentProjectData() {
try {
if (!this.currentProjectId) {
vscode.window.showWarningMessage('未找到当前项目,数据将不会保存');
console.warn('未找到当前项目,数据将不会保存');
return;
}
const projectPath = this.projectPaths.get(this.currentProjectId);
if (!projectPath) {
vscode.window.showWarningMessage('未找到项目存储路径,数据将不会保存');
console.warn('未找到项目存储路径,数据将不会保存');
return;
}
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
@@ -571,15 +672,18 @@ class ConfigPanel {
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));
// 只保存与当前项目容器相关的 Git 仓库
const currentProjectGitRepos = this.gitRepos.filter(repo => currentContainerIds.includes(repo.containerId));
const data = {
projects: this.projects.filter(p => p.id === this.currentProjectId),
aircrafts: currentProjectAircrafts,
containers: currentProjectContainers,
configs: currentProjectConfigs
configs: currentProjectConfigs,
gitRepos: currentProjectGitRepos // 保存 Git 仓库数据
};
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
await vscode.workspace.fs.writeFile(dataUri, uint8Array);
console.log('✅ 当前项目数据已保存');
console.log('✅ 当前项目数据已保存,包含', currentProjectGitRepos.length, '个 Git 仓库');
}
catch (error) {
vscode.window.showErrorMessage(`保存项目数据失败: ${error}`);
@@ -608,6 +712,7 @@ class ConfigPanel {
this.aircrafts = [];
this.containers = [];
this.configs = [];
this.gitRepos = []; // 清空 Git 仓库数据
// 验证数据格式并加载
if (data.projects && Array.isArray(data.projects)) {
this.projects = data.projects;
@@ -621,13 +726,16 @@ class ConfigPanel {
if (data.configs && Array.isArray(data.configs)) {
this.configs = data.configs;
}
if (data.gitRepos && Array.isArray(data.gitRepos)) {
this.gitRepos = data.gitRepos; // 加载 Git 仓库数据
}
// 设置当前项目为第一个项目(如果有的话)
if (this.projects.length > 0) {
this.currentProjectId = this.projects[0].id;
this.projectPaths.set(this.currentProjectId, projectPath);
this.currentView = 'aircrafts';
}
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载`);
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${this.gitRepos.length} 个 Git 仓库`);
this.updateWebview();
return true;
}
@@ -760,26 +868,9 @@ class ConfigPanel {
name: name
};
this.projects.push(newProject);
// 关键修复设置当前项目ID
this.currentProjectId = newId;
vscode.window.showInformationMessage(`新建项目: ${name}`);
// 关键修复:立即要求用户选择项目存储路径
const selectedPath = await this.selectProjectPath(newId, name);
if (selectedPath) {
// 保存初始项目数据
await this.saveCurrentProjectData();
// 自动切换到飞行器视图
this.currentView = 'aircrafts';
this.updateWebview();
}
else {
// 如果用户取消选择路径,移除刚创建的项目
this.projects = this.projects.filter(p => p.id !== newId);
this.currentProjectId = '';
vscode.window.showWarningMessage('项目创建已取消');
this.updateWebview();
}
}
// 删除项目
async deleteProject(projectId) {
const project = this.projects.find(p => p.id === projectId);
@@ -795,6 +886,8 @@ class ConfigPanel {
// 删除相关的配置
const containerIds = this.containers.filter(c => aircraftIds.includes(c.aircraftId)).map(c => c.id);
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
// 删除相关的 Git 仓库
this.gitRepos = this.gitRepos.filter(repo => !containerIds.includes(repo.containerId));
// 删除项目路径映射
this.projectPaths.delete(projectId);
vscode.window.showInformationMessage(`删除项目: ${project.name}`);
@@ -824,29 +917,12 @@ class ConfigPanel {
projectId: this.currentProjectId
};
this.aircrafts.push(newAircraft);
// 新增:创建飞行器目录
// 创建飞行器目录
await this.createAircraftDirectory(newAircraft);
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
await this.saveCurrentProjectData();
this.updateWebview();
}
async createAircraftDirectory(aircraft) {
try {
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
console.warn('未找到项目路径,跳过创建飞行器目录');
return;
}
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
// 创建飞行器目录
await vscode.workspace.fs.createDirectory(aircraftDir);
console.log(`✅ 创建飞行器目录: ${aircraftDir.fsPath}`);
}
catch (error) {
console.error(`创建飞行器目录失败: ${error}`);
vscode.window.showWarningMessage(`创建飞行器目录失败: ${error}`);
}
}
// 删除飞行器
async deleteAircraft(aircraftId) {
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
@@ -858,6 +934,8 @@ 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));
// 删除相关的 Git 仓库
this.gitRepos = this.gitRepos.filter(repo => !containerIds.includes(repo.containerId));
vscode.window.showInformationMessage(`删除飞行器: ${aircraft.name}`);
await this.saveCurrentProjectData();
this.updateWebview();
@@ -885,7 +963,7 @@ class ConfigPanel {
aircraftId: this.currentAircraftId
};
this.containers.push(newContainer);
// 新增:创建容器目录
// 创建容器目录
await this.createContainerDirectory(newContainer);
// 创建两个默认配置文件
const configCount = this.configs.length;
@@ -909,38 +987,6 @@ class ConfigPanel {
await this.saveCurrentProjectData();
this.updateWebview();
}
// 新增方法:创建容器目录
async createContainerDirectory(container) {
try {
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft) {
console.warn('未找到对应的飞行器,跳过创建容器目录');
return;
}
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
console.warn('未找到项目路径,跳过创建容器目录');
return;
}
// 构建路径:项目路径/飞行器名/容器名
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
// 确保飞行器目录存在
try {
await vscode.workspace.fs.createDirectory(aircraftDir);
}
catch (error) {
// 目录可能已存在,忽略错误
}
// 创建容器目录
await vscode.workspace.fs.createDirectory(containerDir);
console.log(`✅ 创建容器目录: ${containerDir.fsPath}`);
}
catch (error) {
console.error(`创建容器目录失败: ${error}`);
vscode.window.showWarningMessage(`创建容器目录失败: ${error}`);
}
}
// 删除容器
async deleteContainer(containerId) {
const container = this.containers.find(c => c.id === containerId);
@@ -950,6 +996,8 @@ class ConfigPanel {
this.containers = this.containers.filter(c => c.id !== containerId);
// 删除相关的配置
this.configs = this.configs.filter(cfg => cfg.containerId !== containerId);
// 删除相关的 Git 仓库
this.gitRepos = this.gitRepos.filter(repo => repo.containerId !== containerId);
vscode.window.showInformationMessage(`删除容器: ${container.name}`);
await this.saveCurrentProjectData();
this.updateWebview();
@@ -985,43 +1033,47 @@ class ConfigPanel {
containerId: this.currentContainerId
};
this.configs.push(newConfig);
// 新增:确保容器目录存在
// 确保容器目录存在
await this.ensureContainerDirectoryExists(this.currentContainerId);
vscode.window.showInformationMessage(`新建配置: ${name}`);
await this.saveCurrentProjectData();
this.updateWebview();
}
// 新增方法:确保容器目录存在
async ensureContainerDirectoryExists(containerId) {
try {
const container = this.containers.find(c => c.id === containerId);
if (!container)
return;
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft)
return;
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath)
return;
// 构建路径并创建目录
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
await vscode.workspace.fs.createDirectory(aircraftDir);
await vscode.workspace.fs.createDirectory(containerDir);
}
catch (error) {
console.error(`确保容器目录存在失败: ${error}`);
}
}
// 删除配置文件
// 删除配置文件 - 修复版本,同时删除磁盘文件
async deleteConfig(configId) {
const config = this.configs.find(c => c.id === configId);
if (config) {
if (!config)
return;
const confirm = await vscode.window.showWarningMessage(`确定要删除配置文件 "${config.name}" 吗?这将同时删除磁盘上的文件。`, { modal: true }, '确定删除', '取消');
if (confirm !== '确定删除') {
return;
}
try {
// 从内存中删除配置
this.configs = this.configs.filter(c => c.id !== configId);
// 删除磁盘上的配置文件
const container = this.containers.find(c => c.id === config.containerId);
if (container) {
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (aircraft) {
const projectPath = this.projectPaths.get(aircraft.projectId);
if (projectPath) {
const filePath = path.join(projectPath, aircraft.name, container.name, config.fileName);
// 检查文件是否存在,如果存在则删除
if (fs.existsSync(filePath)) {
await fs.promises.unlink(filePath);
console.log(`✅ 已删除配置文件: ${filePath}`);
}
}
}
}
vscode.window.showInformationMessage(`删除配置: ${config.name}`);
await this.saveCurrentProjectData();
this.updateWebview();
}
catch (error) {
vscode.window.showErrorMessage(`删除配置文件失败: ${error}`);
}
}
// 保存配置文件到磁盘
async saveConfigFileToDisk(configId, content) {
@@ -1084,19 +1136,33 @@ class ConfigPanel {
}
// 加载配置文件
loadConfigFile(configId) {
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,跳过加载配置文件');
return;
}
const config = this.configs.find(c => c.id === configId);
if (config) {
try {
this.panel.webview.postMessage({
type: 'configFileLoaded',
content: config.content || `# ${config.name} 的配置文件\n# 您可以在此编辑配置内容\n\n`
});
}
catch (error) {
console.log('⚠️ 无法发送配置文件内容Webview 可能已被销毁');
}
}
else {
try {
this.panel.webview.postMessage({
type: 'configFileLoaded',
content: `# 这是 ${configId} 的配置文件\n# 您可以在此编辑配置内容\n\napp.name = "示例应用"\napp.port = 8080\napp.debug = true`
});
}
catch (error) {
console.log('⚠️ 无法发送默认配置文件内容Webview 可能已被销毁');
}
}
}
// === Git 分支管理 ===
async fetchBranches(url) {
@@ -1139,11 +1205,13 @@ class ConfigPanel {
}
progress.report({ increment: 80, message: '处理分支数据...' });
// 发送分支数据到前端
if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: branches,
repoUrl: url
});
}
progress.report({ increment: 100, message: '完成' });
}
catch (error) {
@@ -1156,11 +1224,13 @@ class ConfigPanel {
{ name: 'develop', isCurrent: false, isRemote: false, selected: false },
{ name: 'feature/new-feature', isCurrent: false, isRemote: false, selected: false }
];
if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: mockBranches,
repoUrl: url
});
}
vscode.window.showWarningMessage('使用模拟分支数据,实际分支可能不同');
}
});
@@ -1199,12 +1269,23 @@ class ConfigPanel {
}
generateRepoName(url, branch) {
const repoName = url.split('/').pop()?.replace('.git', '') || 'unknown-repo';
return `${repoName}-${branch.replace(/\//g, '-')}`;
const branchSafeName = branch.replace(/[^a-zA-Z0-9-_]/g, '-');
return `${repoName}-${branchSafeName}`;
}
// 更新视图
updateWebview() {
// 检查 Webview 是否仍然有效
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,跳过更新');
return;
}
try {
this.panel.webview.html = this.getWebviewContent();
}
catch (error) {
console.error('更新 Webview 失败:', error);
}
}
getWebviewContent() {
switch (this.currentView) {
case 'projects':
@@ -1230,10 +1311,12 @@ class ConfigPanel {
const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
const currentRepo = this.gitRepos.find(r => r.id === this.currentRepoId);
// 获取当前容器的 Git 仓库
const containerGitRepos = this.gitRepos.filter(repo => repo.containerId === this.currentContainerId);
return this.configView.render({
container: currentContainer,
configs: containerConfigs,
gitRepos: this.gitRepos,
gitRepos: containerGitRepos,
currentGitRepo: currentRepo,
gitFileTree: this.currentRepoFileTree,
gitLoading: false

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigView = void 0;
// src/panels/views/ConfigView.ts
const BaseView_1 = require("./BaseView");
class ConfigView extends BaseView_1.BaseView {
render(data) {
@@ -13,7 +12,7 @@ class ConfigView extends BaseView_1.BaseView {
const gitLoading = data?.gitLoading || false;
const gitBranches = data?.gitBranches || [];
const gitRepoUrl = data?.gitRepoUrl || '';
// 生成配置列表的 HTML
// 生成配置列表的 HTML - 包含配置文件和 Git 仓库
const configsHtml = configs.map((config) => `
<tr>
<td>
@@ -27,21 +26,17 @@ class ConfigView extends BaseView_1.BaseView {
</td>
</tr>
`).join('');
// 生成 Git 仓库列表的 HTML
// 生成 Git 仓库列表的 HTML - 以配置文件形式显示
const gitReposHtml = gitRepos.map(repo => `
<tr>
<td>
<span class="repo-name" data-repo-id="${repo.id}">📁 ${repo.name}</span>
<span class="editable">📁 ${repo.name}</span>
<div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;">
${repo.url}
</div>
<div style="font-size: 11px; color: var(--vscode-descriptionForeground);">
分支: ${repo.branch} | 最后同步: ${repo.lastSync}
模型1、模型2
</div>
</td>
<td>
<span class="clickable" onclick="loadGitRepo('${repo.id}')">打开</span>
<span class="clickable" onclick="syncGitRepo('${repo.id}')" style="margin-left: 10px;">同步</span>
<span class="clickable" onclick="loadGitRepo('${repo.id}')">${repo.url.split('/').pop()}</span>
</td>
<td>
<button class="btn-delete" onclick="deleteGitRepo('${repo.id}')">删除</button>
@@ -50,8 +45,6 @@ class ConfigView extends BaseView_1.BaseView {
`).join('');
// 生成分支选择的 HTML
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : '';
// 生成文件树的 HTML
const fileTreeHtml = gitFileTree.length > 0 ? this.renderFileTree(gitFileTree) : '<div style="text-align: center; padding: 20px; color: var(--vscode-descriptionForeground);">选择仓库以浏览文件</div>';
return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
@@ -60,77 +53,6 @@ class ConfigView extends BaseView_1.BaseView {
<title>配置管理</title>
${this.getStyles()}
<style>
.git-container {
display: flex;
gap: 20px;
margin-top: 20px;
}
.repo-list {
flex: 1;
min-width: 300px;
}
.file-tree {
flex: 2;
min-width: 400px;
border: 1px solid var(--vscode-panel-border);
border-radius: 4px;
padding: 15px;
background: var(--vscode-panel-background);
max-height: 400px;
overflow-y: auto;
}
.tree-item {
margin: 2px 0;
}
.tree-folder {
cursor: pointer;
padding: 2px 4px;
border-radius: 2px;
display: inline-block;
}
.tree-folder:hover {
background: var(--vscode-list-hoverBackground);
}
.tree-file {
padding: 2px 4px;
border-radius: 2px;
display: inline-block;
}
.tree-file:hover {
background: var(--vscode-list-hoverBackground);
}
.tree-children {
margin-left: 10px;
}
.current-repo {
background: var(--vscode-badge-background);
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
}
.loading {
text-align: center;
padding: 20px;
color: var(--vscode-descriptionForeground);
}
.btn-sync {
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
margin-left: 10px;
}
.btn-sync:hover {
background: var(--vscode-button-hoverBackground);
}
.branch-selection {
border: 1px solid var(--vscode-input-border);
}
.branch-item:hover {
background: var(--vscode-list-hoverBackground);
}
.url-input-section {
background: var(--vscode-panel-background);
padding: 15px;
@@ -138,24 +60,21 @@ class ConfigView extends BaseView_1.BaseView {
margin-bottom: 15px;
border: 1px solid var(--vscode-input-border);
}
.debug-panel {
background: var(--vscode-inputValidation-infoBackground);
padding: 10px;
margin-bottom: 15px;
border-radius: 4px;
border: 1px solid var(--vscode-inputValidation-infoBorder);
}
.debug-info {
font-size: 12px;
color: var(--vscode-input-foreground);
font-family: 'Courier New', monospace;
}
.section-title {
margin: 30px 0 15px 0;
padding-bottom: 10px;
border-bottom: 2px solid var(--vscode-panel-border);
color: var(--vscode-titleBar-activeForeground);
}
.config-section {
margin-bottom: 30px;
}
.branch-selection {
border: 1px solid var(--vscode-input-border);
}
.branch-item:hover {
background: var(--vscode-list-hoverBackground);
}
</style>
</head>
<body>
@@ -164,7 +83,8 @@ class ConfigView extends BaseView_1.BaseView {
<button class="back-btn" onclick="goBackToContainers()">← 返回容器管理</button>
</div>
<!-- 配置管理部分 -->
<!-- 配置文件管理部分 -->
<div class="config-section">
<h3 class="section-title">📋 配置文件管理</h3>
<table class="table">
<thead>
@@ -176,6 +96,7 @@ class ConfigView extends BaseView_1.BaseView {
</thead>
<tbody>
${configsHtml}
${gitReposHtml}
<tr>
<td colspan="3" style="text-align: center; padding: 20px;">
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
@@ -183,8 +104,10 @@ class ConfigView extends BaseView_1.BaseView {
</tr>
</tbody>
</table>
</div>
<!-- Git 仓库管理部分 -->
<div class="config-section">
<h3 class="section-title">📚 Git 仓库管理</h3>
<!-- URL 输入区域 -->
@@ -204,33 +127,12 @@ class ConfigView extends BaseView_1.BaseView {
<div style="margin-bottom: 20px;">
${currentGitRepo ? `
<div class="current-repo">
<div style="background: var(--vscode-badge-background); padding: 10px; border-radius: 4px; margin-bottom: 15px;">
<strong>当前仓库:</strong> ${currentGitRepo.name} (${currentGitRepo.url})
<button class="btn-sync" onclick="syncGitRepo('${currentGitRepo.id}')">同步</button>
<button class="btn-sync" onclick="syncGitRepo('${currentGitRepo.id}')" style="background: var(--vscode-button-background); color: var(--vscode-button-foreground); border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; margin-left: 10px;">同步</button>
</div>
` : ''}
</div>
<div class="git-container">
<div class="repo-list">
<table class="table">
<thead>
<tr>
<th width="60%">仓库</th>
<th width="20%">操作</th>
<th width="20%">管理</th>
</tr>
</thead>
<tbody>
${gitReposHtml}
</tbody>
</table>
</div>
<div class="file-tree">
<h4>📂 文件浏览器</h4>
${gitLoading ? '<div class="loading">🔄 加载中...</div>' : fileTreeHtml}
</div>
</div>
<!-- 配置文件编辑器 -->
@@ -329,14 +231,6 @@ class ConfigView extends BaseView_1.BaseView {
}
// Git 仓库管理功能
function updateDebugInfo(message) {
const debugElement = document.getElementById('debugInfo');
if (debugElement) {
debugElement.innerHTML = message;
console.log('🔍 调试信息:', message);
}
}
function fetchBranches() {
const urlInput = document.getElementById('repoUrlInput');
const repoUrl = urlInput.value.trim();
@@ -353,7 +247,6 @@ class ConfigView extends BaseView_1.BaseView {
currentRepoUrl = repoUrl;
console.log('🌿 获取分支列表:', repoUrl);
updateDebugInfo('🌿 正在获取分支列表...');
vscode.postMessage({
type: 'fetchBranches',
@@ -369,7 +262,6 @@ class ConfigView extends BaseView_1.BaseView {
selectedBranches.delete(branchName);
}
console.log('选中的分支:', Array.from(selectedBranches));
updateDebugInfo('选中的分支: ' + Array.from(selectedBranches).join(', '));
}
function cloneSelectedBranches() {
@@ -379,7 +271,6 @@ class ConfigView extends BaseView_1.BaseView {
}
console.log('🚀 开始克隆选中的分支:', Array.from(selectedBranches));
updateDebugInfo('🚀 开始克隆分支: ' + Array.from(selectedBranches).join(', '));
vscode.postMessage({
type: 'cloneBranches',
@@ -394,7 +285,6 @@ class ConfigView extends BaseView_1.BaseView {
// 隐藏分支选择区域
document.getElementById('branchSelectionContainer').innerHTML = '';
updateDebugInfo('✅ 分支克隆请求已发送');
}
function cancelBranchSelection() {
@@ -405,8 +295,6 @@ class ConfigView extends BaseView_1.BaseView {
// 隐藏分支选择区域
document.getElementById('branchSelectionContainer').innerHTML = '';
updateDebugInfo('❌ 已取消分支选择');
vscode.postMessage({
type: 'cancelBranchSelection'
});
@@ -414,7 +302,6 @@ class ConfigView extends BaseView_1.BaseView {
function loadGitRepo(repoId) {
console.log('📂 加载仓库:', repoId);
updateDebugInfo('📂 正在加载仓库...');
vscode.postMessage({
type: 'loadGitRepo',
repoId: repoId
@@ -423,7 +310,6 @@ class ConfigView extends BaseView_1.BaseView {
function syncGitRepo(repoId) {
console.log('🔄 同步仓库:', repoId);
updateDebugInfo('🔄 正在同步仓库...');
vscode.postMessage({
type: 'syncGitRepo',
repoId: repoId
@@ -433,7 +319,6 @@ class ConfigView extends BaseView_1.BaseView {
function deleteGitRepo(repoId) {
if (confirm('确定删除这个 Git 仓库吗?')) {
console.log('🗑️ 删除仓库:', repoId);
updateDebugInfo('🗑️ 正在删除仓库...');
vscode.postMessage({
type: 'deleteGitRepo',
repoId: repoId
@@ -441,24 +326,6 @@ class ConfigView extends BaseView_1.BaseView {
}
}
function importFile(filePath) {
if (confirm('确定要将此文件导入到当前容器吗?')) {
console.log('📥 导入文件:', filePath);
updateDebugInfo('📥 正在导入文件...');
vscode.postMessage({
type: 'importGitFile',
filePath: filePath
});
}
}
function toggleFolder(folderPath) {
const folderElement = document.getElementById('folder-' + folderPath.replace(/[^a-zA-Z0-9]/g, '-'));
if (folderElement) {
folderElement.style.display = folderElement.style.display === 'none' ? 'block' : 'none';
}
}
// 动态渲染分支选择区域
function renderBranchSelection(branches, repoUrl) {
const container = document.getElementById('branchSelectionContainer');
@@ -577,29 +444,17 @@ class ConfigView extends BaseView_1.BaseView {
if (message.type === 'branchesFetched') {
console.log('🌿 收到分支数据:', message.branches);
updateDebugInfo('✅ 获取到 ' + message.branches.length + ' 个分支');
renderBranchSelection(message.branches, message.repoUrl);
}
if (message.type === 'configFileLoaded') {
document.getElementById('configContent').value = message.content;
}
if (message.type === 'gitRepoLoading') {
updateDebugInfo(message.loading ? '🔄 后端正在加载仓库文件树...' : '✅ 后端文件树加载完成');
}
});
// 初始化
document.addEventListener('DOMContentLoaded', function() {
console.log('📄 ConfigView 页面加载完成');
updateDebugInfo('📄 页面加载完成 - 等待用户操作');
setTimeout(() => {
document.querySelectorAll('.tree-children').forEach(el => {
el.style.display = 'block';
});
}, 100);
});
</script>
</body>
@@ -627,32 +482,6 @@ class ConfigView extends BaseView_1.BaseView {
html += '</div></div>';
return html;
}
renderFileTree(nodes, level = 0) {
return nodes.map(node => {
const paddingLeft = level * 20;
if (node.type === 'folder') {
return `
<div class="tree-item" style="padding-left: ${paddingLeft}px;">
<span class="tree-folder" onclick="toggleFolder('${node.path}')">
📁 ${node.name}
</span>
<div id="folder-${node.path.replace(/[^a-zA-Z0-9]/g, '-')}" class="tree-children">
${this.renderFileTree(node.children || [], level + 1)}
</div>
</div>
`;
}
else {
return `
<div class="tree-item" style="padding-left: ${paddingLeft}px;">
<span class="tree-file clickable" onclick="importFile('${node.path}')">
📄 ${node.name}
</span>
</div>
`;
}
}).join('');
}
}
exports.ConfigView = ConfigView;
//# sourceMappingUR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,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;YACrD,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAAC;QACnE,CAAC,CAAC,CAAC;QAEH,IAAI,IAAI,QAAQ,CAAC;QACjB,IAAI,IAAI,iCAAiC,CAAC;QAC1C,IAAI,IAAI,yGAAyG,CAAC;QAClH,IAAI,IAAI,wEAAwE,CAAC;QACjF,IAAI,IAAI,cAAc,CAAC;QAEvB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA/eD,gCA+eC"}

View File

@@ -1,4 +1,3 @@
// src/panels/ConfigPanel.ts
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
@@ -35,13 +34,6 @@ interface Config {
containerId: string;
}
interface ProjectData {
projects: Project[];
aircrafts: Aircraft[];
containers: Container[];
configs: Config[];
}
// Git 仓库接口
interface GitRepo {
id: string;
@@ -50,6 +42,7 @@ interface GitRepo {
localPath: string;
branch: string;
lastSync: string;
containerId: string; // 关联到特定容器
}
interface GitFileTree {
@@ -59,6 +52,14 @@ interface GitFileTree {
children?: GitFileTree[];
}
interface ProjectData {
projects: Project[];
aircrafts: Aircraft[];
containers: Container[];
configs: Config[];
gitRepos: GitRepo[]; // Git 仓库数据整合到项目数据中
}
// Git 分支接口
interface GitBranch {
name: string;
@@ -83,14 +84,17 @@ export class ConfigPanel {
private aircrafts: Aircraft[] = [];
private containers: Container[] = [];
private configs: Config[] = [];
private gitRepos: GitRepo[] = []; // Git 仓库数据
// Git 仓库存储
private gitRepos: GitRepo[] = [];
// Git 文件树
private currentRepoFileTree: GitFileTree[] = [];
// 项目存储路径映射
private projectPaths: Map<string, string> = new Map();
// Webview 状态跟踪
private isWebviewDisposed: boolean = false;
// 视图实例
private readonly projectView: ProjectView;
private readonly aircraftView: AircraftView;
@@ -122,6 +126,7 @@ export class ConfigPanel {
public constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
this.panel = panel;
this.extensionUri = extensionUri;
this.isWebviewDisposed = false; // 初始化状态
// 初始化各个视图
this.projectView = new ProjectView(extensionUri);
@@ -129,13 +134,11 @@ export class ConfigPanel {
this.containerView = new ContainerView(extensionUri);
this.configView = new ConfigView(extensionUri);
// 加载 Git 仓库数据
this.loadGitRepos();
this.updateWebview();
this.setupMessageListener();
this.panel.onDidDispose(() => {
this.isWebviewDisposed = true; // 标记为已销毁
ConfigPanel.currentPanel = undefined;
});
}
@@ -143,6 +146,14 @@ export class ConfigPanel {
private setupMessageListener() {
this.panel.webview.onDidReceiveMessage(async (data) => {
console.log('📨 收到Webview消息:', data);
// 检查 Webview 是否仍然有效
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,忽略消息');
return;
}
try {
switch (data.type) {
case 'openExistingProject':
await this.openExistingProject();
@@ -295,46 +306,106 @@ export class ConfigPanel {
await this.importGitFile(data.filePath);
break;
}
} catch (error) {
console.error('处理 Webview 消息时出错:', error);
if (!this.isWebviewDisposed) {
vscode.window.showErrorMessage(`处理操作时出错: ${error}`);
}
}
});
}
// === 目录创建方法 ===
/**
* 创建飞行器目录
*/
private async createAircraftDirectory(aircraft: Aircraft): Promise<void> {
try {
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
console.warn('未找到项目路径,跳过创建飞行器目录');
return;
}
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
// 创建飞行器目录
await vscode.workspace.fs.createDirectory(aircraftDir);
console.log(`✅ 创建飞行器目录: ${aircraftDir.fsPath}`);
} catch (error) {
console.error(`创建飞行器目录失败: ${error}`);
}
}
/**
* 创建容器目录
*/
private async createContainerDirectory(container: Container): Promise<void> {
try {
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft) {
console.warn('未找到对应的飞行器,跳过创建容器目录');
return;
}
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
console.warn('未找到项目路径,跳过创建容器目录');
return;
}
// 构建路径:项目路径/飞行器名/容器名
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
// 确保飞行器目录存在
try {
await vscode.workspace.fs.createDirectory(aircraftDir);
} catch (error) {
// 目录可能已存在,忽略错误
}
// 创建容器目录
await vscode.workspace.fs.createDirectory(containerDir);
console.log(`✅ 创建容器目录: ${containerDir.fsPath}`);
} catch (error) {
console.error(`创建容器目录失败: ${error}`);
}
}
/**
* 确保容器目录存在
*/
private async ensureContainerDirectoryExists(containerId: string): Promise<void> {
try {
const container = this.containers.find(c => c.id === containerId);
if (!container) return;
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft) return;
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) return;
// 构建路径并创建目录
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
await vscode.workspace.fs.createDirectory(aircraftDir);
await vscode.workspace.fs.createDirectory(containerDir);
} catch (error) {
console.error(`确保容器目录存在失败: ${error}`);
}
}
// === Git 仓库管理方法 ===
/**
* 加 Git 仓库数据
*/
private async loadGitRepos(): Promise<void> {
try {
const globalStoragePath = this.extensionUri.fsPath;
const reposFile = path.join(globalStoragePath, 'git-repos.json');
if (fs.existsSync(reposFile)) {
const data = await fs.promises.readFile(reposFile, 'utf8');
this.gitRepos = JSON.parse(data);
}
} catch (error) {
vscode.window.showErrorMessage(`加载 Git 仓库数据失败: ${error}`);
}
}
/**
* 保存 Git 仓库数据
*/
private async saveGitRepos(): Promise<void> {
try {
const globalStoragePath = this.extensionUri.fsPath;
const reposFile = path.join(globalStoragePath, 'git-repos.json');
// 确保目录存在
await fs.promises.mkdir(path.dirname(reposFile), { recursive: true });
await fs.promises.writeFile(reposFile, JSON.stringify(this.gitRepos, null, 2));
} catch (error) {
vscode.window.showErrorMessage(`保存 Git 仓库数据失败: ${error}`);
}
}
/**
* 添加 Git 仓库到配置目录
* 加 Git 仓库到容器目录
*/
private async addGitRepo(url: string, name: string, branch?: string): Promise<void> {
try {
@@ -344,48 +415,59 @@ export class ConfigPanel {
return;
}
const repoId = 'git-' + Date.now();
// 构建本地路径
let localPath = '';
if (this.currentContainerId && this.currentProjectId) {
const projectPath = this.projectPaths.get(this.currentProjectId);
const container = this.containers.find(c => c.id === this.currentContainerId);
const aircraft = this.aircrafts.find(a => a.id === container?.aircraftId);
if (projectPath && container && aircraft) {
localPath = path.join(projectPath, aircraft.name, container.name, name);
console.log(`📁 Git仓库将保存到容器目录: ${localPath}`);
}
}
if (!localPath) {
localPath = path.join(this.extensionUri.fsPath, name);
console.log(`📁 Git仓库将保存到扩展目录: ${localPath}`);
}
// 修改:检查目标目录是否已存在
if (fs.existsSync(localPath)) {
vscode.window.showErrorMessage(`目标目录已存在: ${localPath},请选择不同的名称或删除现有目录`);
if (!this.currentContainerId) {
vscode.window.showErrorMessage('请先选择容器');
return;
}
// 修改:放宽重复检查,只检查完全相同的路径
const repoId = 'git-' + Date.now();
// 构建本地路径 - 在容器目录下创建分支子目录
const container = this.containers.find(c => c.id === this.currentContainerId);
if (!container) {
vscode.window.showErrorMessage('未找到容器');
return;
}
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft) {
vscode.window.showErrorMessage('未找到飞行器');
return;
}
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
vscode.window.showErrorMessage('未找到项目路径');
return;
}
// 为每个分支创建独立的子目录
const branchName = branch || 'main';
const branchSafeName = branchName.replace(/[^a-zA-Z0-9-_]/g, '-');
const repoDirName = `${name}-${branchSafeName}`;
// 路径:项目路径/飞行器名/容器名/仓库名-分支名/
const localPath = path.join(projectPath, aircraft.name, container.name, repoDirName);
console.log(`📁 Git仓库将保存到: ${localPath}`);
// 检查是否已存在相同 URL 和分支的仓库
const existingRepo = this.gitRepos.find(repo =>
repo.localPath === localPath // 只检查路径完全相同的情况
repo.url === url && repo.branch === branchName && repo.containerId === this.currentContainerId
);
if (existingRepo) {
vscode.window.showWarningMessage('该路径已存在 Git 仓库');
vscode.window.showWarningMessage('该 Git 仓库和分支组合已存在');
return;
}
const newRepo: GitRepo = {
id: repoId,
name: name,
name: `${name} (${branchName})`, // 在名称中包含分支信息
url: url,
localPath: localPath,
branch: branch || 'main',
lastSync: new Date().toLocaleString()
branch: branchName,
lastSync: new Date().toLocaleString(),
containerId: this.currentContainerId
};
console.log(`📁 准备克隆仓库: ${name}, 分支: ${newRepo.branch}, 路径: ${localPath}`);
@@ -400,7 +482,31 @@ export class ConfigPanel {
try {
// 确保目录存在
await fs.promises.mkdir(path.dirname(localPath), { recursive: true });
await fs.promises.mkdir(localPath, { recursive: true });
// 检查目录是否为空
const dirContents = await fs.promises.readdir(localPath);
if (dirContents.length > 0) {
const confirm = await vscode.window.showWarningMessage(
`目标目录不为空,确定要覆盖吗?`,
{ modal: true },
'确定覆盖',
'取消'
);
if (confirm !== '确定覆盖') {
vscode.window.showInformationMessage('克隆操作已取消');
return;
}
// 清空目录(除了 .git 文件夹,如果存在的话)
for (const item of dirContents) {
const itemPath = path.join(localPath, item);
if (item !== '.git') {
await fs.promises.rm(itemPath, { recursive: true, force: true });
}
}
}
// 克隆仓库
await git.clone({
@@ -410,7 +516,7 @@ export class ConfigPanel {
url: url,
singleBranch: true,
depth: 1,
ref: branch || 'main',
ref: branchName,
onProgress: (event: any) => {
if (event.total) {
const percent = (event.loaded / event.total) * 100;
@@ -422,32 +528,25 @@ export class ConfigPanel {
console.log('✅ Git克隆成功完成');
this.gitRepos.push(newRepo);
await this.saveGitRepos();
console.log('✅ 仓库数据保存成功');
await this.saveCurrentProjectData();
console.log('✅ Git仓库数据保存到项目文件');
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${name} (${newRepo.branch})`);
// 检查 Webview 状态后再加载文件树
if (!this.isWebviewDisposed) {
console.log('🌳 开始加载仓库文件树...');
// 自动加载仓库文件树
this.currentRepoId = repoId;
await this.loadGitRepoFileTree(repoId);
console.log('✅ 仓库文件树加载完成');
// 更新 Webview 显示
this.updateWebview();
} else {
console.log('⚠️ Webview 已被销毁,跳过文件树加载');
}
} catch (error) {
console.error('❌ 在克隆过程中捕获错误:', error);
vscode.window.showErrorMessage(`克隆仓库失败: ${error}`);
// 清理失败的克隆目录
try {
console.log('🧹 开始清理失败的克隆目录...');
await fs.promises.rm(localPath, { recursive: true, force: true });
console.log('✅ 失败目录清理完成');
} catch (cleanupError) {
console.error('❌ 清理失败目录时出错:', cleanupError);
}
}
});
@@ -495,7 +594,7 @@ export class ConfigPanel {
// 更新最后同步时间
repo.lastSync = new Date().toLocaleString();
await this.saveGitRepos();
await this.saveCurrentProjectData();
// 重新加载文件树
await this.loadGitRepoFileTree(repoId);
@@ -517,19 +616,20 @@ export class ConfigPanel {
if (!repo) return;
const confirm = await vscode.window.showWarningMessage(
`确定要删除 Git 仓库 "${repo.name}" 吗?这也会删除本地副本`,
`确定要删除 Git 仓库 "${repo.name}" 吗?这删除本地文件`,
{ modal: true },
'确定删除'
'确定删除',
'取消'
);
if (confirm === '确定删除') {
try {
// 删除本地目录
// 删除整个仓库目录(因为是独立目录
await fs.promises.rm(repo.localPath, { recursive: true, force: true });
// 从列表中移除
this.gitRepos = this.gitRepos.filter(r => r.id !== repoId);
await this.saveGitRepos();
await this.saveCurrentProjectData();
// 如果删除的是当前仓库,清空状态
if (this.currentRepoId === repoId) {
@@ -550,14 +650,25 @@ export class ConfigPanel {
* 加载 Git 仓库文件树
*/
private async loadGitRepoFileTree(repoId: string): Promise<void> {
// 检查 Webview 是否仍然有效
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,跳过文件树加载');
return;
}
const repo = this.gitRepos.find(r => r.id === repoId);
if (!repo) return;
// 通知前端开始加载
try {
this.panel.webview.postMessage({
type: 'gitRepoLoading',
loading: true
});
} catch (error) {
console.log('⚠️ 无法发送加载消息Webview 可能已被销毁');
return;
}
try {
const fileTree = await this.buildFileTree(repo.localPath);
@@ -565,20 +676,30 @@ export class ConfigPanel {
// 更新最后访问时间
repo.lastSync = new Date().toLocaleString();
await this.saveGitRepos();
await this.saveCurrentProjectData();
} catch (error) {
vscode.window.showErrorMessage(`加载仓库文件树失败: ${error}`);
console.error('加载仓库文件树失败:', error);
this.currentRepoFileTree = [];
}
// 再次检查 Webview 状态
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,跳过完成通知');
return;
}
// 通知前端加载完成
try {
this.panel.webview.postMessage({
type: 'gitRepoLoading',
loading: false
});
this.updateWebview();
} catch (error) {
console.log('⚠️ 无法发送完成消息Webview 可能已被销毁');
}
}
/**
@@ -590,8 +711,9 @@ export class ConfigPanel {
const tree: GitFileTree[] = [];
for (const file of files) {
// 忽略 .git 文件夹和其他隐藏文件
if (file.startsWith('.')) continue;
// 忽略 .git 文件夹和 .dcsp-data.json
if (file.startsWith('.') && file !== '.git') continue;
if (file === '.dcsp-data.json') continue;
const filePath = path.join(dir, file);
const stats = await fs.promises.stat(filePath);
@@ -698,13 +820,13 @@ export class ConfigPanel {
private async saveCurrentProjectData(): Promise<void> {
try {
if (!this.currentProjectId) {
vscode.window.showWarningMessage('未找到当前项目,数据将不会保存');
console.warn('未找到当前项目,数据将不会保存');
return;
}
const projectPath = this.projectPaths.get(this.currentProjectId);
if (!projectPath) {
vscode.window.showWarningMessage('未找到项目存储路径,数据将不会保存');
console.warn('未找到项目存储路径,数据将不会保存');
return;
}
@@ -717,17 +839,23 @@ export class ConfigPanel {
const currentContainerIds = currentProjectContainers.map(c => c.id);
const currentProjectConfigs = this.configs.filter(cfg => currentContainerIds.includes(cfg.containerId));
// 只保存与当前项目容器相关的 Git 仓库
const currentProjectGitRepos = this.gitRepos.filter(repo =>
currentContainerIds.includes(repo.containerId)
);
const data: ProjectData = {
projects: this.projects.filter(p => p.id === this.currentProjectId), // 只保存当前项目
projects: this.projects.filter(p => p.id === this.currentProjectId),
aircrafts: currentProjectAircrafts,
containers: currentProjectContainers,
configs: currentProjectConfigs
configs: currentProjectConfigs,
gitRepos: currentProjectGitRepos // 保存 Git 仓库数据
};
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
await vscode.workspace.fs.writeFile(dataUri, uint8Array);
console.log('✅ 当前项目数据已保存');
console.log('✅ 当前项目数据已保存,包含', currentProjectGitRepos.length, '个 Git 仓库');
} catch (error) {
vscode.window.showErrorMessage(`保存项目数据失败: ${error}`);
}
@@ -758,6 +886,7 @@ export class ConfigPanel {
this.aircrafts = [];
this.containers = [];
this.configs = [];
this.gitRepos = []; // 清空 Git 仓库数据
// 验证数据格式并加载
if (data.projects && Array.isArray(data.projects)) {
@@ -772,6 +901,9 @@ export class ConfigPanel {
if (data.configs && Array.isArray(data.configs)) {
this.configs = data.configs;
}
if (data.gitRepos && Array.isArray(data.gitRepos)) {
this.gitRepos = data.gitRepos; // 加载 Git 仓库数据
}
// 设置当前项目为第一个项目(如果有的话)
if (this.projects.length > 0) {
@@ -780,7 +912,7 @@ export class ConfigPanel {
this.currentView = 'aircrafts';
}
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载`);
vscode.window.showInformationMessage(`项目数据已从 ${projectPath} 加载,包含 ${this.gitRepos.length} 个 Git 仓库`);
this.updateWebview();
return true;
} catch (error) {
@@ -934,27 +1066,8 @@ export class ConfigPanel {
};
this.projects.push(newProject);
// 关键修复设置当前项目ID
this.currentProjectId = newId;
vscode.window.showInformationMessage(`新建项目: ${name}`);
// 关键修复:立即要求用户选择项目存储路径
const selectedPath = await this.selectProjectPath(newId, name);
if (selectedPath) {
// 保存初始项目数据
await this.saveCurrentProjectData();
// 自动切换到飞行器视图
this.currentView = 'aircrafts';
this.updateWebview();
} else {
// 如果用户取消选择路径,移除刚创建的项目
this.projects = this.projects.filter(p => p.id !== newId);
this.currentProjectId = '';
vscode.window.showWarningMessage('项目创建已取消');
this.updateWebview();
}
}
// 删除项目
@@ -972,6 +1085,8 @@ export class ConfigPanel {
// 删除相关的配置
const containerIds = this.containers.filter(c => aircraftIds.includes(c.aircraftId)).map(c => c.id);
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
// 删除相关的 Git 仓库
this.gitRepos = this.gitRepos.filter(repo => !containerIds.includes(repo.containerId));
// 删除项目路径映射
this.projectPaths.delete(projectId);
@@ -1006,7 +1121,7 @@ export class ConfigPanel {
};
this.aircrafts.push(newAircraft);
// 新增:创建飞行器目录
// 创建飞行器目录
await this.createAircraftDirectory(newAircraft);
vscode.window.showInformationMessage(`新建飞行器: ${name}`);
@@ -1014,26 +1129,6 @@ export class ConfigPanel {
this.updateWebview();
}
private async createAircraftDirectory(aircraft: Aircraft): Promise<void> {
try {
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
console.warn('未找到项目路径,跳过创建飞行器目录');
return;
}
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
// 创建飞行器目录
await vscode.workspace.fs.createDirectory(aircraftDir);
console.log(`✅ 创建飞行器目录: ${aircraftDir.fsPath}`);
} catch (error) {
console.error(`创建飞行器目录失败: ${error}`);
vscode.window.showWarningMessage(`创建飞行器目录失败: ${error}`);
}
}
// 删除飞行器
private async deleteAircraft(aircraftId: string) {
const aircraft = this.aircrafts.find(a => a.id === aircraftId);
@@ -1045,6 +1140,8 @@ export 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));
// 删除相关的 Git 仓库
this.gitRepos = this.gitRepos.filter(repo => !containerIds.includes(repo.containerId));
vscode.window.showInformationMessage(`删除飞行器: ${aircraft.name}`);
await this.saveCurrentProjectData();
@@ -1070,6 +1167,7 @@ export class ConfigPanel {
}
const newId = 'c' + (this.containers.length + 1);
const newContainer: Container = {
id: newId,
name: name,
@@ -1077,7 +1175,7 @@ export class ConfigPanel {
};
this.containers.push(newContainer);
// 新增:创建容器目录
// 创建容器目录
await this.createContainerDirectory(newContainer);
// 创建两个默认配置文件
@@ -1106,42 +1204,6 @@ export class ConfigPanel {
this.updateWebview();
}
// 新增方法:创建容器目录
private async createContainerDirectory(container: Container): Promise<void> {
try {
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft) {
console.warn('未找到对应的飞行器,跳过创建容器目录');
return;
}
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) {
console.warn('未找到项目路径,跳过创建容器目录');
return;
}
// 构建路径:项目路径/飞行器名/容器名
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
// 确保飞行器目录存在
try {
await vscode.workspace.fs.createDirectory(aircraftDir);
} catch (error) {
// 目录可能已存在,忽略错误
}
// 创建容器目录
await vscode.workspace.fs.createDirectory(containerDir);
console.log(`✅ 创建容器目录: ${containerDir.fsPath}`);
} catch (error) {
console.error(`创建容器目录失败: ${error}`);
vscode.window.showWarningMessage(`创建容器目录失败: ${error}`);
}
}
// 删除容器
private async deleteContainer(containerId: string) {
const container = this.containers.find(c => c.id === containerId);
@@ -1153,6 +1215,9 @@ private async createContainerDirectory(container: Container): Promise<void> {
// 删除相关的配置
this.configs = this.configs.filter(cfg => cfg.containerId !== containerId);
// 删除相关的 Git 仓库
this.gitRepos = this.gitRepos.filter(repo => repo.containerId !== containerId);
vscode.window.showInformationMessage(`删除容器: ${container.name}`);
await this.saveCurrentProjectData();
this.updateWebview();
@@ -1192,7 +1257,7 @@ private async createContainerDirectory(container: Container): Promise<void> {
};
this.configs.push(newConfig);
// 新增:确保容器目录存在
// 确保容器目录存在
await this.ensureContainerDirectoryExists(this.currentContainerId);
vscode.window.showInformationMessage(`新建配置: ${name}`);
@@ -1200,38 +1265,50 @@ private async createContainerDirectory(container: Container): Promise<void> {
this.updateWebview();
}
// 新增方法:确保容器目录存在
private async ensureContainerDirectoryExists(containerId: string): Promise<void> {
try {
const container = this.containers.find(c => c.id === containerId);
if (!container) return;
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (!aircraft) return;
const projectPath = this.projectPaths.get(aircraft.projectId);
if (!projectPath) return;
// 构建路径并创建目录
const aircraftDir = vscode.Uri.joinPath(vscode.Uri.file(projectPath), aircraft.name);
const containerDir = vscode.Uri.joinPath(aircraftDir, container.name);
await vscode.workspace.fs.createDirectory(aircraftDir);
await vscode.workspace.fs.createDirectory(containerDir);
} catch (error) {
console.error(`确保容器目录存在失败: ${error}`);
}
}
// 删除配置文件
// 删除配置文件 - 修复版本,同时删除磁盘文件
private async deleteConfig(configId: string) {
const config = this.configs.find(c => c.id === configId);
if (config) {
if (!config) return;
const confirm = await vscode.window.showWarningMessage(
`确定要删除配置文件 "${config.name}" 吗?这将同时删除磁盘上的文件。`,
{ modal: true },
'确定删除',
'取消'
);
if (confirm !== '确定删除') {
return;
}
try {
// 从内存中删除配置
this.configs = this.configs.filter(c => c.id !== configId);
// 删除磁盘上的配置文件
const container = this.containers.find(c => c.id === config.containerId);
if (container) {
const aircraft = this.aircrafts.find(a => a.id === container.aircraftId);
if (aircraft) {
const projectPath = this.projectPaths.get(aircraft.projectId);
if (projectPath) {
const filePath = path.join(projectPath, aircraft.name, container.name, config.fileName);
// 检查文件是否存在,如果存在则删除
if (fs.existsSync(filePath)) {
await fs.promises.unlink(filePath);
console.log(`✅ 已删除配置文件: ${filePath}`);
}
}
}
}
vscode.window.showInformationMessage(`删除配置: ${config.name}`);
await this.saveCurrentProjectData();
this.updateWebview();
} catch (error) {
vscode.window.showErrorMessage(`删除配置文件失败: ${error}`);
}
}
@@ -1305,17 +1382,30 @@ private async ensureContainerDirectoryExists(containerId: string): Promise<void>
// 加载配置文件
private loadConfigFile(configId: string) {
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,跳过加载配置文件');
return;
}
const config = this.configs.find(c => c.id === configId);
if (config) {
try {
this.panel.webview.postMessage({
type: 'configFileLoaded',
content: config.content || `# ${config.name} 的配置文件\n# 您可以在此编辑配置内容\n\n`
});
} catch (error) {
console.log('⚠️ 无法发送配置文件内容Webview 可能已被销毁');
}
} else {
try {
this.panel.webview.postMessage({
type: 'configFileLoaded',
content: `# 这是 ${configId} 的配置文件\n# 您可以在此编辑配置内容\n\napp.name = "示例应用"\napp.port = 8080\napp.debug = true`
});
} catch (error) {
console.log('⚠️ 无法发送默认配置文件内容Webview 可能已被销毁');
}
}
}
@@ -1376,11 +1466,13 @@ private async ensureContainerDirectoryExists(containerId: string): Promise<void>
progress.report({ increment: 80, message: '处理分支数据...' });
// 发送分支数据到前端
if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: branches,
repoUrl: url
});
}
progress.report({ increment: 100, message: '完成' });
@@ -1396,11 +1488,13 @@ private async ensureContainerDirectoryExists(containerId: string): Promise<void>
{ name: 'feature/new-feature', isCurrent: false, isRemote: false, selected: false }
];
if (!this.isWebviewDisposed) {
this.panel.webview.postMessage({
type: 'branchesFetched',
branches: mockBranches,
repoUrl: url
});
}
vscode.window.showWarningMessage('使用模拟分支数据,实际分支可能不同');
}
@@ -1445,12 +1539,23 @@ private async ensureContainerDirectoryExists(containerId: string): Promise<void>
private generateRepoName(url: string, branch: string): string {
const repoName = url.split('/').pop()?.replace('.git', '') || 'unknown-repo';
return `${repoName}-${branch.replace(/\//g, '-')}`;
const branchSafeName = branch.replace(/[^a-zA-Z0-9-_]/g, '-');
return `${repoName}-${branchSafeName}`;
}
// 更新视图
private updateWebview() {
// 检查 Webview 是否仍然有效
if (this.isWebviewDisposed) {
console.log('⚠️ Webview 已被销毁,跳过更新');
return;
}
try {
this.panel.webview.html = this.getWebviewContent();
} catch (error) {
console.error('更新 Webview 失败:', error);
}
}
private getWebviewContent(): string {
@@ -1480,10 +1585,13 @@ private async ensureContainerDirectoryExists(containerId: string): Promise<void>
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
const currentRepo = this.gitRepos.find(r => r.id === this.currentRepoId);
// 获取当前容器的 Git 仓库
const containerGitRepos = this.gitRepos.filter(repo => repo.containerId === this.currentContainerId);
return this.configView.render({
container: currentContainer,
configs: containerConfigs,
gitRepos: this.gitRepos,
gitRepos: containerGitRepos, // 只显示当前容器的 Git 仓库
currentGitRepo: currentRepo,
gitFileTree: this.currentRepoFileTree,
gitLoading: false

229
src/panels/views/ConfigView.ts Normal file → Executable file
View File

@@ -1,4 +1,3 @@
// src/panels/views/ConfigView.ts
import { BaseView } from './BaseView';
import { ContainerConfigData, ConfigViewData } from '../types/ViewTypes';
@@ -18,10 +17,21 @@ interface GitFileTree {
children?: GitFileTree[];
}
// Git 仓库接口
interface GitRepo {
id: string;
name: string;
url: string;
localPath: string;
branch: string;
lastSync: string;
containerId: string;
}
export class ConfigView extends BaseView {
render(data?: ContainerConfigData & {
gitRepos?: any[];
currentGitRepo?: any;
gitRepos?: GitRepo[];
currentGitRepo?: GitRepo;
gitFileTree?: GitFileTree[];
gitLoading?: boolean;
gitBranches?: GitBranch[];
@@ -36,7 +46,7 @@ export class ConfigView extends BaseView {
const gitBranches = data?.gitBranches || [];
const gitRepoUrl = data?.gitRepoUrl || '';
// 生成配置列表的 HTML
// 生成配置列表的 HTML - 包含配置文件和 Git 仓库
const configsHtml = configs.map((config: ConfigViewData) => `
<tr>
<td>
@@ -51,21 +61,17 @@ export class ConfigView extends BaseView {
</tr>
`).join('');
// 生成 Git 仓库列表的 HTML
// 生成 Git 仓库列表的 HTML - 以配置文件形式显示
const gitReposHtml = gitRepos.map(repo => `
<tr>
<td>
<span class="repo-name" data-repo-id="${repo.id}">📁 ${repo.name}</span>
<span class="editable">📁 ${repo.name}</span>
<div style="font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 4px;">
${repo.url}
</div>
<div style="font-size: 11px; color: var(--vscode-descriptionForeground);">
分支: ${repo.branch} | 最后同步: ${repo.lastSync}
模型1、模型2
</div>
</td>
<td>
<span class="clickable" onclick="loadGitRepo('${repo.id}')">打开</span>
<span class="clickable" onclick="syncGitRepo('${repo.id}')" style="margin-left: 10px;">同步</span>
<span class="clickable" onclick="loadGitRepo('${repo.id}')">${repo.url.split('/').pop()}</span>
</td>
<td>
<button class="btn-delete" onclick="deleteGitRepo('${repo.id}')">删除</button>
@@ -76,9 +82,6 @@ export class ConfigView extends BaseView {
// 生成分支选择的 HTML
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesHtml(gitBranches) : '';
// 生成文件树的 HTML
const fileTreeHtml = gitFileTree.length > 0 ? this.renderFileTree(gitFileTree) : '<div style="text-align: center; padding: 20px; color: var(--vscode-descriptionForeground);">选择仓库以浏览文件</div>';
return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
@@ -87,77 +90,6 @@ export class ConfigView extends BaseView {
<title>配置管理</title>
${this.getStyles()}
<style>
.git-container {
display: flex;
gap: 20px;
margin-top: 20px;
}
.repo-list {
flex: 1;
min-width: 300px;
}
.file-tree {
flex: 2;
min-width: 400px;
border: 1px solid var(--vscode-panel-border);
border-radius: 4px;
padding: 15px;
background: var(--vscode-panel-background);
max-height: 400px;
overflow-y: auto;
}
.tree-item {
margin: 2px 0;
}
.tree-folder {
cursor: pointer;
padding: 2px 4px;
border-radius: 2px;
display: inline-block;
}
.tree-folder:hover {
background: var(--vscode-list-hoverBackground);
}
.tree-file {
padding: 2px 4px;
border-radius: 2px;
display: inline-block;
}
.tree-file:hover {
background: var(--vscode-list-hoverBackground);
}
.tree-children {
margin-left: 10px;
}
.current-repo {
background: var(--vscode-badge-background);
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
}
.loading {
text-align: center;
padding: 20px;
color: var(--vscode-descriptionForeground);
}
.btn-sync {
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
margin-left: 10px;
}
.btn-sync:hover {
background: var(--vscode-button-hoverBackground);
}
.branch-selection {
border: 1px solid var(--vscode-input-border);
}
.branch-item:hover {
background: var(--vscode-list-hoverBackground);
}
.url-input-section {
background: var(--vscode-panel-background);
padding: 15px;
@@ -165,24 +97,21 @@ export class ConfigView extends BaseView {
margin-bottom: 15px;
border: 1px solid var(--vscode-input-border);
}
.debug-panel {
background: var(--vscode-inputValidation-infoBackground);
padding: 10px;
margin-bottom: 15px;
border-radius: 4px;
border: 1px solid var(--vscode-inputValidation-infoBorder);
}
.debug-info {
font-size: 12px;
color: var(--vscode-input-foreground);
font-family: 'Courier New', monospace;
}
.section-title {
margin: 30px 0 15px 0;
padding-bottom: 10px;
border-bottom: 2px solid var(--vscode-panel-border);
color: var(--vscode-titleBar-activeForeground);
}
.config-section {
margin-bottom: 30px;
}
.branch-selection {
border: 1px solid var(--vscode-input-border);
}
.branch-item:hover {
background: var(--vscode-list-hoverBackground);
}
</style>
</head>
<body>
@@ -191,7 +120,8 @@ export class ConfigView extends BaseView {
<button class="back-btn" onclick="goBackToContainers()">← 返回容器管理</button>
</div>
<!-- 配置管理部分 -->
<!-- 配置文件管理部分 -->
<div class="config-section">
<h3 class="section-title">📋 配置文件管理</h3>
<table class="table">
<thead>
@@ -203,6 +133,7 @@ export class ConfigView extends BaseView {
</thead>
<tbody>
${configsHtml}
${gitReposHtml}
<tr>
<td colspan="3" style="text-align: center; padding: 20px;">
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
@@ -210,8 +141,10 @@ export class ConfigView extends BaseView {
</tr>
</tbody>
</table>
</div>
<!-- Git 仓库管理部分 -->
<div class="config-section">
<h3 class="section-title">📚 Git 仓库管理</h3>
<!-- URL 输入区域 -->
@@ -231,33 +164,12 @@ export class ConfigView extends BaseView {
<div style="margin-bottom: 20px;">
${currentGitRepo ? `
<div class="current-repo">
<div style="background: var(--vscode-badge-background); padding: 10px; border-radius: 4px; margin-bottom: 15px;">
<strong>当前仓库:</strong> ${currentGitRepo.name} (${currentGitRepo.url})
<button class="btn-sync" onclick="syncGitRepo('${currentGitRepo.id}')">同步</button>
<button class="btn-sync" onclick="syncGitRepo('${currentGitRepo.id}')" style="background: var(--vscode-button-background); color: var(--vscode-button-foreground); border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; margin-left: 10px;">同步</button>
</div>
` : ''}
</div>
<div class="git-container">
<div class="repo-list">
<table class="table">
<thead>
<tr>
<th width="60%">仓库</th>
<th width="20%">操作</th>
<th width="20%">管理</th>
</tr>
</thead>
<tbody>
${gitReposHtml}
</tbody>
</table>
</div>
<div class="file-tree">
<h4>📂 文件浏览器</h4>
${gitLoading ? '<div class="loading">🔄 加载中...</div>' : fileTreeHtml}
</div>
</div>
<!-- 配置文件编辑器 -->
@@ -356,14 +268,6 @@ export class ConfigView extends BaseView {
}
// Git 仓库管理功能
function updateDebugInfo(message) {
const debugElement = document.getElementById('debugInfo');
if (debugElement) {
debugElement.innerHTML = message;
console.log('🔍 调试信息:', message);
}
}
function fetchBranches() {
const urlInput = document.getElementById('repoUrlInput');
const repoUrl = urlInput.value.trim();
@@ -380,7 +284,6 @@ export class ConfigView extends BaseView {
currentRepoUrl = repoUrl;
console.log('🌿 获取分支列表:', repoUrl);
updateDebugInfo('🌿 正在获取分支列表...');
vscode.postMessage({
type: 'fetchBranches',
@@ -396,7 +299,6 @@ export class ConfigView extends BaseView {
selectedBranches.delete(branchName);
}
console.log('选中的分支:', Array.from(selectedBranches));
updateDebugInfo('选中的分支: ' + Array.from(selectedBranches).join(', '));
}
function cloneSelectedBranches() {
@@ -406,7 +308,6 @@ export class ConfigView extends BaseView {
}
console.log('🚀 开始克隆选中的分支:', Array.from(selectedBranches));
updateDebugInfo('🚀 开始克隆分支: ' + Array.from(selectedBranches).join(', '));
vscode.postMessage({
type: 'cloneBranches',
@@ -421,7 +322,6 @@ export class ConfigView extends BaseView {
// 隐藏分支选择区域
document.getElementById('branchSelectionContainer').innerHTML = '';
updateDebugInfo('✅ 分支克隆请求已发送');
}
function cancelBranchSelection() {
@@ -432,8 +332,6 @@ export class ConfigView extends BaseView {
// 隐藏分支选择区域
document.getElementById('branchSelectionContainer').innerHTML = '';
updateDebugInfo('❌ 已取消分支选择');
vscode.postMessage({
type: 'cancelBranchSelection'
});
@@ -441,7 +339,6 @@ export class ConfigView extends BaseView {
function loadGitRepo(repoId) {
console.log('📂 加载仓库:', repoId);
updateDebugInfo('📂 正在加载仓库...');
vscode.postMessage({
type: 'loadGitRepo',
repoId: repoId
@@ -450,7 +347,6 @@ export class ConfigView extends BaseView {
function syncGitRepo(repoId) {
console.log('🔄 同步仓库:', repoId);
updateDebugInfo('🔄 正在同步仓库...');
vscode.postMessage({
type: 'syncGitRepo',
repoId: repoId
@@ -460,7 +356,6 @@ export class ConfigView extends BaseView {
function deleteGitRepo(repoId) {
if (confirm('确定删除这个 Git 仓库吗?')) {
console.log('🗑️ 删除仓库:', repoId);
updateDebugInfo('🗑️ 正在删除仓库...');
vscode.postMessage({
type: 'deleteGitRepo',
repoId: repoId
@@ -468,24 +363,6 @@ export class ConfigView extends BaseView {
}
}
function importFile(filePath) {
if (confirm('确定要将此文件导入到当前容器吗?')) {
console.log('📥 导入文件:', filePath);
updateDebugInfo('📥 正在导入文件...');
vscode.postMessage({
type: 'importGitFile',
filePath: filePath
});
}
}
function toggleFolder(folderPath) {
const folderElement = document.getElementById('folder-' + folderPath.replace(/[^a-zA-Z0-9]/g, '-'));
if (folderElement) {
folderElement.style.display = folderElement.style.display === 'none' ? 'block' : 'none';
}
}
// 动态渲染分支选择区域
function renderBranchSelection(branches, repoUrl) {
const container = document.getElementById('branchSelectionContainer');
@@ -604,29 +481,17 @@ export class ConfigView extends BaseView {
if (message.type === 'branchesFetched') {
console.log('🌿 收到分支数据:', message.branches);
updateDebugInfo('✅ 获取到 ' + message.branches.length + ' 个分支');
renderBranchSelection(message.branches, message.repoUrl);
}
if (message.type === 'configFileLoaded') {
document.getElementById('configContent').value = message.content;
}
if (message.type === 'gitRepoLoading') {
updateDebugInfo(message.loading ? '🔄 后端正在加载仓库文件树...' : '✅ 后端文件树加载完成');
}
});
// 初始化
document.addEventListener('DOMContentLoaded', function() {
console.log('📄 ConfigView 页面加载完成');
updateDebugInfo('📄 页面加载完成 - 等待用户操作');
setTimeout(() => {
document.querySelectorAll('.tree-children').forEach(el => {
el.style.display = 'block';
});
}, 100);
});
</script>
</body>
@@ -658,30 +523,4 @@ export class ConfigView extends BaseView {
return html;
}
private renderFileTree(nodes: GitFileTree[], level = 0): string {
return nodes.map(node => {
const paddingLeft = level * 20;
if (node.type === 'folder') {
return `
<div class="tree-item" style="padding-left: ${paddingLeft}px;">
<span class="tree-folder" onclick="toggleFolder('${node.path}')">
📁 ${node.name}
</span>
<div id="folder-${node.path.replace(/[^a-zA-Z0-9]/g, '-')}" class="tree-children">
${this.renderFileTree(node.children || [], level + 1)}
</div>
</div>
`;
} else {
return `
<div class="tree-item" style="padding-left: ${paddingLeft}px;">
<span class="tree-file clickable" onclick="importFile('${node.path}')">
📄 ${node.name}
</span>
</div>
`;
}
}).join('');
}
}