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