UNPKG

@uiw-admin/authorized

Version:
45 lines (43 loc) 988 B
import React from 'react'; import { jsx as _jsx } from "react/jsx-runtime"; export var getAuthPath = path => { // @ts-ignore if (AUTH) { var authList = []; var authStr = sessionStorage.getItem('auth'); // @ts-ignore if (STORAGE === 'local') { authStr = localStorage.getItem('auth'); } if (authStr) { authList = JSON.parse(authStr); } var fig = authList.find(item => item === path); return !!fig; } return true; }; /** 校验按钮权限 */ var AuthBtn = props => { var { path, disabled, children } = props; var fig = React.useMemo(() => { // @ts-ignore if (AUTH) { return getAuthPath(path); } return true; }, [path]); if (fig) { return children; } else if (!fig && disabled && /*#__PURE__*/React.isValidElement(children)) { return /*#__PURE__*/React.cloneElement(children, { disabled }); } return /*#__PURE__*/_jsx(React.Fragment, {}); }; export default AuthBtn;