@luck-helper/utils
Advanced tools
| import React from 'react'; | ||
| import { Icon, Popover, Tooltip, Divider } from 'antd'; | ||
| export default function PermissionUtil(component, userPermission) { | ||
| var showForbit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
| var placement = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'right'; | ||
| var maxCount = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 3; | ||
| var childList = []; | ||
| React.Children.forEach(component, function (child) { | ||
| var hasPermission = userPermission && userPermission.indexOf(child.props.wanted) > -1 || child.props.wanted === 'noAuth'; | ||
| if (hasPermission) { | ||
| childList.push(child); | ||
| } | ||
| }); | ||
| if (childList.length > 0 && childList.length <= maxCount) { | ||
| return childList; | ||
| } | ||
| if (childList.length > maxCount) { | ||
| var common = []; | ||
| var more = []; | ||
| childList.forEach(function (child, index) { | ||
| if (index < maxCount - 1) { | ||
| common.push(child); | ||
| } else { | ||
| more.push(child); | ||
| } | ||
| }); | ||
| var moreDom = more.map(function (child, index) { | ||
| if (more.length > 1 && index < more.length - 1) { | ||
| return /*#__PURE__*/React.createElement("div", { | ||
| key: index | ||
| }, child, /*#__PURE__*/React.createElement(Divider, { | ||
| type: "horizontal", | ||
| style: { | ||
| margin: '8px 0' | ||
| } | ||
| })); | ||
| } | ||
| return /*#__PURE__*/React.createElement("div", { | ||
| key: index | ||
| }, child); | ||
| }); | ||
| common.push( /*#__PURE__*/React.createElement(Popover, { | ||
| placement: placement, | ||
| content: moreDom | ||
| }, /*#__PURE__*/React.createElement(Icon, { | ||
| type: "ellipsis" | ||
| }))); | ||
| return common; | ||
| } | ||
| return showForbit ? [/*#__PURE__*/React.createElement(Tooltip, { | ||
| placement: "top", | ||
| title: "\u60A8\u6CA1\u6709\u76F8\u5173\u6743\u9650" | ||
| }, /*#__PURE__*/React.createElement(Icon, { | ||
| type: "stop" | ||
| }))] : []; | ||
| } |
| "use strict"; | ||
| var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = PermissionUtil; | ||
| var _react = _interopRequireDefault(require("react")); | ||
| var _antd = require("antd"); | ||
| function PermissionUtil(component, userPermission) { | ||
| var showForbit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
| var placement = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'right'; | ||
| var maxCount = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 3; | ||
| var childList = []; | ||
| _react.default.Children.forEach(component, function (child) { | ||
| var hasPermission = userPermission && userPermission.indexOf(child.props.wanted) > -1 || child.props.wanted === 'noAuth'; | ||
| if (hasPermission) { | ||
| childList.push(child); | ||
| } | ||
| }); | ||
| if (childList.length > 0 && childList.length <= maxCount) { | ||
| return childList; | ||
| } | ||
| if (childList.length > maxCount) { | ||
| var common = []; | ||
| var more = []; | ||
| childList.forEach(function (child, index) { | ||
| if (index < maxCount - 1) { | ||
| common.push(child); | ||
| } else { | ||
| more.push(child); | ||
| } | ||
| }); | ||
| var moreDom = more.map(function (child, index) { | ||
| if (more.length > 1 && index < more.length - 1) { | ||
| return /*#__PURE__*/_react.default.createElement("div", { | ||
| key: index | ||
| }, child, /*#__PURE__*/_react.default.createElement(_antd.Divider, { | ||
| type: "horizontal", | ||
| style: { | ||
| margin: '8px 0' | ||
| } | ||
| })); | ||
| } | ||
| return /*#__PURE__*/_react.default.createElement("div", { | ||
| key: index | ||
| }, child); | ||
| }); | ||
| common.push( /*#__PURE__*/_react.default.createElement(_antd.Popover, { | ||
| placement: placement, | ||
| content: moreDom | ||
| }, /*#__PURE__*/_react.default.createElement(_antd.Icon, { | ||
| type: "ellipsis" | ||
| }))); | ||
| return common; | ||
| } | ||
| return showForbit ? [/*#__PURE__*/_react.default.createElement(_antd.Tooltip, { | ||
| placement: "top", | ||
| title: "\u60A8\u6CA1\u6709\u76F8\u5173\u6743\u9650" | ||
| }, /*#__PURE__*/_react.default.createElement(_antd.Icon, { | ||
| type: "stop" | ||
| }))] : []; | ||
| } |
+1
-1
| { | ||
| "name": "@luck-helper/utils", | ||
| "version": "0.0.3", | ||
| "version": "0.0.4", | ||
| "scripts": { | ||
@@ -5,0 +5,0 @@ "start": "dumi dev", |
26845
18.27%21
10.53%665
21.13%