(str)
| 8 | import { reloadAuthorized } from './Authorized'; // use localStorage to store the authority info, which might be sent from server in actual project. |
| 9 | |
| 10 | export function getAuthority (str) { |
| 11 | const authorityString = |
| 12 | typeof str === 'undefined' && localStorage ? localStorage.getItem('userRole') : str; // authorityString could be admin, "admin", ["admin"] |
| 13 | |
| 14 | let authority; |
| 15 | |
| 16 | try { |
| 17 | if (authorityString) { |
| 18 | authority = JSON.parse(authorityString); |
| 19 | } |
| 20 | } catch (e) { |
| 21 | authority = authorityString; |
| 22 | } |
| 23 | |
| 24 | if (typeof authority === 'string') { |
| 25 | return [authority]; |
| 26 | } // preview.pro.ant.design only do not use in your production. |
| 27 | // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 |
| 28 | |
| 29 | if (!authority) { |
| 30 | return ['user']; |
| 31 | } |
| 32 | return authority; |
| 33 | } |
| 34 | export function setAuthority (authority) { |
| 35 | const proAuthority = typeof authority === 'string' ? [authority] : authority; |
| 36 | localStorage.setItem('antd-pro-authority', JSON.stringify(proAuthority)); // auto reload |
no outgoing calls
no test coverage detected