A2classify.ts 759 B

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