修复大小写bug
This commit is contained in:
@@ -368,7 +368,7 @@ export class ConfigPanel {
|
||||
'createContainer': (data) => this.createContainer(data.name),
|
||||
'deleteContainer': (data) => this.deleteContainer(data.containerId),
|
||||
|
||||
// 配置管理
|
||||
// 模块管理
|
||||
// [修改] 接收新的文件名
|
||||
'updateConfigName': (data) => this.updateConfigName(data.configId, data.name, data.fileName),
|
||||
'createConfig': (data) => this.createConfig(data.name),
|
||||
@@ -749,7 +749,7 @@ export class ConfigPanel {
|
||||
}
|
||||
|
||||
// =============================================
|
||||
// 配置管理方法
|
||||
// 模块管理方法
|
||||
// =============================================
|
||||
|
||||
/**
|
||||
|
||||
@@ -345,7 +345,6 @@ export class GitService {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建文件树
|
||||
* 这里显式忽略:
|
||||
@@ -363,7 +362,7 @@ export class GitService {
|
||||
if (file === '.git') continue;
|
||||
|
||||
// 2. 不要解析项目数据文件
|
||||
if (file === '.dcsp-data.json') continue;
|
||||
if (file === 'dcsp-data.json') continue;
|
||||
|
||||
// 3. 其它所有隐藏文件/目录统统忽略
|
||||
if (file.startsWith('.')) continue;
|
||||
|
||||
@@ -31,18 +31,21 @@ export class ProjectService {
|
||||
}
|
||||
|
||||
/**
|
||||
* [新增] 文件名/文件夹名净化:只允许中文、字母、数字、-、_
|
||||
* 文件名/文件夹名净化:保留大小写,允许中文、字母、数字、-、_、.
|
||||
*/
|
||||
public sanitizeFileName(name: string): string {
|
||||
// 允许中文、字母、数字、-、_
|
||||
let fileName = name.trim().toLowerCase();
|
||||
let fileName = name.trim(); // 移除 .toLowerCase() 以保留大小写
|
||||
|
||||
// 1. 替换所有空格为下划线
|
||||
fileName = fileName.replace(/\s+/g, '_');
|
||||
// 2. 移除所有不被允许的特殊字符(只保留中文、字母、数字、-、_)
|
||||
fileName = fileName.replace(/[^\u4e00-\u9fa5a-z0-9_-]/g, '');
|
||||
|
||||
// 2. 移除特殊字符
|
||||
// 在正则中增加了 A-Z 以及 \. (注意:\u4e00-\u9fa5 匹配中文)
|
||||
fileName = fileName.replace(/[^\u4e00-\u9fa5a-zA-Z0-9_\-\.]/g, '');
|
||||
|
||||
// 3. 确保不为空
|
||||
if (fileName.length === 0) {
|
||||
return 'config_file';
|
||||
return 'config_file';
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
@@ -340,9 +343,11 @@ export class ProjectService {
|
||||
return this.configs.find(c => c.id === configId);
|
||||
}
|
||||
|
||||
// src/panels/services/ProjectService.ts
|
||||
|
||||
async createConfig(name: string, containerId: string): Promise<string> {
|
||||
const newId = this.generateUniqueId('cfg', this.configs);
|
||||
// 使用新增的 sanitizeFileName 方法来处理文件名
|
||||
// 使用净化后的文件名
|
||||
const newFileName = this.sanitizeFileName(name);
|
||||
|
||||
const newConfig: Config = {
|
||||
@@ -353,7 +358,23 @@ export class ProjectService {
|
||||
};
|
||||
this.configs.push(newConfig);
|
||||
|
||||
// 1. 首先确保父级容器目录存在
|
||||
await this.ensureContainerDirectoryExists(containerId);
|
||||
|
||||
// 2. 获取文件的完整磁盘路径
|
||||
const filePath = this.getConfigFilePath(newId);
|
||||
if (filePath) {
|
||||
try {
|
||||
const fileUri = vscode.Uri.file(filePath);
|
||||
// 3. 真实创建文件:写入一个空的 Uint8Array 即可创建一个空文件
|
||||
// 如果你希望有默认内容,可以在这里自定义 TextEncoder().encode("...")
|
||||
await vscode.workspace.fs.writeFile(fileUri, new Uint8Array());
|
||||
console.log(`✅ 磁盘文件已真实创建: ${filePath}`);
|
||||
} catch (error) {
|
||||
console.error(`❌ 磁盘文件创建失败: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
return newId;
|
||||
}
|
||||
|
||||
@@ -446,18 +467,6 @@ export class ProjectService {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* [删除] 此方法已被 ConfigPanel 中的 updateModuleFolder 替换,以支持同步磁盘操作。
|
||||
*/
|
||||
// renameModuleFolder(folderId: string, newName: string): boolean {
|
||||
// const folder = this.moduleFolders.find(f => f.id === folderId);
|
||||
// if (!folder) return false;
|
||||
//
|
||||
// const oldName = folder.localPath.split('/').pop() || '';
|
||||
// folder.localPath = folder.localPath.replace(/\/[^/]+$/, '/' + newName);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// =============== 文件系统操作 (新增/修改) ===============
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@ export class StorageService {
|
||||
*/
|
||||
static async loadProjectData(projectPath: string): Promise<ProjectData | null> {
|
||||
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 {
|
||||
await vscode.workspace.fs.stat(dataUri);
|
||||
@@ -39,7 +39,7 @@ export class StorageService {
|
||||
*/
|
||||
static async saveProjectData(projectPath: string, data: ProjectData): Promise<boolean> {
|
||||
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');
|
||||
|
||||
const uint8Array = new TextEncoder().encode(JSON.stringify(data, null, 2));
|
||||
await vscode.workspace.fs.writeFile(dataUri, uint8Array);
|
||||
@@ -57,7 +57,7 @@ export class StorageService {
|
||||
*/
|
||||
static async checkProjectPathHasData(projectPath: string): Promise<boolean> {
|
||||
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');
|
||||
await vscode.workspace.fs.stat(dataUri);
|
||||
return true;
|
||||
} catch {
|
||||
|
||||
@@ -11,7 +11,7 @@ export class AircraftView extends BaseView {
|
||||
<span class="aircraft-name" data-aircraft-id="${aircraft.id}">🛸 ${aircraft.name}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openAircraftConfig('${aircraft.id}', '${aircraft.projectId}')">配置容器</span>
|
||||
<span class="clickable" onclick="openAircraftConfig('${aircraft.id}', '${aircraft.projectId}')">打开</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-upload" onclick="uploadAircraft('${aircraft.id}', '${aircraft.name}')" style="margin-right: 5px;">上传</button>
|
||||
@@ -84,7 +84,7 @@ export class AircraftView extends BaseView {
|
||||
.section-title {
|
||||
margin: 30px 0 15px 0;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 2px solid var(--vscode-panel-border);
|
||||
border-bottom: 2px solid var(--vscode-panel-border);
|
||||
color: var(--vscode-titleBar-activeForeground);
|
||||
}
|
||||
.url-input-section {
|
||||
|
||||
@@ -97,7 +97,7 @@ export class ConfigView extends BaseView {
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>配置管理</title>
|
||||
<title>模块管理</title>
|
||||
${this.getBaseStylesAndScripts()}
|
||||
${this.getRepoSelectScript()}
|
||||
<style>
|
||||
@@ -289,7 +289,7 @@ export class ConfigView extends BaseView {
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h2>⚙️ 配置管理 - <span style="color: var(--vscode-textLink-foreground);">${container?.name || '未知容器'}</span></h2>
|
||||
<h2>⚙️ 模块管理 - <span style="color: var(--vscode-textLink-foreground);">${container?.name || '未知容器'}</span></h2>
|
||||
<button class="back-btn" onclick="goBackToContainers()">← 返回容器管理</button>
|
||||
</div>
|
||||
|
||||
@@ -304,7 +304,7 @@ export class ConfigView extends BaseView {
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="25%">配置</th>
|
||||
<th width="25%">模块</th>
|
||||
<th width="15%">类别</th>
|
||||
<th width="35%">文件/文件夹</th>
|
||||
<th width="25%">操作</th>
|
||||
@@ -562,7 +562,7 @@ export class ConfigView extends BaseView {
|
||||
showModuleFolderRenameDialog(folderId, currentName, currentFolderName);
|
||||
}
|
||||
|
||||
// 配置管理功能
|
||||
// 模块管理功能
|
||||
// 原始的 editConfigName 已被修改为接受三个参数
|
||||
|
||||
// 在 VSCode 中打开配置文件
|
||||
|
||||
@@ -13,7 +13,7 @@ export class ContainerView extends BaseView {
|
||||
<span class="editable" onclick="editContainerName('${container.id}', '${container.name}')">📦 ${container.name}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="clickable" onclick="openContainerConfig('${container.id}')">配置文件</span>
|
||||
<span class="clickable" onclick="openContainerConfig('${container.id}')">打开</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-upload" onclick="uploadContainer('${container.id}', '${container.name}')" style="margin-right: 5px;">上传</button>
|
||||
@@ -150,7 +150,7 @@ export class ContainerView extends BaseView {
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="40%">容器</th>
|
||||
<th width="40%">配置文件</th>
|
||||
<th width="40%">打开</th>
|
||||
<th width="20%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -221,7 +221,7 @@ export class ProjectView extends BaseView {
|
||||
<div style="display: flex; gap: 10px; margin-top: 10px; align-items: center;">
|
||||
<button class="btn-new" onclick="openRepoSelectForProject()">获取仓库</button>
|
||||
<span style="font-size: 12px; color: var(--vscode-descriptionForeground);">
|
||||
从仓库配置中选择 Git 仓库,选择分支后可将完整项目克隆到本地(包含 dscp-data.json)
|
||||
从仓库配置中选择 Git 仓库,选择分支后可将完整项目克隆到本地
|
||||
</span>
|
||||
</div>
|
||||
<div id="branchSelectionContainer"></div>
|
||||
|
||||
Reference in New Issue
Block a user