company.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import consts from '@/consts'
  2. import {
  3. LabelStatusColorMap,
  4. TagTypeEnum
  5. } from '@/pages/customer/Company/components/PersonLabel/const'
  6. import { queryTagList } from '@/services/customer'
  7. export default {
  8. namespace: 'company',
  9. state: {
  10. personTags: [], // 个人标签
  11. personTagColorMap: {}, // 个人标签的颜色映射关系
  12. teamTags: [], // 协作标签
  13. teamTagColorMap: {} // 协作标签的颜色映射关系
  14. },
  15. // 用于处理异步操作和业务逻辑,由action触发,但不能修改state
  16. effects: {
  17. *fetchTags({ payload }, { call, put }) {
  18. const response = yield call(queryTagList, payload)
  19. if (response?.code === consts.RET_CODE.SUCCESS) {
  20. const { tagType } = payload
  21. yield put({
  22. type: 'changeState',
  23. payload: {
  24. key: tagType === TagTypeEnum.PERSONTAG ? 'personTags' : 'teamTags',
  25. data: response.data || []
  26. }
  27. })
  28. yield put({
  29. type: 'changeState',
  30. payload: {
  31. key: tagType === TagTypeEnum.PERSONTAG ? 'personTagColorMap' : 'teamTagColorMap',
  32. data: response.data.reduce((curr, prev, idx) => {
  33. const item = { ...curr, [prev.id]: LabelStatusColorMap[tagType][idx] }
  34. return item
  35. }, {})
  36. }
  37. })
  38. }
  39. }
  40. },
  41. reducers: {
  42. // 通用reducer
  43. changeState(state, action) {
  44. return {
  45. ...state,
  46. [action.payload.key]: action.payload.data
  47. }
  48. }
  49. }
  50. }