| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { shallowRef } from 'vue'
- import { queryErrorInfos } from '@/services/api/common'
- import { defineStore } from '../store'
- import { sessionData } from '../storage'
- import { i18n } from '@/stores'
- /**
- * 错误信息存储对象
- */
- export const useErrorInfoStore = defineStore(() => {
- const loading = shallowRef(false)
- const errorInfos = sessionData.getRef('errorInfos')
- // 获取系统错误信息
- const getErrorInfoList = async () => {
- try {
- if (errorInfos.value.length) {
- return Promise.resolve()
- }
- loading.value = true
- const res = await queryErrorInfos()
- errorInfos.value = res.data
- } finally {
- loading.value = false
- }
- }
- // 根据 code 获取错误信息
- const getErrorInfoByCode = (code: number) => {
- const error = errorInfos.value.find((e) => e.errorid === code)
- switch (i18n.global.locale) {
- case 'zh-CN':
- return error?.description
- break;
- case 'en-US':
- return error?.descriptionen
- break;
- case 'zh-TW':
- return error?.descriptionzh_tw
- break;
- default:
- return error?.descriptionth
- break;
- }
- }
- return {
- loading,
- errorInfos,
- getErrorInfoList,
- getErrorInfoByCode,
- }
- })
|