This commit is contained in:
539943419 committed 2024-08-11 01:00:49 +08:00
1 parent a668b3b840
commit 1d4feb471c
9 files changed
+342 -103

No files matched your search

+27 -19
View File
@@ -8,14 +8,14 @@ export class VirtualFile {
this.stats = info.stats;
this.parent = parent;
this.type = "file";
this.uid = generateId()
this.uid = generateId();
}
name: string;
type: "file";
size: number;
stats: stats;
parent: VirtualDirectory;
uid: number
uid: number;
get path() {
return `${this.parent.path}${this.name}`;
}
@@ -27,7 +27,7 @@ class VirtualDirectory {
this.type = "directory";
this.stats = info.stats;
this.parent = parent ?? undefined;
this.uid = generateId()
this.uid = generateId();
}
// 文件夹名
name: string;
@@ -42,7 +42,7 @@ class VirtualDirectory {
// 父文件夹
parent?: VirtualDirectory;
uid: number
uid: number;
/**
* 获取相对于根目录的路径的层数
@@ -87,37 +87,45 @@ class VirtualDirectory {
return this.parent.getParent(layer - 1);
}
setContent(content: (file | directory)[]) {
updateContent(content: (file | directory)[]) {
this.files = this.files ?? [];
this.directorys = this.directorys ?? [];
const fileNames:string[] = this.files.map(v=>v.name)
const dirNames:string[] = this.directorys.map(v=>v.name)
const itemNames:string[] = content.map(v=>v.name)
const fileNames: string[] = this.files.map(v => v.name);
const dirNames: string[] = this.directorys.map(v => v.name);
const itemNames: string[] = content.map(v => v.name);
// 删去远程端已不存在的文件与文件夹
const _delete = (target: (VirtualFile | VirtualDirectory)[]) => {
let index = 0
while(index < target.length){
if(!itemNames.includes(target[index].name)){
target.splice(index, 1)
}else{
index += 1
let index = 0;
while (index < target.length) {
if (!itemNames.includes(target[index].name)) {
target.splice(index, 1);
} else {
index += 1;
}
}
}
_delete(this.files)
_delete(this.directorys)
};
_delete(this.files);
_delete(this.directorys);
// 加入新的文件与文件夹
for (let item of content) {
if (item.type === "file") {
if(!fileNames.includes(item.name)){
if (!fileNames.includes(item.name)) {
this.files.push(new VirtualFile(item, this));
}
} else if (item.type === "directory") {
if(!dirNames.includes(item.name)){
if (!dirNames.includes(item.name)) {
this.directorys.push(new VirtualDirectory(item, this));
}
}
}
}
hasChild(item: VirtualDirectory | VirtualFile): boolean {
if (item.type === "directory") {
return this.directorys?.includes(item) ?? false;
} else {
return this.files?.includes(item) ?? false;
}
}
}
export default VirtualDirectory;
+23 -11
View File
@@ -1,36 +1,48 @@
import VirtualDirectory from "./virtualDirectory";
import generateId from "@/hooks/generateId";
const getRandomWebSafeColor = (() => {
const webSafeColors = ["#009900", "#999900", "#009999", "#990099", "#0000ee"];
let counter = 0
return () => {
const color = webSafeColors[counter % webSafeColors.length]
counter += 1
return color;
};
})();
export default class VirtualPage {
constructor(initDirectory: VirtualDirectory) {
this.visible = true;
this.uid = generateId()
this.currentDirectory = initDirectory
this.refreshKey = Math.random()
this.uid = generateId();
this.currentDirectory = initDirectory;
this.refreshKey = Math.random();
this.color = getRandomWebSafeColor();
}
visible: boolean;
currentDirectory: VirtualDirectory;
// 区分每一个页面的唯一id
uid: number;
// 当refreshKey改变时需要刷新页面,目前还没接入刷新
refreshKey:number;
refreshKey: number;
get title(){
return this.currentDirectory.name
color: string;
get title() {
return this.currentDirectory.name;
}
// 切换显示状态
switchShow() {
this.visible = !this.visible;
}
// 设置(同步)正在展示的文件夹
setCurrrentDirectory(currDir: VirtualDirectory) {
this.currentDirectory = currDir
this.currentDirectory = currDir;
}
refresh(){
this.refreshKey = Math.random()
refresh() {
this.refreshKey = Math.random();
}
}