1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { A2tableType, A2TreeType } from '@/types'
- // 初始化状态
- const initState = {
- // 树数据
- treeData: [] as A2TreeType[],
- treeFlag: false,
- // 列表数据
- tableInfo: {
- list: [] as A2tableType[],
- total: 0
- }
- }
- // 定义 action 类型
- type Props =
- | {
- type: 'A2/getTree'
- payload: A2TreeType[]
- }
- | {
- type: 'A2/treeFlag'
- payload: boolean
- }
- | {
- type: 'A2/getList'
- payload: { list: A2tableType[]; total: number }
- }
- // reducer
- export default function Reducer(state = initState, action: Props) {
- switch (action.type) {
- // 获取树数据
- case 'A2/getTree':
- return { ...state, treeData: action.payload }
- // 获取列表数据
- case 'A2/getList':
- return { ...state, tableInfo: action.payload }
- default:
- return state
- }
- }
|