diff --git a/src/components/ItemTree/CloseDir/index.jsx b/src/components/ItemTree/CloseDir/index.jsx
new file mode 100644
index 0000000..7d3c09e
--- /dev/null
+++ b/src/components/ItemTree/CloseDir/index.jsx
@@ -0,0 +1,15 @@
+import React from 'react';
+import {Menu} from 'antd';
+import {useDispatch} from "react-redux";
+import {dirRemove} from "../../../redux/dirMessage_reducer";
+
+function CloseDir (prop) {
+ console.log("prop",prop)
+ const dispatch = useDispatch()
+ const closeDir = ()=>{
+ dispatch(dirRemove({selectDirKey: prop.filePath}))
+ prop.closeMenu()
+ }
+ return 关闭目录
+}
+export default CloseDir;
\ No newline at end of file
diff --git a/src/components/ItemTree/DirAddFile/index.jsx b/src/components/ItemTree/DirAddFile/index.jsx
new file mode 100644
index 0000000..fd766f2
--- /dev/null
+++ b/src/components/ItemTree/DirAddFile/index.jsx
@@ -0,0 +1,56 @@
+import React, {useRef, useState} from 'react';
+import {Input, message, Modal} from 'antd';
+import {useDispatch} from "react-redux";
+import {newFile} from "../../../utils/File";
+import {dirFileAdd} from "../../../redux/dirMessage_reducer";
+import {addTableBarItem} from "../../../redux/tableBarItem_reducer";
+import {isEmpty} from "../../../utils/ObjectUtils";
+
+const DirAddFile = (prop) => {
+ console.log("prop",prop)
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const dispatch = useDispatch();
+ const inputValue = useRef(null);
+ const [messageApi, contextHolder] = message.useMessage();
+
+ const showModal = () => {
+ setIsModalOpen(true);
+ };
+ const handleOk = () => {
+ console.log("inputValue",inputValue.current.input.value)
+ // 如果为空则提示
+ if (isEmpty(inputValue.current.input.value)){
+ let messageType = messageApi.open({
+ type: 'error',
+ content: '文件名不能为空',
+ });
+ return
+ }
+ // 新建文件
+ let fileName = prop.filePath+"/"+inputValue.current.input.value+".lexical"
+ newFile(fileName)
+ // 更新树
+ dispatch(dirFileAdd({"filePath":prop.filePath,fileName}))
+ // 选中key,添加bar
+ dispatch(addTableBarItem({
+ label: inputValue.current.input.value+".lexical",
+ children: fileName,
+ key: fileName,
+ activeKey: fileName
+ }))
+ setIsModalOpen(false);
+ prop.closeMenu()
+ };
+ const handleCancel = () => {
+ setIsModalOpen(false);
+ prop.closeMenu()
+ };
+ return <>
+ {contextHolder}
+ 添加文件
+
+
+
+ >;
+};
+export default DirAddFile;
\ No newline at end of file
diff --git a/src/components/ItemTree/DirDeleteFile/index.jsx b/src/components/ItemTree/DirDeleteFile/index.jsx
new file mode 100644
index 0000000..c5152e6
--- /dev/null
+++ b/src/components/ItemTree/DirDeleteFile/index.jsx
@@ -0,0 +1,55 @@
+import React from 'react';
+import {Popconfirm} from 'antd';
+import {deleteFileAndDir} from "../../../utils/File";
+import {useDispatch, useSelector} from "react-redux";
+import {dirFileRemove} from "../../../redux/dirMessage_reducer";
+import {removeTableBarItem, setActiveKey} from "../../../redux/tableBarItem_reducer";
+const DirDeleteFile = (prop) => {
+ console.log("prop",prop)
+ const dispatch= useDispatch()
+ const activeKey=useSelector(state => state.tableBarItem.activeKey);
+ const items = useSelector(state => state.tableBarItem.data)
+
+ const deleteFile = () => {
+ // 删除文件
+ deleteFileAndDir(prop.filePath)
+ // 更新树
+ dispatch(dirFileRemove({"filePath":prop.filePath}))
+ // 更新bar
+ let targetKey = prop.filePath
+ let newActiveKey = activeKey;
+ let lastIndex = -1;
+ items.forEach((item, i) => {
+ if (item.key === targetKey) {
+ lastIndex = i - 1;
+ }
+ });
+ dispatch(removeTableBarItem(targetKey));
+ const newPanes = items.filter((item) => item.key !== targetKey);
+ if (newPanes.length && newActiveKey === targetKey) {
+ if (lastIndex >= 0) {
+ newActiveKey = newPanes[lastIndex].key;
+ } else {
+ newActiveKey = newPanes[0].key;
+ }
+ }
+ dispatch(setActiveKey({"activeKey":newActiveKey}));
+ prop.closeMenu()
+ };
+ const cancelDeleteFile = () => {
+
+ prop.closeMenu()
+ };
+ return
+ 删除文件
+ ;
+};
+export default DirDeleteFile;
\ No newline at end of file
diff --git a/src/components/ItemTree/RefreshDir/index.jsx b/src/components/ItemTree/RefreshDir/index.jsx
new file mode 100644
index 0000000..fc43820
--- /dev/null
+++ b/src/components/ItemTree/RefreshDir/index.jsx
@@ -0,0 +1,19 @@
+import React, {useRef, useState} from 'react';
+import {Button, Input, Menu, Modal} from 'antd';
+import {readDir} from "../../../utils/File";
+import {nextDirAdd} from "../../../redux/dirMessage_reducer";
+import {useDispatch} from "react-redux";
+
+const RefreshDir = (prop) => {
+ console.log("prop",prop)
+ const dispatch = useDispatch()
+ const refreshDir = () => {
+ prop.refreshDir(prop.filePath)
+ prop.closeMenu()
+ };
+
+ return (
+ 更新目录
+ );
+};
+export default RefreshDir;
\ No newline at end of file
diff --git a/src/components/ItemTree/UpdateFileName/index.jsx b/src/components/ItemTree/UpdateFileName/index.jsx
new file mode 100644
index 0000000..8088680
--- /dev/null
+++ b/src/components/ItemTree/UpdateFileName/index.jsx
@@ -0,0 +1,48 @@
+import React, {useRef, useState} from 'react';
+import {Input, Menu, Modal} from 'antd';
+import {updateFileName} from "../../../utils/File";
+import {useDispatch} from "react-redux";
+import {updateFileName as updateFileNameRedux} from "../../../redux/dirMessage_reducer";
+import {updateFileName as updateFileNameBar} from "../../../redux/tableBarItem_reducer";
+
+const UpdateFileName = (prop) => {
+ console.log("prop",prop)
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const dispatch = useDispatch();
+ const inputValue = useRef(null);
+ const showModal = () => {
+ setIsModalOpen(true);
+ };
+ const handleOk = () => {
+ setIsModalOpen(false);
+ console.log("inputValue",inputValue.current.input.value)
+ // 如果和原始名称一样,关闭菜单直接返回
+ // 如果不一样,修改文件名并且更新树,同步条目
+ if (prop.fileName!==inputValue.current.input.value){
+ // 修改文件名
+ let first = prop.filePath.lastIndexOf("/")
+ let second = prop.filePath.lastIndexOf(".")
+ let newFilePath= prop.filePath.substring(0,first+1)+inputValue.current.input.value+prop.filePath.substring(second)
+ updateFileName(prop.filePath,newFilePath)
+ // 更新树
+ dispatch(updateFileNameRedux({"oldFilePath":prop.filePath,"newFilePath":newFilePath}))
+ // 同步条目
+ dispatch(updateFileNameBar({"oldFilePath":prop.filePath,"newFilePath":newFilePath}))
+
+ }
+ prop.closeMenu()
+ };
+ const handleCancel = () => {
+ setIsModalOpen(false);
+ prop.closeMenu()
+ };
+ return (
+ <>
+ 修改文件名
+
+
+
+ >
+ );
+};
+export default UpdateFileName;
\ No newline at end of file
diff --git a/src/components/ItemTree/index.jsx b/src/components/ItemTree/index.jsx
index 5856aa8..1281472 100644
--- a/src/components/ItemTree/index.jsx
+++ b/src/components/ItemTree/index.jsx
@@ -1,16 +1,19 @@
import React, {useEffect, useMemo, useState} from 'react';
import {Input, Menu, Tree} from 'antd';
import {FolderOutlined, FileMarkdownOutlined, FileOutlined, DeleteOutlined, RedoOutlined} from '@ant-design/icons';
-import {message, Popconfirm} from 'antd';
import "./index.less"
-
+import {getFileNameByPath} from "../../utils/File";
const {Search} = Input;
import {useSelector, useDispatch} from "react-redux";
import {addExpandedKeys, addTableBarItem, setExpandedKeys} from "../../redux/tableBarItem_reducer";
import {readDir} from "../../utils/File";
import {nextDirAdd} from "../../redux/dirMessage_reducer";
-import Icon from "antd/lib/icon";
import {isEmpty} from "../../utils/ObjectUtils";
+import UpdateFileName from "./UpdateFileName";
+import RefreshDir from "./RefreshDir";
+import CloseDir from "./CloseDir";
+import DirAddFile from "./DirAddFile";
+import DirDeleteFile from "./DirDeleteFile";
// const defaultData = [];
// 将树平铺用于查找
const dataList = [];
@@ -54,7 +57,7 @@ function generateChildList(fileList) {
}
result.push({
"key": filePath,
- "title": titleExtended(fileName,dirFlag,filePath),
+ "title": titleExtended(fileName, dirFlag, filePath),
"icon": dirFlag ? : fileName.endsWith(".md") ? : ,
"dirFlag": dirFlag,
"children": childListM
@@ -63,40 +66,8 @@ function generateChildList(fileList) {
return result;
}
-const titleExtended = (fileName, dirFlag,filePath) => {
-
- const confirm = (e) => {
- console.log(e);
- message.success('Click on Yes');
- };
- const cancel = (e) => {
- console.log(e);
- message.error('Click on No');
- };
- return {fileName}
- {dirFlag &&
-
-
-
-
-
-
- }
-
+const titleExtended = (fileName, dirFlag, filePath) => {
+ return {fileName}
}
/**
* 将文件信息改为树信息
@@ -117,7 +88,7 @@ const flushTree = (fileDirDate) => {
defaultValueStateSet.push({
"key": filePath,
// 修改属性后此处也需要修改
- "title": titleExtended(fileName.substring(fileName.lastIndexOf("/")+1), dirFlag,filePath),
+ "title": titleExtended(getFileNameByPath(fileName), dirFlag, filePath),
"icon": ,
"dirFlag": dirFlag,
"children": childListM
@@ -171,30 +142,38 @@ const ItemTree = (prop) => {
setSearchValue(value);
setAutoExpandParent(true);
};
+
+ const refreshDir = (filePath) => {
+ readDir(filePath).then(fileStateList => {
+ if (Array.isArray(fileStateList[0].childList) && fileStateList[0].childList.length > 0) {
+ dispatch(nextDirAdd({selectDirKey: filePath, fileStateList}))
+ // 添加下级节点
+ addChildNode(defaultValueState, flushTree(fileStateList))
+ const result = [...defaultValueState]
+ console.log("[...defaultValueState]:", result)
+ setDefaultValueState(result)
+ // 打开当前目录
+ dispatch(addExpandedKeys([filePath]));
+ setAutoExpandParent(false);
+ }
+ })
+ }
const onSelect = (selectedKeys, e) => {
if (e.selected) {
console.log('onSelect.selectedKeys', selectedKeys, e)
if (e.node.dirFlag) {
// 加载目录下一级文件信息
if (!Array.isArray(e.node.children) || e.node.children.length === 0) {
- readDir(e.node.key).then(fileStateList => {
- if (Array.isArray(fileStateList[0].childList) && fileStateList[0].childList.length > 0) {
- dispatch(nextDirAdd({selectDirKey: e.node.key, fileStateList}))
- // 添加下级节点
- addChildNode(defaultValueState, flushTree(fileStateList))
- const result = [...defaultValueState]
- console.log("[...defaultValueState]:", result)
- setDefaultValueState(result)
- }
- })
+ refreshDir(e.node.key)
+ } else {
+ // 打开当前目录
+ dispatch(addExpandedKeys([e.node.key]));
+ setAutoExpandParent(false);
}
- // 打开当前目录
- dispatch(addExpandedKeys([e.node.key]));
- setAutoExpandParent(false);
} else {
// 打开文件
dispatch(addTableBarItem({
- label: e.node.title.props.children[0],
+ label: e.node.title.props.children,
children: e.node.key,
key: e.node.key,
activeKey: e.node.key
@@ -232,35 +211,59 @@ const ItemTree = (prop) => {
// });
// return loop(defaultData);
// }, [searchValue]);
- const treeNodeOnRightClick=(e,node)=> {
- console.log("e,node",node)
+ const treeNodeOnRightClick = (e) => {
+ console.log("e,node", e)
setState({
rightClickNodeTreeItem: {
pageX: e.event.pageX,
pageY: e.event.pageY,
- id: e.node.key
+ key: e.node.key,
+ dirFlag: e.node.dirFlag,
+ title: getFileNameByPath(e.node.key),
}
});
}
- const getNodeTreeRightClickMenu=()=> {
- console.log("state",state,isEmpty(state))
- if (isEmpty(state)){
+ const getNodeTreeRightClickMenu = () => {
+ console.log("state", state, isEmpty(state))
+ if (isEmpty(state)) {
return
}
- const {pageX, pageY} = {...state.rightClickNodeTreeItem};
+ const {pageX, pageY, title, dirFlag, key} = {...state.rightClickNodeTreeItem};
const tmpStyle = {
position: 'absolute',
left: `${pageX}px`,
top: `${pageY}px`,
- popupBg:"#ec0f0f",
- "z-index":"9999"
+ popupBg: "#ec0f0f",
+ zIndex: "9999"
};
+ const menuItem = [
+ !dirFlag &&
+
+ setState("")}/>
+ ,
+ dirFlag &&
+
+ setState("")}/>
+ ,
+ dirFlag &&
+
+ setState("")}/>
+ ,
+ !dirFlag &&
+
+ setState("")}>
+ ,
+ dirFlag &&
+
+ setState("")}/>
+ ,
+ {
+ setState("")
+ }}>关闭菜单
+ ]
return (
-