check page, fix output format
This commit is contained in:
88
src/App.vue
88
src/App.vue
@@ -274,6 +274,81 @@ const handleDeleteEmptyDirs = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to format paths as tree structure
|
||||
interface TreeNode {
|
||||
name: string;
|
||||
isFile: boolean;
|
||||
children: Map<string, TreeNode>;
|
||||
}
|
||||
|
||||
const formatTreeStructure = (paths: string[], rootPath: string): string[] => {
|
||||
if (paths.length === 0) return [];
|
||||
|
||||
const root: TreeNode = { name: '', isFile: false, children: new Map() };
|
||||
|
||||
// Build the tree data structure
|
||||
paths.forEach(fullPath => {
|
||||
let relPath = fullPath;
|
||||
if (rootPath && fullPath.startsWith(rootPath)) {
|
||||
relPath = fullPath.substring(rootPath.length);
|
||||
if (relPath.startsWith('/') || relPath.startsWith('\\')) {
|
||||
relPath = relPath.substring(1);
|
||||
}
|
||||
}
|
||||
relPath = relPath.replace(/\\/g, '/'); // Normalize to forward slashes
|
||||
|
||||
const parts = relPath.split('/').filter(p => p.length > 0);
|
||||
|
||||
let currentNode = root;
|
||||
parts.forEach((part, i) => {
|
||||
if (!currentNode.children.has(part)) {
|
||||
currentNode.children.set(part, { name: part, isFile: false, children: new Map() });
|
||||
}
|
||||
currentNode = currentNode.children.get(part)!;
|
||||
if (i === parts.length - 1) { // Mark last part as file
|
||||
currentNode.isFile = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const output: string[] = [];
|
||||
|
||||
// Recursive function to print the tree
|
||||
const printTreeRecursive = (node: TreeNode, prefix: string, isLastChildArr: boolean[]) => {
|
||||
const sortedChildrenNames = Array.from(node.children.keys()).sort();
|
||||
|
||||
sortedChildrenNames.forEach((childName, index) => {
|
||||
const childNode = node.children.get(childName)!;
|
||||
const isLastChildOfCurrentNode = (index === sortedChildrenNames.length - 1);
|
||||
|
||||
let currentLine = prefix;
|
||||
for (let i = 0; i < isLastChildArr.length; i++) {
|
||||
currentLine += isLastChildArr[i] ? " " : "│ ";
|
||||
}
|
||||
|
||||
currentLine += isLastChildOfCurrentNode ? "└── " : "├── ";
|
||||
|
||||
output.push(`${currentLine}${childNode.name}`);
|
||||
|
||||
// Recurse for children
|
||||
// Only recurse if the childNode is a directory (has children itself)
|
||||
// or if it's a file but represents a path segment that also needs further processing.
|
||||
// In our case, `isFile` marks only the actual file at the end of path.
|
||||
// If it's a directory (i.e., has children or might have children in other paths), we recurse.
|
||||
if (childNode.children.size > 0) {
|
||||
printTreeRecursive(childNode, prefix, [...isLastChildArr, isLastChildOfCurrentNode]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Print the root node first
|
||||
output.push(`${rootPath || '.'}`);
|
||||
// Then print its children
|
||||
printTreeRecursive(root, "", []);
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
const handleCheckNaming = async () => {
|
||||
appendLog("\n" + "=".repeat(20));
|
||||
appendLog(`正在检查文件命名,前缀要求: ${videoNamePrefix.value} ...`);
|
||||
@@ -287,16 +362,9 @@ const handleCheckNaming = async () => {
|
||||
appendLog("检查完毕,所有文件均符合命名规范。");
|
||||
} else {
|
||||
appendLog(`发现 ${mismatches.length} 个文件不符合规范:`);
|
||||
mismatches.sort();
|
||||
|
||||
// Format logs first
|
||||
const formattedLogs = mismatches.map(path => {
|
||||
let displayPath = path;
|
||||
if (path.startsWith(currentDir.value)) {
|
||||
displayPath = "." + path.substring(currentDir.value.length);
|
||||
}
|
||||
return displayPath;
|
||||
});
|
||||
// Format logs as tree
|
||||
const formattedLogs = formatTreeStructure(mismatches, currentDir.value);
|
||||
|
||||
const batchSize = 100;
|
||||
for (let i = 0; i < formattedLogs.length; i += batchSize) {
|
||||
@@ -750,4 +818,4 @@ body {
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user