2026-01-06 15:24:18 +08:00
|
|
|
import { request } from "@cqsjjb/jjb-common-lib/http.js";
|
2025-11-08 12:07:29 +08:00
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary";
|
|
|
|
|
import BasicSelectTree from "../Basic";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据字典下拉树组件
|
|
|
|
|
*/
|
|
|
|
|
function DictionarySelectTree(props) {
|
|
|
|
|
const {
|
|
|
|
|
appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
|
|
|
|
|
dictValue = "",
|
|
|
|
|
nameKey = "dictLabel",
|
|
|
|
|
idKey = "dictValue",
|
|
|
|
|
...restProps
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
const [treeData, setTreeData] = useState([]);
|
|
|
|
|
|
|
|
|
|
const getData = async () => {
|
2026-02-06 15:52:51 +08:00
|
|
|
setTreeData([]);
|
|
|
|
|
|
2025-12-20 16:42:46 +08:00
|
|
|
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
|
2026-01-13 09:05:08 +08:00
|
|
|
console.error(`【DictionarySelectTree】 传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中,当前传入的 appKey 是 ${appKey}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dictValue) {
|
|
|
|
|
console.error(`【DictionarySelectTree】 缺少 dictValue 参数`);
|
2025-12-20 16:42:46 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2025-11-08 12:07:29 +08:00
|
|
|
|
|
|
|
|
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
|
|
|
|
|
setTreeData(data);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-02-06 15:52:51 +08:00
|
|
|
getData();
|
2025-11-08 12:07:29 +08:00
|
|
|
}, [dictValue]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<BasicSelectTree treeData={treeData} nameKey={nameKey} idKey={idKey} {...restProps} />
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DictionarySelectTree.displayName = "DictionarySelectTree";
|
|
|
|
|
|
|
|
|
|
export default DictionarySelectTree;
|