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; const {Search} = Input;
import {store} from "../../redux/store"; import {store} from "../../redux/store";
import {clickFile} from "../../redux/clickFile_reducer"; import {clickFile} from "../../redux/clickFile_reducer";
import {useSelector} from "react-redux";
const defaultData = []; const defaultData = [];
// //
@ -58,16 +59,12 @@ function generateChildList(fileList) {
const ItemTree = () => { const ItemTree = () => {
const [expandedKeys, setExpandedKeys] = useState([]); const [expandedKeys, setExpandedKeys] = useState([]);
const [searchValue, setSearchValue] = useState(''); const [searchValue, setSearchValue] = useState('');
const [defaultValueState, setDefaultValueState] = useState([]);
const [autoExpandParent, setAutoExpandParent] = useState(true); const [autoExpandParent, setAutoExpandParent] = useState(true);
useEffect(() => { const defaultValueStateSet = [];
let unsubscribe = store.subscribe(() => { let fileDirDate = useSelector(state => state.dirMessage.data);
let fileDirDate = store.getState().dirMessage.data; if (fileDirDate.length>0){
if (fileDirDate.length===0){
return
}
console.log("打开目录1fileDirDate:", fileDirDate)
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)
@ -76,9 +73,7 @@ const ItemTree = () => {
if (childList.length > 0) { if (childList.length > 0) {
childListM.push(...generateChildList(childList)); childListM.push(...generateChildList(childList));
} }
if (defaultData.filter(fileMessage => if (defaultData.filter(fileMessage => fileMessage.key === filePath).length === 0) {
fileMessage.key === filePath
).length === 0) {
defaultData.push({ defaultData.push({
"key": filePath, "key": filePath,
"title": fileName, "title": fileName,
@ -89,10 +84,9 @@ const ItemTree = () => {
} }
} }
console.log("Array.from(new Set(defaultData)):", Array.from(new Set(defaultData))) console.log("Array.from(new Set(defaultData)):", Array.from(new Set(defaultData)))
setDefaultValueState(Array.from(new Set(defaultData))) defaultValueStateSet.push(...Array.from(new Set(defaultData)))
}) }
return ()=>unsubscribe() const [defaultValueState, setDefaultValueState] = useState(defaultValueStateSet);
}, [])
const onExpand = (newExpandedKeys) => { const onExpand = (newExpandedKeys) => {
setExpandedKeys(newExpandedKeys); setExpandedKeys(newExpandedKeys);

View File

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