diff --git a/src/components/ItemTree/index.jsx b/src/components/ItemTree/index.jsx index 5c2fa6b..9b37b67 100644 --- a/src/components/ItemTree/index.jsx +++ b/src/components/ItemTree/index.jsx @@ -1,6 +1,7 @@ import React, {useEffect, useMemo, useState} from 'react'; import {Input, Tree} from 'antd'; -import {FolderOutlined, FileMarkdownOutlined, FileOutlined} from '@ant-design/icons'; +import {FolderOutlined, FileMarkdownOutlined, FileOutlined, DeleteOutlined, RedoOutlined} from '@ant-design/icons'; +import {message, Popconfirm} from 'antd'; import "./index.less" const {Search} = Input; @@ -51,7 +52,7 @@ function generateChildList(fileList) { } result.push({ "key": filePath, - "title": fileName, + "title": titleExtended(fileName,dirFlag), "icon": dirFlag ? : fileName.endsWith(".md") ? : , "dirFlag": dirFlag, "children": childListM @@ -60,6 +61,41 @@ function generateChildList(fileList) { return result; } +const titleExtended = (fileName, dirFlag) => { + + 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 && + + + + + + + } + +} /** * 将文件信息改为树信息 * @param fileDirDate @@ -78,17 +114,18 @@ const flushTree = (fileDirDate) => { } defaultValueStateSet.push({ "key": filePath, - "title": fileName, + "title": titleExtended(fileName.substring(fileName.lastIndexOf("/")+1), dirFlag), "icon": , "dirFlag": dirFlag, "children": childListM }); + } } return defaultValueStateSet; } const ItemTree = (prop) => { - console.log("prop.filePath:",prop.filePath) + console.log("prop.filePath:", prop.filePath) const [expandedKeys, setExpandedKeys] = useState([]); const [searchValue, setSearchValue] = useState(''); const dispatch = useDispatch() @@ -105,7 +142,7 @@ const ItemTree = (prop) => { const addChildNode = (valueState, fileStateList) => { valueState.forEach(file => { - if (fileStateList[0].key.startsWith(file.key)){ + if (fileStateList[0].key.startsWith(file.key)) { if (file.key === fileStateList[0].key) { file.children = fileStateList[0].children } else if (Array.isArray(file.children) && file.children.length > 0) { @@ -141,7 +178,7 @@ const ItemTree = (prop) => { // 添加下级节点 addChildNode(defaultValueState, flushTree(fileStateList)) const result = [...defaultValueState] - console.log("[...defaultValueState]:",result) + console.log("[...defaultValueState]:", result) setDefaultValueState(result) } }) @@ -192,7 +229,7 @@ const ItemTree = (prop) => { // return loop(defaultData); // }, [searchValue]); return ( -
+
{ console.log("dirMessage:dirAdd", state, action) if (action.payload) { - // 新添加进来的目录,要判断是否重复,如果重复则提示 - let filter = state.data.filter((fileMessage) => - fileMessage.filePath === action.payload[0].filePath + // 新添加进来的目录,要判断是否包含或者被包含,如果包含则统一树结构 + let fileFilter = state.data.filter((fileMessage) => + fileMessage.filePath.startsWith(action.payload[0].filePath) ); - if (filter.length > 0) { - console.log('filter', filter) - } else { + let actionFilter = state.data.filter((fileMessage) => + action.payload[0].filePath.startsWith(fileMessage.filePath) + ); + let equalsFilter = state.data.filter((fileMessage) => + action.payload[0].filePath===fileMessage.filePath + ); + // 打开相同目录不用处理 + if (equalsFilter.length > 0) { + console.log('equalsFilter', filter) + } + // 打开上级目录 + else if (actionFilter.length>0){ + + } + // 打开下级目录 + else if (fileFilter.length>0){ + + } + // 无关目录 + else { // 添加进当前目录 state.data = [...new Set([...state.data, ...action.payload])]; console.log('state.data:', state.data) diff --git a/src/store/fileListState.js b/src/store/fileListState.js deleted file mode 100644 index 5b5e9fd..0000000 --- a/src/store/fileListState.js +++ /dev/null @@ -1,8 +0,0 @@ -const schema = { - "fileId": { - type: 'number', - maximum: 100, - minimum: 1, - default: 50 - } -} \ No newline at end of file