import { OptionsRow } from 'yc-pro-components/es/types'; import { InjectionKey } from 'vue'; /** * 字典 Store 标准接口 * @description 所有项目的字典 Store 必须实现此接口才能使用自动字典注入功能 * @version v0.2.0 * @example * ```ts * import type { DictStoreInterface } from 'yc-components' * * export const useDictStore = defineStore('dict', () => { * const getDictData = (field: string): OptionsRow[] => { * // 返回字典数据 * return dictData.value[field] || [] * } * * const hasDict = (field: string): boolean => { * return !!dictData.value[field] * } * * const getDictLabel = (field: string, value: string | number): string => { * const items = dictData.value[field] || [] * const item = items.find(item => item.value === value) * return item?.label || String(value) * } * * return { getDictData, hasDict, getDictLabel } * }) * ``` */ export interface DictStoreInterface { /** * 根据字段名或字典 code 获取字典数据 * @param field 字段名(如 "status")或字典 code(如 "ORDER_STATUS") * @returns 字典选项数组 * @description 此方法是核心方法,必须实现 */ getDictData: (field: string) => OptionsRow[]; /** * 检查字段是否有字典映射 * @param field 字段名或字典 code * @returns 是否存在字典数据 * @description 可选方法,用于优化性能 */ hasDict?: (field: string) => boolean; /** * 获取字典标签 * @param field 字段名或字典 code * @param value 字典值 * @returns 字典标签 * @description 可选方法,用于显示字典标签 */ getDictLabel?: (field: string, value: string | number) => string; } /** * 字典 Store 注入 Key * @description 用于 provide/inject 传递字典 Store 实例 * @version v0.2.0 * @example * ```ts * // 提供字典 Store * import { provide } from 'vue' * import { DictStoreInjectionKey } from 'yc-components' * * const dictStore = useDictStore() * provide(DictStoreInjectionKey, dictStore) * ``` * * ```ts * // 注入字典 Store * import { inject } from 'vue' * import { DictStoreInjectionKey } from 'yc-components' * * const dictStore = inject(DictStoreInjectionKey) * ``` */ export declare const DictStoreInjectionKey: InjectionKey;