feat:来回自由切换

This commit is contained in:
shixiaohua 2024-02-04 11:08:49 +08:00
parent 13a9830aa6
commit 172723e3b0
3 changed files with 17 additions and 3 deletions

View File

@ -66,6 +66,10 @@ app.whenReady().then(() => {
}) })
ipcMain.handle("electronStoreSave",(listen,key,value)=>{ ipcMain.handle("electronStoreSave",(listen,key,value)=>{
console.log("electronStoreSave",key,value) console.log("electronStoreSave",key,value)
if (store.get(key)===value){
return ;
}
console.log("electronStoreSaveDisk",key,value)
return store.set(key,value) return store.set(key,value)
}) })
ipcMain.handle("electronStoreGet",(listen,args)=>{ ipcMain.handle("electronStoreGet",(listen,args)=>{

View File

@ -9,7 +9,7 @@ import './index.less'
import {store} from "../../redux/store"; import {store} from "../../redux/store";
import {isEmpty} from "../../utils/ObjectUtils"; import {isEmpty} from "../../utils/ObjectUtils";
import {useSelector, useDispatch} from "react-redux"; import {useSelector, useDispatch} from "react-redux";
import {addTableBarItem} from "../../redux/tableBarItem_reducer" import {addTableBarItem, removeTableBarItem} from "../../redux/tableBarItem_reducer"
const {Header, Sider, Content} = Layout; const {Header, Sider, Content} = Layout;
const Note = () => { const Note = () => {
@ -62,6 +62,7 @@ const Note = () => {
setActiveKey(newActiveKey); setActiveKey(newActiveKey);
}; };
const remove = (targetKey) => { const remove = (targetKey) => {
console.log("remove = (targetKey):",targetKey)
let newActiveKey = activeKey; let newActiveKey = activeKey;
let lastIndex = -1; let lastIndex = -1;
items.forEach((item, i) => { items.forEach((item, i) => {
@ -69,6 +70,7 @@ const Note = () => {
lastIndex = i - 1; lastIndex = i - 1;
} }
}); });
dispatch(removeTableBarItem(targetKey));
const newPanes = items.filter((item) => item.key !== targetKey); const newPanes = items.filter((item) => item.key !== targetKey);
if (newPanes.length && newActiveKey === targetKey) { if (newPanes.length && newActiveKey === targetKey) {
if (lastIndex >= 0) { if (lastIndex >= 0) {
@ -77,6 +79,7 @@ const Note = () => {
newActiveKey = newPanes[0].key; newActiveKey = newPanes[0].key;
} }
} }
console.log("remove = (newActiveKey):",newActiveKey)
// setItems(newPanes); // setItems(newPanes);
setActiveKey(newActiveKey); setActiveKey(newActiveKey);
}; };

View File

@ -9,17 +9,24 @@ export const tableBarItemSlice = createSlice({
}, },
reducers: { reducers: {
addTableBarItem: (state, action) => { addTableBarItem: (state, action) => {
console.log("tableBarItemSlice:tableBarItem=====", state, action,) console.log("tableBarItemSlice:tableBarItem", state, action,)
if (state.data.filter(file=>file.key===action.payload.key).length===0){ if (state.data.filter(file=>file.key===action.payload.key).length===0){
state.data.push(action.payload) state.data.push(action.payload)
} }
}, },
removeTableBarItem: (state, action) => {
console.log("tableBarItemSlice:removeTableBarItem",action.payload)
state.data=state.data.filter(file=>file.key!==action.payload)
},
setActiveKey:(state,action)=>{ setActiveKey:(state,action)=>{
console.log("tableBarItemSlice:setActiveKey",action.payload)
if (state.activeKey!==action.payload){ if (state.activeKey!==action.payload){
state.activeKey=action.payload; state.activeKey=action.payload;
} }
} }
} }
}) })
export const { addTableBarItem,setActiveKey } = tableBarItemSlice.actions export const { addTableBarItem,
removeTableBarItem,
setActiveKey } = tableBarItemSlice.actions
export default tableBarItemSlice.reducer export default tableBarItemSlice.reducer