4 changed files with 13 additions and 84 deletions
@ -0,0 +1,13 @@ |
|||||||
|
import { defHttp } from '@/utils/http/axios' |
||||||
|
|
||||||
|
export function getSystemDictionary(code: string) { |
||||||
|
return defHttp.get({ |
||||||
|
url: `/baymax-system/dict/dictionary?code=${code}`, |
||||||
|
}).then((res) => { |
||||||
|
return res.map(item => ({ |
||||||
|
...item, |
||||||
|
label: item.dictValue, |
||||||
|
value: item.dictKey, |
||||||
|
})) |
||||||
|
}) |
||||||
|
} |
@ -1,8 +0,0 @@ |
|||||||
import type { SystemEnum } from './types' |
|
||||||
import { defHttp } from '@/utils/http/axios' |
|
||||||
|
|
||||||
export function getSystemEnumAll() { |
|
||||||
return defHttp.get<SystemEnum>({ |
|
||||||
url: '/system/enum/getAllEnum', |
|
||||||
}) |
|
||||||
} |
|
@ -1,19 +0,0 @@ |
|||||||
interface SystemEnumValue { |
|
||||||
val: number |
|
||||||
desc: string |
|
||||||
} |
|
||||||
|
|
||||||
export type SystemEnumKeys = |
|
||||||
| 'eProductSecurityType' |
|
||||||
| 'eProductTopicCategory' |
|
||||||
| 'eDataType' |
|
||||||
| 'eProductTopicType' |
|
||||||
| 'eNetworkProtocol' |
|
||||||
| 'eNetworkType' |
|
||||||
| 'eProductNodeType' |
|
||||||
| 'eRoleAlias' |
|
||||||
| 'eAuthType' |
|
||||||
| 'eSubscribeMessageType' |
|
||||||
| 'eDeviceLogBizType' |
|
||||||
|
|
||||||
export type SystemEnum = Record<SystemEnumKeys, SystemEnumValue[]> |
|
@ -1,57 +0,0 @@ |
|||||||
import { defineStore } from 'pinia' |
|
||||||
import { ref, shallowRef } from 'vue' |
|
||||||
import { store } from '@/store' |
|
||||||
import { noop } from '@/utils' |
|
||||||
import { getSystemEnumAll } from '@/api/common' |
|
||||||
import type { SystemEnum, SystemEnumKeys } from '@/api/common/types' |
|
||||||
|
|
||||||
export const useSystemEnumStore = defineStore('systemEnum', () => { |
|
||||||
const systemEnumAll = shallowRef<SystemEnum>() |
|
||||||
|
|
||||||
function setSystemEnumAll() { |
|
||||||
getSystemEnumAll() |
|
||||||
.then((res) => { |
|
||||||
systemEnumAll.value = res |
|
||||||
}) |
|
||||||
.catch(noop) |
|
||||||
} |
|
||||||
|
|
||||||
function getSystemEnumLabel(enumType: SystemEnumKeys, value: number) { |
|
||||||
if (!systemEnumAll.value) |
|
||||||
return |
|
||||||
|
|
||||||
const ret = systemEnumAll.value[enumType].find(item => item.val === value) |
|
||||||
return ret && ret.desc |
|
||||||
} |
|
||||||
|
|
||||||
function getSystemEnums(enumType: SystemEnumKeys, options?: { labelField: string, valueField: string }) { |
|
||||||
if (!systemEnumAll.value) |
|
||||||
return [] |
|
||||||
|
|
||||||
const enums = systemEnumAll.value[enumType] || [] |
|
||||||
const { labelField, valueField } = options || { labelField: 'label', valueField: 'value' } |
|
||||||
return enums.map((item) => { |
|
||||||
return { |
|
||||||
[labelField]: item.desc, |
|
||||||
[valueField]: item.val, |
|
||||||
} |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
const initialized = ref(false) |
|
||||||
function initialize() { |
|
||||||
initialized.value = true |
|
||||||
setSystemEnumAll() |
|
||||||
} |
|
||||||
|
|
||||||
return { |
|
||||||
initialized, |
|
||||||
initialize, |
|
||||||
getSystemEnumLabel, |
|
||||||
getSystemEnums, |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
export function useSystemEnumStoreWithOut() { |
|
||||||
return useSystemEnumStore(store) |
|
||||||
} |
|
Loading…
Reference in new issue