feat:左侧树信息持久化

This commit is contained in:
shixiaohua 2024-02-04 12:30:40 +08:00
parent 172723e3b0
commit ed8ce9ae79
2 changed files with 26 additions and 31 deletions

View File

@ -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": <FolderOutlined/>,
"dirFlag": dirFlag,
"children": childListM
});
}
if (defaultData.filter(fileMessage => fileMessage.key === filePath).length === 0) {
defaultData.push({
"key": filePath,
"title": fileName,
"icon": <FolderOutlined/>,
"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);

View File

@ -7,6 +7,7 @@ export const clickFileSlice = createSlice({
data: {}
},
reducers: {
// 点击文件添加item设置单前文件
clickFile: (state, action) => {
console.log("clickFileSlice:clickFile", state, action)
state.data=action.payload