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