errorInfo.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { queryErrorInfos } from '@/services/api/common'
  2. import { createStore } from '../base'
  3. import { sessionData } from '../storage'
  4. /**
  5. * 错误信息存储对象
  6. */
  7. export const errorInfoStore = createStore({
  8. state() {
  9. return {
  10. loading: false,
  11. errorInfos: sessionData.getRef('errorInfos'),
  12. }
  13. },
  14. actions: {
  15. // 获取系统错误信息
  16. getErrorInfoList() {
  17. if (this.state.errorInfos.length) {
  18. return Promise.resolve()
  19. }
  20. this.state.loading = true
  21. return queryErrorInfos({
  22. success: (res) => {
  23. this.state.errorInfos = res.data
  24. },
  25. complete: () => {
  26. this.state.loading = false
  27. }
  28. })
  29. },
  30. // 根据 code 获取错误信息
  31. getErrorInfoByCode(code: number) {
  32. const errorInfos = this.state.errorInfos
  33. const error = errorInfos.find((e) => e.errorid === code)
  34. return error?.description
  35. }
  36. }
  37. })