diff --git a/src/main/index.js b/src/main/index.js index 9f31876..b4b6a1e 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,8 +1,7 @@ import { app, shell, BrowserWindow, nativeImage, ipcMain } from 'electron' import * as path from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' -import { machineIdSync } from 'node-machine-id'; - +const fs = require('fs'); // logo const logoIcon = nativeImage.createFromPath(path.join(__dirname, '../../public/icon/icon.jpg')) // 主窗口 @@ -55,10 +54,107 @@ app.whenReady().then(() => { // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) - ipcMain.on('deviceIdentify', () => { - let res = machineIdSync() - mainWindow.webContents.send(`deviceResult`, res) + // 新增文件夹 + ipcMain.on('createFloder', (e, pathListStr) => { + let pathList = JSON.parse(pathListStr) + // 获取应用程序的用户数据目录 + let successList = [] + let errorList = [] + for (let index = 0; index < pathList.length; index++) { + let element = pathList[index]; + let folderPath = path.join("E:\\test\\", element); + try { + fs.mkdirSync(`${folderPath}\\`, { recursive: true }); + successList.push(element) + } catch (error) { + errorList.push(element) + } + } + mainWindow.webContents.send(`createFloderResult`, JSON.stringify({ successList, errorList })) + }) + // 重命名文件夹 + ipcMain.on('putFloder', (e, pathObjStr) => { + let pathObj = JSON.parse(pathObjStr) + // 获取应用程序的用户数据目录 + let successList = [] + let errorList = [] + let oldfolderPath = path.join("E:\\test\\", pathObj.oldPath); + let newfolderPath = path.join("E:\\test\\", pathObj.newPath); + try { + fs.rename(`${oldfolderPath}\\`, `${newfolderPath}\\`, error => { + if (error) { + errorList.push(pathObj) + } else { + successList.push(pathObj) + } + mainWindow.webContents.send(`putFloderResult`, JSON.stringify({ successList, errorList })) + }); + } catch (error) { + } + }) + // 删除文件夹 + ipcMain.on('delFloder', (e, pathObjStr) => { + let pathObj = JSON.parse(pathObjStr) + // 获取应用程序的用户数据目录 + let successList = [] + let errorList = [] + let folderPath = path.join("E:\\test\\", pathObj.name); + fs.rm(folderPath, { recursive: true, force: true }, function (err) { + if (err) { + errorList.push(pathObj) + } else { + successList.push(pathObj) + } + mainWindow.webContents.send(`delFloderResult`, JSON.stringify({ successList, errorList })) + }); + }) + // 新增文件 + ipcMain.on('createFile', (e, pathListStr) => { + let pathList = JSON.parse(pathListStr) + // 获取应用程序的用户数据目录 + let successList = [] + let errorList = [] + for (let index = 0; index < pathList.length; index++) { + let element = pathList[index]; + let destinationFilePath = path.join("E:\\test\\", element.path); + let sourceFilePath = element.prePath; + try { + fs.copyFileSync(sourceFilePath, destinationFilePath); + successList.push(element) + } catch (error) { + errorList.push(element) + } + } + mainWindow.webContents.send(`createFileResult`, JSON.stringify({ successList, errorList })) + }) + // 重命名文件 + ipcMain.on('putFile', (e, paramsStr) => { + let paramsObj = JSON.parse(paramsStr) + mainWindow.webContents.send(`putFileResult`, paramsObj) + }) + // 删除文件 + ipcMain.on('delFile', (e, paramsStr) => { + let paramsObj = JSON.parse(paramsStr) + mainWindow.webContents.send(`delFileResult`, paramsObj) + }) + // 打开文件 + ipcMain.on('openFile', (e, pathStr) => { + let filePath = path.join("E:\\test\\", pathStr); + shell.openPath(filePath) }) + // 下载文件 + ipcMain.on('downloadFile', (e, pathStr) => { + let filePath = path.join("E:\\test\\", pathStr); + // 读取文件后传给前端 + fs.readFile(filePath, function (err, data) { + if (err) { + console.error('读取文件时出错:', err); + mainWindow.webContents.send(`downloadFileResult`, { success: false, error: err.message }); + } else { + mainWindow.webContents.send(`downloadFileResult`, { success: true, data, path: pathStr }); + } + }); + }); }) app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required'); // Quit when all windows are closed, except on macOS. There, it's common diff --git a/src/renderer/src/assets/js/db.js b/src/renderer/src/assets/js/db.js index 5214de3..fb7f425 100644 --- a/src/renderer/src/assets/js/db.js +++ b/src/renderer/src/assets/js/db.js @@ -4,6 +4,6 @@ export const myDatabase = new Dexie('myDatabase'); // 定义数据库版本 myDatabase.version(1).stores({ - treeList: '++id, label, currentId, preId, prepreId, level, note, create_at, update_at', + treeList: '++id, label, currentId, path, status, preId, delete, fileList, prepreId, level, note, create_at, update_at', fileList: '++id, treeId, xiangmuName, juanName, fileName, fileType, uploadTime, status, path, note, create_at, update_at' }); \ No newline at end of file diff --git a/src/renderer/src/assets/json/file.json b/src/renderer/src/assets/json/file.json index 5be6ccb..e849f28 100644 --- a/src/renderer/src/assets/json/file.json +++ b/src/renderer/src/assets/json/file.json @@ -4,7 +4,6 @@ "prop": "xiangmuName", "type": "text", "tableShow": true, - "formShow": true, "export": true }, { @@ -17,50 +16,68 @@ "label": "文件名", "prop": "fileName", "type": "text", + "tooltip": "如果不填写则默认使用上传文件的文件名", "tableShow": true, - "formShow": true, + "formShow": false, "export": true }, + { + "label": "文件", + "prop": "file", + "type": "file", + "tableShow": false, + "formShow": true, + "export": false + }, + { + "label": "文件大小", + "prop": "size", + "type": "size", + "tableShow": true, + "formShow": false, + "export": false + }, { "label": "文件类型", "prop": "fileType", "type": "select", + "tooltip": "如果不填写则默认使用上传文件的文件类型,如果填写请正确填写", "option": [ { "label": "doc", - "value": "doc" + "value": "application/msword" }, { "label": "docx", - "value": "docx" + "value": "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, { "label": "jpg", - "value": "jpg" + "value": "image/jpeg" }, { "label": "mp4", - "value": "mp4" + "value": "video/mp4" }, { "label": "pdf", - "value": "pdf" + "value": "application/pdf" }, { "label": "png", - "value": "png" + "value": "image/png" }, { "label": "xls", - "value": "xls" + "value": "application/vnd.ms-excel" }, { "label": "xlsx", - "value": "xlsx" + "value": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" } ], "tableShow": true, - "formShow": true, + "formShow": false, "export": true }, { @@ -77,11 +94,15 @@ "type": "select", "option": [ { - "value": "0", + "value": "", + "label": "全部" + }, + { + "value": "正常", "label": "正常" }, { - "value": "1", + "value": "注销", "label": "注销" } ], @@ -94,7 +115,7 @@ "prop": "path", "type": "text", "tableShow": true, - "formShow": true, + "formShow": false, "export": true }, { diff --git a/src/renderer/src/components/formcomponent.vue b/src/renderer/src/components/formcomponent.vue index a845edb..d6f8d3a 100644 --- a/src/renderer/src/components/formcomponent.vue +++ b/src/renderer/src/components/formcomponent.vue @@ -1,14 +1,14 @@ - + - + - + @@ -30,13 +30,27 @@ :disabled="['create_at', 'update_at'].indexOf(formItem.prop) !== -1" :placeholder="`请选择${formItem.label}`" /> + + + + + + + 选择文件 + + +