2024-02-02 01:40:28 -05:00
|
|
|
|
import { createSlice } from '@reduxjs/toolkit'
|
2024-02-04 01:42:20 -05:00
|
|
|
|
import {isEmpty} from "../utils/ObjectUtils";
|
2024-02-02 01:40:28 -05:00
|
|
|
|
|
2024-02-04 05:11:14 -05:00
|
|
|
|
/**
|
|
|
|
|
* {
|
|
|
|
|
* label: e.node.title,
|
|
|
|
|
* children: e.node.key,
|
|
|
|
|
* key: e.node.key,
|
|
|
|
|
* activeKey:e.node.key
|
|
|
|
|
* }
|
|
|
|
|
*/
|
2024-02-02 01:40:28 -05:00
|
|
|
|
export const tableBarItemSlice = createSlice({
|
|
|
|
|
name: 'tableBarItem',
|
|
|
|
|
initialState: {
|
|
|
|
|
type:"tableBarItem",
|
2024-02-03 20:29:00 -05:00
|
|
|
|
data: [],
|
2024-02-06 20:46:28 -05:00
|
|
|
|
activeKey:"",
|
|
|
|
|
expandedKeyList:[]
|
2024-02-02 01:40:28 -05:00
|
|
|
|
},
|
|
|
|
|
reducers: {
|
2024-02-03 20:29:00 -05:00
|
|
|
|
addTableBarItem: (state, action) => {
|
2024-02-06 03:03:26 -05:00
|
|
|
|
console.log("tableBarItemSlice:addTableBarItem", state, action)
|
2024-02-03 20:29:00 -05:00
|
|
|
|
if (state.data.filter(file=>file.key===action.payload.key).length===0){
|
2024-02-06 03:03:26 -05:00
|
|
|
|
state.data.push({"label":action.payload.label,"key":action.payload.key,"children":action.payload.children})
|
2024-02-03 20:29:00 -05:00
|
|
|
|
}
|
2024-02-04 01:42:20 -05:00
|
|
|
|
if (action.payload.activeKey){
|
|
|
|
|
state.activeKey=action.payload.activeKey
|
|
|
|
|
}
|
2024-02-03 20:29:00 -05:00
|
|
|
|
},
|
2024-02-03 22:08:49 -05:00
|
|
|
|
removeTableBarItem: (state, action) => {
|
|
|
|
|
console.log("tableBarItemSlice:removeTableBarItem",action.payload)
|
|
|
|
|
state.data=state.data.filter(file=>file.key!==action.payload)
|
2024-02-04 01:42:20 -05:00
|
|
|
|
if (action.payload.activeKey){
|
|
|
|
|
state.activeKey=action.payload.activeKey
|
|
|
|
|
}
|
2024-02-04 05:11:14 -05:00
|
|
|
|
},
|
2024-02-04 01:42:20 -05:00
|
|
|
|
setActiveKey: (state, action) => {
|
2024-02-03 22:08:49 -05:00
|
|
|
|
console.log("tableBarItemSlice:setActiveKey",action.payload)
|
2024-02-04 01:42:20 -05:00
|
|
|
|
if (action.payload.activeKey){
|
|
|
|
|
state.activeKey=action.payload.activeKey
|
2024-02-03 20:29:00 -05:00
|
|
|
|
}
|
2024-02-04 05:11:14 -05:00
|
|
|
|
},
|
|
|
|
|
updatedSavedFile:(state, action)=>{
|
|
|
|
|
console.log("tableBarItemSlice:updatedSavedFile",action.payload)
|
|
|
|
|
// 如果其中包含了相同的key,则是文件覆盖。
|
|
|
|
|
if (state.data.filter(file=>file.key===action.payload.filePath).length>0){
|
|
|
|
|
state.data= state.data.filter(file=>file.key!==action.payload.filePath)
|
|
|
|
|
}
|
|
|
|
|
state.data.forEach(file=>{
|
|
|
|
|
if (file.key===state.activeKey){
|
|
|
|
|
file.children=action.payload.filePath;
|
|
|
|
|
file.key = action.payload.filePath;
|
|
|
|
|
let split = action.payload.filePath.split("/");
|
|
|
|
|
console.log("action.payload.filePath.split()",split)
|
|
|
|
|
file.label =split[split.length-1]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
state.activeKey = action.payload.filePath
|
2024-02-06 20:46:28 -05:00
|
|
|
|
},
|
|
|
|
|
addExpandedKeys:(state, action)=>{
|
|
|
|
|
state.expandedKeyList.push(...action.payload)
|
|
|
|
|
state.expandedKeyList=Array.from(new Set([...state.expandedKeyList]))
|
|
|
|
|
},
|
|
|
|
|
setExpandedKeys:(state, action)=>{
|
|
|
|
|
state.expandedKeyList=action.payload
|
|
|
|
|
},
|
|
|
|
|
removeExpandedKeys:(state, action)=>{
|
|
|
|
|
state.expandedKeyList=state.expandedKeyList.filter(key=>key!==action.payload)
|
2024-02-02 01:40:28 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-02-03 22:08:49 -05:00
|
|
|
|
export const { addTableBarItem,
|
|
|
|
|
removeTableBarItem,
|
2024-02-04 05:11:14 -05:00
|
|
|
|
setActiveKey,
|
2024-02-06 20:46:28 -05:00
|
|
|
|
updatedSavedFile,
|
|
|
|
|
setExpandedKeys,
|
|
|
|
|
removeExpandedKeys,
|
|
|
|
|
addExpandedKeys
|
|
|
|
|
} = tableBarItemSlice.actions
|
2024-02-02 01:40:28 -05:00
|
|
|
|
export default tableBarItemSlice.reducer
|