Complete frontend console redesign

This commit is contained in:
2026-07-19 19:49:05 +08:00
parent 1b1d983060
commit 12b7e31783
7 changed files with 1097 additions and 214 deletions
+39 -5
View File
@@ -4,19 +4,35 @@
* 前端仅用于「预览」派生路径,实际创建目录由后端完成。为了与后端
* PathUtils.joinPath 的行为保持一致,这里统一:
* - 将反斜杠 \ 归一化为正斜杠 /
* - 去除父路径末尾多余的分隔符
* - 去除父路径末尾多余的分隔符(但保留文件系统根 `/` 与 Windows 盘符根)
* - 去除子路径开头多余的分隔符
* - 以单个 / 连接
*
* 注意:这只是显示层的规范化,不做真实文件系统解析。
*/
/** 归一化根路径:转 POSIX 分隔符去掉结尾斜杠。 */
/** 归一化根路径:转 POSIX 分隔符去掉结尾斜杠,但保留 `/` 与 `C:` 形式的根。 */
export function normalizeRoot(raw: string): string {
if (!raw) {
return '';
}
return raw.replace(/\\/g, '/').replace(/\/+$/, '');
const posix = raw.replace(/\\/g, '/');
// 纯根斜杠:'/'、'//' → '/'
if (/^\/+$/.test(posix)) {
return '/';
}
// Windows 盘符根:'C:'、'C:/'、'C://' → 'C:'
const driveRoot = posix.match(/^([A-Za-z]:)\/+$/);
if (driveRoot) {
return driveRoot[1];
}
if (/^[A-Za-z]:$/.test(posix)) {
return posix;
}
return posix.replace(/\/+$/, '');
}
/** 以规范化方式拼接父/子路径,返回 POSIX 形式字符串。 */
@@ -29,20 +45,38 @@ export function joinPath(parent: string, child: string): string {
return parentPosix;
}
const childPosix = child.replace(/\\/g, '/').replace(/^\/+/, '');
// 文件系统根:'/' + 'Input' → '/Input'
if (parentPosix === '/') {
return `/${childPosix}`;
}
return `${parentPosix}/${childPosix}`;
}
/**
* 校验路径是否合法(与后端 PathUtils.isValidPath 对齐)。
* Windows 盘符后的冒号是合法的,其余情况下不允许出现 < > " | ? *。
* 文件系统根 `/` 与 Windows 盘符根(`C:` / `C:/`)视为合法。
*/
export function isValidPath(path: string): boolean {
if (!path || !path.trim()) {
return false;
}
let pathToValidate = path.trim();
if (/^[A-Za-z]:[/\\]/.test(pathToValidate)) {
let pathToValidate = path.trim().replace(/\\/g, '/');
// POSIX 根
if (pathToValidate === '/' || /^\/+$/.test(pathToValidate)) {
return true;
}
// Windows 盘符根
if (/^[A-Za-z]:\/?$/.test(pathToValidate)) {
return true;
}
// 去掉 Windows 盘符再检查非法字符
if (/^[A-Za-z]:\//.test(pathToValidate)) {
pathToValidate = pathToValidate.substring(2);
}
return !/[<>"|?*]/.test(pathToValidate);
}