system-copyright-react/src/store/index.ts

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-08-12 14:43:58 +08:00
import { createStore } from "redux"
2024-07-31 16:00:30 +08:00
// 设置数据
const baseState = {
2024-08-12 14:43:58 +08:00
// msg: '嘻嘻嘻嘻嘻嘻',
// num: 10,
// shuju: {
// name: '小白',
// hobby: '吃饭',
// val: ''
// },
2024-08-23 11:16:52 +08:00
belongArray: [],
refunArray:[],
2024-08-26 18:03:35 +08:00
correctionArray:[],
refunTotal:0,
correctionTotal:0
2024-07-31 16:00:30 +08:00
}
// 创建仓库
2024-08-12 14:43:58 +08:00
const reducer = (state = baseState, action: any) => {
const nstate: any = JSON.parse(JSON.stringify(state))
// if (action.type == "numadd") {
// nstate.num++
// // console.log('123');
// }
// if (action.type == 'new') {
// nstate.shuju.val = action.val
// console.log(nstate.shuju.val);
// }
2024-07-31 16:00:30 +08:00
// redux 要求 state必须深拷贝一次 才能返回
2024-08-12 14:43:58 +08:00
if (action.type == 'uparray') {
2024-07-31 16:00:30 +08:00
nstate.belongArray = action.val
}
2024-08-23 11:16:52 +08:00
if (action.type == 'upRefunArray') {
nstate.refunArray = action.val
}
if (action.type == 'upRefunTotal') {
nstate.refunTotal = action.val
}
2024-08-26 18:03:35 +08:00
if (action.type == 'upCorrectionArray') {
nstate.correctionArray = action.val
}
if (action.type == 'upCorrectionTotal') {
nstate.correctionTotal = action.val
}
2024-07-31 16:00:30 +08:00
return nstate
}
const store = createStore(reducer)
export default store