feat:打开文件
This commit is contained in:
parent
ef1aa74011
commit
34fb22536f
|
@ -3,6 +3,7 @@ import routes from './routes'
|
||||||
import {Outlet, useNavigate, useRoutes} from 'react-router-dom'
|
import {Outlet, useNavigate, useRoutes} from 'react-router-dom'
|
||||||
import useIpcRenderer from '../src/utils/useIpcRenderer'
|
import useIpcRenderer from '../src/utils/useIpcRenderer'
|
||||||
import {dirAdd} from "./redux/dirMessage_reducer";
|
import {dirAdd} from "./redux/dirMessage_reducer";
|
||||||
|
import {openFile} from "./redux/clickFile_reducer"
|
||||||
import {store} from "./redux/store";
|
import {store} from "./redux/store";
|
||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,17 @@ exports.menuRebuild = (mainWindow) => {
|
||||||
})
|
})
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const state = await stat(result.filePaths[0] + '/' + files[i]);
|
const state = await stat(result.filePaths[0] + '/' + files[i]);
|
||||||
|
if (state.isDirectory()
|
||||||
|
||files[i].endsWith(".md")
|
||||||
|
||files[i].endsWith(".html")
|
||||||
|
||files[i].endsWith(".lexical")){
|
||||||
fileChildList.push({
|
fileChildList.push({
|
||||||
'fileName': files[i],
|
'fileName': files[i],
|
||||||
"filePath": result.filePaths[0]+ '/' +files[i],
|
"filePath": result.filePaths[0]+ '/' +files[i],
|
||||||
'dirFlag': state.isDirectory()
|
'dirFlag': state.isDirectory()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mainWindow.webContents.send('openDirectory', fileStateList)
|
mainWindow.webContents.send('openDirectory', fileStateList)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
|
@ -3,33 +3,9 @@ import { Input, Tree } from 'antd';
|
||||||
import {FolderOutlined,FileMarkdownOutlined} from '@ant-design/icons';
|
import {FolderOutlined,FileMarkdownOutlined} from '@ant-design/icons';
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
import store from "../../redux/store";
|
import store from "../../redux/store";
|
||||||
const defaultData = [
|
import {clickFile} from "../../redux/clickFile_reducer";
|
||||||
// {
|
|
||||||
// "title": "/media/shixiaohua/homedisk",
|
const defaultData = [];
|
||||||
// "key": "0-0",
|
|
||||||
// "icon": <FolderOutlined />,
|
|
||||||
// "children": [
|
|
||||||
// {
|
|
||||||
// "title": "electron",
|
|
||||||
// "key": "0-0-0",
|
|
||||||
// "icon": <FolderOutlined />,
|
|
||||||
// "children": [
|
|
||||||
// {
|
|
||||||
// "title": "leaf",
|
|
||||||
// "key": "0-0-0-0",
|
|
||||||
// "icon": <FileMarkdownOutlined />
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// "title": "media",
|
|
||||||
// "key": "0-1",
|
|
||||||
// "icon": <FolderOutlined />,
|
|
||||||
// "children": []
|
|
||||||
// }
|
|
||||||
];
|
|
||||||
// 将树平铺用于查找
|
// 将树平铺用于查找
|
||||||
const dataList = [];
|
const dataList = [];
|
||||||
const generateList = (data) => {
|
const generateList = (data) => {
|
||||||
|
@ -65,17 +41,22 @@ const getParentKey = (key, tree) => {
|
||||||
function generateChildList(fileList){
|
function generateChildList(fileList){
|
||||||
const result = []
|
const result = []
|
||||||
for (let i = 0; i < fileList.length; i++) {
|
for (let i = 0; i < fileList.length; i++) {
|
||||||
const {fileName,filePath}=fileList[i];
|
const {fileName,filePath,dirFlag}=fileList[i];
|
||||||
result.push({
|
result.push({
|
||||||
"key":filePath,
|
"key":filePath,
|
||||||
"title":fileName,
|
"title":fileName,
|
||||||
"icon":<FolderOutlined />,
|
"icon":<FolderOutlined />,
|
||||||
|
"dirFlag":dirFlag,
|
||||||
"children":[]
|
"children":[]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
const ItemTree = () => {
|
const ItemTree = () => {
|
||||||
|
const [expandedKeys, setExpandedKeys] = useState([]);
|
||||||
|
const [searchValue, setSearchValue] = useState('');
|
||||||
|
const [defaultValueState, setDefaultValueState] = useState([]);
|
||||||
|
const [autoExpandParent, setAutoExpandParent] = useState(true);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
store.subscribe(() =>{
|
store.subscribe(() =>{
|
||||||
|
@ -84,7 +65,7 @@ const ItemTree = () => {
|
||||||
for (let i = 0; i < fileDirDate.length; i++) {
|
for (let i = 0; i < fileDirDate.length; i++) {
|
||||||
const node = fileDirDate[i];
|
const node = fileDirDate[i];
|
||||||
console.log("node:",node)
|
console.log("node:",node)
|
||||||
const { fileName,filePath,childList } = node;
|
const { fileName,filePath,childList,dirFlag } = node;
|
||||||
const childListM=[]
|
const childListM=[]
|
||||||
if (childList.length>0) {
|
if (childList.length>0) {
|
||||||
childListM.push(...generateChildList(childList));
|
childListM.push(...generateChildList(childList));
|
||||||
|
@ -96,6 +77,7 @@ const ItemTree = () => {
|
||||||
"key":filePath,
|
"key":filePath,
|
||||||
"title":fileName,
|
"title":fileName,
|
||||||
"icon":<FolderOutlined />,
|
"icon":<FolderOutlined />,
|
||||||
|
"dirFlag":dirFlag,
|
||||||
"children":childListM
|
"children":childListM
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -105,10 +87,6 @@ const ItemTree = () => {
|
||||||
})
|
})
|
||||||
},[])
|
},[])
|
||||||
|
|
||||||
const [expandedKeys, setExpandedKeys] = useState([]);
|
|
||||||
const [searchValue, setSearchValue] = useState('');
|
|
||||||
const [defaultValueState, setDefaultValueState] = useState([]);
|
|
||||||
const [autoExpandParent, setAutoExpandParent] = useState(true);
|
|
||||||
const onExpand = (newExpandedKeys) => {
|
const onExpand = (newExpandedKeys) => {
|
||||||
setExpandedKeys(newExpandedKeys);
|
setExpandedKeys(newExpandedKeys);
|
||||||
setAutoExpandParent(false);
|
setAutoExpandParent(false);
|
||||||
|
@ -127,6 +105,12 @@ const ItemTree = () => {
|
||||||
setSearchValue(value);
|
setSearchValue(value);
|
||||||
setAutoExpandParent(true);
|
setAutoExpandParent(true);
|
||||||
};
|
};
|
||||||
|
const onSelect = (selectedKeys,e) =>{
|
||||||
|
if (e.selected){
|
||||||
|
console.log('onSelect.selectedKeys',selectedKeys,e)
|
||||||
|
store.dispatch(clickFile({"fileName":e.node.title,"filePath":e.node.key}))
|
||||||
|
}
|
||||||
|
}
|
||||||
// const treeData = useMemo(() => {
|
// const treeData = useMemo(() => {
|
||||||
// const loop = (data) =>
|
// const loop = (data) =>
|
||||||
// data.map((item) => {
|
// data.map((item) => {
|
||||||
|
@ -174,6 +158,7 @@ const ItemTree = () => {
|
||||||
showIcon ={true}
|
showIcon ={true}
|
||||||
// treeNodes 数据,如果设置则不需要手动构造 TreeNode 节点(key 在整个树范围内唯一)
|
// treeNodes 数据,如果设置则不需要手动构造 TreeNode 节点(key 在整个树范围内唯一)
|
||||||
treeData={defaultValueState}
|
treeData={defaultValueState}
|
||||||
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, {useRef, useState } from 'react';
|
import React, {useEffect, useRef, useState} from 'react';
|
||||||
import {
|
import {
|
||||||
MenuFoldOutlined,
|
MenuFoldOutlined,
|
||||||
MenuUnfoldOutlined,
|
MenuUnfoldOutlined,
|
||||||
|
@ -10,39 +10,31 @@ import { Layout, Menu, Button, theme, Avatar,Tabs } from 'antd';
|
||||||
import Hlexical from './Hlexical';
|
import Hlexical from './Hlexical';
|
||||||
import ItemTree from "../../components/ItemTree";
|
import ItemTree from "../../components/ItemTree";
|
||||||
import './index.less'
|
import './index.less'
|
||||||
|
import store from "../../redux/store";
|
||||||
const {Header, Sider, Content} = Layout;
|
const {Header, Sider, Content} = Layout;
|
||||||
|
|
||||||
|
|
||||||
const initialItems = [
|
|
||||||
{
|
|
||||||
label: 'Tab 1',
|
|
||||||
children: <div className="HlexicalName"><Hlexical/></div>,
|
|
||||||
key: '1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Tab 2',
|
|
||||||
children: 'Content of Tab 2',
|
|
||||||
key: '2',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Tab 3',
|
|
||||||
children: 'Content of Tab 3',
|
|
||||||
key: '3',
|
|
||||||
closable: false,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const Note = () => {
|
const Note = () => {
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
// const {
|
// const {
|
||||||
// token: { colorBgContainer },
|
// token: { colorBgContainer },
|
||||||
// } = theme.useToken();
|
// } = theme.useToken();
|
||||||
const colorBgContainer = '#800080'
|
const colorBgContainer = '#800080'
|
||||||
|
const [activeKey, setActiveKey] = useState();
|
||||||
|
const [items, setItems] = useState([]);
|
||||||
const [activeKey, setActiveKey] = useState(initialItems[0].key);
|
|
||||||
const [items, setItems] = useState(initialItems);
|
|
||||||
const newTabIndex = useRef(0);
|
const newTabIndex = useRef(0);
|
||||||
|
store.subscribe(() => {
|
||||||
|
const openFile = store.getState().clickFileMessage.data;
|
||||||
|
console.log("store.getState().clickFileMessage.data:",openFile,items)
|
||||||
|
if (items.filter(fileItem => fileItem.key === openFile.filePath).length === 0) {
|
||||||
|
setItems([...items,
|
||||||
|
{
|
||||||
|
label: openFile.fileName,
|
||||||
|
children: <div className="HlexicalName"><Hlexical/></div>,
|
||||||
|
key: openFile.filePath,
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
const onChange = (newActiveKey) => {
|
const onChange = (newActiveKey) => {
|
||||||
setActiveKey(newActiveKey);
|
setActiveKey(newActiveKey);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { createSlice } from '@reduxjs/toolkit'
|
||||||
|
|
||||||
|
export const clickFileSlice = createSlice({
|
||||||
|
name: 'clickFile',
|
||||||
|
initialState: {
|
||||||
|
data: {}
|
||||||
|
},
|
||||||
|
reducers: {
|
||||||
|
clickFile: (state, action) => {
|
||||||
|
console.log("clickFileSlice:clickFile", state, action)
|
||||||
|
state.data=action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export const { clickFile } = clickFileSlice.actions
|
||||||
|
export default clickFileSlice.reducer
|
|
@ -21,9 +21,7 @@ export const dirMessageSlice = createSlice({
|
||||||
state.data=[...new Set([...state.data,...action.payload])];
|
state.data=[...new Set([...state.data,...action.payload])];
|
||||||
console.log('state.data:',state.data)
|
console.log('state.data:',state.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,12 +2,14 @@ import { configureStore } from '@reduxjs/toolkit'
|
||||||
import historyReducer from './historyRecord_reducer'
|
import historyReducer from './historyRecord_reducer'
|
||||||
import redirectReducer from './redirectUrl_reducer'
|
import redirectReducer from './redirectUrl_reducer'
|
||||||
import dirMessageReducer from './dirMessage_reducer'
|
import dirMessageReducer from './dirMessage_reducer'
|
||||||
|
import clickFileReducer from './clickFile_reducer'
|
||||||
// 用于支持异步函数
|
// 用于支持异步函数
|
||||||
export const store = configureStore({
|
export const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
historyRecord:historyReducer,
|
historyRecord:historyReducer,
|
||||||
redirectUrl:redirectReducer,
|
redirectUrl:redirectReducer,
|
||||||
dirMessage:dirMessageReducer
|
dirMessage:dirMessageReducer,
|
||||||
|
clickFileMessage:clickFileReducer
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export default store
|
export default store
|
Loading…
Reference in New Issue