authority.js 606 B

12345678910111213141516171819
  1. // use localStorage to store the authority info, which might be sent from server in actual project.
  2. export function getAuthority() {
  3. // return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
  4. let authority = localStorage.getItem('antd-pro-authority');
  5. if (authority) {
  6. if (authority.includes('[')) {
  7. authority = JSON.parse(authority);
  8. } else {
  9. authority = [authority];
  10. }
  11. } else {
  12. authority = ['admin'];
  13. }
  14. return authority;
  15. }
  16. export function setAuthority(authority) {
  17. return localStorage.setItem('antd-pro-authority', JSON.stringify(authority));
  18. }