用户:
145a查看:15 回复:19 评论:15 创建时间:2023-02-25T22:20:09


说一下实现方法吧。就是用岛3提供的resources接口结合Array.prototyor.reduce
以下是源代码(用了145lab,当伪代码就行)
Box3Entity.prototype.viewFiles = async function (path = "") {
const files = resources.ls(path);
let options = files.reduce(
(l, v) => {
l.push(
concat(
"[",
v.type,
"]",
v.path.includes("/")?v.path.sliceFrom("/").slice(1):v.path
)
);
return l;
},
["[directory]..."]
);
await this.selectDialog(
"查看文件",
concat(
"/",
path
),
options
);
if (!this.dialogResult || this.dialogResult.value == "[directory]...") return;
const index = this.dialogResult.index - 1;
const viewFile = files[index];
if (viewFile.type == "directory") {
await this.viewFiles(viewFile.path);
return await this.viewFiles(path);
} else {
const viewPath = viewFile.path;
await this.textDialog(
"查看文件",
concat(
viewPath,
endline,
"请在创作端左侧控件区域的文件菜单中查看类型为",
"“",
viewFile.type,
"”",
"的文件。"
)
);
return await this.viewFiles(path);
}
}
()
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
点赞0
评论