UNPKG

@alitajs/antd-plus

Version:

基于 ant-design 封装的偏业务组件

28 lines (23 loc) 880 B
import React from 'react'; import isFunction from 'lodash/isFunction'; import checkAuthority from './check-authority'; var Authorized = function Authorized(props) { var policy = props.policy, children = props.children, authority = props.authority, noMatch = props.noMatch; var childrenRender = typeof children === 'undefined' ? null : children; // 防止policy不存在报错 if (!policy) { return /*#__PURE__*/React.createElement(React.Fragment, null, childrenRender); } var checkResult = checkAuthority(policy, authority); if (isFunction(children)) { return /*#__PURE__*/React.createElement(React.Fragment, null, children(checkResult)); } else { return /*#__PURE__*/React.createElement(React.Fragment, null, checkResult ? childrenRender : noMatch); } }; Authorized.defaultProps = { noMatch: null }; export default Authorized;