This commit is contained in:
539943419 committed 2024-08-10 18:57:12 +08:00
1 parent d9363d3b93
commit a668b3b840
13 files changed
+554 -145

No files matched your search

+32 -6
View File
@@ -1,18 +1,21 @@
import generateId from "@/hooks/generateId";
import type { stats, file, directory } from "@/types/type.ts";
class VirtualFile {
export class VirtualFile {
constructor(info: file, parent: VirtualDirectory) {
this.name = info.name;
this.size = info.size;
this.stats = info.stats;
this.parent = parent;
this.type = "file";
this.uid = generateId()
}
name: string;
type: "file";
size: number;
stats: stats;
parent: VirtualDirectory;
uid: number
get path() {
return `${this.parent.path}${this.name}`;
}
@@ -24,7 +27,7 @@ class VirtualDirectory {
this.type = "directory";
this.stats = info.stats;
this.parent = parent ?? undefined;
// 这里要改
this.uid = generateId()
}
// 文件夹名
name: string;
@@ -39,6 +42,8 @@ class VirtualDirectory {
// 父文件夹
parent?: VirtualDirectory;
uid: number
/**
* 获取相对于根目录的路径的层数
* 用于目录下文件定位
@@ -83,13 +88,34 @@ class VirtualDirectory {
}
setContent(content: (file | directory)[]) {
this.files = [];
this.directorys = [];
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 _delete = (target: (VirtualFile | VirtualDirectory)[]) => {
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)
// 加入新的文件与文件夹
for (let item of content) {
if (item.type === "file") {
this.files.push(new VirtualFile(item, this));
if(!fileNames.includes(item.name)){
this.files.push(new VirtualFile(item, this));
}
} else if (item.type === "directory") {
this.directorys.push(new VirtualDirectory(item, this));
if(!dirNames.includes(item.name)){
this.directorys.push(new VirtualDirectory(item, this));
}
}
}
}
+26 -12
View File
@@ -1,22 +1,36 @@
import { ref, Ref } from "vue";
import VirtualDirectory from "./virtualDirectory";
import generateId from "@/hooks/generateId";
export default class VirtualPage {
constructor() {
this.visible = ref<boolean>(true);
this.title = ref<string>("");
this.uid = Math.ceil(Math.random() * 10000000000000);
constructor(initDirectory: VirtualDirectory) {
this.visible = true;
this.uid = generateId()
this.currentDirectory = initDirectory
this.refreshKey = Math.random()
}
visible: Ref<boolean>;
title: Ref<string>;
visible: boolean;
currentDirectory: VirtualDirectory;
// 区分每一个页面的唯一id
uid: number;
// 当refreshKey改变时需要刷新页面,目前还没接入刷新
refreshKey:number;
get title(){
return this.currentDirectory.name
}
// 切换显示状态
switchShow() {
// @ts-ignore 你只要知道这是对的就行了
this.visible = !this.visible;
}
setTitle(newTitle: string) {
// @ts-ignore 你只要知道这是对的就行了
this.title = newTitle;
// 设置(同步)正在展示的文件夹
setCurrrentDirectory(currDir: VirtualDirectory) {
this.currentDirectory = currDir
}
refresh(){
this.refreshKey = Math.random()
}
}