字典 Dictionary
该模块提供统一的静态与动态字典定义入口,可用于下拉框、状态映射、表格标签渲染等场景。
💡 使用示例
1. 📚 App.jsx 内初始化字典
import React, { useLayoutEffect } from 'react';
import { initDictData } from '@npmqg/utils-dictionary-data';
import { useGlobalStore } from '@/store';
function AppIndex() {
const setState = useGlobalStore((state) => state.setState);
//初始化
useLayoutEffect(() => {
//初始化字典项
initDictData(require.context('@/dictionary', false, /\.js$/), setState, useGlobalStore.getState).then();
}, []);
return <Routers />;
}
📚 2. 配置字典
src/dictionary/system.js
import { requestAigcModelVendors } from '@/services/public';
const Dict = {
DictPublicMap: {},
//(静态字典、动态字典正反向Map自动生成 所以不需要手动添加)
//静态字典
DictStatic: {
//是否
SystemWhetherOrNot: () => [
{
label: '