icon.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { fetchVehIcon, fetchUserIcon, fetchFacIcon } from "@/api/iconConfig/iconConfig";
  2. import { isEmpty } from 'lodash';
  3. const icon = {
  4. state: {
  5. vehIcon: null,
  6. userIcon: null,
  7. facIcon: null,
  8. },
  9. mutations: {
  10. SET_ICON: (state, {key,data}) => {
  11. state[key] = data
  12. },
  13. },
  14. actions: {
  15. // 获取车辆图标
  16. async getVehIcon({ commit, state }) {
  17. // console.log(this,'this')
  18. if (!isEmpty(state.vehIcon)) {
  19. return new Promise((resolve) => {
  20. resolve(state.vehIcon)
  21. })
  22. } else {
  23. let { code, data } = await fetchVehIcon({})
  24. if (code == 0) {
  25. commit('SET_ICON', {key: 'vehIcon',data},)
  26. }
  27. return new Promise((resolve) => {
  28. resolve(state.vehIcon)
  29. })
  30. }
  31. },
  32. // 获取人员类型图标
  33. async getUserIcon({ commit, state }) {
  34. if (!isEmpty(state.userIcon)) {
  35. return new Promise((resolve) => {
  36. resolve(state.userIcon)
  37. })
  38. } else {
  39. let { code, data } = await fetchUserIcon({})
  40. if (code == 0) {
  41. commit('SET_ICON', {key: 'userIcon',data},)
  42. }
  43. return new Promise((resolve) => {
  44. resolve(state.userIcon)
  45. })
  46. }
  47. },
  48. // 获取设施类型图标
  49. async getFacIcon({ commit, state }) {
  50. if (!isEmpty(state.facIcon)) {
  51. return new Promise((resolve) => {
  52. resolve(state.facIcon)
  53. })
  54. } else {
  55. let { code, data } = await fetchFacIcon({})
  56. if (code == 0) {
  57. commit('SET_ICON', {key: 'facIcon',data},)
  58. }
  59. return new Promise((resolve) => {
  60. resolve(state.facIcon)
  61. })
  62. }
  63. },
  64. }
  65. }
  66. export default icon