| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /**
- * 人资模块
- */
- import consts from '@/consts'
- import { getDepartMentList } from '@/services/department'
- const StaffModel = {
- namespace: 'staff',
- state: {
- departments: [],
- departmentsMap: {}
- },
- effects: {
- *fetchDepartments({ payload }, { call, put }) {
- const response = yield call(getDepartMentList, payload)
- if (response?.code === consts.RET_CODE.SUCCESS) {
- yield put({
- type: 'changState',
- payload: {
- key: 'departments',
- value: response?.data || []
- }
- })
- yield put({
- type: 'changState',
- payload: {
- key: 'departmentsMap',
- value: (response?.data || []).reduce((prev, curr) => {
- return { ...prev, [curr.id]: { text: curr.name } }
- }, {})
- }
- })
- }
- }
- },
- reducers: {
- // 通用的reducer
- changState(state, action) {
- return {
- ...state,
- [action.payload.key]: action.payload.value
- }
- }
- }
- }
- export default StaffModel
|