1234567891011121314151617181920212223242526272829303132
  1. import React from 'react';
  2. let allBtns = [];
  3. let current = [];
  4. const AuthButton = ({ children, name, noRight }) => {
  5. const btn = allBtns.filter(x => x.code === name)[0]
  6. // 没维护的按钮, 或者不需要权限的按钮直接通过
  7. // if (!btn || !btn.roles || !btn.roles.length) {
  8. // return <>{children}</>
  9. // }
  10. // const hasRight = btn.roles.some(x => current.some(y => x === y))
  11. if (!btn) {
  12. return <>{children}</>
  13. }
  14. const hasRight = current.filter(x => x.code === name)[0]
  15. return hasRight ? <>{children}</> : <>{noRight}</>
  16. }
  17. const setAllBtnAuth = x => allBtns = x;
  18. const setUserBtnAuth = x => current = x;
  19. export default AuthButton;
  20. export {
  21. setAllBtnAuth,
  22. setUserBtnAuth,
  23. };