feat: update...

This commit is contained in:
539943419 committed 2024-09-29 01:29:26 +08:00
1 parent 641700d730
commit 53ab0ad45b
2 files changed
+24 -4

No files matched your search

+23 -3
View File
@@ -5,14 +5,16 @@ import type { stats, file, directory } from "@/types/type.ts";
const miaoFetchApi = useMiaoFetchApi(); const miaoFetchApi = useMiaoFetchApi();
const vItemMap = new Map();
export interface Tree { export interface Tree {
name: string; name: string;
type: 'directory'; type: "directory";
path: string; path: string;
stats: stats; stats: stats;
files?: { files?: {
name: string; name: string;
type: 'file'; type: "file";
size: number; size: number;
stats: stats; stats: stats;
url: string; url: string;
@@ -28,6 +30,7 @@ export class VirtualFile {
this.parent = parent; this.parent = parent;
this.type = "file"; this.type = "file";
this.id = generateId(); this.id = generateId();
vItemMap.set(this.path, this);
} }
name: string; name: string;
type: "file"; type: "file";
@@ -46,11 +49,15 @@ export class VirtualFile {
} }
class VirtualDirectory { class VirtualDirectory {
/**
* 除非为根节点,否则必须设置parent
*/
constructor(info: directory, parent?: VirtualDirectory) { constructor(info: directory, parent?: VirtualDirectory) {
this.name = info.name; this.name = info.name;
this.stats = info.stats; this.stats = info.stats;
this.parent = parent ?? undefined; this.parent = parent ?? undefined;
this.id = generateId(); this.id = generateId();
vItemMap.set(this.path, this);
} }
// 文件夹名 // 文件夹名
name: string; name: string;
@@ -59,14 +66,17 @@ class VirtualDirectory {
// 子目录 // 子目录
directories?: VirtualDirectory[]; directories?: VirtualDirectory[];
// 没啥意义,标注一下就是了 // 没啥意义,标注一下就是了
type: "directory" = 'directory'; type: "directory" = "directory";
// 文件夹创建时间等杂项属性 // 文件夹创建时间等杂项属性
stats: stats; stats: stats;
// 父文件夹 // 父文件夹
parent?: VirtualDirectory; parent?: VirtualDirectory;
_isUpdated: boolean = false;
id: number; id: number;
// 用来存储一些标记信息啥的
storage: { [key: string]: any } = {}; storage: { [key: string]: any } = {};
/** /**
@@ -100,6 +110,13 @@ class VirtualDirectory {
return [...this.parent.getParents, this]; return [...this.parent.getParents, this];
} }
/**
* 获取当前文件夹是否已经请求过至少一次数据
*/
get isUpdated() {
return this._isUpdated;
}
/** /**
* 获取 layer 级父文件夹, 如getParent(1)就返回父级 * 获取 layer 级父文件夹, 如getParent(1)就返回父级
* @param {number} layer 需要跳转的层数 * @param {number} layer 需要跳转的层数
@@ -130,7 +147,10 @@ class VirtualDirectory {
}; };
} }
// todo: 重构这个函数
updateContent(content: (file | directory)[]) { updateContent(content: (file | directory)[]) {
this._isUpdated = true;
this.files = this.files ?? []; this.files = this.files ?? [];
this.directories = this.directories ?? []; this.directories = this.directories ?? [];
const fileNames: string[] = this.files.map(v => v.name); const fileNames: string[] = this.files.map(v => v.name);
+1 -1
View File
@@ -17,7 +17,7 @@ const pluginConfig: registerComponentOption = {
return false return false
} }
for (let i of vFiles) { for (let i of vFiles) {
for (let s of ['mp3']) { for (let s of ['mp3', 'flac', 'ogg']) {
if (i.name.endsWith(s)) { if (i.name.endsWith(s)) {
return true return true
} }