diff --git a/src/components/ItemTree/index.jsx b/src/components/ItemTree/index.jsx
index 0c5b042..207ed4b 100644
--- a/src/components/ItemTree/index.jsx
+++ b/src/components/ItemTree/index.jsx
@@ -5,6 +5,7 @@ import "./index.less"
const {Search} = Input;
import {store} from "../../redux/store";
import {clickFile} from "../../redux/clickFile_reducer";
+import {useSelector} from "react-redux";
const defaultData = [];
// 将树平铺用于查找
@@ -58,41 +59,34 @@ function generateChildList(fileList) {
const ItemTree = () => {
const [expandedKeys, setExpandedKeys] = useState([]);
const [searchValue, setSearchValue] = useState('');
- const [defaultValueState, setDefaultValueState] = useState([]);
+
const [autoExpandParent, setAutoExpandParent] = useState(true);
- useEffect(() => {
- let unsubscribe = store.subscribe(() => {
- let fileDirDate = store.getState().dirMessage.data;
- if (fileDirDate.length===0){
- return
+ const defaultValueStateSet = [];
+ let fileDirDate = useSelector(state => state.dirMessage.data);
+ if (fileDirDate.length>0){
+ for (let i = 0; i < fileDirDate.length; i++) {
+ const node = fileDirDate[i];
+ console.log("node:", node)
+ const {fileName, filePath, childList, dirFlag} = node;
+ const childListM = []
+ if (childList.length > 0) {
+ childListM.push(...generateChildList(childList));
}
- console.log("打开目录1fileDirDate:", fileDirDate)
- for (let i = 0; i < fileDirDate.length; i++) {
- const node = fileDirDate[i];
- console.log("node:", node)
- const {fileName, filePath, childList, dirFlag} = 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": ,
- "dirFlag": dirFlag,
- "children": childListM
- });
- }
+ if (defaultData.filter(fileMessage => fileMessage.key === filePath).length === 0) {
+ defaultData.push({
+ "key": filePath,
+ "title": fileName,
+ "icon": ,
+ "dirFlag": dirFlag,
+ "children": childListM
+ });
}
- console.log("Array.from(new Set(defaultData)):", Array.from(new Set(defaultData)))
- setDefaultValueState(Array.from(new Set(defaultData)))
- })
- return ()=>unsubscribe()
- }, [])
+ }
+ console.log("Array.from(new Set(defaultData)):", Array.from(new Set(defaultData)))
+ defaultValueStateSet.push(...Array.from(new Set(defaultData)))
+ }
+ const [defaultValueState, setDefaultValueState] = useState(defaultValueStateSet);
const onExpand = (newExpandedKeys) => {
setExpandedKeys(newExpandedKeys);
diff --git a/src/redux/clickFile_reducer.js b/src/redux/clickFile_reducer.js
index 0373533..19b6e1a 100644
--- a/src/redux/clickFile_reducer.js
+++ b/src/redux/clickFile_reducer.js
@@ -7,6 +7,7 @@ export const clickFileSlice = createSlice({
data: {}
},
reducers: {
+ // 点击文件添加item,设置单前文件
clickFile: (state, action) => {
console.log("clickFileSlice:clickFile", state, action)
state.data=action.payload