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

41 lines
1.1 KiB
JavaScript
Raw 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 BasicLeftTree from "../Basic";
/**
* 数据字典左侧树组件
*/
function DictionaryLeftTree(props) {
const {
appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
dictValue = "",
nameKey = "dictLabel",
idKey = "dictValue",
...restProps
} = props;
const [treeData, setTreeData] = useState([]);
const getData = async () => {
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey))
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
setTreeData([]);
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
setTreeData(data);
};
useEffect(() => {
dictValue && getData();
}, [dictValue]);
return (
<BasicLeftTree treeData={treeData} nameKey={nameKey} idKey={idKey} {...restProps} />
);
}
DictionaryLeftTree.displayName = "DictionaryLeftTree";
export default DictionaryLeftTree;