7 changed files with 33 additions and 8 deletions
@ -1,16 +1,24 @@ |
|||
import { isJsonString } from '@/utils/utils'; |
|||
|
|||
// use localStorage to store the authority info, which might be sent from server in actual project.
|
|||
export function getAuthority() { |
|||
// return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
|
|||
const authorityString = localStorage.getItem('antd-pro-authority'); |
|||
let authority; |
|||
try { |
|||
if (isJsonString(authorityString)) { |
|||
authority = JSON.parse(authorityString); |
|||
} catch (e) { |
|||
} else { |
|||
authority = [authorityString]; |
|||
} |
|||
return authority || ['admin']; |
|||
} |
|||
|
|||
export function setAuthority(authority) { |
|||
return localStorage.setItem('antd-pro-authority', JSON.stringify(authority)); |
|||
let authorityString; |
|||
if (isJsonString(authority)) { |
|||
authorityString = JSON.stringify(authority); |
|||
} else { |
|||
authorityString = [authority]; |
|||
} |
|||
return localStorage.setItem('antd-pro-authority', authorityString); |
|||
} |
|||
|
|||
Loading…
Reference in new issue