feat: 支持浏览器环境打开界面
This commit is contained in:
parent
23cadb8da4
commit
d5d49014e5
12
src/App.vue
12
src/App.vue
@ -79,7 +79,12 @@ watch(markdownCode, (newMarkdownCode) => {
|
|||||||
})
|
})
|
||||||
async function readFileContent(filePath) {
|
async function readFileContent(filePath) {
|
||||||
try {
|
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()) {
|
if (mainEditor.value.isEditorLoadingCompleted()) {
|
||||||
mainEditor.value.setMarkdownCode(fileContent);
|
mainEditor.value.setMarkdownCode(fileContent);
|
||||||
} else {
|
} else {
|
||||||
@ -98,11 +103,16 @@ async function writeFileContent(markdownCode) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (window.__TAURI_INTERNALS__ === undefined) {
|
||||||
|
// TODO 调用接口更新 currentFilePath 文件内容
|
||||||
|
Message.warning('暂未实现接口');
|
||||||
|
} else {
|
||||||
const exist = await exists(currentFilePath.value);
|
const exist = await exists(currentFilePath.value);
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
throw new Error(currentFilePath.value + " 文件不存在.");
|
throw new Error(currentFilePath.value + " 文件不存在.");
|
||||||
}
|
}
|
||||||
await writeTextFile(currentFilePath.value, markdownCode);
|
await writeTextFile(currentFilePath.value, markdownCode);
|
||||||
|
}
|
||||||
Message.success('文件更新成功:' + currentFilePath.value);
|
Message.success('文件更新成功:' + currentFilePath.value);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Message.error('文件更新失败:' + err);
|
Message.error('文件更新失败:' + err);
|
||||||
|
|||||||
@ -65,6 +65,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async selectFolder() {
|
async selectFolder() {
|
||||||
|
if (window.__TAURI_INTERNALS__ === undefined) {
|
||||||
|
// TODO 请求后端接口,选择目录
|
||||||
|
// 告诉父组件,rootPath 的值已变化
|
||||||
|
this.$emit('update:rootPath', '/root')
|
||||||
|
await this.exposeTreeData('/root')
|
||||||
|
return;
|
||||||
|
}
|
||||||
const folderPath = await open(
|
const folderPath = await open(
|
||||||
{
|
{
|
||||||
filters: [{ name: 'All Files', extensions: ['.'] }],
|
filters: [{ name: 'All Files', extensions: ['.'] }],
|
||||||
@ -79,6 +86,26 @@ export default {
|
|||||||
},
|
},
|
||||||
// 遍历文件夹,返回文件树
|
// 遍历文件夹,返回文件树
|
||||||
async readDirRecursively(folderPath) {
|
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 = {
|
let folderTreeNode = {
|
||||||
"path": folderPath,
|
"path": folderPath,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user