知与行后台管理端

user.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { fetch, apis } from '@/utils/request';
  2. import { setAllBtnAuth, setUserBtnAuth } from '@/components/AuthButton';
  3. const getCurrentUser = fetch(apis.user.current)
  4. const UserModel = {
  5. namespace: 'user',
  6. state: {
  7. currentUser: {},
  8. menuList: [],
  9. buttonList: [],
  10. },
  11. effects: {
  12. // *fetch(_, { call, put }) {
  13. // const response = yield call(queryUsers);
  14. // yield put({
  15. // type: 'save',
  16. // payload: response,
  17. // });
  18. // },
  19. *fetchCurrent(_, { call, put }) {
  20. const response = yield call(getCurrentUser);
  21. yield put({
  22. type: 'saveCurrentUser',
  23. payload: response,
  24. });
  25. },
  26. },
  27. reducers: {
  28. saveCurrentUser(state, { payload }) {
  29. const { taUser = {} , menuList = [], buttonList = [] } = payload || {}
  30. const currentUser = { ...taUser, roles: (taUser.roles || []).map(x => x.roleId) }
  31. setAllBtnAuth(buttonList)
  32. setUserBtnAuth(currentUser.roles)
  33. return { ...state, currentUser, menuList, buttonList };
  34. },
  35. changeNotifyCount(
  36. state = {
  37. currentUser: {},
  38. },
  39. action,
  40. ) {
  41. return {
  42. ...state,
  43. currentUser: {
  44. ...state.currentUser,
  45. notifyCount: action.payload.totalCount,
  46. unreadCount: action.payload.unreadCount,
  47. },
  48. };
  49. },
  50. },
  51. };
  52. export default UserModel;