feat: 支持浏览器环境打开界面

This commit is contained in:
Frankie Huang 2025-04-28 03:24:19 +08:00
parent 23cadb8da4
commit d5d49014e5
2 changed files with 42 additions and 5 deletions

View File

@ -79,7 +79,12 @@ watch(markdownCode, (newMarkdownCode) => {
})
async function readFileContent(filePath) {
try {
const fileContent = await readTextFile(filePath);
let fileContent = '';
if (window.__TAURI_INTERNALS__ === undefined) {
fileContent = "# this is " + filePath;
} else {
fileContent = await readTextFile(filePath);
}
if (mainEditor.value.isEditorLoadingCompleted()) {
mainEditor.value.setMarkdownCode(fileContent);
} else {
@ -98,11 +103,16 @@ async function writeFileContent(markdownCode) {
return;
}
try {
const exist = await exists(currentFilePath.value);
if (!exist) {
throw new Error(currentFilePath.value + " 文件不存在.");
if (window.__TAURI_INTERNALS__ === undefined) {
// TODO currentFilePath
Message.warning('暂未实现接口');
} else {
const exist = await exists(currentFilePath.value);
if (!exist) {
throw new Error(currentFilePath.value + " 文件不存在.");
}
await writeTextFile(currentFilePath.value, markdownCode);
}
await writeTextFile(currentFilePath.value, markdownCode);
Message.success('文件更新成功:' + currentFilePath.value);
} catch (err) {
Message.error('文件更新失败:' + err);

View File

@ -65,6 +65,13 @@ export default {
}
},
async selectFolder() {
if (window.__TAURI_INTERNALS__ === undefined) {
// TODO
// rootPath
this.$emit('update:rootPath', '/root')
await this.exposeTreeData('/root')
return;
}
const folderPath = await open(
{
filters: [{ name: 'All Files', extensions: ['.'] }],
@ -79,6 +86,26 @@ export default {
},
//
async readDirRecursively(folderPath) {
if (window.__TAURI_INTERNALS__ === undefined) {
// TODO
const folderTreeData = {
"path": folderPath,
"name": folderPath.split('/').pop(),
"nodes": [{
"path": '/root/test.md',
"name": 'test.md',
"suffix": "md",
"directory": false,
},{
"path": '/root/test1.md',
"name": 'test1.md',
"suffix": "md",
"directory": false,
}],
"directory": true,
}
return folderTreeData;
}
//
let folderTreeNode = {
"path": folderPath,