model.js 2.2 KB

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