数据字典集中治理

This commit is contained in:
Cheng Zhou
2025-12-17 20:58:42 +08:00
parent c2328594b0
commit b0bffbc75e
16 changed files with 170 additions and 39 deletions
+15
View File
@@ -0,0 +1,15 @@
import type { Dict, DictItem } from "./types";
export const createDict = (items: DictItem[]): Dict => {
const normalized = items.map((item, idx) => ({ order: idx, ...item }));
const get = (value?: string | null) => normalized.find((i) => i.value === value);
const list = () =>
[...normalized].sort((a, b) => (a.order || 0) - (b.order || 0));
return { items: normalized, get, list };
};
export const getDictItem = (dict: Dict, value?: string | null) => dict.get(value);
export const getDictLabel = (dict: Dict, value?: string | null) => dict.get(value)?.label || value || "";
export const getDictColor = (dict: Dict, value?: string | null) => dict.get(value)?.color;
export const getDictOptions = (dict: Dict) =>
dict.list().map((i) => ({ label: i.label, value: i.value, disabled: false }));