diff --git a/src/main/file.js b/src/main/file.js index c0b8810..eecd08c 100644 --- a/src/main/file.js +++ b/src/main/file.js @@ -5,13 +5,27 @@ import { dialog } from 'electron' const manager = new ElectronDownloadManager() export default async function ({ app, shell, BrowserWindow, ipcMain }) { const userDataPath = app.getPath('userData') + const appRootFilePath = userDataPath + '\\selfFile\\' + ipcMain.on('is-have-local-file', (e, fileNewName) => { + let filePath = appRootFilePath + fileNewName + fs.access(filePath, fs.constants.F_OK, (err) => { + if (err) { + e.reply('is-have-local-file-reply'+fileNewName, false) + return + } + e.reply('is-have-local-file-reply'+fileNewName, true) + }) + }) //默认浏览器打开url ipcMain.on('open-url-browser', (e, url) => { shell.openPath(url) }) //使用默认应用打开本地文件 - ipcMain.on('open-path-app', (e, path) => { - shell.openExternal(path) + ipcMain.on('open-path-app', (e, destination) => { + let path = appRootFilePath + destination + shell.openExternal(path).catch((error) => { + console.log(error) + }) }) //复制文件 @@ -21,32 +35,42 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) { }) }) + //获取应用文件目录 + ipcMain.on('get-root-file-path', (e) => { + e.reply('get-root-file-path-reply', appRootFilePath) + }) + //下载文件 - ipcMain.on('download-file-default', (e, url) => { + ipcMain.on('download-file-default', (e, { url, fileName }) => { createFolder('selfFile').then(async () => { const browserWindow = BrowserWindow.fromId(e.sender.id) const id = await manager.download({ window: browserWindow, url: url, - directory: userDataPath + '/selfFile/', + saveAsFilename: fileName, + directory: appRootFilePath, callbacks: { onDownloadStarted: async ({ id, item, webContents }) => { // Do something with the download id }, onDownloadProgress: async ({ id, item, percentCompleted }) => { - browserWindow.webContents.invoke('download-progress', { - id, - percentCompleted, - // Get the number of bytes received so far - bytesReceived: item.getReceivedBytes() - }) }, onDownloadCompleted: async ({ id, item }) => { - console.log(item) + console.log('完成') + e.reply('download-file-default'+fileName,true) }, - onDownloadCancelled: async () => {}, - onDownloadInterrupted: async () => {}, - onError: (err, data) => {} + onDownloadCancelled: async () => { + console.log('取消') + e.reply('download-file-default'+fileName,false) + }, + onDownloadInterrupted: async () => { + console.log('中断') + e.reply('download-file-default'+fileName,false) + }, + onError: (err, data) => { + console.log(err.toString()) + e.reply('download-file-default'+fileName,false) + } } }) }) @@ -59,7 +83,7 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) { * @param {String} fileName 文件名称包括后缀名,例如图1.png */ ipcMain.on('save-as', function (event, url, fileName) { - let win = BrowserWindow.getFocusedWindow(); + let win = BrowserWindow.getFocusedWindow() //通过扩展名识别文件类型 let filters = [{ name: '全部文件', extensions: ['*'] }] let ext = path.extname(fileName) //获取扩展名 @@ -101,7 +125,7 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) { }) function copyFile(source, destination, callback) { - let path = userDataPath + '\\selfFile\\' + destination + let path = appRootFilePath + destination createFolder('selfFile').then(() => { const readStream = fs.createReadStream(source) const writeStream = fs.createWriteStream(path) diff --git a/src/renderer/src/api/file/index.js b/src/renderer/src/api/file/index.js index c4b877f..d4394ac 100644 --- a/src/renderer/src/api/file/index.js +++ b/src/renderer/src/api/file/index.js @@ -16,6 +16,13 @@ export function deleteSmarttalk(id) { }) } +export function deleteSmarttalkBatch(ids) { + return request({ + url: '/smarttalk/file/' + ids, + method: 'delete' + }) +} + export const updateSmarttalk = (params) => { return request({ url: '/smarttalk/file/updateSmarttalk', @@ -23,3 +30,11 @@ export const updateSmarttalk = (params) => { params }) } + +export const moveSmarttalk = (params) => { + return request({ + url: '/smarttalk/file/moveSmarttalk', + method: 'post', + params + }) +} diff --git a/src/renderer/src/layout/components/Uploader.vue b/src/renderer/src/layout/components/Uploader.vue index 5d554ce..1dc7d9d 100644 --- a/src/renderer/src/layout/components/Uploader.vue +++ b/src/renderer/src/layout/components/Uploader.vue @@ -1,5 +1,5 @@