添加了一个可视化仓库功能
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 });
|
||||
exports.ConfigPanel = void 0;
|
||||
// src/panels/ConfigPanel.ts
|
||||
const vscode = __importStar(require("vscode"));
|
||||
const path = __importStar(require("path"));
|
||||
const fs = __importStar(require("fs"));
|
||||
@@ -71,6 +72,8 @@ class ConfigPanel {
|
||||
this.moduleFolders = [];
|
||||
this.currentModuleFolderFileTree = [];
|
||||
this.projectPaths = new Map();
|
||||
// 仓库配置
|
||||
this.repoConfigs = [];
|
||||
// 状态管理
|
||||
this.isWebviewDisposed = false;
|
||||
this.panel = panel;
|
||||
@@ -81,6 +84,8 @@ class ConfigPanel {
|
||||
this.aircraftView = new AircraftView_1.AircraftView(extensionUri);
|
||||
this.containerView = new ContainerView_1.ContainerView(extensionUri);
|
||||
this.configView = new ConfigView_1.ConfigView(extensionUri);
|
||||
// 尝试加载仓库配置
|
||||
void this.loadRepoConfigs();
|
||||
this.updateWebview();
|
||||
this.setupMessageListener();
|
||||
this.panel.onDidDispose(() => {
|
||||
@@ -108,6 +113,94 @@ class ConfigPanel {
|
||||
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 消息处理
|
||||
// =============================================
|
||||
setupMessageListener() {
|
||||
@@ -157,9 +250,13 @@ class ConfigPanel {
|
||||
'deleteConfig': (data) => this.deleteConfig(data.configId),
|
||||
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
||||
'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),
|
||||
'cloneBranches': (data) => this.cloneBranches(data.url, data.branches),
|
||||
'cloneBranches': (data) => this.cloneBranches(data.branches),
|
||||
'cancelBranchSelection': () => this.handleCancelBranchSelection(),
|
||||
// 模块文件夹管理
|
||||
'loadModuleFolder': (data) => this.loadModuleFolder(data.folderId),
|
||||
@@ -242,14 +339,12 @@ class ConfigPanel {
|
||||
}
|
||||
}
|
||||
async createProject(name) {
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('p', this.projects);
|
||||
const newProject = {
|
||||
id: newId,
|
||||
name: name
|
||||
};
|
||||
this.projects.push(newProject);
|
||||
// 设置当前项目
|
||||
this.currentProjectId = newId;
|
||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||
this.updateWebview();
|
||||
@@ -259,7 +354,6 @@ class ConfigPanel {
|
||||
if (!project)
|
||||
return;
|
||||
this.projects = this.projects.filter(p => p.id !== projectId);
|
||||
// 删除相关数据
|
||||
const relatedAircrafts = this.aircrafts.filter(a => a.projectId === projectId);
|
||||
const aircraftIds = relatedAircrafts.map(a => a.id);
|
||||
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
||||
@@ -289,7 +383,6 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage('无法创建飞行器:未找到当前项目');
|
||||
return;
|
||||
}
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('a', this.aircrafts);
|
||||
const newAircraft = {
|
||||
id: newId,
|
||||
@@ -332,7 +425,6 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage('无法创建容器:未找到当前飞行器');
|
||||
return;
|
||||
}
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('c', this.containers);
|
||||
const newContainer = {
|
||||
id: newId,
|
||||
@@ -370,7 +462,6 @@ class ConfigPanel {
|
||||
}
|
||||
}
|
||||
async createConfig(name) {
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('cfg', this.configs);
|
||||
const newConfig = {
|
||||
id: newId,
|
||||
@@ -426,7 +517,6 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage('部分配置文件未找到');
|
||||
return;
|
||||
}
|
||||
// 创建合并文件夹并复制文件
|
||||
const mergeFolderPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||
await fs.promises.mkdir(mergeFolderPath, { recursive: true });
|
||||
for (const config of selectedConfigs) {
|
||||
@@ -439,9 +529,7 @@ class ConfigPanel {
|
||||
await fs.promises.writeFile(targetPath, config.content || '');
|
||||
}
|
||||
}
|
||||
// 创建合并文件夹记录
|
||||
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('local-', this.moduleFolders);
|
||||
const newFolder = {
|
||||
id: newId,
|
||||
@@ -451,7 +539,6 @@ class ConfigPanel {
|
||||
containerId: this.currentContainerId
|
||||
};
|
||||
this.moduleFolders.push(newFolder);
|
||||
// 删除原始配置文件
|
||||
for (const configId of configIds) {
|
||||
await this.deleteConfigInternal(configId);
|
||||
}
|
||||
@@ -467,7 +554,10 @@ class ConfigPanel {
|
||||
// =============================================
|
||||
// Git 分支管理方法
|
||||
// =============================================
|
||||
async fetchBranches(url) {
|
||||
async fetchBranchesForRepo(repo) {
|
||||
await this.fetchBranches(repo.url, repo);
|
||||
}
|
||||
async fetchBranches(url, repo) {
|
||||
try {
|
||||
console.log('🌿 开始获取分支列表:', url);
|
||||
await vscode.window.withProgress({
|
||||
@@ -478,15 +568,20 @@ class ConfigPanel {
|
||||
progress.report({ increment: 0, message: '连接远程仓库...' });
|
||||
try {
|
||||
progress.report({ increment: 30, message: '获取远程引用...' });
|
||||
const refs = await isomorphic_git_1.default.listServerRefs({
|
||||
const options = {
|
||||
http: node_1.default,
|
||||
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);
|
||||
// 过滤出分支引用
|
||||
const branchRefs = refs.filter(ref => ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/'));
|
||||
// 构建分支数据
|
||||
const branches = branchRefs.map(ref => {
|
||||
const branchRefs = refs.filter((ref) => ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/'));
|
||||
const branches = branchRefs.map((ref) => {
|
||||
let branchName;
|
||||
if (ref.ref.startsWith('refs/remotes/')) {
|
||||
branchName = ref.ref.replace('refs/remotes/origin/', '');
|
||||
@@ -504,15 +599,14 @@ class ConfigPanel {
|
||||
throw new Error('未找到任何分支');
|
||||
}
|
||||
progress.report({ increment: 80, message: '处理分支数据...' });
|
||||
// 构建分支树状结构
|
||||
const branchTree = this.buildBranchTree(branches);
|
||||
// 发送分支数据到前端
|
||||
if (!this.isWebviewDisposed) {
|
||||
this.panel.webview.postMessage({
|
||||
type: 'branchesFetched',
|
||||
branches: branches,
|
||||
branchTree: branchTree,
|
||||
repoUrl: url
|
||||
repoUrl: url,
|
||||
repoName: repo?.name
|
||||
});
|
||||
}
|
||||
progress.report({ increment: 100, message: '完成' });
|
||||
@@ -528,7 +622,13 @@ class ConfigPanel {
|
||||
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 {
|
||||
console.log('🚀 开始克隆分支:', { url, branches });
|
||||
let successCount = 0;
|
||||
@@ -548,7 +648,7 @@ class ConfigPanel {
|
||||
console.log(`📥 开始克隆分支: ${branch}`);
|
||||
try {
|
||||
const folderNames = this.generateModuleFolderName(url, branch);
|
||||
await this.addGitModuleFolder(url, folderNames.displayName, folderNames.folderName, branch);
|
||||
await this.addGitModuleFolder(url, repoDisplayName, folderNames.folderName, branch);
|
||||
successCount++;
|
||||
console.log(`✅ 分支克隆成功: ${branch}`);
|
||||
}
|
||||
@@ -558,7 +658,6 @@ class ConfigPanel {
|
||||
}
|
||||
}
|
||||
});
|
||||
// 显示最终结果
|
||||
if (failCount === 0) {
|
||||
vscode.window.showInformationMessage(`成功克隆 ${successCount} 个分支`);
|
||||
}
|
||||
@@ -591,12 +690,10 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage('未找到相关项目数据');
|
||||
return;
|
||||
}
|
||||
// 使用新的 ID 生成方法
|
||||
const folderId = this.generateUniqueId('git-', this.moduleFolders);
|
||||
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
||||
const localPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||
console.log(`📁 准备克隆仓库: ${displayName}, 分支: ${branch}, 路径: ${localPath}`);
|
||||
// 检查是否已存在相同路径的模块文件夹
|
||||
const existingFolder = this.moduleFolders.find(folder => folder.localPath === relativePath && folder.containerId === this.currentContainerId);
|
||||
if (existingFolder) {
|
||||
vscode.window.showWarningMessage(`该路径的模块文件夹已存在: ${folderName}`);
|
||||
@@ -616,10 +713,8 @@ class ConfigPanel {
|
||||
}, async (progress) => {
|
||||
progress.report({ increment: 0 });
|
||||
try {
|
||||
// 确保父目录存在
|
||||
const parentDir = path.dirname(localPath);
|
||||
await fs.promises.mkdir(parentDir, { recursive: true });
|
||||
// 检查目标目录是否已存在
|
||||
let dirExists = false;
|
||||
try {
|
||||
await fs.promises.access(localPath);
|
||||
@@ -636,7 +731,6 @@ class ConfigPanel {
|
||||
vscode.window.showInformationMessage('克隆操作已取消');
|
||||
return;
|
||||
}
|
||||
// 清空目录(除了 .git 文件夹)
|
||||
for (const item of dirContents) {
|
||||
const itemPath = path.join(localPath, item);
|
||||
if (item !== '.git') {
|
||||
@@ -646,7 +740,6 @@ class ConfigPanel {
|
||||
}
|
||||
}
|
||||
console.log(`🚀 开始克隆: ${url} -> ${localPath}, 分支: ${branch}`);
|
||||
// 克隆仓库
|
||||
await isomorphic_git_1.default.clone({
|
||||
fs: fs,
|
||||
http: node_1.default,
|
||||
@@ -670,18 +763,15 @@ class ConfigPanel {
|
||||
}
|
||||
});
|
||||
console.log('✅ Git克隆成功完成');
|
||||
// 验证克隆是否真的成功
|
||||
const clonedContents = await fs.promises.readdir(localPath);
|
||||
console.log(`📁 克隆后的目录内容:`, clonedContents);
|
||||
if (clonedContents.length === 0) {
|
||||
throw new Error('克隆后目录为空,可能克隆失败');
|
||||
}
|
||||
// 只有在克隆成功后才添加到列表
|
||||
this.moduleFolders.push(newFolder);
|
||||
await this.saveCurrentProjectData();
|
||||
console.log('✅ Git模块文件夹数据已保存到项目文件');
|
||||
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${displayName}`);
|
||||
// 自动加载文件树
|
||||
if (!this.isWebviewDisposed) {
|
||||
console.log('🌳 开始加载模块文件夹文件树...');
|
||||
this.currentModuleFolderId = folderId;
|
||||
@@ -691,7 +781,6 @@ class ConfigPanel {
|
||||
}
|
||||
catch (error) {
|
||||
console.error('❌ 在克隆过程中捕获错误:', error);
|
||||
// 清理:如果克隆失败,删除可能创建的不完整目录
|
||||
try {
|
||||
if (fs.existsSync(localPath)) {
|
||||
await fs.promises.rm(localPath, { recursive: true, force: true });
|
||||
@@ -802,7 +891,6 @@ class ConfigPanel {
|
||||
const fileFullPath = path.join(fullPath, filePath);
|
||||
const content = await fs.promises.readFile(fileFullPath, 'utf8');
|
||||
const fileName = path.basename(filePath);
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('cfg', this.configs);
|
||||
const newConfig = {
|
||||
id: newId,
|
||||
@@ -850,7 +938,7 @@ class ConfigPanel {
|
||||
}
|
||||
catch (error) {
|
||||
console.error('❌ Git 上传失败:', error);
|
||||
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
|
||||
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -892,8 +980,7 @@ class ConfigPanel {
|
||||
}
|
||||
catch (error) {
|
||||
console.error('❌ 本地文件夹上传失败:', error);
|
||||
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
|
||||
// 清理:删除可能创建的 .git 文件夹
|
||||
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
||||
try {
|
||||
const gitDir = path.join(fullPath, '.git');
|
||||
if (fs.existsSync(gitDir)) {
|
||||
@@ -914,7 +1001,6 @@ class ConfigPanel {
|
||||
const { exec } = require('child_process');
|
||||
console.log('🚀 使用命令行 Git 提交并推送...');
|
||||
console.log(`📁 工作目录: ${fullPath}`);
|
||||
// 先检查是否有更改
|
||||
exec('git status --porcelain', {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
@@ -924,14 +1010,12 @@ class ConfigPanel {
|
||||
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
|
||||
return;
|
||||
}
|
||||
// 如果没有更改
|
||||
if (!statusStdout.trim()) {
|
||||
console.log('ℹ️ 没有需要提交的更改');
|
||||
reject(new Error('没有需要提交的更改'));
|
||||
return;
|
||||
}
|
||||
console.log('📋 检测到更改:', statusStdout);
|
||||
// 有更改时才提交并推送
|
||||
const commands = [
|
||||
'git add .',
|
||||
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
|
||||
@@ -996,14 +1080,13 @@ class ConfigPanel {
|
||||
console.log('💾 提交初始文件...');
|
||||
const commands = [
|
||||
'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(' && '), {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
// 检查是否是"没有更改可提交"的错误
|
||||
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
|
||||
console.log('ℹ️ 没有需要提交的更改');
|
||||
resolve();
|
||||
@@ -1099,8 +1182,6 @@ class ConfigPanel {
|
||||
}
|
||||
}
|
||||
async createDefaultConfigs(container) {
|
||||
const configCount = this.configs.length;
|
||||
// 第一个配置文件
|
||||
this.configs.push({
|
||||
id: this.generateUniqueId('cfg', this.configs),
|
||||
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"]`,
|
||||
containerId: container.id
|
||||
});
|
||||
// 第二个配置文件
|
||||
this.configs.push({
|
||||
id: this.generateUniqueId('cfg', this.configs),
|
||||
name: '配置2',
|
||||
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
|
||||
});
|
||||
}
|
||||
@@ -1161,7 +1241,6 @@ class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||
// 构建当前项目的完整数据
|
||||
const data = {
|
||||
projects: [this.projects.find(p => p.id === this.currentProjectId)],
|
||||
aircrafts: this.aircrafts.filter(a => a.projectId === this.currentProjectId),
|
||||
@@ -1195,7 +1274,6 @@ class ConfigPanel {
|
||||
async loadProjectData(projectPath) {
|
||||
try {
|
||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||
// 检查数据文件是否存在
|
||||
try {
|
||||
await vscode.workspace.fs.stat(dataUri);
|
||||
}
|
||||
@@ -1203,14 +1281,11 @@ class ConfigPanel {
|
||||
vscode.window.showErrorMessage('选择的文件夹中没有找到项目数据文件 (.dcsp-data.json)');
|
||||
return false;
|
||||
}
|
||||
// 读取数据文件
|
||||
const fileData = await vscode.workspace.fs.readFile(dataUri);
|
||||
const dataStr = new TextDecoder().decode(fileData);
|
||||
const data = JSON.parse(dataStr);
|
||||
// 只清空当前项目相关的数据,保留其他项目数据
|
||||
const projectId = data.projects[0]?.id;
|
||||
if (projectId) {
|
||||
// 移除当前项目的旧数据
|
||||
this.projects = this.projects.filter(p => p.id !== projectId);
|
||||
this.aircrafts = this.aircrafts.filter(a => a.projectId !== projectId);
|
||||
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);
|
||||
this.configs = this.configs.filter(cfg => !containerIds.includes(cfg.containerId));
|
||||
this.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
||||
// 添加新数据
|
||||
this.projects.push(...data.projects);
|
||||
this.aircrafts.push(...data.aircrafts);
|
||||
this.containers.push(...data.containers);
|
||||
this.configs.push(...data.configs);
|
||||
this.moduleFolders.push(...data.moduleFolders);
|
||||
// 设置当前项目
|
||||
this.currentProjectId = projectId;
|
||||
this.projectPaths.set(projectId, projectPath);
|
||||
this.currentView = 'aircrafts';
|
||||
@@ -1370,7 +1443,6 @@ class ConfigPanel {
|
||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
if (!folder)
|
||||
return;
|
||||
// 通知前端开始加载
|
||||
try {
|
||||
this.panel.webview.postMessage({
|
||||
type: 'moduleFolderLoading',
|
||||
@@ -1392,12 +1464,10 @@ class ConfigPanel {
|
||||
console.error('加载模块文件夹文件树失败:', error);
|
||||
this.currentModuleFolderFileTree = [];
|
||||
}
|
||||
// 再次检查 Webview 状态
|
||||
if (this.isWebviewDisposed) {
|
||||
console.log('⚠️ Webview 已被销毁,跳过完成通知');
|
||||
return;
|
||||
}
|
||||
// 通知前端加载完成
|
||||
try {
|
||||
this.panel.webview.postMessage({
|
||||
type: 'moduleFolderLoading',
|
||||
@@ -1414,7 +1484,6 @@ class ConfigPanel {
|
||||
const files = await fs.promises.readdir(dir);
|
||||
const tree = [];
|
||||
for (const file of files) {
|
||||
// 忽略 .git 文件夹和 .dcsp-data.json
|
||||
if (file.startsWith('.') && file !== '.git')
|
||||
continue;
|
||||
if (file === '.dcsp-data.json')
|
||||
@@ -1583,7 +1652,6 @@ class ConfigPanel {
|
||||
projectPaths: this.projectPaths
|
||||
});
|
||||
case 'aircrafts':
|
||||
// 只显示当前项目的飞行器
|
||||
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
||||
return this.aircraftView.render({
|
||||
aircrafts: projectAircrafts
|
||||
@@ -1591,7 +1659,6 @@ class ConfigPanel {
|
||||
case 'containers':
|
||||
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
||||
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
|
||||
// 只显示当前飞行器的容器
|
||||
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
||||
return this.containerView.render({
|
||||
project: currentProject,
|
||||
@@ -1600,9 +1667,8 @@ class ConfigPanel {
|
||||
});
|
||||
case 'configs':
|
||||
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 containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
||||
const containerModuleFolders = this.moduleFolders.filter(folder => folder.containerId === this.currentContainerId);
|
||||
return this.configView.render({
|
||||
container: currentContainer,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -115,59 +115,154 @@ class BaseView {
|
||||
cursor: pointer;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
background: var(--vscode-editor-background);
|
||||
border: 1px solid var(--vscode-panel-border);
|
||||
border-radius: 4px;
|
||||
padding: 20px;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
margin-bottom: 15px;
|
||||
font-weight: bold;
|
||||
color: var(--vscode-editor-foreground);
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.modal-btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-btn-primary {
|
||||
background: var(--vscode-button-background);
|
||||
color: var(--vscode-button-foreground);
|
||||
}
|
||||
|
||||
.modal-btn-secondary {
|
||||
background: var(--vscode-button-secondaryBackground);
|
||||
color: var(--vscode-button-secondaryForeground);
|
||||
}
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
background: var(--vscode-editor-background);
|
||||
border: 1px solid var(--vscode-panel-border);
|
||||
border-radius: 4px;
|
||||
padding: 20px;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
margin-bottom: 15px;
|
||||
font-weight: bold;
|
||||
color: var(--vscode-editor-foreground);
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.modal-btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-btn-primary {
|
||||
background: var(--vscode-button-background);
|
||||
color: var(--vscode-button-foreground);
|
||||
}
|
||||
|
||||
.modal-btn-secondary {
|
||||
background: var(--vscode-button-secondaryBackground);
|
||||
color: var(--vscode-button-secondaryForeground);
|
||||
}
|
||||
</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 moduleFolderLoading = data?.moduleFolderLoading || false;
|
||||
const gitBranches = data?.gitBranches || [];
|
||||
const gitRepoUrl = data?.gitRepoUrl || '';
|
||||
// 生成配置列表的 HTML - 包含配置文件和模块文件夹
|
||||
const configsHtml = configs.map((config) => `
|
||||
<tr>
|
||||
@@ -37,22 +36,22 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
category += '(已上传)';
|
||||
}
|
||||
return `
|
||||
<tr>
|
||||
<td>
|
||||
<span class="editable">${icon} ${folder.name}</span>
|
||||
</td>
|
||||
<td class="category-${folder.type}">${category}</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
|
||||
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
<tr>
|
||||
<td>
|
||||
<span class="editable">${icon} ${folder.name}</span>
|
||||
</td>
|
||||
<td class="category-${folder.type}">${category}</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
|
||||
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
// 生成分支选择的 HTML - 使用树状结构
|
||||
// 生成分支选择的 HTML - 使用树状结构(首次渲染可以为空,后续通过 message 更新)
|
||||
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
@@ -237,25 +236,25 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
}
|
||||
|
||||
/* 类别标签样式 */
|
||||
.category-git {
|
||||
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
.category-git {
|
||||
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.category-local {
|
||||
color: var(--vscode-charts-orange);
|
||||
font-weight: bold;
|
||||
}
|
||||
.category-local {
|
||||
color: var(--vscode-charts-orange);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.category-git(已上传) {
|
||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
.category-git(已上传) {
|
||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.category-local(已上传) {
|
||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
.category-local(已上传) {
|
||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -294,15 +293,14 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
<div class="config-section">
|
||||
<h3 class="section-title">📚 模块云仓库</h3>
|
||||
|
||||
<!-- URL 输入区域 -->
|
||||
<!-- 仓库选择区域:不再手动输入 URL,通过弹窗获取仓库 -->
|
||||
<div class="url-input-section">
|
||||
<h4>🔗 添加 Git 仓库</h4>
|
||||
<div style="display: flex; gap: 10px; margin-top: 10px;">
|
||||
<input type="text" id="repoUrlInput"
|
||||
placeholder="请输入 Git 仓库 URL,例如: https://github.com/username/repo.git"
|
||||
value="${gitRepoUrl}"
|
||||
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;">
|
||||
<button class="btn-new" onclick="fetchBranches()">获取分支</button>
|
||||
<h4>🔗 获取仓库</h4>
|
||||
<div style="display: flex; gap: 10px; margin-top: 10px; align-items: center;">
|
||||
<button class="btn-new" onclick="openRepoSelect()">获取仓库</button>
|
||||
<span style="font-size: 12px; color: var(--vscode-descriptionForeground);">
|
||||
从仓库配置中选择 Git 仓库,随后可以选择分支并克隆到本地
|
||||
</span>
|
||||
</div>
|
||||
<div id="branchSelectionContainer">
|
||||
${branchesHtml}
|
||||
@@ -315,7 +313,6 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
const vscode = acquireVsCodeApi();
|
||||
let currentConfigId = null;
|
||||
let selectedBranches = new Set();
|
||||
let currentRepoUrl = '';
|
||||
let branchTreeData = [];
|
||||
let selectedConfigs = new Set();
|
||||
|
||||
@@ -337,7 +334,7 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
);
|
||||
}
|
||||
|
||||
// 新功能:在 VSCode 中打开配置文件
|
||||
// 在 VSCode 中打开配置文件
|
||||
function openConfigFileInVSCode(configId) {
|
||||
console.log('📄 在 VSCode 中打开配置文件:', configId);
|
||||
vscode.postMessage({
|
||||
@@ -436,7 +433,7 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
}
|
||||
}
|
||||
|
||||
// 添加上传对话框函数
|
||||
// 上传对话框函数(本地->Git)
|
||||
function showUploadDialog(folderId) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
@@ -522,30 +519,16 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
vscode.postMessage({ type: 'goBackToContainers' });
|
||||
}
|
||||
|
||||
// Git 仓库管理功能
|
||||
function fetchBranches() {
|
||||
const urlInput = document.getElementById('repoUrlInput');
|
||||
const repoUrl = urlInput.value.trim();
|
||||
|
||||
if (!repoUrl) {
|
||||
alert('请输入 Git 仓库 URL');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!repoUrl.startsWith('http')) {
|
||||
alert('请输入有效的 Git 仓库 URL');
|
||||
return;
|
||||
}
|
||||
|
||||
currentRepoUrl = repoUrl;
|
||||
console.log('🌿 获取分支列表:', repoUrl);
|
||||
|
||||
// 🔁 新逻辑:通过弹窗获取仓库(不再手动输入 URL)
|
||||
function openRepoSelect() {
|
||||
console.log('📦 请求仓库列表以选择 Git 仓库');
|
||||
vscode.postMessage({
|
||||
type: 'fetchBranches',
|
||||
url: repoUrl
|
||||
type: 'openRepoSelect'
|
||||
});
|
||||
}
|
||||
|
||||
// 不再在前端手动输入/校验 URL,分支拉取由 repo 选择 + 后端完成
|
||||
|
||||
function toggleBranch(branchName) {
|
||||
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9-]/g, '-'));
|
||||
if (checkbox.checked) {
|
||||
@@ -566,7 +549,6 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
|
||||
vscode.postMessage({
|
||||
type: 'cloneBranches',
|
||||
url: currentRepoUrl,
|
||||
branches: Array.from(selectedBranches)
|
||||
});
|
||||
|
||||
@@ -625,7 +607,7 @@ class ConfigView extends BaseView_1.BaseView {
|
||||
showMergeDialog();
|
||||
}
|
||||
|
||||
// 新的合并对话框函数
|
||||
// 合并对话框
|
||||
function showMergeDialog() {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ProjectView = void 0;
|
||||
// src/panels/views/ProjectView.ts
|
||||
const BaseView_1 = require("./BaseView");
|
||||
class ProjectView extends BaseView_1.BaseView {
|
||||
render(data) {
|
||||
@@ -95,7 +94,10 @@ class ProjectView extends BaseView_1.BaseView {
|
||||
</style>
|
||||
</head>
|
||||
<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">
|
||||
<thead>
|
||||
@@ -125,6 +127,12 @@ class ProjectView extends BaseView_1.BaseView {
|
||||
<script>
|
||||
const vscode = acquireVsCodeApi();
|
||||
|
||||
function openRepoConfig() {
|
||||
vscode.postMessage({
|
||||
type: 'openRepoConfig'
|
||||
});
|
||||
}
|
||||
|
||||
function configureProject(projectId, projectName, 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 path from 'path';
|
||||
import * as fs from 'fs';
|
||||
@@ -59,6 +60,14 @@ interface ProjectData {
|
||||
moduleFolders: ModuleFolder[];
|
||||
}
|
||||
|
||||
// 仓库配置项
|
||||
interface RepoConfigItem {
|
||||
name: string;
|
||||
url: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
// =============================================
|
||||
// 主面板类
|
||||
// =============================================
|
||||
@@ -84,6 +93,10 @@ export class ConfigPanel {
|
||||
private currentModuleFolderFileTree: GitFileTree[] = [];
|
||||
private projectPaths: Map<string, string> = new Map();
|
||||
|
||||
// 仓库配置
|
||||
private repoConfigs: RepoConfigItem[] = [];
|
||||
private currentRepoForBranches: RepoConfigItem | undefined;
|
||||
|
||||
// 状态管理
|
||||
private isWebviewDisposed: boolean = false;
|
||||
|
||||
@@ -130,6 +143,9 @@ export class ConfigPanel {
|
||||
this.containerView = new ContainerView(extensionUri);
|
||||
this.configView = new ConfigView(extensionUri);
|
||||
|
||||
// 尝试加载仓库配置
|
||||
void this.loadRepoConfigs();
|
||||
|
||||
this.updateWebview();
|
||||
this.setupMessageListener();
|
||||
|
||||
@@ -163,6 +179,106 @@ export class ConfigPanel {
|
||||
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 消息处理
|
||||
// =============================================
|
||||
@@ -221,9 +337,14 @@ export class ConfigPanel {
|
||||
'openConfigFileInVSCode': (data) => this.openConfigFileInVSCode(data.configId),
|
||||
'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),
|
||||
'cloneBranches': (data) => this.cloneBranches(data.url, data.branches),
|
||||
'cloneBranches': (data) => this.cloneBranches(data.branches),
|
||||
'cancelBranchSelection': () => this.handleCancelBranchSelection(),
|
||||
|
||||
// 模块文件夹管理
|
||||
@@ -320,7 +441,6 @@ export class ConfigPanel {
|
||||
}
|
||||
|
||||
private async createProject(name: string): Promise<void> {
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('p', this.projects);
|
||||
const newProject: Project = {
|
||||
id: newId,
|
||||
@@ -328,7 +448,6 @@ export class ConfigPanel {
|
||||
};
|
||||
this.projects.push(newProject);
|
||||
|
||||
// 设置当前项目
|
||||
this.currentProjectId = newId;
|
||||
|
||||
vscode.window.showInformationMessage(`新建项目: ${name}`);
|
||||
@@ -341,7 +460,6 @@ export class ConfigPanel {
|
||||
|
||||
this.projects = this.projects.filter(p => p.id !== projectId);
|
||||
|
||||
// 删除相关数据
|
||||
const relatedAircrafts = this.aircrafts.filter(a => a.projectId === projectId);
|
||||
const aircraftIds = relatedAircrafts.map(a => a.id);
|
||||
|
||||
@@ -379,7 +497,6 @@ export class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('a', this.aircrafts);
|
||||
const newAircraft: Aircraft = {
|
||||
id: newId,
|
||||
@@ -430,7 +547,6 @@ export class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('c', this.containers);
|
||||
const newContainer: Container = {
|
||||
id: newId,
|
||||
@@ -475,7 +591,6 @@ export class ConfigPanel {
|
||||
}
|
||||
|
||||
private async createConfig(name: string): Promise<void> {
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('cfg', this.configs);
|
||||
const newConfig: Config = {
|
||||
id: newId,
|
||||
@@ -547,7 +662,6 @@ export class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建合并文件夹并复制文件
|
||||
const mergeFolderPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||
await fs.promises.mkdir(mergeFolderPath, { recursive: true });
|
||||
|
||||
@@ -562,9 +676,7 @@ export class ConfigPanel {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建合并文件夹记录
|
||||
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('local-', this.moduleFolders);
|
||||
const newFolder: ModuleFolder = {
|
||||
id: newId,
|
||||
@@ -576,7 +688,6 @@ export class ConfigPanel {
|
||||
|
||||
this.moduleFolders.push(newFolder);
|
||||
|
||||
// 删除原始配置文件
|
||||
for (const configId of configIds) {
|
||||
await this.deleteConfigInternal(configId);
|
||||
}
|
||||
@@ -595,7 +706,11 @@ export class ConfigPanel {
|
||||
// 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 {
|
||||
console.log('🌿 开始获取分支列表:', url);
|
||||
|
||||
@@ -608,21 +723,28 @@ export class ConfigPanel {
|
||||
|
||||
try {
|
||||
progress.report({ increment: 30, message: '获取远程引用...' });
|
||||
|
||||
const refs = await git.listServerRefs({
|
||||
|
||||
const options: any = {
|
||||
http: http,
|
||||
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);
|
||||
|
||||
// 过滤出分支引用
|
||||
const branchRefs = refs.filter(ref =>
|
||||
const branchRefs = refs.filter((ref: any) =>
|
||||
ref.ref.startsWith('refs/heads/') || ref.ref.startsWith('refs/remotes/origin/')
|
||||
);
|
||||
|
||||
// 构建分支数据
|
||||
const branches: GitBranch[] = branchRefs.map(ref => {
|
||||
const branches: GitBranch[] = branchRefs.map((ref: any) => {
|
||||
let branchName: string;
|
||||
|
||||
if (ref.ref.startsWith('refs/remotes/')) {
|
||||
@@ -644,16 +766,15 @@ export class ConfigPanel {
|
||||
|
||||
progress.report({ increment: 80, message: '处理分支数据...' });
|
||||
|
||||
// 构建分支树状结构
|
||||
const branchTree = this.buildBranchTree(branches);
|
||||
|
||||
// 发送分支数据到前端
|
||||
if (!this.isWebviewDisposed) {
|
||||
this.panel.webview.postMessage({
|
||||
type: 'branchesFetched',
|
||||
branches: branches,
|
||||
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 {
|
||||
console.log('🚀 开始克隆分支:', { url, branches });
|
||||
|
||||
@@ -694,7 +823,7 @@ export class ConfigPanel {
|
||||
console.log(`📥 开始克隆分支: ${branch}`);
|
||||
try {
|
||||
const folderNames = this.generateModuleFolderName(url, branch);
|
||||
await this.addGitModuleFolder(url, folderNames.displayName, folderNames.folderName, branch);
|
||||
await this.addGitModuleFolder(url, repoDisplayName, folderNames.folderName, branch);
|
||||
successCount++;
|
||||
console.log(`✅ 分支克隆成功: ${branch}`);
|
||||
} catch (error) {
|
||||
@@ -704,7 +833,6 @@ export class ConfigPanel {
|
||||
}
|
||||
});
|
||||
|
||||
// 显示最终结果
|
||||
if (failCount === 0) {
|
||||
vscode.window.showInformationMessage(`成功克隆 ${successCount} 个分支`);
|
||||
} else {
|
||||
@@ -742,14 +870,12 @@ export class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用新的 ID 生成方法
|
||||
const folderId = this.generateUniqueId('git-', this.moduleFolders);
|
||||
const relativePath = `/${aircraft.projectId}/${aircraft.name}/${container.name}/${folderName}`;
|
||||
const localPath = path.join(projectPath, aircraft.name, container.name, folderName);
|
||||
|
||||
console.log(`📁 准备克隆仓库: ${displayName}, 分支: ${branch}, 路径: ${localPath}`);
|
||||
|
||||
// 检查是否已存在相同路径的模块文件夹
|
||||
const existingFolder = this.moduleFolders.find(folder =>
|
||||
folder.localPath === relativePath && folder.containerId === this.currentContainerId
|
||||
);
|
||||
@@ -774,11 +900,9 @@ export class ConfigPanel {
|
||||
progress.report({ increment: 0 });
|
||||
|
||||
try {
|
||||
// 确保父目录存在
|
||||
const parentDir = path.dirname(localPath);
|
||||
await fs.promises.mkdir(parentDir, { recursive: true });
|
||||
|
||||
// 检查目标目录是否已存在
|
||||
let dirExists = false;
|
||||
try {
|
||||
await fs.promises.access(localPath);
|
||||
@@ -802,7 +926,6 @@ export class ConfigPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
// 清空目录(除了 .git 文件夹)
|
||||
for (const item of dirContents) {
|
||||
const itemPath = path.join(localPath, item);
|
||||
if (item !== '.git') {
|
||||
@@ -814,7 +937,6 @@ export class ConfigPanel {
|
||||
|
||||
console.log(`🚀 开始克隆: ${url} -> ${localPath}, 分支: ${branch}`);
|
||||
|
||||
// 克隆仓库
|
||||
await git.clone({
|
||||
fs: fs,
|
||||
http: http,
|
||||
@@ -839,7 +961,6 @@ export class ConfigPanel {
|
||||
|
||||
console.log('✅ Git克隆成功完成');
|
||||
|
||||
// 验证克隆是否真的成功
|
||||
const clonedContents = await fs.promises.readdir(localPath);
|
||||
console.log(`📁 克隆后的目录内容:`, clonedContents);
|
||||
|
||||
@@ -847,14 +968,12 @@ export class ConfigPanel {
|
||||
throw new Error('克隆后目录为空,可能克隆失败');
|
||||
}
|
||||
|
||||
// 只有在克隆成功后才添加到列表
|
||||
this.moduleFolders.push(newFolder);
|
||||
await this.saveCurrentProjectData();
|
||||
console.log('✅ Git模块文件夹数据已保存到项目文件');
|
||||
|
||||
vscode.window.showInformationMessage(`Git 仓库克隆成功: ${displayName}`);
|
||||
|
||||
// 自动加载文件树
|
||||
if (!this.isWebviewDisposed) {
|
||||
console.log('🌳 开始加载模块文件夹文件树...');
|
||||
this.currentModuleFolderId = folderId;
|
||||
@@ -865,7 +984,6 @@ export class ConfigPanel {
|
||||
} catch (error) {
|
||||
console.error('❌ 在克隆过程中捕获错误:', error);
|
||||
|
||||
// 清理:如果克隆失败,删除可能创建的不完整目录
|
||||
try {
|
||||
if (fs.existsSync(localPath)) {
|
||||
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 fileName = path.basename(filePath);
|
||||
|
||||
// 使用新的 ID 生成方法
|
||||
const newId = this.generateUniqueId('cfg', this.configs);
|
||||
const newConfig: Config = {
|
||||
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);
|
||||
if (!folder || folder.type !== 'git') {
|
||||
vscode.window.showErrorMessage('未找到指定的 Git 模块文件夹');
|
||||
@@ -1054,9 +1171,9 @@ export class ConfigPanel {
|
||||
vscode.window.showInformationMessage(`✅ Git 仓库上传成功: ${folder.name}`);
|
||||
this.updateWebview();
|
||||
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
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}`);
|
||||
this.updateWebview();
|
||||
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('❌ 本地文件夹上传失败:', error);
|
||||
vscode.window.showErrorMessage(`推送失败: ${error.message}`);
|
||||
vscode.window.showErrorMessage(`推送失败: ${error.message || error}`);
|
||||
|
||||
// 清理:删除可能创建的 .git 文件夹
|
||||
try {
|
||||
const gitDir = path.join(fullPath, '.git');
|
||||
if (fs.existsSync(gitDir)) {
|
||||
@@ -1135,18 +1251,16 @@ export class ConfigPanel {
|
||||
console.log('🚀 使用命令行 Git 提交并推送...');
|
||||
console.log(`📁 工作目录: ${fullPath}`);
|
||||
|
||||
// 先检查是否有更改
|
||||
exec('git status --porcelain', {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (statusError, statusStdout, statusStderr) => {
|
||||
}, (statusError: any, statusStdout: string, statusStderr: string) => {
|
||||
if (statusError) {
|
||||
console.error('❌ 检查 Git 状态失败:', statusError);
|
||||
reject(new Error(`检查 Git 状态失败: ${statusStderr || statusError.message}`));
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果没有更改
|
||||
if (!statusStdout.trim()) {
|
||||
console.log('ℹ️ 没有需要提交的更改');
|
||||
reject(new Error('没有需要提交的更改'));
|
||||
@@ -1155,7 +1269,6 @@ export class ConfigPanel {
|
||||
|
||||
console.log('📋 检测到更改:', statusStdout);
|
||||
|
||||
// 有更改时才提交并推送
|
||||
const commands = [
|
||||
'git add .',
|
||||
`git commit -m "Auto commit from DCSP - ${new Date().toLocaleString()}"`,
|
||||
@@ -1165,7 +1278,7 @@ export class ConfigPanel {
|
||||
exec(commands.join(' && '), {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
}, (error: any, stdout: string, stderr: string) => {
|
||||
console.log('📋 Git 命令输出:', stdout);
|
||||
console.log('📋 Git 命令错误:', stderr);
|
||||
|
||||
@@ -1191,7 +1304,7 @@ export class ConfigPanel {
|
||||
exec(`git init && git checkout -b ${branchName}`, {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
}, (error: any, stdout: string, stderr: string) => {
|
||||
if (error) {
|
||||
console.error('❌ Git 初始化失败:', error);
|
||||
reject(new Error(stderr || error.message));
|
||||
@@ -1213,7 +1326,7 @@ export class ConfigPanel {
|
||||
exec(`git remote add origin ${repoUrl}`, {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
}, (error: any, stdout: string, stderr: string) => {
|
||||
if (error) {
|
||||
console.error('❌ 添加远程仓库失败:', error);
|
||||
reject(new Error(stderr || error.message));
|
||||
@@ -1234,15 +1347,14 @@ export class ConfigPanel {
|
||||
|
||||
const commands = [
|
||||
'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(' && '), {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
}, (error: any, stdout: string, stderr: string) => {
|
||||
if (error) {
|
||||
// 检查是否是"没有更改可提交"的错误
|
||||
if (stderr.includes('nothing to commit') || stdout.includes('nothing to commit')) {
|
||||
console.log('ℹ️ 没有需要提交的更改');
|
||||
resolve();
|
||||
@@ -1269,7 +1381,7 @@ export class ConfigPanel {
|
||||
exec(`git push -u origin ${branchName} --force`, {
|
||||
cwd: fullPath,
|
||||
encoding: 'utf8'
|
||||
}, (error, stdout, stderr) => {
|
||||
}, (error: any, stdout: string, stderr: string) => {
|
||||
console.log('📋 Git push stdout:', stdout);
|
||||
console.log('📋 Git push stderr:', stderr);
|
||||
|
||||
@@ -1355,9 +1467,6 @@ export class ConfigPanel {
|
||||
}
|
||||
|
||||
private async createDefaultConfigs(container: Container): Promise<void> {
|
||||
const configCount = this.configs.length;
|
||||
|
||||
// 第一个配置文件
|
||||
this.configs.push({
|
||||
id: this.generateUniqueId('cfg', this.configs),
|
||||
name: '配置1',
|
||||
@@ -1366,12 +1475,11 @@ export class ConfigPanel {
|
||||
containerId: container.id
|
||||
});
|
||||
|
||||
// 第二个配置文件
|
||||
this.configs.push({
|
||||
id: this.generateUniqueId('cfg', this.configs),
|
||||
name: '配置2',
|
||||
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
|
||||
});
|
||||
}
|
||||
@@ -1427,9 +1535,8 @@ export class ConfigPanel {
|
||||
|
||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||
|
||||
// 构建当前项目的完整数据
|
||||
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),
|
||||
containers: this.containers.filter(c => {
|
||||
const aircraft = this.aircrafts.find(a => a.id === c.aircraftId);
|
||||
@@ -1462,7 +1569,6 @@ export class ConfigPanel {
|
||||
try {
|
||||
const dataUri = vscode.Uri.joinPath(vscode.Uri.file(projectPath), '.dcsp-data.json');
|
||||
|
||||
// 检查数据文件是否存在
|
||||
try {
|
||||
await vscode.workspace.fs.stat(dataUri);
|
||||
} catch {
|
||||
@@ -1470,15 +1576,12 @@ export class ConfigPanel {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 读取数据文件
|
||||
const fileData = await vscode.workspace.fs.readFile(dataUri);
|
||||
const dataStr = new TextDecoder().decode(fileData);
|
||||
const data: ProjectData = JSON.parse(dataStr);
|
||||
|
||||
// 只清空当前项目相关的数据,保留其他项目数据
|
||||
const projectId = data.projects[0]?.id;
|
||||
if (projectId) {
|
||||
// 移除当前项目的旧数据
|
||||
this.projects = this.projects.filter(p => p.id !== 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.moduleFolders = this.moduleFolders.filter(folder => !containerIds.includes(folder.containerId));
|
||||
|
||||
// 添加新数据
|
||||
this.projects.push(...data.projects);
|
||||
this.aircrafts.push(...data.aircrafts);
|
||||
this.containers.push(...data.containers);
|
||||
this.configs.push(...data.configs);
|
||||
this.moduleFolders.push(...data.moduleFolders);
|
||||
|
||||
// 设置当前项目
|
||||
this.currentProjectId = projectId;
|
||||
this.projectPaths.set(projectId, projectPath);
|
||||
this.currentView = 'aircrafts';
|
||||
@@ -1666,7 +1767,6 @@ export class ConfigPanel {
|
||||
const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
if (!folder) return;
|
||||
|
||||
// 通知前端开始加载
|
||||
try {
|
||||
this.panel.webview.postMessage({
|
||||
type: 'moduleFolderLoading',
|
||||
@@ -1689,13 +1789,11 @@ export class ConfigPanel {
|
||||
this.currentModuleFolderFileTree = [];
|
||||
}
|
||||
|
||||
// 再次检查 Webview 状态
|
||||
if (this.isWebviewDisposed) {
|
||||
console.log('⚠️ Webview 已被销毁,跳过完成通知');
|
||||
return;
|
||||
}
|
||||
|
||||
// 通知前端加载完成
|
||||
try {
|
||||
this.panel.webview.postMessage({
|
||||
type: 'moduleFolderLoading',
|
||||
@@ -1714,7 +1812,6 @@ export class ConfigPanel {
|
||||
const tree: GitFileTree[] = [];
|
||||
|
||||
for (const file of files) {
|
||||
// 忽略 .git 文件夹和 .dcsp-data.json
|
||||
if (file.startsWith('.') && file !== '.git') continue;
|
||||
if (file === '.dcsp-data.json') continue;
|
||||
|
||||
@@ -1907,7 +2004,6 @@ export class ConfigPanel {
|
||||
projectPaths: this.projectPaths
|
||||
});
|
||||
case 'aircrafts':
|
||||
// 只显示当前项目的飞行器
|
||||
const projectAircrafts = this.aircrafts.filter(a => a.projectId === this.currentProjectId);
|
||||
return this.aircraftView.render({
|
||||
aircrafts: projectAircrafts
|
||||
@@ -1915,7 +2011,6 @@ export class ConfigPanel {
|
||||
case 'containers':
|
||||
const currentProject = this.projects.find(p => p.id === this.currentProjectId);
|
||||
const currentAircraft = this.aircrafts.find(a => a.id === this.currentAircraftId);
|
||||
// 只显示当前飞行器的容器
|
||||
const projectContainers = this.containers.filter(c => c.aircraftId === this.currentAircraftId);
|
||||
|
||||
return this.containerView.render({
|
||||
@@ -1925,9 +2020,8 @@ export class ConfigPanel {
|
||||
});
|
||||
case 'configs':
|
||||
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 containerConfigs = this.configs.filter(cfg => cfg.containerId === this.currentContainerId);
|
||||
const containerModuleFolders = this.moduleFolders.filter(folder => folder.containerId === this.currentContainerId);
|
||||
|
||||
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';
|
||||
|
||||
export abstract class BaseView {
|
||||
@@ -120,59 +119,154 @@ export abstract class BaseView {
|
||||
cursor: pointer;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
background: var(--vscode-editor-background);
|
||||
border: 1px solid var(--vscode-panel-border);
|
||||
border-radius: 4px;
|
||||
padding: 20px;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
margin-bottom: 15px;
|
||||
font-weight: bold;
|
||||
color: var(--vscode-editor-foreground);
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.modal-btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-btn-primary {
|
||||
background: var(--vscode-button-background);
|
||||
color: var(--vscode-button-foreground);
|
||||
}
|
||||
|
||||
.modal-btn-secondary {
|
||||
background: var(--vscode-button-secondaryBackground);
|
||||
color: var(--vscode-button-secondaryForeground);
|
||||
}
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
background: var(--vscode-editor-background);
|
||||
border: 1px solid var(--vscode-panel-border);
|
||||
border-radius: 4px;
|
||||
padding: 20px;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
margin-bottom: 15px;
|
||||
font-weight: bold;
|
||||
color: var(--vscode-editor-foreground);
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.modal-btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-btn-primary {
|
||||
background: var(--vscode-button-background);
|
||||
color: var(--vscode-button-foreground);
|
||||
}
|
||||
|
||||
.modal-btn-secondary {
|
||||
background: var(--vscode-button-secondaryBackground);
|
||||
color: var(--vscode-button-secondaryForeground);
|
||||
}
|
||||
</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[];
|
||||
moduleFolderLoading?: boolean;
|
||||
gitBranches?: GitBranch[];
|
||||
gitRepoUrl?: string;
|
||||
}): string {
|
||||
const container = data?.container;
|
||||
const configs = data?.configs || [];
|
||||
@@ -54,7 +53,6 @@ export class ConfigView extends BaseView {
|
||||
const moduleFolderFileTree = data?.moduleFolderFileTree || [];
|
||||
const moduleFolderLoading = data?.moduleFolderLoading || false;
|
||||
const gitBranches = data?.gitBranches || [];
|
||||
const gitRepoUrl = data?.gitRepoUrl || '';
|
||||
|
||||
// 生成配置列表的 HTML - 包含配置文件和模块文件夹
|
||||
const configsHtml = configs.map((config: ConfigViewData) => `
|
||||
@@ -74,32 +72,32 @@ export class ConfigView extends BaseView {
|
||||
`).join('');
|
||||
|
||||
// 生成模块文件夹的 HTML - 按类别分类显示
|
||||
const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
const icon = folder.type === 'git' ? '📁' : '📁';
|
||||
// 根据类型和上传状态确定类别显示
|
||||
let category = folder.type === 'git' ? 'git' : 'local';
|
||||
if (folder.uploaded) {
|
||||
category += '(已上传)';
|
||||
}
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td>
|
||||
<span class="editable">${icon} ${folder.name}</span>
|
||||
</td>
|
||||
<td class="category-${folder.type}">${category}</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
|
||||
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
const icon = folder.type === 'git' ? '📁' : '📁';
|
||||
// 根据类型和上传状态确定类别显示
|
||||
let category = folder.type === 'git' ? 'git' : 'local';
|
||||
if (folder.uploaded) {
|
||||
category += '(已上传)';
|
||||
}
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td>
|
||||
<span class="editable">${icon} ${folder.name}</span>
|
||||
</td>
|
||||
<td class="category-${folder.type}">${category}</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openTheModuleFolder('${folder.id}', '${folder.type}')">${folder.localPath.split('/').pop()}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-upload" onclick="uploadModuleFolder('${folder.id}', '${folder.type}')" style="margin-right: 5px;">上传</button>
|
||||
<button class="btn-delete" onclick="deleteModuleFolder('${folder.id}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
// 生成分支选择的 HTML - 使用树状结构
|
||||
// 生成分支选择的 HTML - 使用树状结构(首次渲染可以为空,后续通过 message 更新)
|
||||
const branchesHtml = gitBranches.length > 0 ? this.generateBranchesTreeHtml(gitBranches) : '';
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
@@ -285,25 +283,25 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
}
|
||||
|
||||
/* 类别标签样式 */
|
||||
.category-git {
|
||||
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
.category-git {
|
||||
color: var(--vscode-gitDecoration-untrackedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.category-local {
|
||||
color: var(--vscode-charts-orange);
|
||||
font-weight: bold;
|
||||
}
|
||||
.category-local {
|
||||
color: var(--vscode-charts-orange);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.category-git(已上传) {
|
||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
.category-git(已上传) {
|
||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.category-local(已上传) {
|
||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
.category-local(已上传) {
|
||||
color: var(--vscode-gitDecoration-addedResourceForeground);
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -342,15 +340,14 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
<div class="config-section">
|
||||
<h3 class="section-title">📚 模块云仓库</h3>
|
||||
|
||||
<!-- URL 输入区域 -->
|
||||
<!-- 仓库选择区域:不再手动输入 URL,通过弹窗获取仓库 -->
|
||||
<div class="url-input-section">
|
||||
<h4>🔗 添加 Git 仓库</h4>
|
||||
<div style="display: flex; gap: 10px; margin-top: 10px;">
|
||||
<input type="text" id="repoUrlInput"
|
||||
placeholder="请输入 Git 仓库 URL,例如: https://github.com/username/repo.git"
|
||||
value="${gitRepoUrl}"
|
||||
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;">
|
||||
<button class="btn-new" onclick="fetchBranches()">获取分支</button>
|
||||
<h4>🔗 获取仓库</h4>
|
||||
<div style="display: flex; gap: 10px; margin-top: 10px; align-items: center;">
|
||||
<button class="btn-new" onclick="openRepoSelect()">获取仓库</button>
|
||||
<span style="font-size: 12px; color: var(--vscode-descriptionForeground);">
|
||||
从仓库配置中选择 Git 仓库,随后可以选择分支并克隆到本地
|
||||
</span>
|
||||
</div>
|
||||
<div id="branchSelectionContainer">
|
||||
${branchesHtml}
|
||||
@@ -363,7 +360,6 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
const vscode = acquireVsCodeApi();
|
||||
let currentConfigId = null;
|
||||
let selectedBranches = new Set();
|
||||
let currentRepoUrl = '';
|
||||
let branchTreeData = [];
|
||||
let selectedConfigs = new Set();
|
||||
|
||||
@@ -385,7 +381,7 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
);
|
||||
}
|
||||
|
||||
// 新功能:在 VSCode 中打开配置文件
|
||||
// 在 VSCode 中打开配置文件
|
||||
function openConfigFileInVSCode(configId) {
|
||||
console.log('📄 在 VSCode 中打开配置文件:', configId);
|
||||
vscode.postMessage({
|
||||
@@ -484,7 +480,7 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 添加上传对话框函数
|
||||
// 上传对话框函数(本地->Git)
|
||||
function showUploadDialog(folderId) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
@@ -570,30 +566,16 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
vscode.postMessage({ type: 'goBackToContainers' });
|
||||
}
|
||||
|
||||
// Git 仓库管理功能
|
||||
function fetchBranches() {
|
||||
const urlInput = document.getElementById('repoUrlInput');
|
||||
const repoUrl = urlInput.value.trim();
|
||||
|
||||
if (!repoUrl) {
|
||||
alert('请输入 Git 仓库 URL');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!repoUrl.startsWith('http')) {
|
||||
alert('请输入有效的 Git 仓库 URL');
|
||||
return;
|
||||
}
|
||||
|
||||
currentRepoUrl = repoUrl;
|
||||
console.log('🌿 获取分支列表:', repoUrl);
|
||||
|
||||
// 🔁 新逻辑:通过弹窗获取仓库(不再手动输入 URL)
|
||||
function openRepoSelect() {
|
||||
console.log('📦 请求仓库列表以选择 Git 仓库');
|
||||
vscode.postMessage({
|
||||
type: 'fetchBranches',
|
||||
url: repoUrl
|
||||
type: 'openRepoSelect'
|
||||
});
|
||||
}
|
||||
|
||||
// 不再在前端手动输入/校验 URL,分支拉取由 repo 选择 + 后端完成
|
||||
|
||||
function toggleBranch(branchName) {
|
||||
const checkbox = document.getElementById('branch-' + branchName.replace(/[^a-zA-Z0-9-]/g, '-'));
|
||||
if (checkbox.checked) {
|
||||
@@ -614,7 +596,6 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
|
||||
vscode.postMessage({
|
||||
type: 'cloneBranches',
|
||||
url: currentRepoUrl,
|
||||
branches: Array.from(selectedBranches)
|
||||
});
|
||||
|
||||
@@ -673,7 +654,7 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
showMergeDialog();
|
||||
}
|
||||
|
||||
// 新的合并对话框函数
|
||||
// 合并对话框
|
||||
function showMergeDialog() {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
@@ -1107,4 +1088,4 @@ const moduleFoldersHtml = moduleFolders.map((folder: ModuleFolder) => {
|
||||
});
|
||||
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 { ProjectViewData } from '../types/ViewTypes';
|
||||
|
||||
@@ -96,7 +95,10 @@ export class ProjectView extends BaseView {
|
||||
</style>
|
||||
</head>
|
||||
<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">
|
||||
<thead>
|
||||
@@ -126,6 +128,12 @@ export class ProjectView extends BaseView {
|
||||
<script>
|
||||
const vscode = acquireVsCodeApi();
|
||||
|
||||
function openRepoConfig() {
|
||||
vscode.postMessage({
|
||||
type: 'openRepoConfig'
|
||||
});
|
||||
}
|
||||
|
||||
function configureProject(projectId, projectName, isConfigured) {
|
||||
if (isConfigured) {
|
||||
// 已配置的项目直接打开
|
||||
@@ -296,4 +304,4 @@ export class ProjectView extends BaseView {
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user