A2introduction.ts 839 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { A2tableType, A2TreeType } from '@/types'
  2. // 初始化状态
  3. const initState = {
  4. // 树数据
  5. treeData: [] as A2TreeType[],
  6. treeFlag: false,
  7. // 列表数据
  8. tableInfo: {
  9. list: [] as A2tableType[],
  10. total: 0
  11. }
  12. }
  13. // 定义 action 类型
  14. type Props =
  15. | {
  16. type: 'A2/getTree'
  17. payload: A2TreeType[]
  18. }
  19. | {
  20. type: 'A2/treeFlag'
  21. payload: boolean
  22. }
  23. | {
  24. type: 'A2/getList'
  25. payload: { list: A2tableType[]; total: number }
  26. }
  27. // reducer
  28. export default function Reducer(state = initState, action: Props) {
  29. switch (action.type) {
  30. // 获取树数据
  31. case 'A2/getTree':
  32. return { ...state, treeData: action.payload }
  33. // 获取列表数据
  34. case 'A2/getList':
  35. return { ...state, tableInfo: action.payload }
  36. default:
  37. return state
  38. }
  39. }