diff --git a/src/App.vue b/src/App.vue index e08af9b..33380a2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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); diff --git a/src/components/UI/SelectFolder.vue b/src/components/UI/SelectFolder.vue index 6ce10be..57a5aed 100644 --- a/src/components/UI/SelectFolder.vue +++ b/src/components/UI/SelectFolder.vue @@ -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,