添加了一个可视化仓库功能
This commit is contained in:
16
dcsp-repos.json
Normal file
16
dcsp-repos.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"repos": [
|
||||||
|
{
|
||||||
|
"name": "卫星模型",
|
||||||
|
"url": "http://117.72.162.127:3000/xb/test.git",
|
||||||
|
"username": "xb",
|
||||||
|
"password": "1627031394xb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "动力学仓库",
|
||||||
|
"url": "http://117.72.162.127:3000/xb/build.git",
|
||||||
|
"username": "xb",
|
||||||
|
"password": "1627031394xb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.ConfigPanel = void 0;
|
exports.ConfigPanel = void 0;
|
||||||
|
// src/panels/ConfigPanel.ts
|
||||||
const vscode = __importStar(require("vscode"));
|
const vscode = __importStar(require("vscode"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
@@ -71,6 +72,8 @@ class ConfigPanel {
|
|||||||
this.moduleFolders = [];
|
this.moduleFolders = [];
|
||||||
this.currentModuleFolderFileTree = [];
|
this.currentModuleFolderFileTree = [];
|
||||||
this.projectPaths = new Map();
|
this.projectPaths = new Map();
|
||||||
|
// 仓库配置
|
||||||
|
this.repoConfigs = [];
|
||||||
// 状态管理
|
// 状态管理
|
||||||
this.isWebviewDisposed = false;
|
this.isWebviewDisposed = false;
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
@@ -81,6 +84,8 @@ class ConfigPanel {
|
|||||||
this.aircraftView = new AircraftView_1.AircraftView(extensionUri);
|
this.aircraftView = new AircraftView_1.AircraftView(extensionUri);
|
||||||
this.containerView = new ContainerView_1.ContainerView(extensionUri);
|
this.containerView = new ContainerView_1.ContainerView(extensionUri);
|
||||||
this.configView = new ConfigView_1.ConfigView(extensionUri);
|
this.configView = new ConfigView_1.ConfigView(extensionUri);
|
||||||
|
// 尝试加载仓库配置
|
||||||
|
void this.loadRepoConfigs();
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
this.setupMessageListener();
|
this.setupMessageListener();
|
||||||
this.panel.onDidDispose(() => {
|
this.panel.onDidDispose(() => {
|
||||||
@@ -108,6 +113,94 @@ class ConfigPanel {
|
|||||||
return `${prefix}${idNumber}`;
|
return `${prefix}${idNumber}`;
|
||||||
}
|
}
|
||||||
// =============================================
|
// =============================================
|
||||||
|
// 仓库配置相关
|
||||||
|
// =============================================
|
||||||
|
getRepoConfigPath() {
|
||||||
|
// 按你的需求:配置文件保存在插件安装位置
|
||||||
|
return path.join(this.extensionUri.fsPath, 'dcsp-repos.json');
|
||||||
|
}
|
||||||
|
async loadRepoConfigs() {
|
||||||
|
try {
|
||||||
|
const configPath = this.getRepoConfigPath();
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
this.repoConfigs = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const content = await fs.promises.readFile(configPath, 'utf8');
|
||||||
|
if (!content.trim()) {
|
||||||
|
this.repoConfigs = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parsed = JSON.parse(content);
|
||||||
|
if (Array.isArray(parsed)) {
|
||||||
|
// 兼容老格式:直接是数组
|
||||||
|
this.repoConfigs = parsed;
|
||||||
|
}
|
||||||
|
else if (parsed && Array.isArray(parsed.repos)) {
|
||||||
|
this.repoConfigs = parsed.repos;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.repoConfigs = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('加载仓库配置失败:', error);
|
||||||
|
vscode.window.showErrorMessage('读取仓库配置文件失败(dcsp-repos.json),请检查文件格式。');
|
||||||
|
this.repoConfigs = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async ensureRepoConfigFileExists() {
|
||||||
|
const configPath = this.getRepoConfigPath();
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
const defaultContent = JSON.stringify({
|
||||||
|
repos: [
|
||||||
|
{
|
||||||
|
name: 'example-repo',
|
||||||
|
url: 'https://github.com/username/repo.git',
|
||||||
|
username: '',
|
||||||
|
password: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, null, 2);
|
||||||
|
await fs.promises.writeFile(configPath, defaultContent, 'utf8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async openRepoConfig() {
|
||||||
|
try {
|
||||||
|
await this.ensureRepoConfigFileExists();
|
||||||
|
const configPath = this.getRepoConfigPath();
|
||||||
|
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(configPath));
|
||||||
|
await vscode.window.showTextDocument(doc);
|
||||||
|
await this.loadRepoConfigs();
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
vscode.window.showErrorMessage(`打开仓库配置文件失败: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async openRepoSelect() {
|
||||||
|
await this.loadRepoConfigs();
|
||||||
|
if (!this.repoConfigs || this.repoConfigs.length === 0) {
|
||||||
|
vscode.window.showWarningMessage('尚未配置任何仓库,请先点击右上角 “仓库配置” 按钮编辑 dcsp-repos.json。');
|
||||||
|
}
|
||||||
|
if (this.isWebviewDisposed)
|
||||||
|
return;
|
||||||
|
// 仅传递仓库名给前端,用于下拉选择
|
||||||
|
this.panel.webview.postMessage({
|
||||||
|
type: 'showRepoSelect',
|
||||||
|
repos: this.repoConfigs.map(r => ({ name: r.name }))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async handleRepoSelectedForBranches(repoName) {
|
||||||
|
await this.loadRepoConfigs();
|
||||||
|
const repo = this.repoConfigs.find(r => r.name === repoName);
|
||||||
|
if (!repo) {
|
||||||
|
vscode.window.showErrorMessage(`在仓库配置中未找到名为 "${repoName}" 的仓库,请检查 dcsp-repos.json。`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.currentRepoForBranches = repo;
|
||||||
|
await this.fetchBranchesForRepo(repo);
|
||||||
|
}
|
||||||
|
// =============================================
|
||||||
// Webview 消息处理
|
// Webview 消息处理
|
||||||
// =============================================
|
// =============================================
|
||||||
setupMessageListener() {
|
setupMessageListener() {
|
||||||
@@ -157,9 +250,13 @@ class ConfigPanel {
|
|||||||
'deleteConfig': (data) => this.deleteConfig(data.configId),
|
'deleteConfig': (data) => this.deleteConfig(data.configId),
|
||||||
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
||||||
'mergeConfigs': (data) => this.mergeConfigs(data.configIds, data.displayName, data.folderName),
|
'mergeConfigs': (data) => this.mergeConfigs(data.configIds, data.displayName, data.folderName),
|
||||||
// Git 仓库管理
|
// Git 仓库管理(新:基于配置)
|
||||||
|
'openRepoConfig': () => this.openRepoConfig(),
|
||||||
|
'openRepoSelect': () => this.openRepoSelect(),
|
||||||
|
'repoSelectedForBranches': (data) => this.handleRepoSelectedForBranches(data.repoName),
|
||||||
|
// Git 仓库管理(老接口:为了兼容,仍然保留)
|
||||||
'fetchBranches': (data) => this.fetchBranches(data.url),
|
'fetchBranches': (data) => this.fetchBranches(data.url),
|
||||||
'cloneBranches': (data) => this.cloneBranches(data.url, data.branches),
|
'cloneBranches': (data) => this.cloneBranches(data.branches),
|
||||||
'cancelBranchSelection': () => this.handleCancelBranchSelection(),
|
'cancelBranchSelection': () => this.handleCancelBranchSelection(),
|
||||||
// 模块文件夹管理
|
// 模块文件夹管理
|
||||||
'loadModuleFolder': (data) => this.loadModuleFolder(data.folderId),
|
'loadModuleFolder': (data) => this.loadModuleFolder(data.folderId),
|
||||||
@@ -242,14 +339,12 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async createProject(name) {
|
async createProject(name) {
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('p', this.projects);
|
const newId = this.generateUniqueId('p', this.projects);
|
||||||
const newProject = {
|
const newProject = {
|
||||||
id: newId,
|
id: newId,
|
||||||
name: name
|
name: name
|
||||||
};
|
};
|
||||||
this.projects.push(newProject);
|
this.projects.push(newProject);
|
||||||
// 设置当前项目
|
|
||||||
this.currentProjectId = newId;
|
this.currentProjectId = newId;
|
||||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
@@ -259,7 +354,6 @@ class ConfigPanel {
|
|||||||
if (!project)
|
if (!project)
|
||||||
return;
|
return;
|
||||||
this.projects = this.projects.filter(p => p.id !== projectId);
|
this.projects = this.projects.filter(p => p.id !== projectId);
|
||||||
// 删除相关数据
|
|
||||||
const relatedAircrafts = this.aircrafts.filter(a => a.projectId === projectId);
|
const relatedAircrafts = this.aircrafts.filter(a => a.projectId === projectId);
|
||||||
const aircraftIds = relatedAircrafts.map(a => a.id);
|
const aircraftIds = relatedAircrafts.map(a => a.id);
|
||||||
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
||||||
@@ -289,7 +383,6 @@ class ConfigPanel {
|
|||||||
vscode.window.showErrorMessage('无法创建飞行器:未找到当前项目');
|
vscode.window.showErrorMessage('无法创建飞行器:未找到当前项目');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('a', this.aircrafts);
|
const newId = this.generateUniqueId('a', this.aircrafts);
|
||||||
const newAircraft = {
|
const newAircraft = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -332,7 +425,6 @@ class ConfigPanel {
|
|||||||
vscode.window.showErrorMessage('无法创建容器:未找到当前飞行器');
|
vscode.window.showErrorMessage('无法创建容器:未找到当前飞行器');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('c', this.containers);
|
const newId = this.generateUniqueId('c', this.containers);
|
||||||
const newContainer = {
|
const newContainer = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -370,7 +462,6 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async createConfig(name) {
|
async createConfig(name) {
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('cfg', this.configs);
|
const newId = this.generateUniqueId('cfg', this.configs);
|
||||||
const newConfig = {
|
const newConfig = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -426,7 +517,6 @@ class ConfigPanel {
|
|||||||
vscode.window.showErrorMessage('部分配置文件未找到');
|
vscode.window.showErrorMessage('部分配置文件未找到');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 创建合并文件夹并复制文件
|
|
||||||
const mergeFolderPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
const mergeFolderPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||||
await fs.promises.mkdir(mergeFolderPath, { recursive: true });
|
await fs.promises.mkdir(mergeFolderPath, { recursive: true });
|
||||||
for (const config of selectedConfigs) {
|
for (const config of selectedConfigs) {
|
||||||
@@ -439,9 +529,7 @@ class ConfigPanel {
|
|||||||
await fs.promises.writeFile(targetPath, config.content || '');
|
await fs.promises.writeFile(targetPath, config.content || '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 创建合并文件夹记录
|
|
||||||
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('local-', this.moduleFolders);
|
const newId = this.generateUniqueId('local-', this.moduleFolders);
|
||||||
const newFolder = {
|
const newFolder = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -451,7 +539,6 @@ class ConfigPanel {
|
|||||||
containerId: this.currentContainerId
|
containerId: this.currentContainerId
|
||||||
};
|
};
|
||||||
this.moduleFolders.push(newFolder);
|
this.moduleFolders.push(newFolder);
|
||||||
// 删除原始配置文件
|
|
||||||
for (const configId of configIds) {
|
for (const configId of configIds) {
|
||||||
await this.deleteConfigInternal(configId);
|
await this.deleteConfigInternal(configId);
|
||||||
}
|
}
|
||||||
@@ -467,7 +554,10 @@ class ConfigPanel {
|
|||||||
// =============================================
|
// =============================================
|
||||||
// Git 分支管理方法
|
// Git 分支管理方法
|
||||||
// =============================================
|
// =============================================
|
||||||
async fetchBranches(url) {
|
async fetchBranchesForRepo(repo) {
|
||||||
|
await this.fetchBranches(repo.url, repo);
|
||||||
|
}
|
||||||
|
async fetchBranches(url, repo) {
|
||||||
try {
|
try {
|
||||||
console.log('🌿 开始获取分支列表:', url);
|
console.log('🌿 开始获取分支列表:', url);
|
||||||
await vscode.window.withProgress({
|
await vscode.window.withProgress({
|
||||||
@@ -478,15 +568,20 @@ class ConfigPanel {
|
|||||||
progress.report({ increment: 0, message: '连接远程仓库...' });
|
progress.report({ increment: 0, message: '连接远程仓库...' });
|
||||||
try {
|
try {
|
||||||
progress.report({ increment: 30, message: '获取远程引用...' });
|
progress.report({ increment: 30, message: '获取远程引用...' });
|
||||||
const refs = await isomorphic_git_1.default.listServerRefs({
|
const options = {
|
||||||
http: node_1.default,
|
http: node_1.default,
|
||||||
url: url
|
url: url
|
||||||
});
|
};
|
||||||
|
if (repo && (repo.username || repo.password)) {
|
||||||
|
options.onAuth = () => ({
|
||||||
|
username: repo.username || '',
|
||||||
|
password: repo.password || ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const refs = await isomorphic_git_1.default.listServerRefs(options);
|
||||||
console.log('📋 获取到的引用:', refs);
|
console.log('📋 获取到的引用:', refs);
|
||||||
// 过滤出分支引用
|
const branchRefs = refs.filter((ref) => ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/'));
|
||||||
const branchRefs = refs.filter(ref => ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/'));
|
const branches = branchRefs.map((ref) => {
|
||||||
// 构建分支数据
|
|
||||||
const branches = branchRefs.map(ref => {
|
|
||||||
let branchName;
|
let branchName;
|
||||||
if (ref.ref.startsWith('refs/remotes/')) {
|
if (ref.ref.startsWith('refs/remotes/')) {
|
||||||
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
||||||
@@ -504,15 +599,14 @@ class ConfigPanel {
|
|||||||
throw new Error('未找到任何分支');
|
throw new Error('未找到任何分支');
|
||||||
}
|
}
|
||||||
progress.report({ increment: 80, message: '处理分支数据...' });
|
progress.report({ increment: 80, message: '处理分支数据...' });
|
||||||
// 构建分支树状结构
|
|
||||||
const branchTree = this.buildBranchTree(branches);
|
const branchTree = this.buildBranchTree(branches);
|
||||||
// 发送分支数据到前端
|
|
||||||
if (!this.isWebviewDisposed) {
|
if (!this.isWebviewDisposed) {
|
||||||
this.panel.webview.postMessage({
|
this.panel.webview.postMessage({
|
||||||
type: 'branchesFetched',
|
type: 'branchesFetched',
|
||||||
branches: branches,
|
branches: branches,
|
||||||
branchTree: branchTree,
|
branchTree: branchTree,
|
||||||
repoUrl: url
|
repoUrl: url,
|
||||||
|
repoName: repo?.name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
progress.report({ increment: 100, message: '完成' });
|
progress.report({ increment: 100, message: '完成' });
|
||||||
@@ -528,7 +622,13 @@ class ConfigPanel {
|
|||||||
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
vscode.window.showErrorMessage(`获取分支失败: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async cloneBranches(url, branches) {
|
async cloneBranches(branches) {
|
||||||
|
if (!this.currentRepoForBranches) {
|
||||||
|
vscode.window.showErrorMessage('请先通过“获取仓库”选择一个仓库');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const url = this.currentRepoForBranches.url;
|
||||||
|
const repoDisplayName = this.currentRepoForBranches.name;
|
||||||
try {
|
try {
|
||||||
console.log('🚀 开始克隆分支:', { url, branches });
|
console.log('🚀 开始克隆分支:', { url, branches });
|
||||||
let successCount = 0;
|
let successCount = 0;
|
||||||
@@ -548,7 +648,7 @@ class ConfigPanel {
|
|||||||
console.log(`📥 开始克隆分支: ${branch}`);
|
console.log(`📥 开始克隆分支: ${branch}`);
|
||||||
try {
|
try {
|
||||||
const folderNames = this.generateModuleFolderName(url, branch);
|
const folderNames = this.generateModuleFolderName(url, branch);
|
||||||
await this.addGitModuleFolder(url, folderNames.displayName, folderNames.folderName, branch);
|
await this.addGitModuleFolder(url, repoDisplayName, folderNames.folderName, branch);
|
||||||
successCount++;
|
successCount++;
|
||||||
console.log(`✅ 分支克隆成功: ${branch}`);
|
console.log(`✅ 分支克隆成功: ${branch}`);
|
||||||
}
|
}
|
||||||
@@ -558,7 +658,6 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 显示最终结果
|
|
||||||
if (failCount === 0) {
|
if (failCount === 0) {
|
||||||
vscode.window.showInformationMessage(`成功克隆 ${successCount} 个分支`);
|
vscode.window.showInformationMessage(`成功克隆 ${successCount} 个分支`);
|
||||||
}
|
}
|
||||||
@@ -591,12 +690,10 @@ class ConfigPanel {
|
|||||||
vscode.window.showErrorMessage('未找到相关项目数据');
|
vscode.window.showErrorMessage('未找到相关项目数据');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const folderId = this.generateUniqueId('git-', this.moduleFolders);
|
const folderId = this.generateUniqueId('git-', this.moduleFolders);
|
||||||
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
||||||
const localPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
const localPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||||
console.log(`📁 准备克隆仓库: ${displayName}, 分支: ${branch}, 路径: ${localPath}`);
|
console.log(`📁 准备克隆仓库: ${displayName}, 分支: ${branch}, 路径: ${localPath}`);
|
||||||
// 检查是否已存在相同路径的模块文件夹
|
|
||||||
const existingFolder = this.moduleFolders.find(folder => folder.localPath === relativePath && folder.containerId === this.currentContainerId);
|
const existingFolder = this.moduleFolders.find(folder => folder.localPath === relativePath && folder.containerId === this.currentContainerId);
|
||||||
if (existingFolder) {
|
if (existingFolder) {
|
||||||
vscode.window.showWarningMessage(`该路径的模块文件夹已存在: ${folderName}`);
|
vscode.window.showWarningMessage(`该路径的模块文件夹已存在: ${folderName}`);
|
||||||
@@ -616,10 +713,8 @@ class ConfigPanel {
|
|||||||
}, async (progress) => {
|
}, async (progress) => {
|
||||||
progress.report({ increment: 0 });
|
progress.report({ increment: 0 });
|
||||||
try {
|
try {
|
||||||
// 确保父目录存在
|
|
||||||
const parentDir = path.dirname(localPath);
|
const parentDir = path.dirname(localPath);
|
||||||
await fs.promises.mkdir(parentDir, { recursive: true });
|
await fs.promises.mkdir(parentDir, { recursive: true });
|
||||||
// 检查目标目录是否已存在
|
|
||||||
let dirExists = false;
|
let dirExists = false;
|
||||||
try {
|
try {
|
||||||
await fs.promises.access(localPath);
|
await fs.promises.access(localPath);
|
||||||
@@ -636,7 +731,6 @@ class ConfigPanel {
|
|||||||
vscode.window.showInformationMessage('克隆操作已取消');
|
vscode.window.showInformationMessage('克隆操作已取消');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 清空目录(除了 .git 文件夹)
|
|
||||||
for (const item of dirContents) {
|
for (const item of dirContents) {
|
||||||
const itemPath = path.join(localPath, item);
|
const itemPath = path.join(localPath, item);
|
||||||
if (item !== '.git') {
|
if (item !== '.git') {
|
||||||
@@ -646,7 +740,6 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(`🚀 开始克隆: ${url} -> ${localPath}, 分支: ${branch}`);
|
console.log(`🚀 开始克隆: ${url} -> ${localPath}, 分支: ${branch}`);
|
||||||
// 克隆仓库
|
|
||||||
await isomorphic_git_1.default.clone({
|
await isomorphic_git_1.default.clone({
|
||||||
fs: fs,
|
fs: fs,
|
||||||
http: node_1.default,
|
http: node_1.default,
|
||||||
@@ -670,18 +763,15 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log('✅ Git克隆成功完成');
|
console.log('✅ Git克隆成功完成');
|
||||||
// 验证克隆是否真的成功
|
|
||||||
const clonedContents = await fs.promises.readdir(localPath);
|
const clonedContents = await fs.promises.readdir(localPath);
|
||||||
console.log(`📁 克隆后的目录内容:`, clonedContents);
|
console.log(`📁 克隆后的目录内容:`, clonedContents);
|
||||||
if (clonedContents.length === 0) {
|
if (clonedContents.length === 0) {
|
||||||
throw new Error('克隆后目录为空,可能克隆失败');
|
throw new Error('克隆后目录为空,可能克隆失败');
|
||||||
}
|
}
|
||||||
// 只有在克隆成功后才添加到列表
|
|
||||||
this.moduleFolders.push(newFolder);
|
this.moduleFolders.push(newFolder);
|
||||||
await this.saveCurrentProjectData();
|
await this.saveCurrentProjectData();
|
||||||
console.log('✅ Git模块文件夹数据已保存到项目文件');
|
console.log('✅ Git模块文件夹数据已保存到项目文件');
|
||||||
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${displayName}`);
|
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${displayName}`);
|
||||||
// 自动加载文件树
|
|
||||||
if (!this.isWebviewDisposed) {
|
if (!this.isWebviewDisposed) {
|
||||||
console.log('🌳 开始加载模块文件夹文件树...');
|
console.log('🌳 开始加载模块文件夹文件树...');
|
||||||
this.currentModuleFolderId = folderId;
|
this.currentModuleFolderId = folderId;
|
||||||
@@ -691,7 +781,6 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('❌ 在克隆过程中捕获错误:', error);
|
console.error('❌ 在克隆过程中捕获错误:', error);
|
||||||
// 清理:如果克隆失败,删除可能创建的不完整目录
|
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(localPath)) {
|
if (fs.existsSync(localPath)) {
|
||||||
await fs.promises.rm(localPath, { recursive: true, force: true });
|
await fs.promises.rm(localPath, { recursive: true, force: true });
|
||||||
@@ -802,7 +891,6 @@ class ConfigPanel {
|
|||||||
const fileFullPath = path.join(fullPath, filePath);
|
const fileFullPath = path.join(fullPath, filePath);
|
||||||
const content = await fs.promises.readFile(fileFullPath, 'utf8');
|
const content = await fs.promises.readFile(fileFullPath, 'utf8');
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('cfg', this.configs);
|
const newId = this.generateUniqueId('cfg', this.configs);
|
||||||
const newConfig = {
|
const newConfig = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -850,7 +938,7 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('❌ Git 上传失败:', error);
|
console.error('❌ Git 上传失败:', error);
|
||||||
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
|
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -892,8 +980,7 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('❌ 本地文件夹上传失败:', error);
|
console.error('❌ 本地文件夹上传失败:', error);
|
||||||
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
|
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
||||||
// 清理:删除可能创建的 .git 文件夹
|
|
||||||
try {
|
try {
|
||||||
const gitDir = path.join(fullPath, '.git');
|
const gitDir = path.join(fullPath, '.git');
|
||||||
if (fs.existsSync(gitDir)) {
|
if (fs.existsSync(gitDir)) {
|
||||||
@@ -914,7 +1001,6 @@ class ConfigPanel {
|
|||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
console.log('🚀 使用命令行 Git 提交并推送...');
|
console.log('🚀 使用命令行 Git 提交并推送...');
|
||||||
console.log(`📁 工作目录: ${fullPath}`);
|
console.log(`📁 工作目录: ${fullPath}`);
|
||||||
// 先检查是否有更改
|
|
||||||
exec('git status --porcelain', {
|
exec('git status --porcelain', {
|
||||||
cwd: fullPath,
|
cwd: fullPath,
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
@@ -924,14 +1010,12 @@ class ConfigPanel {
|
|||||||
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
|
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 如果没有更改
|
|
||||||
if (!statusStdout.trim()) {
|
if (!statusStdout.trim()) {
|
||||||
console.log('ℹ️ 没有需要提交的更改');
|
console.log('ℹ️ 没有需要提交的更改');
|
||||||
reject(new Error('没有需要提交的更改'));
|
reject(new Error('没有需要提交的更改'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('📋 检测到更改:', statusStdout);
|
console.log('📋 检测到更改:', statusStdout);
|
||||||
// 有更改时才提交并推送
|
|
||||||
const commands = [
|
const commands = [
|
||||||
'git add .',
|
'git add .',
|
||||||
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
|
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
|
||||||
@@ -996,14 +1080,13 @@ class ConfigPanel {
|
|||||||
console.log('💾 提交初始文件...');
|
console.log('💾 提交初始文件...');
|
||||||
const commands = [
|
const commands = [
|
||||||
'git add .',
|
'git add .',
|
||||||
`git commit -m "Initial commit from DCSP - ${new Date().toLocaleString()}"`
|
`git commit -m "Initial commit from DCSP - ${new Date().toLocaleString()}"`,
|
||||||
];
|
];
|
||||||
exec(commands.join(' && '), {
|
exec(commands.join(' && '), {
|
||||||
cwd: fullPath,
|
cwd: fullPath,
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
}, (error, stdout, stderr) => {
|
}, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
// 检查是否是"没有更改可提交"的错误
|
|
||||||
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
|
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
|
||||||
console.log('ℹ️ 没有需要提交的更改');
|
console.log('ℹ️ 没有需要提交的更改');
|
||||||
resolve();
|
resolve();
|
||||||
@@ -1099,8 +1182,6 @@ class ConfigPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async createDefaultConfigs(container) {
|
async createDefaultConfigs(container) {
|
||||||
const configCount = this.configs.length;
|
|
||||||
// 第一个配置文件
|
|
||||||
this.configs.push({
|
this.configs.push({
|
||||||
id: this.generateUniqueId('cfg', this.configs),
|
id: this.generateUniqueId('cfg', this.configs),
|
||||||
name: '配置1',
|
name: '配置1',
|
||||||
@@ -1108,12 +1189,11 @@ class ConfigPanel {
|
|||||||
content: `# ${container.name} 的 Dockerfile\nFROM ubuntu:20.04\n\n# 设置工作目录\nWORKDIR /app\n\n# 复制文件\nCOPY . .\n\n# 安装依赖\nRUN apt-get update && apt-get install -y \\\n python3 \\\n python3-pip\n\n# 暴露端口\nEXPOSE 8080\n\n# 启动命令\nCMD ["python3", "app.py"]`,
|
content: `# ${container.name} 的 Dockerfile\nFROM ubuntu:20.04\n\n# 设置工作目录\nWORKDIR /app\n\n# 复制文件\nCOPY . .\n\n# 安装依赖\nRUN apt-get update && apt-get install -y \\\n python3 \\\n python3-pip\n\n# 暴露端口\nEXPOSE 8080\n\n# 启动命令\nCMD ["python3", "app.py"]`,
|
||||||
containerId: container.id
|
containerId: container.id
|
||||||
});
|
});
|
||||||
// 第二个配置文件
|
|
||||||
this.configs.push({
|
this.configs.push({
|
||||||
id: this.generateUniqueId('cfg', this.configs),
|
id: this.generateUniqueId('cfg', this.configs),
|
||||||
name: '配置2',
|
name: '配置2',
|
||||||
fileName: 'docker-compose.yml',
|
fileName: 'docker-compose.yml',
|
||||||
content: `# ${container.name} 的 Docker Compose 配置\nversion: '3.8'\n\nservices:\n ${container.name.toLowerCase().replace(/\\s+/g, '-')}:\n build: .\n container_name: ${container.name}\n ports:\n - "8080:8080"\n environment:\n - NODE_ENV=production\n volumes:\n - ./data:/app/data\n restart: unless-stopped`,
|
content: `# ${container.name} 的 Docker Compose 配置\nversion: '3.8'\n\nservices:\n ${container.name.toLowerCase().replace(/\s+/g, '-')}:\n build: .\n container_name: ${container.name}\n ports:\n - "8080:8080"\n environment:\n - NODE_ENV=production\n volumes:\n - ./data:/app/data\n restart: unless-stopped`,
|
||||||
containerId: container.id
|
containerId: container.id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1161,7 +1241,6 @@ class ConfigPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||||
// 构建当前项目的完整数据
|
|
||||||
const data = {
|
const data = {
|
||||||
projects: [this.projects.find(p => p.id === this.currentProjectId)],
|
projects: [this.projects.find(p => p.id === this.currentProjectId)],
|
||||||
aircrafts: this.aircrafts.filter(a => a.projectId === this.currentProjectId),
|
aircrafts: this.aircrafts.filter(a => a.projectId === this.currentProjectId),
|
||||||
@@ -1195,7 +1274,6 @@ class ConfigPanel {
|
|||||||
async loadProjectData(projectPath) {
|
async loadProjectData(projectPath) {
|
||||||
try {
|
try {
|
||||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||||
// 检查数据文件是否存在
|
|
||||||
try {
|
try {
|
||||||
await vscode.workspace.fs.stat(dataUri);
|
await vscode.workspace.fs.stat(dataUri);
|
||||||
}
|
}
|
||||||
@@ -1203,14 +1281,11 @@ class ConfigPanel {
|
|||||||
vscode.window.showErrorMessage('选择的文件夹中没有找到项目数据文件 (.dcsp-data.json)');
|
vscode.window.showErrorMessage('选择的文件夹中没有找到项目数据文件 (.dcsp-data.json)');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 读取数据文件
|
|
||||||
const fileData = await vscode.workspace.fs.readFile(dataUri);
|
const fileData = await vscode.workspace.fs.readFile(dataUri);
|
||||||
const dataStr = new TextDecoder().decode(fileData);
|
const dataStr = new TextDecoder().decode(fileData);
|
||||||
const data = JSON.parse(dataStr);
|
const data = JSON.parse(dataStr);
|
||||||
// 只清空当前项目相关的数据,保留其他项目数据
|
|
||||||
const projectId = data.projects[0]?.id;
|
const projectId = data.projects[0]?.id;
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
// 移除当前项目的旧数据
|
|
||||||
this.projects = this.projects.filter(p => p.id !== projectId);
|
this.projects = this.projects.filter(p => p.id !== projectId);
|
||||||
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
||||||
const aircraftIds = this.aircrafts.filter(a => a.projectId === projectId).map(a => a.id);
|
const aircraftIds = this.aircrafts.filter(a => a.projectId === projectId).map(a => a.id);
|
||||||
@@ -1218,13 +1293,11 @@ class ConfigPanel {
|
|||||||
const containerIds = this.containers.filter(c => aircraftIds.includes(c.aircraftId)).map(c => c.id);
|
const containerIds = this.containers.filter(c => aircraftIds.includes(c.aircraftId)).map(c => c.id);
|
||||||
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
||||||
this.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
this.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
||||||
// 添加新数据
|
|
||||||
this.projects.push(...data.projects);
|
this.projects.push(...data.projects);
|
||||||
this.aircrafts.push(...data.aircrafts);
|
this.aircrafts.push(...data.aircrafts);
|
||||||
this.containers.push(...data.containers);
|
this.containers.push(...data.containers);
|
||||||
this.configs.push(...data.configs);
|
this.configs.push(...data.configs);
|
||||||
this.moduleFolders.push(...data.moduleFolders);
|
this.moduleFolders.push(...data.moduleFolders);
|
||||||
// 设置当前项目
|
|
||||||
this.currentProjectId = projectId;
|
this.currentProjectId = projectId;
|
||||||
this.projectPaths.set(projectId, projectPath);
|
this.projectPaths.set(projectId, projectPath);
|
||||||
this.currentView = 'aircrafts';
|
this.currentView = 'aircrafts';
|
||||||
@@ -1370,7 +1443,6 @@ class ConfigPanel {
|
|||||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||||
if (!folder)
|
if (!folder)
|
||||||
return;
|
return;
|
||||||
// 通知前端开始加载
|
|
||||||
try {
|
try {
|
||||||
this.panel.webview.postMessage({
|
this.panel.webview.postMessage({
|
||||||
type: 'moduleFolderLoading',
|
type: 'moduleFolderLoading',
|
||||||
@@ -1392,12 +1464,10 @@ class ConfigPanel {
|
|||||||
console.error('加载模块文件夹文件树失败:', error);
|
console.error('加载模块文件夹文件树失败:', error);
|
||||||
this.currentModuleFolderFileTree = [];
|
this.currentModuleFolderFileTree = [];
|
||||||
}
|
}
|
||||||
// 再次检查 Webview 状态
|
|
||||||
if (this.isWebviewDisposed) {
|
if (this.isWebviewDisposed) {
|
||||||
console.log('⚠️ Webview 已被销毁,跳过完成通知');
|
console.log('⚠️ Webview 已被销毁,跳过完成通知');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 通知前端加载完成
|
|
||||||
try {
|
try {
|
||||||
this.panel.webview.postMessage({
|
this.panel.webview.postMessage({
|
||||||
type: 'moduleFolderLoading',
|
type: 'moduleFolderLoading',
|
||||||
@@ -1414,7 +1484,6 @@ class ConfigPanel {
|
|||||||
const files = await fs.promises.readdir(dir);
|
const files = await fs.promises.readdir(dir);
|
||||||
const tree = [];
|
const tree = [];
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
// 忽略 .git 文件夹和 .dcsp-data.json
|
|
||||||
if (file.startsWith('.') && file !== '.git')
|
if (file.startsWith('.') && file !== '.git')
|
||||||
continue;
|
continue;
|
||||||
if (file === '.dcsp-data.json')
|
if (file === '.dcsp-data.json')
|
||||||
@@ -1583,7 +1652,6 @@ class ConfigPanel {
|
|||||||
projectPaths: this.projectPaths
|
projectPaths: this.projectPaths
|
||||||
});
|
});
|
||||||
case 'aircrafts':
|
case 'aircrafts':
|
||||||
// 只显示当前项目的飞行器
|
|
||||||
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
||||||
return this.aircraftView.render({
|
return this.aircraftView.render({
|
||||||
aircrafts: projectAircrafts
|
aircrafts: projectAircrafts
|
||||||
@@ -1591,7 +1659,6 @@ class ConfigPanel {
|
|||||||
case 'containers':
|
case 'containers':
|
||||||
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
||||||
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
|
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
|
||||||
// 只显示当前飞行器的容器
|
|
||||||
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
||||||
return this.containerView.render({
|
return this.containerView.render({
|
||||||
project: currentProject,
|
project: currentProject,
|
||||||
@@ -1600,9 +1667,8 @@ class ConfigPanel {
|
|||||||
});
|
});
|
||||||
case 'configs':
|
case 'configs':
|
||||||
const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
|
const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
|
||||||
// 只显示当前容器的配置和模块文件夹
|
|
||||||
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
|
||||||
const currentModuleFolder = this.moduleFolders.find(f => f.id === this.currentModuleFolderId);
|
const currentModuleFolder = this.moduleFolders.find(f => f.id === this.currentModuleFolderId);
|
||||||
|
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
||||||
const containerModuleFolders = this.moduleFolders.filter(folder => folder.containerId === this.currentContainerId);
|
const containerModuleFolders = this.moduleFolders.filter(folder => folder.containerId === this.currentContainerId);
|
||||||
return this.configView.render({
|
return this.configView.render({
|
||||||
container: currentContainer,
|
container: currentContainer,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -115,59 +115,154 @@ class BaseView {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
.modal-overlay {
|
.modal-overlay {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
background: rgba(0, 0, 0, 0.5);
|
background: rgba(0, 0, 0, 0.5);
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-dialog {
|
.modal-dialog {
|
||||||
background: var(--vscode-editor-background);
|
background: var(--vscode-editor-background);
|
||||||
border: 1px solid var(--vscode-panel-border);
|
border: 1px solid var(--vscode-panel-border);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
min-width: 300px;
|
min-width: 300px;
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-title {
|
.modal-title {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: var(--vscode-editor-foreground);
|
color: var(--vscode-editor-foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-buttons {
|
.modal-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-btn {
|
.modal-btn {
|
||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-btn-primary {
|
.modal-btn-primary {
|
||||||
background: var(--vscode-button-background);
|
background: var(--vscode-button-background);
|
||||||
color: var(--vscode-button-foreground);
|
color: var(--vscode-button-foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-btn-secondary {
|
.modal-btn-secondary {
|
||||||
background: var(--vscode-button-secondaryBackground);
|
background: var(--vscode-button-secondaryBackground);
|
||||||
color: var(--vscode-button-secondaryForeground);
|
color: var(--vscode-button-secondaryForeground);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
// 避免在同一个 Webview 中重复注册
|
||||||
|
if (window.__dcspRepoDialogInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.__dcspRepoDialogInitialized = true;
|
||||||
|
|
||||||
|
function showRepoSelectDialog(repos) {
|
||||||
|
// 移除已有弹窗
|
||||||
|
var existing = document.getElementById('repoSelectModal');
|
||||||
|
if (existing) {
|
||||||
|
existing.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
var overlay = document.createElement('div');
|
||||||
|
overlay.className = 'modal-overlay';
|
||||||
|
overlay.id = 'repoSelectModal';
|
||||||
|
|
||||||
|
var hasRepos = Array.isArray(repos) && repos.length > 0;
|
||||||
|
var optionsHtml = '';
|
||||||
|
if (hasRepos) {
|
||||||
|
for (var i = 0; i < repos.length; i++) {
|
||||||
|
var r = repos[i];
|
||||||
|
if (!r || !r.name) continue;
|
||||||
|
optionsHtml += '<option value="' + r.name + '">' + r.name + '</option>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var disabledAttr = hasRepos ? '' : 'disabled';
|
||||||
|
|
||||||
|
var noRepoTip = '';
|
||||||
|
if (!hasRepos) {
|
||||||
|
noRepoTip = '<div style="margin-top:8px; font-size:12px; color: var(--vscode-descriptionForeground);">当前配置中没有仓库,请先在“仓库配置”中添加。</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
overlay.innerHTML =
|
||||||
|
'<div class="modal-dialog">' +
|
||||||
|
'<div class="modal-title">获取仓库</div>' +
|
||||||
|
'<div style="margin-bottom: 10px;">' +
|
||||||
|
'<label style="display:block; margin-bottom:6px;">请选择仓库:</label>' +
|
||||||
|
'<select id="repoSelect" style="width:100%; padding:6px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border:1px solid var(--vscode-input-border); border-radius:4px;">' +
|
||||||
|
optionsHtml +
|
||||||
|
'</select>' +
|
||||||
|
noRepoTip +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="modal-buttons">' +
|
||||||
|
'<button class="modal-btn modal-btn-secondary" id="repoSelectCancelBtn">取消</button>' +
|
||||||
|
'<button class="modal-btn modal-btn-primary" id="repoSelectOkBtn" ' + disabledAttr + '>确定</button>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
document.body.appendChild(overlay);
|
||||||
|
|
||||||
|
var cancelBtn = document.getElementById('repoSelectCancelBtn');
|
||||||
|
var okBtn = document.getElementById('repoSelectOkBtn');
|
||||||
|
var select = document.getElementById('repoSelect');
|
||||||
|
|
||||||
|
if (cancelBtn) {
|
||||||
|
cancelBtn.addEventListener('click', function () {
|
||||||
|
overlay.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (okBtn) {
|
||||||
|
okBtn.addEventListener('click', function () {
|
||||||
|
if (!select || !(select instanceof HTMLSelectElement)) {
|
||||||
|
overlay.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var repoName = select.value;
|
||||||
|
if (!repoName) {
|
||||||
|
alert('请选择一个仓库');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof vscode !== 'undefined') {
|
||||||
|
vscode.postMessage({
|
||||||
|
type: 'repoSelectedForBranches',
|
||||||
|
repoName: repoName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
overlay.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('message', function (event) {
|
||||||
|
var message = event.data;
|
||||||
|
if (!message || !message.type) return;
|
||||||
|
if (message.type === 'showRepoSelect') {
|
||||||
|
showRepoSelectDialog(message.repos || []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"BaseView.js","sourceRoot":"","sources":["../../../src/panels/views/BaseView.ts"],"names":[],"mappings":";;;AAGA,MAAsB,QAAQ;IAG1B,YAAY,YAAwB;QAChC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAIS,SAAS;QACf,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAkKN,CAAC;IACN,CAAC;CACJ;AA9KD,4BA8KC"}
|
{"version":3,"file":"BaseView.js","sourceRoot":"","sources":["../../../src/panels/views/BaseView.ts"],"names":[],"mappings":";;;AAEA,MAAsB,QAAQ;IAG1B,YAAY,YAAwB;QAChC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAIS,SAAS;QACf,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAiQN,CAAC;IACN,CAAC;CACJ;AA7QD,4BA6QC"}
|
||||||
@@ -11,7 +11,6 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
const moduleFolderFileTree = data?.moduleFolderFileTree || [];
|
const moduleFolderFileTree = data?.moduleFolderFileTree || [];
|
||||||
const moduleFolderLoading = data?.moduleFolderLoading || false;
|
const moduleFolderLoading = data?.moduleFolderLoading || false;
|
||||||
const gitBranches = data?.gitBranches || [];
|
const gitBranches = data?.gitBranches || [];
|
||||||
const gitRepoUrl = data?.gitRepoUrl || '';
|
|
||||||
// 生成配置列表的 HTML - 包含配置文件和模块文件夹
|
// 生成配置列表的 HTML - 包含配置文件和模块文件夹
|
||||||
const configsHtml = configs.map((config) => `
|
const configsHtml = configs.map((config) => `
|
||||||
<tr>
|
<tr>
|
||||||
@@ -37,22 +36,22 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
category += '(已上传)';
|
category += '(已上传)';
|
||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span class="editable">${icon} ${folder.name}</span>
|
<span class="editable">${icon} ${folder.name}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="category-${folder.type}">${category}</td>
|
<td class="category-${folder.type}">${category}</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
|
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
|
||||||
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
|
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
// 生成分支选择的 HTML - 使用树状结构
|
// 生成分支选择的 HTML - 使用树状结构(首次渲染可以为空,后续通过 message 更新)
|
||||||
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
|
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
@@ -237,25 +236,25 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 类别标签样式 */
|
/* 类别标签样式 */
|
||||||
.category-git {
|
.category-git {
|
||||||
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-local {
|
.category-local {
|
||||||
color: var(--vscode-charts-orange);
|
color: var(--vscode-charts-orange);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-git(已上传) {
|
.category-git(已上传) {
|
||||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-local(已上传) {
|
.category-local(已上传) {
|
||||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -294,15 +293,14 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
<div class="config-section">
|
<div class="config-section">
|
||||||
<h3 class="section-title">📚 模块云仓库</h3>
|
<h3 class="section-title">📚 模块云仓库</h3>
|
||||||
|
|
||||||
<!-- URL 输入区域 -->
|
<!-- 仓库选择区域:不再手动输入 URL,通过弹窗获取仓库 -->
|
||||||
<div class="url-input-section">
|
<div class="url-input-section">
|
||||||
<h4>🔗 添加 Git 仓库</h4>
|
<h4>🔗 获取仓库</h4>
|
||||||
<div style="display: flex; gap: 10px; margin-top: 10px;">
|
<div style="display: flex; gap: 10px; margin-top: 10px; align-items: center;">
|
||||||
<input type="text" id="repoUrlInput"
|
<button class="btn-new" onclick="openRepoSelect()">获取仓库</button>
|
||||||
placeholder="请输入 Git 仓库 URL,例如: https://github.com/username/repo.git"
|
<span style="font-size: 12px; color: var(--vscode-descriptionForeground);">
|
||||||
value="${gitRepoUrl}"
|
从仓库配置中选择 Git 仓库,随后可以选择分支并克隆到本地
|
||||||
style="flex: 1; padding: 8px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border: 1px solid var(--vscode-input-border); border-radius: 4px;">
|
</span>
|
||||||
<button class="btn-new" onclick="fetchBranches()">获取分支</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="branchSelectionContainer">
|
<div id="branchSelectionContainer">
|
||||||
${branchesHtml}
|
${branchesHtml}
|
||||||
@@ -315,7 +313,6 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
const vscode = acquireVsCodeApi();
|
const vscode = acquireVsCodeApi();
|
||||||
let currentConfigId = null;
|
let currentConfigId = null;
|
||||||
let selectedBranches = new Set();
|
let selectedBranches = new Set();
|
||||||
let currentRepoUrl = '';
|
|
||||||
let branchTreeData = [];
|
let branchTreeData = [];
|
||||||
let selectedConfigs = new Set();
|
let selectedConfigs = new Set();
|
||||||
|
|
||||||
@@ -337,7 +334,7 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新功能:在 VSCode 中打开配置文件
|
// 在 VSCode 中打开配置文件
|
||||||
function openConfigFileInVSCode(configId) {
|
function openConfigFileInVSCode(configId) {
|
||||||
console.log('📄 在 VSCode 中打开配置文件:', configId);
|
console.log('📄 在 VSCode 中打开配置文件:', configId);
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
@@ -436,7 +433,7 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加上传对话框函数
|
// 上传对话框函数(本地->Git)
|
||||||
function showUploadDialog(folderId) {
|
function showUploadDialog(folderId) {
|
||||||
const overlay = document.createElement('div');
|
const overlay = document.createElement('div');
|
||||||
overlay.className = 'modal-overlay';
|
overlay.className = 'modal-overlay';
|
||||||
@@ -522,30 +519,16 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
vscode.postMessage({ type: 'goBackToContainers' });
|
vscode.postMessage({ type: 'goBackToContainers' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Git 仓库管理功能
|
// 🔁 新逻辑:通过弹窗获取仓库(不再手动输入 URL)
|
||||||
function fetchBranches() {
|
function openRepoSelect() {
|
||||||
const urlInput = document.getElementById('repoUrlInput');
|
console.log('📦 请求仓库列表以选择 Git 仓库');
|
||||||
const repoUrl = urlInput.value.trim();
|
|
||||||
|
|
||||||
if (!repoUrl) {
|
|
||||||
alert('请输入 Git 仓库 URL');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!repoUrl.startsWith('http')) {
|
|
||||||
alert('请输入有效的 Git 仓库 URL');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentRepoUrl = repoUrl;
|
|
||||||
console.log('🌿 获取分支列表:', repoUrl);
|
|
||||||
|
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
type: 'fetchBranches',
|
type: 'openRepoSelect'
|
||||||
url: repoUrl
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 不再在前端手动输入/校验 URL,分支拉取由 repo 选择 + 后端完成
|
||||||
|
|
||||||
function toggleBranch(branchName) {
|
function toggleBranch(branchName) {
|
||||||
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9-]/g, '-'));
|
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9-]/g, '-'));
|
||||||
if (checkbox.checked) {
|
if (checkbox.checked) {
|
||||||
@@ -566,7 +549,6 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
|
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
type: 'cloneBranches',
|
type: 'cloneBranches',
|
||||||
url: currentRepoUrl,
|
|
||||||
branches: Array.from(selectedBranches)
|
branches: Array.from(selectedBranches)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -625,7 +607,7 @@ class ConfigView extends BaseView_1.BaseView {
|
|||||||
showMergeDialog();
|
showMergeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新的合并对话框函数
|
// 合并对话框
|
||||||
function showMergeDialog() {
|
function showMergeDialog() {
|
||||||
const overlay = document.createElement('div');
|
const overlay = document.createElement('div');
|
||||||
overlay.className = 'modal-overlay';
|
overlay.className = 'modal-overlay';
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,7 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.ProjectView = void 0;
|
exports.ProjectView = void 0;
|
||||||
// src/panels/views/ProjectView.ts
|
|
||||||
const BaseView_1 = require("./BaseView");
|
const BaseView_1 = require("./BaseView");
|
||||||
class ProjectView extends BaseView_1.BaseView {
|
class ProjectView extends BaseView_1.BaseView {
|
||||||
render(data) {
|
render(data) {
|
||||||
@@ -95,7 +94,10 @@ class ProjectView extends BaseView_1.BaseView {
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2><span class="satellite-icon">🛰️</span>数字卫星构建平台</h2>
|
<div class="header">
|
||||||
|
<h2><span class="satellite-icon">🛰️</span>数字卫星构建平台</h2>
|
||||||
|
<button class="back-btn" onclick="openRepoConfig()">⚙️ 仓库配置</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -125,6 +127,12 @@ class ProjectView extends BaseView_1.BaseView {
|
|||||||
<script>
|
<script>
|
||||||
const vscode = acquireVsCodeApi();
|
const vscode = acquireVsCodeApi();
|
||||||
|
|
||||||
|
function openRepoConfig() {
|
||||||
|
vscode.postMessage({
|
||||||
|
type: 'openRepoConfig'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function configureProject(projectId, projectName, isConfigured) {
|
function configureProject(projectId, projectName, isConfigured) {
|
||||||
if (isConfigured) {
|
if (isConfigured) {
|
||||||
// 已配置的项目直接打开
|
// 已配置的项目直接打开
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"ProjectView.js","sourceRoot":"","sources":["../../../src/panels/views/ProjectView.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAClC,yCAAsC;AAGtC,MAAa,WAAY,SAAQ,mBAAQ;IACrC,MAAM,CAAC,IAA0E;QAC7E,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,EAAE,CAAC;QACtC,MAAM,YAAY,GAAG,IAAI,EAAE,YAAY,IAAI,IAAI,GAAG,EAAE,CAAC;QAErD,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAwB,EAAE,EAAE;YAC3D,MAAM,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAClD,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;YAC7C,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;YAEhD,OAAO;;;kEAG+C,OAAO,CAAC,EAAE,KAAK,UAAU,IAAI,OAAO,CAAC,IAAI;;0BAEjF,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;;;;yEAItB,OAAO,CAAC,EAAE,OAAO,OAAO,CAAC,IAAI,MAAM,YAAY;0BAC9F,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;yEAIqB,OAAO,CAAC,EAAE;;;SAG1E,CAAA;QAAA,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEb,OAAO;;;;;;MAMT,IAAI,CAAC,SAAS,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsER,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA2LlB,CAAC;IACL,CAAC;CACJ;AAtSD,kCAsSC"}
|
{"version":3,"file":"ProjectView.js","sourceRoot":"","sources":["../../../src/panels/views/ProjectView.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC,MAAa,WAAY,SAAQ,mBAAQ;IACrC,MAAM,CAAC,IAA0E;QAC7E,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,EAAE,CAAC;QACtC,MAAM,YAAY,GAAG,IAAI,EAAE,YAAY,IAAI,IAAI,GAAG,EAAE,CAAC;QAErD,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAwB,EAAE,EAAE;YAC3D,MAAM,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAClD,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;YAC7C,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;YAEhD,OAAO;;;kEAG+C,OAAO,CAAC,EAAE,KAAK,UAAU,IAAI,OAAO,CAAC,IAAI;;0BAEjF,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;;;;yEAItB,OAAO,CAAC,EAAE,OAAO,OAAO,CAAC,IAAI,MAAM,YAAY;0BAC9F,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;yEAIqB,OAAO,CAAC,EAAE;;;SAG1E,CAAA;QAAA,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEb,OAAO;;;;;;MAMT,IAAI,CAAC,SAAS,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAyER,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAiMlB,CAAC;IACL,CAAC;CACJ;AA/SD,kCA+SC"}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// src/panels/ConfigPanel.ts
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
@@ -59,6 +60,14 @@ interface ProjectData {
|
|||||||
moduleFolders: ModuleFolder[];
|
moduleFolders: ModuleFolder[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 仓库配置项
|
||||||
|
interface RepoConfigItem {
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
// 主面板类
|
// 主面板类
|
||||||
// =============================================
|
// =============================================
|
||||||
@@ -84,6 +93,10 @@ export class ConfigPanel {
|
|||||||
private currentModuleFolderFileTree: GitFileTree[] = [];
|
private currentModuleFolderFileTree: GitFileTree[] = [];
|
||||||
private projectPaths: Map<string, string> = new Map();
|
private projectPaths: Map<string, string> = new Map();
|
||||||
|
|
||||||
|
// 仓库配置
|
||||||
|
private repoConfigs: RepoConfigItem[] = [];
|
||||||
|
private currentRepoForBranches: RepoConfigItem | undefined;
|
||||||
|
|
||||||
// 状态管理
|
// 状态管理
|
||||||
private isWebviewDisposed: boolean = false;
|
private isWebviewDisposed: boolean = false;
|
||||||
|
|
||||||
@@ -130,6 +143,9 @@ export class ConfigPanel {
|
|||||||
this.containerView = new ContainerView(extensionUri);
|
this.containerView = new ContainerView(extensionUri);
|
||||||
this.configView = new ConfigView(extensionUri);
|
this.configView = new ConfigView(extensionUri);
|
||||||
|
|
||||||
|
// 尝试加载仓库配置
|
||||||
|
void this.loadRepoConfigs();
|
||||||
|
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
this.setupMessageListener();
|
this.setupMessageListener();
|
||||||
|
|
||||||
@@ -163,6 +179,106 @@ export class ConfigPanel {
|
|||||||
return `${prefix}${idNumber}`;
|
return `${prefix}${idNumber}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// 仓库配置相关
|
||||||
|
// =============================================
|
||||||
|
|
||||||
|
private getRepoConfigPath(): string {
|
||||||
|
// 按你的需求:配置文件保存在插件安装位置
|
||||||
|
return path.join(this.extensionUri.fsPath, 'dcsp-repos.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
private async loadRepoConfigs(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const configPath = this.getRepoConfigPath();
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
this.repoConfigs = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = await fs.promises.readFile(configPath, 'utf8');
|
||||||
|
if (!content.trim()) {
|
||||||
|
this.repoConfigs = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = JSON.parse(content);
|
||||||
|
if (Array.isArray(parsed)) {
|
||||||
|
// 兼容老格式:直接是数组
|
||||||
|
this.repoConfigs = parsed;
|
||||||
|
} else if (parsed && Array.isArray(parsed.repos)) {
|
||||||
|
this.repoConfigs = parsed.repos;
|
||||||
|
} else {
|
||||||
|
this.repoConfigs = [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载仓库配置失败:', error);
|
||||||
|
vscode.window.showErrorMessage('读取仓库配置文件失败(dcsp-repos.json),请检查文件格式。');
|
||||||
|
this.repoConfigs = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async ensureRepoConfigFileExists(): Promise<void> {
|
||||||
|
const configPath = this.getRepoConfigPath();
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
const defaultContent = JSON.stringify(
|
||||||
|
{
|
||||||
|
repos: [
|
||||||
|
{
|
||||||
|
name: 'example-repo',
|
||||||
|
url: 'https://github.com/username/repo.git',
|
||||||
|
username: '',
|
||||||
|
password: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
await fs.promises.writeFile(configPath, defaultContent, 'utf8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async openRepoConfig(): Promise<void> {
|
||||||
|
try {
|
||||||
|
await this.ensureRepoConfigFileExists();
|
||||||
|
const configPath = this.getRepoConfigPath();
|
||||||
|
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(configPath));
|
||||||
|
await vscode.window.showTextDocument(doc);
|
||||||
|
await this.loadRepoConfigs();
|
||||||
|
} catch (error) {
|
||||||
|
vscode.window.showErrorMessage(`打开仓库配置文件失败: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async openRepoSelect(): Promise<void> {
|
||||||
|
await this.loadRepoConfigs();
|
||||||
|
|
||||||
|
if (!this.repoConfigs || this.repoConfigs.length === 0) {
|
||||||
|
vscode.window.showWarningMessage('尚未配置任何仓库,请先点击右上角 “仓库配置” 按钮编辑 dcsp-repos.json。');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isWebviewDisposed) return;
|
||||||
|
|
||||||
|
// 仅传递仓库名给前端,用于下拉选择
|
||||||
|
this.panel.webview.postMessage({
|
||||||
|
type: 'showRepoSelect',
|
||||||
|
repos: this.repoConfigs.map(r => ({ name: r.name }))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleRepoSelectedForBranches(repoName: string): Promise<void> {
|
||||||
|
await this.loadRepoConfigs();
|
||||||
|
const repo = this.repoConfigs.find(r => r.name === repoName);
|
||||||
|
if (!repo) {
|
||||||
|
vscode.window.showErrorMessage(`在仓库配置中未找到名为 "${repoName}" 的仓库,请检查 dcsp-repos.json。`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentRepoForBranches = repo;
|
||||||
|
await this.fetchBranchesForRepo(repo);
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
// Webview 消息处理
|
// Webview 消息处理
|
||||||
// =============================================
|
// =============================================
|
||||||
@@ -221,9 +337,14 @@ export class ConfigPanel {
|
|||||||
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
||||||
'mergeConfigs': (data) => this.mergeConfigs(data.configIds, data.displayName, data.folderName),
|
'mergeConfigs': (data) => this.mergeConfigs(data.configIds, data.displayName, data.folderName),
|
||||||
|
|
||||||
// Git 仓库管理
|
// Git 仓库管理(新:基于配置)
|
||||||
|
'openRepoConfig': () => this.openRepoConfig(),
|
||||||
|
'openRepoSelect': () => this.openRepoSelect(),
|
||||||
|
'repoSelectedForBranches': (data) => this.handleRepoSelectedForBranches(data.repoName),
|
||||||
|
|
||||||
|
// Git 仓库管理(老接口:为了兼容,仍然保留)
|
||||||
'fetchBranches': (data) => this.fetchBranches(data.url),
|
'fetchBranches': (data) => this.fetchBranches(data.url),
|
||||||
'cloneBranches': (data) => this.cloneBranches(data.url, data.branches),
|
'cloneBranches': (data) => this.cloneBranches(data.branches),
|
||||||
'cancelBranchSelection': () => this.handleCancelBranchSelection(),
|
'cancelBranchSelection': () => this.handleCancelBranchSelection(),
|
||||||
|
|
||||||
// 模块文件夹管理
|
// 模块文件夹管理
|
||||||
@@ -320,7 +441,6 @@ export class ConfigPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async createProject(name: string): Promise<void> {
|
private async createProject(name: string): Promise<void> {
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('p', this.projects);
|
const newId = this.generateUniqueId('p', this.projects);
|
||||||
const newProject: Project = {
|
const newProject: Project = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -328,7 +448,6 @@ export class ConfigPanel {
|
|||||||
};
|
};
|
||||||
this.projects.push(newProject);
|
this.projects.push(newProject);
|
||||||
|
|
||||||
// 设置当前项目
|
|
||||||
this.currentProjectId = newId;
|
this.currentProjectId = newId;
|
||||||
|
|
||||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||||
@@ -341,7 +460,6 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
this.projects = this.projects.filter(p => p.id !== projectId);
|
this.projects = this.projects.filter(p => p.id !== projectId);
|
||||||
|
|
||||||
// 删除相关数据
|
|
||||||
const relatedAircrafts = this.aircrafts.filter(a => a.projectId === projectId);
|
const relatedAircrafts = this.aircrafts.filter(a => a.projectId === projectId);
|
||||||
const aircraftIds = relatedAircrafts.map(a => a.id);
|
const aircraftIds = relatedAircrafts.map(a => a.id);
|
||||||
|
|
||||||
@@ -379,7 +497,6 @@ export class ConfigPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('a', this.aircrafts);
|
const newId = this.generateUniqueId('a', this.aircrafts);
|
||||||
const newAircraft: Aircraft = {
|
const newAircraft: Aircraft = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -430,7 +547,6 @@ export class ConfigPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('c', this.containers);
|
const newId = this.generateUniqueId('c', this.containers);
|
||||||
const newContainer: Container = {
|
const newContainer: Container = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -475,7 +591,6 @@ export class ConfigPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async createConfig(name: string): Promise<void> {
|
private async createConfig(name: string): Promise<void> {
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('cfg', this.configs);
|
const newId = this.generateUniqueId('cfg', this.configs);
|
||||||
const newConfig: Config = {
|
const newConfig: Config = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -547,7 +662,6 @@ export class ConfigPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建合并文件夹并复制文件
|
|
||||||
const mergeFolderPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
const mergeFolderPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||||
await fs.promises.mkdir(mergeFolderPath, { recursive: true });
|
await fs.promises.mkdir(mergeFolderPath, { recursive: true });
|
||||||
|
|
||||||
@@ -562,9 +676,7 @@ export class ConfigPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建合并文件夹记录
|
|
||||||
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('local-', this.moduleFolders);
|
const newId = this.generateUniqueId('local-', this.moduleFolders);
|
||||||
const newFolder: ModuleFolder = {
|
const newFolder: ModuleFolder = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -576,7 +688,6 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
this.moduleFolders.push(newFolder);
|
this.moduleFolders.push(newFolder);
|
||||||
|
|
||||||
// 删除原始配置文件
|
|
||||||
for (const configId of configIds) {
|
for (const configId of configIds) {
|
||||||
await this.deleteConfigInternal(configId);
|
await this.deleteConfigInternal(configId);
|
||||||
}
|
}
|
||||||
@@ -595,7 +706,11 @@ export class ConfigPanel {
|
|||||||
// Git 分支管理方法
|
// Git 分支管理方法
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|
||||||
private async fetchBranches(url: string): Promise<void> {
|
private async fetchBranchesForRepo(repo: RepoConfigItem): Promise<void> {
|
||||||
|
await this.fetchBranches(repo.url, repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async fetchBranches(url: string, repo?: RepoConfigItem): Promise<void> {
|
||||||
try {
|
try {
|
||||||
console.log('🌿 开始获取分支列表:', url);
|
console.log('🌿 开始获取分支列表:', url);
|
||||||
|
|
||||||
@@ -608,21 +723,28 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
progress.report({ increment: 30, message: '获取远程引用...' });
|
progress.report({ increment: 30, message: '获取远程引用...' });
|
||||||
|
|
||||||
const refs = await git.listServerRefs({
|
const options: any = {
|
||||||
http: http,
|
http: http,
|
||||||
url: url
|
url: url
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (repo && (repo.username || repo.password)) {
|
||||||
|
options.onAuth = () => ({
|
||||||
|
username: repo.username || '',
|
||||||
|
password: repo.password || ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const refs = await git.listServerRefs(options);
|
||||||
|
|
||||||
console.log('📋 获取到的引用:', refs);
|
console.log('📋 获取到的引用:', refs);
|
||||||
|
|
||||||
// 过滤出分支引用
|
const branchRefs = refs.filter((ref: any) =>
|
||||||
const branchRefs = refs.filter(ref =>
|
|
||||||
ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/')
|
ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/')
|
||||||
);
|
);
|
||||||
|
|
||||||
// 构建分支数据
|
const branches: GitBranch[] = branchRefs.map((ref: any) => {
|
||||||
const branches: GitBranch[] = branchRefs.map(ref => {
|
|
||||||
let branchName: string;
|
let branchName: string;
|
||||||
|
|
||||||
if (ref.ref.startsWith('refs/remotes/')) {
|
if (ref.ref.startsWith('refs/remotes/')) {
|
||||||
@@ -644,16 +766,15 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
progress.report({ increment: 80, message: '处理分支数据...' });
|
progress.report({ increment: 80, message: '处理分支数据...' });
|
||||||
|
|
||||||
// 构建分支树状结构
|
|
||||||
const branchTree = this.buildBranchTree(branches);
|
const branchTree = this.buildBranchTree(branches);
|
||||||
|
|
||||||
// 发送分支数据到前端
|
|
||||||
if (!this.isWebviewDisposed) {
|
if (!this.isWebviewDisposed) {
|
||||||
this.panel.webview.postMessage({
|
this.panel.webview.postMessage({
|
||||||
type: 'branchesFetched',
|
type: 'branchesFetched',
|
||||||
branches: branches,
|
branches: branches,
|
||||||
branchTree: branchTree,
|
branchTree: branchTree,
|
||||||
repoUrl: url
|
repoUrl: url,
|
||||||
|
repoName: repo?.name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,7 +792,15 @@ export class ConfigPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async cloneBranches(url: string, branches: string[]): Promise<void> {
|
private async cloneBranches(branches: string[]): Promise<void> {
|
||||||
|
if (!this.currentRepoForBranches) {
|
||||||
|
vscode.window.showErrorMessage('请先通过“获取仓库”选择一个仓库');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = this.currentRepoForBranches.url;
|
||||||
|
const repoDisplayName = this.currentRepoForBranches.name;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('🚀 开始克隆分支:', { url, branches });
|
console.log('🚀 开始克隆分支:', { url, branches });
|
||||||
|
|
||||||
@@ -694,7 +823,7 @@ export class ConfigPanel {
|
|||||||
console.log(`📥 开始克隆分支: ${branch}`);
|
console.log(`📥 开始克隆分支: ${branch}`);
|
||||||
try {
|
try {
|
||||||
const folderNames = this.generateModuleFolderName(url, branch);
|
const folderNames = this.generateModuleFolderName(url, branch);
|
||||||
await this.addGitModuleFolder(url, folderNames.displayName, folderNames.folderName, branch);
|
await this.addGitModuleFolder(url, repoDisplayName, folderNames.folderName, branch);
|
||||||
successCount++;
|
successCount++;
|
||||||
console.log(`✅ 分支克隆成功: ${branch}`);
|
console.log(`✅ 分支克隆成功: ${branch}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -704,7 +833,6 @@ export class ConfigPanel {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 显示最终结果
|
|
||||||
if (failCount === 0) {
|
if (failCount === 0) {
|
||||||
vscode.window.showInformationMessage(`成功克隆 ${successCount} 个分支`);
|
vscode.window.showInformationMessage(`成功克隆 ${successCount} 个分支`);
|
||||||
} else {
|
} else {
|
||||||
@@ -742,14 +870,12 @@ export class ConfigPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const folderId = this.generateUniqueId('git-', this.moduleFolders);
|
const folderId = this.generateUniqueId('git-', this.moduleFolders);
|
||||||
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
||||||
const localPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
const localPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||||
|
|
||||||
console.log(`📁 准备克隆仓库: ${displayName}, 分支: ${branch}, 路径: ${localPath}`);
|
console.log(`📁 准备克隆仓库: ${displayName}, 分支: ${branch}, 路径: ${localPath}`);
|
||||||
|
|
||||||
// 检查是否已存在相同路径的模块文件夹
|
|
||||||
const existingFolder = this.moduleFolders.find(folder =>
|
const existingFolder = this.moduleFolders.find(folder =>
|
||||||
folder.localPath === relativePath && folder.containerId === this.currentContainerId
|
folder.localPath === relativePath && folder.containerId === this.currentContainerId
|
||||||
);
|
);
|
||||||
@@ -774,11 +900,9 @@ export class ConfigPanel {
|
|||||||
progress.report({ increment: 0 });
|
progress.report({ increment: 0 });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 确保父目录存在
|
|
||||||
const parentDir = path.dirname(localPath);
|
const parentDir = path.dirname(localPath);
|
||||||
await fs.promises.mkdir(parentDir, { recursive: true });
|
await fs.promises.mkdir(parentDir, { recursive: true });
|
||||||
|
|
||||||
// 检查目标目录是否已存在
|
|
||||||
let dirExists = false;
|
let dirExists = false;
|
||||||
try {
|
try {
|
||||||
await fs.promises.access(localPath);
|
await fs.promises.access(localPath);
|
||||||
@@ -802,7 +926,6 @@ export class ConfigPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空目录(除了 .git 文件夹)
|
|
||||||
for (const item of dirContents) {
|
for (const item of dirContents) {
|
||||||
const itemPath = path.join(localPath, item);
|
const itemPath = path.join(localPath, item);
|
||||||
if (item !== '.git') {
|
if (item !== '.git') {
|
||||||
@@ -814,7 +937,6 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
console.log(`🚀 开始克隆: ${url} -> ${localPath}, 分支: ${branch}`);
|
console.log(`🚀 开始克隆: ${url} -> ${localPath}, 分支: ${branch}`);
|
||||||
|
|
||||||
// 克隆仓库
|
|
||||||
await git.clone({
|
await git.clone({
|
||||||
fs: fs,
|
fs: fs,
|
||||||
http: http,
|
http: http,
|
||||||
@@ -839,7 +961,6 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
console.log('✅ Git克隆成功完成');
|
console.log('✅ Git克隆成功完成');
|
||||||
|
|
||||||
// 验证克隆是否真的成功
|
|
||||||
const clonedContents = await fs.promises.readdir(localPath);
|
const clonedContents = await fs.promises.readdir(localPath);
|
||||||
console.log(`📁 克隆后的目录内容:`, clonedContents);
|
console.log(`📁 克隆后的目录内容:`, clonedContents);
|
||||||
|
|
||||||
@@ -847,14 +968,12 @@ export class ConfigPanel {
|
|||||||
throw new Error('克隆后目录为空,可能克隆失败');
|
throw new Error('克隆后目录为空,可能克隆失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只有在克隆成功后才添加到列表
|
|
||||||
this.moduleFolders.push(newFolder);
|
this.moduleFolders.push(newFolder);
|
||||||
await this.saveCurrentProjectData();
|
await this.saveCurrentProjectData();
|
||||||
console.log('✅ Git模块文件夹数据已保存到项目文件');
|
console.log('✅ Git模块文件夹数据已保存到项目文件');
|
||||||
|
|
||||||
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${displayName}`);
|
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${displayName}`);
|
||||||
|
|
||||||
// 自动加载文件树
|
|
||||||
if (!this.isWebviewDisposed) {
|
if (!this.isWebviewDisposed) {
|
||||||
console.log('🌳 开始加载模块文件夹文件树...');
|
console.log('🌳 开始加载模块文件夹文件树...');
|
||||||
this.currentModuleFolderId = folderId;
|
this.currentModuleFolderId = folderId;
|
||||||
@@ -865,7 +984,6 @@ export class ConfigPanel {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ 在克隆过程中捕获错误:', error);
|
console.error('❌ 在克隆过程中捕获错误:', error);
|
||||||
|
|
||||||
// 清理:如果克隆失败,删除可能创建的不完整目录
|
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(localPath)) {
|
if (fs.existsSync(localPath)) {
|
||||||
await fs.promises.rm(localPath, { recursive: true, force: true });
|
await fs.promises.rm(localPath, { recursive: true, force: true });
|
||||||
@@ -998,7 +1116,6 @@ export class ConfigPanel {
|
|||||||
const content = await fs.promises.readFile(fileFullPath, 'utf8');
|
const content = await fs.promises.readFile(fileFullPath, 'utf8');
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
|
|
||||||
// 使用新的 ID 生成方法
|
|
||||||
const newId = this.generateUniqueId('cfg', this.configs);
|
const newId = this.generateUniqueId('cfg', this.configs);
|
||||||
const newConfig: Config = {
|
const newConfig: Config = {
|
||||||
id: newId,
|
id: newId,
|
||||||
@@ -1023,7 +1140,7 @@ export class ConfigPanel {
|
|||||||
// 上传功能方法
|
// 上传功能方法
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|
||||||
private async uploadGitModuleFolder(folderId: string, username: string, password: string): Promise<void> {
|
private async uploadGitModuleFolder(folderId: string, username?: string, password?: string): Promise<void> {
|
||||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||||
if (!folder || folder.type !== 'git') {
|
if (!folder || folder.type !== 'git') {
|
||||||
vscode.window.showErrorMessage('未找到指定的 Git 模块文件夹');
|
vscode.window.showErrorMessage('未找到指定的 Git 模块文件夹');
|
||||||
@@ -1054,9 +1171,9 @@ export class ConfigPanel {
|
|||||||
vscode.window.showInformationMessage(`✅ Git 仓库上传成功: ${folder.name}`);
|
vscode.window.showInformationMessage(`✅ Git 仓库上传成功: ${folder.name}`);
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('❌ Git 上传失败:', error);
|
console.error('❌ Git 上传失败:', error);
|
||||||
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
|
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1107,11 +1224,10 @@ export class ConfigPanel {
|
|||||||
vscode.window.showInformationMessage(`本地文件夹成功上传到 Git 仓库: ${folder.name} -> ${branchName}`);
|
vscode.window.showInformationMessage(`本地文件夹成功上传到 Git 仓库: ${folder.name} -> ${branchName}`);
|
||||||
this.updateWebview();
|
this.updateWebview();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('❌ 本地文件夹上传失败:', error);
|
console.error('❌ 本地文件夹上传失败:', error);
|
||||||
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
|
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
||||||
|
|
||||||
// 清理:删除可能创建的 .git 文件夹
|
|
||||||
try {
|
try {
|
||||||
const gitDir = path.join(fullPath, '.git');
|
const gitDir = path.join(fullPath, '.git');
|
||||||
if (fs.existsSync(gitDir)) {
|
if (fs.existsSync(gitDir)) {
|
||||||
@@ -1135,18 +1251,16 @@ export class ConfigPanel {
|
|||||||
console.log('🚀 使用命令行 Git 提交并推送...');
|
console.log('🚀 使用命令行 Git 提交并推送...');
|
||||||
console.log(`📁 工作目录: ${fullPath}`);
|
console.log(`📁 工作目录: ${fullPath}`);
|
||||||
|
|
||||||
// 先检查是否有更改
|
|
||||||
exec('git status --porcelain', {
|
exec('git status --porcelain', {
|
||||||
cwd: fullPath,
|
cwd: fullPath,
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
}, (statusError, statusStdout, statusStderr) => {
|
}, (statusError: any, statusStdout: string, statusStderr: string) => {
|
||||||
if (statusError) {
|
if (statusError) {
|
||||||
console.error('❌ 检查 Git 状态失败:', statusError);
|
console.error('❌ 检查 Git 状态失败:', statusError);
|
||||||
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
|
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果没有更改
|
|
||||||
if (!statusStdout.trim()) {
|
if (!statusStdout.trim()) {
|
||||||
console.log('ℹ️ 没有需要提交的更改');
|
console.log('ℹ️ 没有需要提交的更改');
|
||||||
reject(new Error('没有需要提交的更改'));
|
reject(new Error('没有需要提交的更改'));
|
||||||
@@ -1155,7 +1269,6 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
console.log('📋 检测到更改:', statusStdout);
|
console.log('📋 检测到更改:', statusStdout);
|
||||||
|
|
||||||
// 有更改时才提交并推送
|
|
||||||
const commands = [
|
const commands = [
|
||||||
'git add .',
|
'git add .',
|
||||||
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
|
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
|
||||||
@@ -1165,7 +1278,7 @@ export class ConfigPanel {
|
|||||||
exec(commands.join(' && '), {
|
exec(commands.join(' && '), {
|
||||||
cwd: fullPath,
|
cwd: fullPath,
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
}, (error, stdout, stderr) => {
|
}, (error: any, stdout: string, stderr: string) => {
|
||||||
console.log('📋 Git 命令输出:', stdout);
|
console.log('📋 Git 命令输出:', stdout);
|
||||||
console.log('📋 Git 命令错误:', stderr);
|
console.log('📋 Git 命令错误:', stderr);
|
||||||
|
|
||||||
@@ -1191,7 +1304,7 @@ export class ConfigPanel {
|
|||||||
exec(`git init && git checkout -b ${branchName}`, {
|
exec(`git init && git checkout -b ${branchName}`, {
|
||||||
cwd: fullPath,
|
cwd: fullPath,
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
}, (error, stdout, stderr) => {
|
}, (error: any, stdout: string, stderr: string) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('❌ Git 初始化失败:', error);
|
console.error('❌ Git 初始化失败:', error);
|
||||||
reject(new Error(stderr || error.message));
|
reject(new Error(stderr || error.message));
|
||||||
@@ -1213,7 +1326,7 @@ export class ConfigPanel {
|
|||||||
exec(`git remote add origin ${repoUrl}`, {
|
exec(`git remote add origin ${repoUrl}`, {
|
||||||
cwd: fullPath,
|
cwd: fullPath,
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
}, (error, stdout, stderr) => {
|
}, (error: any, stdout: string, stderr: string) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('❌ 添加远程仓库失败:', error);
|
console.error('❌ 添加远程仓库失败:', error);
|
||||||
reject(new Error(stderr || error.message));
|
reject(new Error(stderr || error.message));
|
||||||
@@ -1234,15 +1347,14 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
const commands = [
|
const commands = [
|
||||||
'git add .',
|
'git add .',
|
||||||
`git commit -m "Initial commit from DCSP - ${new Date().toLocaleString()}"`
|
`git commit -m "Initial commit from DCSP - ${new Date().toLocaleString()}"`,
|
||||||
];
|
];
|
||||||
|
|
||||||
exec(commands.join(' && '), {
|
exec(commands.join(' && '), {
|
||||||
cwd: fullPath,
|
cwd: fullPath,
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
}, (error, stdout, stderr) => {
|
}, (error: any, stdout: string, stderr: string) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
// 检查是否是"没有更改可提交"的错误
|
|
||||||
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
|
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
|
||||||
console.log('ℹ️ 没有需要提交的更改');
|
console.log('ℹ️ 没有需要提交的更改');
|
||||||
resolve();
|
resolve();
|
||||||
@@ -1269,7 +1381,7 @@ export class ConfigPanel {
|
|||||||
exec(`git push -u origin ${branchName} --force`, {
|
exec(`git push -u origin ${branchName} --force`, {
|
||||||
cwd: fullPath,
|
cwd: fullPath,
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
}, (error, stdout, stderr) => {
|
}, (error: any, stdout: string, stderr: string) => {
|
||||||
console.log('📋 Git push stdout:', stdout);
|
console.log('📋 Git push stdout:', stdout);
|
||||||
console.log('📋 Git push stderr:', stderr);
|
console.log('📋 Git push stderr:', stderr);
|
||||||
|
|
||||||
@@ -1355,9 +1467,6 @@ export class ConfigPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async createDefaultConfigs(container: Container): Promise<void> {
|
private async createDefaultConfigs(container: Container): Promise<void> {
|
||||||
const configCount = this.configs.length;
|
|
||||||
|
|
||||||
// 第一个配置文件
|
|
||||||
this.configs.push({
|
this.configs.push({
|
||||||
id: this.generateUniqueId('cfg', this.configs),
|
id: this.generateUniqueId('cfg', this.configs),
|
||||||
name: '配置1',
|
name: '配置1',
|
||||||
@@ -1366,12 +1475,11 @@ export class ConfigPanel {
|
|||||||
containerId: container.id
|
containerId: container.id
|
||||||
});
|
});
|
||||||
|
|
||||||
// 第二个配置文件
|
|
||||||
this.configs.push({
|
this.configs.push({
|
||||||
id: this.generateUniqueId('cfg', this.configs),
|
id: this.generateUniqueId('cfg', this.configs),
|
||||||
name: '配置2',
|
name: '配置2',
|
||||||
fileName: 'docker-compose.yml',
|
fileName: 'docker-compose.yml',
|
||||||
content: `# ${container.name} 的 Docker Compose 配置\nversion: '3.8'\n\nservices:\n ${container.name.toLowerCase().replace(/\\s+/g, '-')}:\n build: .\n container_name: ${container.name}\n ports:\n - "8080:8080"\n environment:\n - NODE_ENV=production\n volumes:\n - ./data:/app/data\n restart: unless-stopped`,
|
content: `# ${container.name} 的 Docker Compose 配置\nversion: '3.8'\n\nservices:\n ${container.name.toLowerCase().replace(/\s+/g, '-')}:\n build: .\n container_name: ${container.name}\n ports:\n - "8080:8080"\n environment:\n - NODE_ENV=production\n volumes:\n - ./data:/app/data\n restart: unless-stopped`,
|
||||||
containerId: container.id
|
containerId: container.id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1427,9 +1535,8 @@ export class ConfigPanel {
|
|||||||
|
|
||||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||||
|
|
||||||
// 构建当前项目的完整数据
|
|
||||||
const data: ProjectData = {
|
const data: ProjectData = {
|
||||||
projects: [this.projects.find(p => p.id === this.currentProjectId)!], // 只保存当前项目
|
projects: [this.projects.find(p => p.id === this.currentProjectId)!],
|
||||||
aircrafts: this.aircrafts.filter(a => a.projectId === this.currentProjectId),
|
aircrafts: this.aircrafts.filter(a => a.projectId === this.currentProjectId),
|
||||||
containers: this.containers.filter(c => {
|
containers: this.containers.filter(c => {
|
||||||
const aircraft = this.aircrafts.find(a => a.id === c.aircraftId);
|
const aircraft = this.aircrafts.find(a => a.id === c.aircraftId);
|
||||||
@@ -1462,7 +1569,6 @@ export class ConfigPanel {
|
|||||||
try {
|
try {
|
||||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||||
|
|
||||||
// 检查数据文件是否存在
|
|
||||||
try {
|
try {
|
||||||
await vscode.workspace.fs.stat(dataUri);
|
await vscode.workspace.fs.stat(dataUri);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -1470,15 +1576,12 @@ export class ConfigPanel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取数据文件
|
|
||||||
const fileData = await vscode.workspace.fs.readFile(dataUri);
|
const fileData = await vscode.workspace.fs.readFile(dataUri);
|
||||||
const dataStr = new TextDecoder().decode(fileData);
|
const dataStr = new TextDecoder().decode(fileData);
|
||||||
const data: ProjectData = JSON.parse(dataStr);
|
const data: ProjectData = JSON.parse(dataStr);
|
||||||
|
|
||||||
// 只清空当前项目相关的数据,保留其他项目数据
|
|
||||||
const projectId = data.projects[0]?.id;
|
const projectId = data.projects[0]?.id;
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
// 移除当前项目的旧数据
|
|
||||||
this.projects = this.projects.filter(p => p.id !== projectId);
|
this.projects = this.projects.filter(p => p.id !== projectId);
|
||||||
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
||||||
|
|
||||||
@@ -1489,14 +1592,12 @@ export class ConfigPanel {
|
|||||||
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
||||||
this.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
this.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
||||||
|
|
||||||
// 添加新数据
|
|
||||||
this.projects.push(...data.projects);
|
this.projects.push(...data.projects);
|
||||||
this.aircrafts.push(...data.aircrafts);
|
this.aircrafts.push(...data.aircrafts);
|
||||||
this.containers.push(...data.containers);
|
this.containers.push(...data.containers);
|
||||||
this.configs.push(...data.configs);
|
this.configs.push(...data.configs);
|
||||||
this.moduleFolders.push(...data.moduleFolders);
|
this.moduleFolders.push(...data.moduleFolders);
|
||||||
|
|
||||||
// 设置当前项目
|
|
||||||
this.currentProjectId = projectId;
|
this.currentProjectId = projectId;
|
||||||
this.projectPaths.set(projectId, projectPath);
|
this.projectPaths.set(projectId, projectPath);
|
||||||
this.currentView = 'aircrafts';
|
this.currentView = 'aircrafts';
|
||||||
@@ -1666,7 +1767,6 @@ export class ConfigPanel {
|
|||||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||||
if (!folder) return;
|
if (!folder) return;
|
||||||
|
|
||||||
// 通知前端开始加载
|
|
||||||
try {
|
try {
|
||||||
this.panel.webview.postMessage({
|
this.panel.webview.postMessage({
|
||||||
type: 'moduleFolderLoading',
|
type: 'moduleFolderLoading',
|
||||||
@@ -1689,13 +1789,11 @@ export class ConfigPanel {
|
|||||||
this.currentModuleFolderFileTree = [];
|
this.currentModuleFolderFileTree = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 再次检查 Webview 状态
|
|
||||||
if (this.isWebviewDisposed) {
|
if (this.isWebviewDisposed) {
|
||||||
console.log('⚠️ Webview 已被销毁,跳过完成通知');
|
console.log('⚠️ Webview 已被销毁,跳过完成通知');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知前端加载完成
|
|
||||||
try {
|
try {
|
||||||
this.panel.webview.postMessage({
|
this.panel.webview.postMessage({
|
||||||
type: 'moduleFolderLoading',
|
type: 'moduleFolderLoading',
|
||||||
@@ -1714,7 +1812,6 @@ export class ConfigPanel {
|
|||||||
const tree: GitFileTree[] = [];
|
const tree: GitFileTree[] = [];
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
// 忽略 .git 文件夹和 .dcsp-data.json
|
|
||||||
if (file.startsWith('.') && file !== '.git') continue;
|
if (file.startsWith('.') && file !== '.git') continue;
|
||||||
if (file === '.dcsp-data.json') continue;
|
if (file === '.dcsp-data.json') continue;
|
||||||
|
|
||||||
@@ -1907,7 +2004,6 @@ export class ConfigPanel {
|
|||||||
projectPaths: this.projectPaths
|
projectPaths: this.projectPaths
|
||||||
});
|
});
|
||||||
case 'aircrafts':
|
case 'aircrafts':
|
||||||
// 只显示当前项目的飞行器
|
|
||||||
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
||||||
return this.aircraftView.render({
|
return this.aircraftView.render({
|
||||||
aircrafts: projectAircrafts
|
aircrafts: projectAircrafts
|
||||||
@@ -1915,7 +2011,6 @@ export class ConfigPanel {
|
|||||||
case 'containers':
|
case 'containers':
|
||||||
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
||||||
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
|
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
|
||||||
// 只显示当前飞行器的容器
|
|
||||||
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
||||||
|
|
||||||
return this.containerView.render({
|
return this.containerView.render({
|
||||||
@@ -1925,9 +2020,8 @@ export class ConfigPanel {
|
|||||||
});
|
});
|
||||||
case 'configs':
|
case 'configs':
|
||||||
const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
|
const currentContainer = this.containers.find(c => c.id === this.currentContainerId);
|
||||||
// 只显示当前容器的配置和模块文件夹
|
|
||||||
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
|
||||||
const currentModuleFolder = this.moduleFolders.find(f => f.id === this.currentModuleFolderId);
|
const currentModuleFolder = this.moduleFolders.find(f => f.id === this.currentModuleFolderId);
|
||||||
|
const containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
||||||
const containerModuleFolders = this.moduleFolders.filter(folder => folder.containerId === this.currentContainerId);
|
const containerModuleFolders = this.moduleFolders.filter(folder => folder.containerId === this.currentContainerId);
|
||||||
|
|
||||||
return this.configView.render({
|
return this.configView.render({
|
||||||
@@ -1945,4 +2039,4 @@ export class ConfigPanel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
202
src/panels/views/BaseView.ts
Normal file → Executable file
202
src/panels/views/BaseView.ts
Normal file → Executable file
@@ -1,4 +1,3 @@
|
|||||||
// src/panels/views/BaseView.ts
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
export abstract class BaseView {
|
export abstract class BaseView {
|
||||||
@@ -120,59 +119,154 @@ export abstract class BaseView {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
.modal-overlay {
|
.modal-overlay {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
background: rgba(0, 0, 0, 0.5);
|
background: rgba(0, 0, 0, 0.5);
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-dialog {
|
.modal-dialog {
|
||||||
background: var(--vscode-editor-background);
|
background: var(--vscode-editor-background);
|
||||||
border: 1px solid var(--vscode-panel-border);
|
border: 1px solid var(--vscode-panel-border);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
min-width: 300px;
|
min-width: 300px;
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-title {
|
.modal-title {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: var(--vscode-editor-foreground);
|
color: var(--vscode-editor-foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-buttons {
|
.modal-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-btn {
|
.modal-btn {
|
||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-btn-primary {
|
.modal-btn-primary {
|
||||||
background: var(--vscode-button-background);
|
background: var(--vscode-button-background);
|
||||||
color: var(--vscode-button-foreground);
|
color: var(--vscode-button-foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-btn-secondary {
|
.modal-btn-secondary {
|
||||||
background: var(--vscode-button-secondaryBackground);
|
background: var(--vscode-button-secondaryBackground);
|
||||||
color: var(--vscode-button-secondaryForeground);
|
color: var(--vscode-button-secondaryForeground);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
// 避免在同一个 Webview 中重复注册
|
||||||
|
if (window.__dcspRepoDialogInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.__dcspRepoDialogInitialized = true;
|
||||||
|
|
||||||
|
function showRepoSelectDialog(repos) {
|
||||||
|
// 移除已有弹窗
|
||||||
|
var existing = document.getElementById('repoSelectModal');
|
||||||
|
if (existing) {
|
||||||
|
existing.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
var overlay = document.createElement('div');
|
||||||
|
overlay.className = 'modal-overlay';
|
||||||
|
overlay.id = 'repoSelectModal';
|
||||||
|
|
||||||
|
var hasRepos = Array.isArray(repos) && repos.length > 0;
|
||||||
|
var optionsHtml = '';
|
||||||
|
if (hasRepos) {
|
||||||
|
for (var i = 0; i < repos.length; i++) {
|
||||||
|
var r = repos[i];
|
||||||
|
if (!r || !r.name) continue;
|
||||||
|
optionsHtml += '<option value="' + r.name + '">' + r.name + '</option>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var disabledAttr = hasRepos ? '' : 'disabled';
|
||||||
|
|
||||||
|
var noRepoTip = '';
|
||||||
|
if (!hasRepos) {
|
||||||
|
noRepoTip = '<div style="margin-top:8px; font-size:12px; color: var(--vscode-descriptionForeground);">当前配置中没有仓库,请先在“仓库配置”中添加。</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
overlay.innerHTML =
|
||||||
|
'<div class="modal-dialog">' +
|
||||||
|
'<div class="modal-title">获取仓库</div>' +
|
||||||
|
'<div style="margin-bottom: 10px;">' +
|
||||||
|
'<label style="display:block; margin-bottom:6px;">请选择仓库:</label>' +
|
||||||
|
'<select id="repoSelect" style="width:100%; padding:6px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border:1px solid var(--vscode-input-border); border-radius:4px;">' +
|
||||||
|
optionsHtml +
|
||||||
|
'</select>' +
|
||||||
|
noRepoTip +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="modal-buttons">' +
|
||||||
|
'<button class="modal-btn modal-btn-secondary" id="repoSelectCancelBtn">取消</button>' +
|
||||||
|
'<button class="modal-btn modal-btn-primary" id="repoSelectOkBtn" ' + disabledAttr + '>确定</button>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
document.body.appendChild(overlay);
|
||||||
|
|
||||||
|
var cancelBtn = document.getElementById('repoSelectCancelBtn');
|
||||||
|
var okBtn = document.getElementById('repoSelectOkBtn');
|
||||||
|
var select = document.getElementById('repoSelect');
|
||||||
|
|
||||||
|
if (cancelBtn) {
|
||||||
|
cancelBtn.addEventListener('click', function () {
|
||||||
|
overlay.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (okBtn) {
|
||||||
|
okBtn.addEventListener('click', function () {
|
||||||
|
if (!select || !(select instanceof HTMLSelectElement)) {
|
||||||
|
overlay.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var repoName = select.value;
|
||||||
|
if (!repoName) {
|
||||||
|
alert('请选择一个仓库');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof vscode !== 'undefined') {
|
||||||
|
vscode.postMessage({
|
||||||
|
type: 'repoSelectedForBranches',
|
||||||
|
repoName: repoName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
overlay.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('message', function (event) {
|
||||||
|
var message = event.data;
|
||||||
|
if (!message || !message.type) return;
|
||||||
|
if (message.type === 'showRepoSelect') {
|
||||||
|
showRepoSelectDialog(message.repos || []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ export class ConfigView extends BaseView {
|
|||||||
moduleFolderFileTree?: GitFileTree[];
|
moduleFolderFileTree?: GitFileTree[];
|
||||||
moduleFolderLoading?: boolean;
|
moduleFolderLoading?: boolean;
|
||||||
gitBranches?: GitBranch[];
|
gitBranches?: GitBranch[];
|
||||||
gitRepoUrl?: string;
|
|
||||||
}): string {
|
}): string {
|
||||||
const container = data?.container;
|
const container = data?.container;
|
||||||
const configs = data?.configs || [];
|
const configs = data?.configs || [];
|
||||||
@@ -54,7 +53,6 @@ export class ConfigView extends BaseView {
|
|||||||
const moduleFolderFileTree = data?.moduleFolderFileTree || [];
|
const moduleFolderFileTree = data?.moduleFolderFileTree || [];
|
||||||
const moduleFolderLoading = data?.moduleFolderLoading || false;
|
const moduleFolderLoading = data?.moduleFolderLoading || false;
|
||||||
const gitBranches = data?.gitBranches || [];
|
const gitBranches = data?.gitBranches || [];
|
||||||
const gitRepoUrl = data?.gitRepoUrl || '';
|
|
||||||
|
|
||||||
// 生成配置列表的 HTML - 包含配置文件和模块文件夹
|
// 生成配置列表的 HTML - 包含配置文件和模块文件夹
|
||||||
const configsHtml = configs.map((config: ConfigViewData) => `
|
const configsHtml = configs.map((config: ConfigViewData) => `
|
||||||
@@ -74,32 +72,32 @@ export class ConfigView extends BaseView {
|
|||||||
`).join('');
|
`).join('');
|
||||||
|
|
||||||
// 生成模块文件夹的 HTML - 按类别分类显示
|
// 生成模块文件夹的 HTML - 按类别分类显示
|
||||||
const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||||
const icon = folder.type === 'git' ? '📁' : '📁';
|
const icon = folder.type === 'git' ? '📁' : '📁';
|
||||||
// 根据类型和上传状态确定类别显示
|
// 根据类型和上传状态确定类别显示
|
||||||
let category = folder.type === 'git' ? 'git' : 'local';
|
let category = folder.type === 'git' ? 'git' : 'local';
|
||||||
if (folder.uploaded) {
|
if (folder.uploaded) {
|
||||||
category += '(已上传)';
|
category += '(已上传)';
|
||||||
}
|
}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span class="editable">${icon} ${folder.name}</span>
|
<span class="editable">${icon} ${folder.name}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="category-${folder.type}">${category}</td>
|
<td class="category-${folder.type}">${category}</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
|
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
|
||||||
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
|
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|
||||||
// 生成分支选择的 HTML - 使用树状结构
|
// 生成分支选择的 HTML - 使用树状结构(首次渲染可以为空,后续通过 message 更新)
|
||||||
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
|
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
@@ -285,25 +283,25 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 类别标签样式 */
|
/* 类别标签样式 */
|
||||||
.category-git {
|
.category-git {
|
||||||
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-local {
|
.category-local {
|
||||||
color: var(--vscode-charts-orange);
|
color: var(--vscode-charts-orange);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-git(已上传) {
|
.category-git(已上传) {
|
||||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-local(已上传) {
|
.category-local(已上传) {
|
||||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -342,15 +340,14 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
<div class="config-section">
|
<div class="config-section">
|
||||||
<h3 class="section-title">📚 模块云仓库</h3>
|
<h3 class="section-title">📚 模块云仓库</h3>
|
||||||
|
|
||||||
<!-- URL 输入区域 -->
|
<!-- 仓库选择区域:不再手动输入 URL,通过弹窗获取仓库 -->
|
||||||
<div class="url-input-section">
|
<div class="url-input-section">
|
||||||
<h4>🔗 添加 Git 仓库</h4>
|
<h4>🔗 获取仓库</h4>
|
||||||
<div style="display: flex; gap: 10px; margin-top: 10px;">
|
<div style="display: flex; gap: 10px; margin-top: 10px; align-items: center;">
|
||||||
<input type="text" id="repoUrlInput"
|
<button class="btn-new" onclick="openRepoSelect()">获取仓库</button>
|
||||||
placeholder="请输入 Git 仓库 URL,例如: https://github.com/username/repo.git"
|
<span style="font-size: 12px; color: var(--vscode-descriptionForeground);">
|
||||||
value="${gitRepoUrl}"
|
从仓库配置中选择 Git 仓库,随后可以选择分支并克隆到本地
|
||||||
style="flex: 1; padding: 8px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border: 1px solid var(--vscode-input-border); border-radius: 4px;">
|
</span>
|
||||||
<button class="btn-new" onclick="fetchBranches()">获取分支</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="branchSelectionContainer">
|
<div id="branchSelectionContainer">
|
||||||
${branchesHtml}
|
${branchesHtml}
|
||||||
@@ -363,7 +360,6 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
const vscode = acquireVsCodeApi();
|
const vscode = acquireVsCodeApi();
|
||||||
let currentConfigId = null;
|
let currentConfigId = null;
|
||||||
let selectedBranches = new Set();
|
let selectedBranches = new Set();
|
||||||
let currentRepoUrl = '';
|
|
||||||
let branchTreeData = [];
|
let branchTreeData = [];
|
||||||
let selectedConfigs = new Set();
|
let selectedConfigs = new Set();
|
||||||
|
|
||||||
@@ -385,7 +381,7 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新功能:在 VSCode 中打开配置文件
|
// 在 VSCode 中打开配置文件
|
||||||
function openConfigFileInVSCode(configId) {
|
function openConfigFileInVSCode(configId) {
|
||||||
console.log('📄 在 VSCode 中打开配置文件:', configId);
|
console.log('📄 在 VSCode 中打开配置文件:', configId);
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
@@ -484,7 +480,7 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加上传对话框函数
|
// 上传对话框函数(本地->Git)
|
||||||
function showUploadDialog(folderId) {
|
function showUploadDialog(folderId) {
|
||||||
const overlay = document.createElement('div');
|
const overlay = document.createElement('div');
|
||||||
overlay.className = 'modal-overlay';
|
overlay.className = 'modal-overlay';
|
||||||
@@ -570,30 +566,16 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
vscode.postMessage({ type: 'goBackToContainers' });
|
vscode.postMessage({ type: 'goBackToContainers' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Git 仓库管理功能
|
// 🔁 新逻辑:通过弹窗获取仓库(不再手动输入 URL)
|
||||||
function fetchBranches() {
|
function openRepoSelect() {
|
||||||
const urlInput = document.getElementById('repoUrlInput');
|
console.log('📦 请求仓库列表以选择 Git 仓库');
|
||||||
const repoUrl = urlInput.value.trim();
|
|
||||||
|
|
||||||
if (!repoUrl) {
|
|
||||||
alert('请输入 Git 仓库 URL');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!repoUrl.startsWith('http')) {
|
|
||||||
alert('请输入有效的 Git 仓库 URL');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentRepoUrl = repoUrl;
|
|
||||||
console.log('🌿 获取分支列表:', repoUrl);
|
|
||||||
|
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
type: 'fetchBranches',
|
type: 'openRepoSelect'
|
||||||
url: repoUrl
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 不再在前端手动输入/校验 URL,分支拉取由 repo 选择 + 后端完成
|
||||||
|
|
||||||
function toggleBranch(branchName) {
|
function toggleBranch(branchName) {
|
||||||
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9-]/g, '-'));
|
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9-]/g, '-'));
|
||||||
if (checkbox.checked) {
|
if (checkbox.checked) {
|
||||||
@@ -614,7 +596,6 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
|
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
type: 'cloneBranches',
|
type: 'cloneBranches',
|
||||||
url: currentRepoUrl,
|
|
||||||
branches: Array.from(selectedBranches)
|
branches: Array.from(selectedBranches)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -673,7 +654,7 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
showMergeDialog();
|
showMergeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新的合并对话框函数
|
// 合并对话框
|
||||||
function showMergeDialog() {
|
function showMergeDialog() {
|
||||||
const overlay = document.createElement('div');
|
const overlay = document.createElement('div');
|
||||||
overlay.className = 'modal-overlay';
|
overlay.className = 'modal-overlay';
|
||||||
@@ -1107,4 +1088,4 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
|||||||
});
|
});
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/panels/views/ProjectView.ts
Normal file → Executable file
14
src/panels/views/ProjectView.ts
Normal file → Executable file
@@ -1,4 +1,3 @@
|
|||||||
// src/panels/views/ProjectView.ts
|
|
||||||
import { BaseView } from './BaseView';
|
import { BaseView } from './BaseView';
|
||||||
import { ProjectViewData } from '../types/ViewTypes';
|
import { ProjectViewData } from '../types/ViewTypes';
|
||||||
|
|
||||||
@@ -96,7 +95,10 @@ export class ProjectView extends BaseView {
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2><span class="satellite-icon">🛰️</span>数字卫星构建平台</h2>
|
<div class="header">
|
||||||
|
<h2><span class="satellite-icon">🛰️</span>数字卫星构建平台</h2>
|
||||||
|
<button class="back-btn" onclick="openRepoConfig()">⚙️ 仓库配置</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -126,6 +128,12 @@ export class ProjectView extends BaseView {
|
|||||||
<script>
|
<script>
|
||||||
const vscode = acquireVsCodeApi();
|
const vscode = acquireVsCodeApi();
|
||||||
|
|
||||||
|
function openRepoConfig() {
|
||||||
|
vscode.postMessage({
|
||||||
|
type: 'openRepoConfig'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function configureProject(projectId, projectName, isConfigured) {
|
function configureProject(projectId, projectName, isConfigured) {
|
||||||
if (isConfigured) {
|
if (isConfigured) {
|
||||||
// 已配置的项目直接打开
|
// 已配置的项目直接打开
|
||||||
@@ -296,4 +304,4 @@ export class ProjectView extends BaseView {
|
|||||||
</body>
|
</body>
|
||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user