const {join, basename// 拿到文件名, extname// 文件拓展名, dirname// 文件的路径} = window.require('path')const {remote} = window.require('electron')remote.dialog.showOpenDialog({ title: '选择导入的markdown文件', properties: ['openFile', 'multiSelections'], filters: [ { name: 'Markdown files', extensions: ['md'] } ] }).then(res => { if (Array.isArray(res.filePaths)) { // filter files had beed shown in fileList const filteredPaths = res.filePaths.filter(path => { const alreadyAddedFile = Object.values(files).find(file => { return file.path === path }) return !alreadyAddedFile }) // 转成需要格式的数组 const importFilesArr = filteredPaths.map(path => { return { id: uuidv4(), title: basename(path, extname(path)), // 拿到文件名 没有后缀名 path } }) const newFiles = {...files, ...flattenArr(importFilesArr)} setFiles(newFiles) saveFilesToStore(newFiles) if (importFilesArr.length) { remote.dialog.showMessageBox({ type:'info', message: `成功导入了${importFilesArr.length}个文件`, title: '提示' }) } } })