feat:打开目录显示

This commit is contained in:
shixiaohua 2024-01-25 10:07:09 +08:00
parent fa2222386e
commit ef1aa74011
5 changed files with 223 additions and 89 deletions

133
package-lock.json generated
View File

@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.1.0",
"node-sass": "^7.0.3"
},
"devDependencies": {
@ -7105,7 +7106,6 @@
"version": "2.1.1",
"resolved": "https://registry.npmmirror.com/ajv-formats/-/ajv-formats-2.1.1.tgz",
"integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
"dev": true,
"dependencies": {
"ajv": "^8.0.0"
},
@ -7122,7 +7122,6 @@
"version": "8.12.0",
"resolved": "https://registry.npmmirror.com/ajv/-/ajv-8.12.0.tgz",
"integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==",
"dev": true,
"dependencies": {
"fast-deep-equal": "^3.1.1",
"json-schema-traverse": "^1.0.0",
@ -7133,8 +7132,7 @@
"node_modules/ajv-formats/node_modules/json-schema-traverse": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
"dev": true
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="
},
"node_modules/ajv-keywords": {
"version": "3.5.2",
@ -7627,6 +7625,14 @@
"node": ">= 4.0.0"
}
},
"node_modules/atomically": {
"version": "1.7.0",
"resolved": "https://registry.npmmirror.com/atomically/-/atomically-1.7.0.tgz",
"integrity": "sha512-Xcz9l0z7y9yQ9rdDaxlmaI4uJHf/T8g9hOEzJcsEqX2SjCj4J20uK7+ldkDHMbpJDK76wF7xEIgxc/vSlsfw5w==",
"engines": {
"node": ">=10.12.0"
}
},
"node_modules/author-regex": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/author-regex/-/author-regex-1.0.0.tgz",
@ -9292,6 +9298,56 @@
"decamelize": "^1.2.0"
}
},
"node_modules/conf": {
"version": "10.2.0",
"resolved": "https://registry.npmmirror.com/conf/-/conf-10.2.0.tgz",
"integrity": "sha512-8fLl9F04EJqjSqH+QjITQfJF8BrOVaYr1jewVgSRAEWePfxT0sku4w2hrGQ60BC/TNLGQ2pgxNlTbWQmMPFvXg==",
"dependencies": {
"ajv": "^8.6.3",
"ajv-formats": "^2.1.1",
"atomically": "^1.7.0",
"debounce-fn": "^4.0.0",
"dot-prop": "^6.0.1",
"env-paths": "^2.2.1",
"json-schema-typed": "^7.0.3",
"onetime": "^5.1.2",
"pkg-up": "^3.1.0",
"semver": "^7.3.5"
},
"engines": {
"node": ">=12"
}
},
"node_modules/conf/node_modules/ajv": {
"version": "8.12.0",
"resolved": "https://registry.npmmirror.com/ajv/-/ajv-8.12.0.tgz",
"integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==",
"dependencies": {
"fast-deep-equal": "^3.1.1",
"json-schema-traverse": "^1.0.0",
"require-from-string": "^2.0.2",
"uri-js": "^4.2.2"
}
},
"node_modules/conf/node_modules/json-schema-traverse": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="
},
"node_modules/conf/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmmirror.com/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/confusing-browser-globals": {
"version": "1.0.11",
"resolved": "https://registry.npmmirror.com/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz",
@ -10074,6 +10130,25 @@
"integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==",
"dev": true
},
"node_modules/debounce-fn": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/debounce-fn/-/debounce-fn-4.0.0.tgz",
"integrity": "sha512-8pYCQiL9Xdcg0UPSD3d+0KMlOjp+KGU5EPwYddgzQ7DATsg4fuUDjQtsYLmWjnk2obnNHgV3vE2Y4jejSOJVBQ==",
"dependencies": {
"mimic-fn": "^3.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/debounce-fn/node_modules/mimic-fn": {
"version": "3.1.0",
"resolved": "https://registry.npmmirror.com/mimic-fn/-/mimic-fn-3.1.0.tgz",
"integrity": "sha512-Ysbi9uYW9hFyfrThdDEQuykN4Ey6BuwPD2kpI5ES/nFTDn/98yxYNLZJcgUAKPT/mcrLLKaGzJR9YVxJrIdASQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz",
@ -10586,6 +10661,25 @@
"tslib": "^2.0.3"
}
},
"node_modules/dot-prop": {
"version": "6.0.1",
"resolved": "https://registry.npmmirror.com/dot-prop/-/dot-prop-6.0.1.tgz",
"integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==",
"dependencies": {
"is-obj": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/dot-prop/node_modules/is-obj": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/is-obj/-/is-obj-2.0.0.tgz",
"integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==",
"engines": {
"node": ">=8"
}
},
"node_modules/dotenv": {
"version": "10.0.0",
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
@ -11209,6 +11303,23 @@
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
},
"node_modules/electron-store": {
"version": "8.1.0",
"resolved": "https://registry.npmmirror.com/electron-store/-/electron-store-8.1.0.tgz",
"integrity": "sha512-2clHg/juMjOH0GT9cQ6qtmIvK183B39ZXR0bUoPwKwYHJsEF3quqyDzMFUAu+0OP8ijmN2CbPRAelhNbWUbzwA==",
"dependencies": {
"conf": "^10.2.0",
"type-fest": "^2.17.0"
}
},
"node_modules/electron-store/node_modules/type-fest": {
"version": "2.19.0",
"resolved": "https://registry.npmmirror.com/type-fest/-/type-fest-2.19.0.tgz",
"integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==",
"engines": {
"node": ">=12.20"
}
},
"node_modules/electron-to-chromium": {
"version": "1.4.628",
"resolved": "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.628.tgz",
@ -17103,6 +17214,11 @@
"resolved": "https://registry.npmmirror.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
},
"node_modules/json-schema-typed": {
"version": "7.0.3",
"resolved": "https://registry.npmmirror.com/json-schema-typed/-/json-schema-typed-7.0.3.tgz",
"integrity": "sha512-7DE8mpG+/fVw+dTpjbxnx47TaMnDfOI1jwft9g1VybltZCduyRQPJPvc+zzKY9WPHxhPWczyFuYa6I8Mw4iU5A=="
},
"node_modules/json-stable-stringify-without-jsonify": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
@ -18133,7 +18249,6 @@
"version": "2.1.0",
"resolved": "https://registry.npmmirror.com/mimic-fn/-/mimic-fn-2.1.0.tgz",
"integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",
"dev": true,
"engines": {
"node": ">=6"
}
@ -19221,7 +19336,6 @@
"version": "5.1.2",
"resolved": "https://registry.npmmirror.com/onetime/-/onetime-5.1.2.tgz",
"integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==",
"dev": true,
"dependencies": {
"mimic-fn": "^2.1.0"
},
@ -19671,7 +19785,6 @@
"version": "3.1.0",
"resolved": "https://registry.npmmirror.com/pkg-up/-/pkg-up-3.1.0.tgz",
"integrity": "sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==",
"dev": true,
"dependencies": {
"find-up": "^3.0.0"
},
@ -19683,7 +19796,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/find-up/-/find-up-3.0.0.tgz",
"integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==",
"dev": true,
"dependencies": {
"locate-path": "^3.0.0"
},
@ -19695,7 +19807,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/locate-path/-/locate-path-3.0.0.tgz",
"integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==",
"dev": true,
"dependencies": {
"p-locate": "^3.0.0",
"path-exists": "^3.0.0"
@ -19708,7 +19819,6 @@
"version": "2.3.0",
"resolved": "https://registry.npmmirror.com/p-limit/-/p-limit-2.3.0.tgz",
"integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
"dev": true,
"dependencies": {
"p-try": "^2.0.0"
},
@ -19720,7 +19830,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/p-locate/-/p-locate-3.0.0.tgz",
"integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==",
"dev": true,
"dependencies": {
"p-limit": "^2.0.0"
},
@ -19732,7 +19841,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/path-exists/-/path-exists-3.0.0.tgz",
"integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==",
"dev": true,
"engines": {
"node": ">=4"
}
@ -22725,7 +22833,6 @@
"version": "2.0.2",
"resolved": "https://registry.npmmirror.com/require-from-string/-/require-from-string-2.0.2.tgz",
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}

View File

@ -50,6 +50,7 @@
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.1.0",
"node-sass": "^7.0.3"
},
"browser": {

View File

@ -1,22 +1,22 @@
const { app, Menu, shell, dialog} = require('electron')
const {stat,readdir} = require("fs/promises");
const {app, Menu, shell, dialog} = require('electron')
const {stat, readdir} = require("fs/promises");
const isMac = process.platform === 'darwin'
exports.menuRebuild=(mainWindow)=> {
exports.menuRebuild = (mainWindow) => {
return template = [
// { role: 'appMenu' }
...(isMac
? [{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
{role: 'about'},
{type: 'separator'},
{role: 'services'},
{type: 'separator'},
{role: 'hide'},
{role: 'hideOthers'},
{role: 'unhide'},
{type: 'separator'},
{role: 'quit'}
]
}]
: []),
@ -24,27 +24,36 @@ exports.menuRebuild=(mainWindow)=> {
{
label: 'File',
submenu: [
{label:'打开目录',
{
label: '打开目录',
click: async () => {
const { dialog } = require('electron')
const {dialog} = require('electron')
dialog.showOpenDialog({
properties: ['openDirectory']
}).then(async result => {
console.log(result.canceled)
// 不取消就发送目录
if (!result.canceled) {
console.log('result.filePaths',result.filePaths)
const {readdir,stat} = require('fs/promises')
console.log('result.filePaths', result.filePaths)
const {readdir, stat} = require('fs/promises')
try {
const files = await readdir(result.filePaths[0]);
const fileStats = []
const fileStateList = []
const fileChildList = []
fileStateList.push({
"fileName": result.filePaths[0],
"filePath": result.filePaths[0],
"dirFlag": true,
"childList": fileChildList
})
for (let i = 0; i < files.length; i++) {
const state = await stat(result.filePaths+'/'+files[i]);
fileStats.push({'fileName': files[i], 'dir':state.isDirectory()})
const state = await stat(result.filePaths[0] + '/' + files[i]);
fileChildList.push({
'fileName': files[i],
"filePath": result.filePaths[0]+ '/' +files[i],
'dirFlag': state.isDirectory()
})
}
mainWindow.webContents.send('openDirectory',
{'fileDir':result.filePaths[0],'fileList':fileStats}
)
mainWindow.webContents.send('openDirectory', fileStateList)
} catch (err) {
console.error(err);
}
@ -54,42 +63,43 @@ exports.menuRebuild=(mainWindow)=> {
})
}
},
{label:'全部应用',
{
label: '全部应用',
click: () => {
mainWindow.webContents.send('redirectUrl', '/GateWay')
}
},
isMac ? { role: 'close' } : { role: 'quit' },
isMac ? {role: 'close'} : {role: 'quit'},
]
},
// { role: 'editMenu' }
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },// 分割线
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{role: 'undo'},
{role: 'redo'},
{type: 'separator'},// 分割线
{role: 'cut'},
{role: 'copy'},
{role: 'paste'},
...(isMac
? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{role: 'pasteAndMatchStyle'},
{role: 'delete'},
{role: 'selectAll'},
{type: 'separator'},
{
label: 'Speech',
submenu: [
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
{role: 'startSpeaking'},
{role: 'stopSpeaking'}
]
}
]
: [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
{role: 'delete'},
{type: 'separator'},
{role: 'selectAll'}
])
]
},
@ -97,33 +107,33 @@ exports.menuRebuild=(mainWindow)=> {
{
label: 'View',
submenu: [
{ label: '界面布局' },
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
{label: '界面布局'},
{role: 'reload'},
{role: 'forceReload'},
{role: 'toggleDevTools'},
{type: 'separator'},
{role: 'resetZoom'},
{role: 'zoomIn'},
{role: 'zoomOut'},
{type: 'separator'},
{role: 'togglefullscreen'}
]
},
// { role: 'windowMenu' }
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
{role: 'minimize'},
{role: 'zoom'},
...(isMac
? [
{ type: 'separator' },
{ role: 'front' },
{ type: 'separator' },
{ role: 'window' }
{type: 'separator'},
{role: 'front'},
{type: 'separator'},
{role: 'window'}
]
: [
{ role: 'close' }
{role: 'close'}
])
]
},
@ -133,7 +143,7 @@ exports.menuRebuild=(mainWindow)=> {
{
label: 'Learn More',
click: async () => {
const { shell } = require('electron')
const {shell} = require('electron')
await shell.openExternal('http://www.huaruyu.com')
}
}

View File

@ -65,9 +65,9 @@ const getParentKey = (key, tree) => {
function generateChildList(fileList){
const result = []
for (let i = 0; i < fileList.length; i++) {
const {fileName,dir}=fileList[i];
const {fileName,filePath}=fileList[i];
result.push({
"key":fileName,
"key":filePath,
"title":fileName,
"icon":<FolderOutlined />,
"children":[]
@ -79,26 +79,31 @@ const ItemTree = () => {
useEffect(()=>{
store.subscribe(() =>{
console.log("打开目录")
let fileDirDate = store.getState().dirMessage.data;
console.log("打开目录fileDirDate:",fileDirDate)
for (let i = 0; i < fileDirDate.length; i++) {
const node = fileDirDate[i];
console.log('dataNode:',node)
const { fileDir,fileList } = node;
const childList=[]
if (fileList) {
childList.push(generateChildList(fileList));
console.log("node:",node)
const { fileName,filePath,childList } = node;
const childListM=[]
if (childList.length>0) {
childListM.push(...generateChildList(childList));
}
if (defaultData.filter(fileMessage=>
fileMessage.key===filePath
).length===0){
defaultData.push({
"key":filePath,
"title":fileName,
"icon":<FolderOutlined />,
"children":childListM
});
}
defaultData.push({
"key":fileDir,
"title":fileDir,
"icon":<FolderOutlined />,
"children":childList
});
}
setDefaultValueState(defaultData)
console.log("Array.from(new Set(defaultData)):",Array.from(new Set(defaultData)))
setDefaultValueState(Array.from(new Set(defaultData)))
})
},defaultData)
},[])
const [expandedKeys, setExpandedKeys] = useState([]);
const [searchValue, setSearchValue] = useState('');

View File

@ -1,4 +1,5 @@
import { createSlice } from '@reduxjs/toolkit'
import {Alert} from "antd";
export const dirMessageSlice = createSlice({
name: 'dirMessage',
@ -9,8 +10,18 @@ export const dirMessageSlice = createSlice({
dirAdd: (state, action) => {
console.log("dirMessage:dirAdd", state, action)
if(action.payload){
// 路径跳转
state.data=[...state.data,action.payload];
// 新添加进来的目录,要判断是否重复,如果重复则提示
let filter = state.data.filter((fileMessage)=>
fileMessage.filePath===action.payload[0].filePath
);
if (filter.length>0){
console.log('filter',filter)
}else {
// 添加进当前目录
state.data=[...new Set([...state.data,...action.payload])];
console.log('state.data:',state.data)
}
}
}