model.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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: 'client',
  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:用于处理同步操作,由action触发,可修改state
  42. reducers: {
  43. // 通用reducer
  44. changeState(state, action) {
  45. return {
  46. ...state,
  47. [action.payload.key]: action.payload.data
  48. }
  49. }
  50. }
  51. }