Просмотр исходного кода

add Secured check instantiation

jim 8 лет назад
Родитель
Сommit
295580c09b
1 измененных файлов с 13 добавлено и 1 удалено
  1. 13 1
      src/components/Authorized/Secured.js

+ 13 - 1
src/components/Authorized/Secured.js

@@ -9,6 +9,17 @@ const Exception403 = () => (
   <Exception type="403" style={{ minHeight: 500, height: '80%' }} />
 );
 
+// Determine whether the incoming component has been instantiated
+// AuthorizedRoute is already instantiated
+// Authorized  render is already instantiated, children is no instantiated
+// Secured is not instantiated
+const checkIsInstantiation = (target) => {
+  if (!React.isValidElement(target)) {
+    return target;
+  }
+  return () => target;
+};
+
 /**
  * 用于判断是否拥有权限访问此view权限
  * authority 支持传入  string ,funtion:()=>boolean|Promise
@@ -38,7 +49,8 @@ const authorize = (authority, error) => {
     throw new Error('authority is required');
   }
   return function decideAuthority(targer) {
-    return () => CheckPermissions(authority, targer, classError || Exception403);
+    const component = CheckPermissions(authority, targer, classError || Exception403);
+    return checkIsInstantiation(component);
   };
 };