浏览代码

Fix JSON parse error in authority

close #2243
close #2276
close #2185
close #2226
close #2218
close #2241
ref #2170
afc163 7 年之前
父节点
当前提交
f3178a8171
共有 2 个文件被更改,包括 7 次插入11 次删除
  1. 0 1
      src/components/SiderMenu/SiderMenu.js
  2. 7 10
      src/utils/authority.js

+ 0 - 1
src/components/SiderMenu/SiderMenu.js

@@ -98,7 +98,6 @@ export default class SiderMenu extends PureComponent {
 
     return (
       <Sider
-        trigger={null}
         collapsible
         collapsed={collapsed}
         breakpoint="lg"

+ 7 - 10
src/utils/authority.js

@@ -1,17 +1,14 @@
 // 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'];
-  let authority = localStorage.getItem('antd-pro-authority');
-  if (authority) {
-    if (authority.includes('[')) {
-      authority = JSON.parse(authority);
-    } else {
-      authority = [JSON.parse(authority)];
-    }
-  } else {
-    authority = ['admin'];
+  const authorityString = localStorage.getItem('antd-pro-authority');
+  let authority;
+  try {
+    authority = JSON.parse(authorityString);
+  } catch (e) {
+    authority = [authorityString];
   }
-  return authority;
+  return authority || ['admin'];
 }
 
 export function setAuthority(authority) {