| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import consts from '@/consts'
- import {
- LabelStatusColorMap,
- TagTypeEnum
- } from '@/pages/customer/Company/components/PersonLabel/const'
- import { queryTagList } from '@/services/customer'
- export default {
- namespace: 'company',
- state: {
- personTags: [], // 个人标签
- personTagColorMap: {}, // 个人标签的颜色映射关系
- teamTags: [], // 协作标签
- teamTagColorMap: {} // 协作标签的颜色映射关系
- },
- // 用于处理异步操作和业务逻辑,由action触发,但不能修改state
- effects: {
- *fetchTags({ payload }, { call, put }) {
- const response = yield call(queryTagList, payload)
- if (response?.code === consts.RET_CODE.SUCCESS) {
- const { tagType } = payload
- yield put({
- type: 'changeState',
- payload: {
- key: tagType === TagTypeEnum.PERSONTAG ? 'personTags' : 'teamTags',
- data: response.data || []
- }
- })
- yield put({
- type: 'changeState',
- payload: {
- key: tagType === TagTypeEnum.PERSONTAG ? 'personTagColorMap' : 'teamTagColorMap',
- data: response.data.reduce((curr, prev, idx) => {
- const item = { ...curr, [prev.id]: LabelStatusColorMap[tagType][idx] }
- return item
- }, {})
- }
- })
- }
- }
- },
- reducers: {
- // 通用reducer
- changeState(state, action) {
- return {
- ...state,
- [action.payload.key]: action.payload.data
- }
- }
- }
- }
|