/** * 字典工具 */ import { getConfigByName } from '@af-mobile-client-vue3/services/api/common' /** * 获取字典 * @param configName 配置名 * @param callback 获取到字典的回调 * @param serviceName 服务名 */ export function getDict(configName: string, callback: Function, serviceName = import.meta.env.VITE_APP_SYSTEM_NAME) { getConfigByName(configName, (result) => { if (result != null && result.value) { callback(result.value) } else { console.warn(`dict [${configName}] not found`) callback(null) } }, serviceName) } export function getDictItemByValue(configName: string, serviceName: string, value: string, callback: Function) { getDict(configName, (result) => { if (result != null) { for (const item of result) { if (item.value.toString() === value) { callback(item) return } } console.warn(`dict [${configName}] 's value [${value}] not found`) } callback(null) }, serviceName) } export function getDictItemByLabel(configName: string, serviceName: string, label: string, callback: Function) { getDict(configName, (result) => { if (result != null) { for (const item of result) { if (item.label.toString() === label) { callback(item) return } } console.warn(`dict [${configName}] 's label [${label}] not found`) } callback(null) }, serviceName) }