import { fetchVehIcon, fetchUserIcon, fetchFacIcon } from "@/api/iconConfig/iconConfig"; import { isEmpty } from 'lodash'; const icon = { state: { vehIcon: null, userIcon: null, facIcon: null, }, mutations: { SET_ICON: (state, {key,data}) => { state[key] = data }, }, actions: { // 获取车辆图标 async getVehIcon({ commit, state }) { // console.log(this,'this') if (!isEmpty(state.vehIcon)) { return new Promise((resolve) => { resolve(state.vehIcon) }) } else { let { code, data } = await fetchVehIcon({}) if (code == 0) { commit('SET_ICON', {key: 'vehIcon',data},) } return new Promise((resolve) => { resolve(state.vehIcon) }) } }, // 获取人员类型图标 async getUserIcon({ commit, state }) { if (!isEmpty(state.userIcon)) { return new Promise((resolve) => { resolve(state.userIcon) }) } else { let { code, data } = await fetchUserIcon({}) if (code == 0) { commit('SET_ICON', {key: 'userIcon',data},) } return new Promise((resolve) => { resolve(state.userIcon) }) } }, // 获取设施类型图标 async getFacIcon({ commit, state }) { if (!isEmpty(state.facIcon)) { return new Promise((resolve) => { resolve(state.facIcon) }) } else { let { code, data } = await fetchFacIcon({}) if (code == 0) { commit('SET_ICON', {key: 'facIcon',data},) } return new Promise((resolve) => { resolve(state.facIcon) }) } }, } } export default icon