From cabb37c5b94c7933b716861f180c662bd7f291ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Wed, 28 Aug 2024 09:33:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=EF=BC=9A=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E9=80=89=E6=8B=A9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/electron/fileHandle.js | 13 +++++++++---- web/src/electron/preload.js | 2 +- web/src/pages/Edit/components/NodeAttachment.vue | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/web/src/electron/fileHandle.js b/web/src/electron/fileHandle.js index 2001fa7b..8739b04c 100644 --- a/web/src/electron/fileHandle.js +++ b/web/src/electron/fileHandle.js @@ -128,9 +128,14 @@ export const bindFileHandleEvent = ({ mainWindow }) => { }) // 选择本地文件 - ipcMain.handle('selectFile', event => { + ipcMain.handle('selectFile', (event, openDirectory = false) => { + const properties = [] + if (openDirectory) { + properties.push('openDirectory') + } const res = dialog.showOpenDialogSync({ - title: '选择' + title: '选择', + properties }) if (res && res[0]) { console.log(111, res[0]) @@ -229,8 +234,8 @@ export const bindFileHandleEvent = ({ mainWindow }) => { shell.showItemInFolder(file) }) - // 打开指定文件 - ipcMain.handle('openPath', (event, file) => { + // 打开指定文件 + ipcMain.handle('openPath', (event, file) => { const exist = fs.existsSync(file) if (!exist) { return '文件不存在' diff --git a/web/src/electron/preload.js b/web/src/electron/preload.js index 1dd5dfb1..3738af34 100644 --- a/web/src/electron/preload.js +++ b/web/src/electron/preload.js @@ -25,7 +25,7 @@ contextBridge.exposeInMainWorld('electronAPI', { openFile: file => ipcRenderer.invoke('openFile', file), selectOpenFile: () => ipcRenderer.send('selectOpenFile'), copyFile: file => ipcRenderer.invoke('copyFile', file), - selectFile: () => ipcRenderer.invoke('selectFile'), + selectFile: openDirectory => ipcRenderer.invoke('selectFile', openDirectory), openPath: path => ipcRenderer.invoke('openPath', path), saveClientConfig: config => ipcRenderer.invoke('saveClientConfig', config), getClientConfig: () => ipcRenderer.invoke('getClientConfig') diff --git a/web/src/pages/Edit/components/NodeAttachment.vue b/web/src/pages/Edit/components/NodeAttachment.vue index 065fccdd..ca2ba575 100644 --- a/web/src/pages/Edit/components/NodeAttachment.vue +++ b/web/src/pages/Edit/components/NodeAttachment.vue @@ -70,7 +70,7 @@ export default { // activeNodes.forEach(node => { // node.setAttachment('/test.md', '我去') // }) - const file = await window.electronAPI.selectFile() + const file = await window.electronAPI.selectFile(true) if (file) { activeNodes.forEach(node => { node.setAttachment(file.file, file.name)