zy-react-library/components/Select/Dictionary/index.js

41 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

import { request } from "@cqsjjb/jjb-common-lib/http";
import { useEffect, useState } from "react";
import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary";
import BasicSelect from "../Basic";
/**
* 数据字典下拉组件
*/
function DictionarySelect(props) {
const {
appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
dictValue = "",
nameKey = "dictLabel",
idKey = "dictValue",
...restProps
} = props;
const [data, setData] = useState([]);
const getData = async () => {
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
setData([]);
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
setData(data);
};
useEffect(() => {
dictValue && getData();
}, [dictValue]);
return (
2025-11-10 16:00:14 +08:00
<BasicSelect data={data} nameKey={nameKey} idKey={idKey} {...restProps} />
);
}
DictionarySelect.displayName = "DictionarySelect";
export default DictionarySelect;