authority.js 783 Bytes
Newer Older
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
1 2
import { isJsonString } from '@/utils/utils';

ddcat1115's avatar
ddcat1115 committed
3 4
// use localStorage to store the authority info, which might be sent from server in actual project.
export function getAuthority() {
5
  // return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
afc163's avatar
afc163 committed
6 7
  const authorityString = localStorage.getItem('antd-pro-authority');
  let authority;
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
8
  if (isJsonString(authorityString)) {
afc163's avatar
afc163 committed
9
    authority = JSON.parse(authorityString);
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
10
  } else {
afc163's avatar
afc163 committed
11
    authority = [authorityString];
12
  }
afc163's avatar
afc163 committed
13
  return authority || ['admin'];
ddcat1115's avatar
ddcat1115 committed
14 15 16
}

export function setAuthority(authority) {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
17 18 19 20 21 22 23
  let authorityString;
  if (isJsonString(authority)) {
    authorityString = JSON.stringify(authority);
  } else {
    authorityString = [authority];
  }
  return localStorage.setItem('antd-pro-authority', authorityString);
ddcat1115's avatar
ddcat1115 committed
24
}