model.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * 人资模块
  3. */
  4. import consts from '@/consts'
  5. import { getDepartMentList } from '@/services/department'
  6. const StaffModel = {
  7. namespace: 'staff',
  8. state: {
  9. departments: [],
  10. departmentsMap: {}
  11. },
  12. effects: {
  13. *fetchDepartments({ payload }, { call, put }) {
  14. const response = yield call(getDepartMentList, payload)
  15. if (response?.code === consts.RET_CODE.SUCCESS) {
  16. yield put({
  17. type: 'changState',
  18. payload: {
  19. key: 'departments',
  20. value: response?.data || []
  21. }
  22. })
  23. yield put({
  24. type: 'changState',
  25. payload: {
  26. key: 'departmentsMap',
  27. value: (response?.data || []).reduce((prev, curr) => {
  28. return { ...prev, [curr.id]: { text: curr.name } }
  29. }, {})
  30. }
  31. })
  32. }
  33. }
  34. },
  35. reducers: {
  36. // 通用的reducer
  37. changState(state, action) {
  38. return {
  39. ...state,
  40. [action.payload.key]: action.payload.value
  41. }
  42. }
  43. }
  44. }
  45. export default StaffModel