jim 8 лет назад
Родитель
Сommit
ecef62591f

+ 23 - 0
src/components/Authorized/demo/AuthorizedArray.md

@@ -0,0 +1,23 @@
+---
+order: 1
+title: 
+  zh-CN: 使用数组作为参数
+  en-US: Use Array as a parameter
+---
+
+Use Array as a parameter
+
+```jsx
+import RenderAuthorized from 'ant-design-pro/lib/Authorized';
+import { Alert } from 'antd';
+
+const Authorized = RenderAuthorized('user');
+const noMatch = <Alert message="No permission." type="error" showIcon />;
+
+ReactDOM.render(
+  <Authorized authority={['user', 'admin']} noMatch={noMatch}>
+    <Alert message="Use Array as a parameter passed!" type="success" showIcon />
+  </Authorized>,
+  mountNode,
+);
+```

+ 31 - 0
src/components/Authorized/demo/AuthorizedFunction.md

@@ -0,0 +1,31 @@
+---
+order: 2
+title: 
+  zh-CN: 使用方法作为参数
+  en-US: Use function as a parameter
+---
+
+Use Function as a parameter
+
+```jsx
+import RenderAuthorized from 'ant-design-pro/lib/Authorized';
+import { Alert } from 'antd';
+
+const Authorized = RenderAuthorized('user');
+const noMatch = <Alert message="No permission." type="error" showIcon />;
+
+const havePermission = () => {
+  return false;
+};
+
+ReactDOM.render(
+  <Authorized authority={havePermission} noMatch={noMatch}>
+    <Alert
+      message="Use Function as a parameter passed!"
+      type="success"
+      showIcon
+    />
+  </Authorized>,
+  mountNode,
+);
+```

+ 4 - 23
src/components/Authorized/demo/basic.md

@@ -1,11 +1,11 @@
 ---
 order: 0
 title: 
-  zh-CN: 基
-  en-US: Basic
+  zh-CN: 基本使用
+  en-US: Basic use
 ---
 
-Authorized demo used
+Basic use
 
 ```jsx
 import RenderAuthorized from 'ant-design-pro/lib/Authorized';
@@ -14,31 +14,12 @@ import { Alert } from 'antd';
 const Authorized = RenderAuthorized('user');
 const noMatch = <Alert message="No permission." type="error" showIcon />;
 
-
-const havePermission = () => {
-  return false;
-};
-
-const havePermissionAsync = new Promise((resolve,reject)=>{
-  // Call resolve on behalf of passed
-  setTimeout( ()=> resolve() , 1000)
-});
-
 ReactDOM.render(
   <div>
     <Authorized authority="admin" noMatch={noMatch}>
       <Alert message="user Passed!" type="success" showIcon />
     </Authorized>
-    <Authorized authority={['user','admin']} noMatch={noMatch}>
-      <Alert message="Use Array as a parameter passed!" type="success" showIcon />
-    </Authorized>
-    <Authorized authority={havePermission} noMatch={noMatch}>
-      <Alert message="Use function as a parameter passed!" type="success" showIcon />
-    </Authorized>
-    <Authorized authority={havePermissionAsync} noMatch={noMatch}>
-      <Alert message="Use Promise as a parameter passed!" type="success" showIcon />
-    </Authorized>
   </div>,
-  mountNode
+  mountNode,
 );
 ```

+ 4 - 51
src/components/Authorized/demo/secured.md

@@ -1,8 +1,8 @@
 ---
-order: 1
+order: 3
 title: 
-  zh-CN: 注解
-  en-US: secured
+  zh-CN: 注解基本使用
+  en-US: Basic use secured
 ---
 
 secured demo used
@@ -12,63 +12,16 @@ import RenderAuthorized from 'ant-design-pro/lib/Authorized';
 import { Alert } from 'antd';
 
 const { Secured } = RenderAuthorized('user');
-const noMatch = <Alert message="No permission." type="error" showIcon />;
 
-const havePermission = () => {
-  return false;
-};
-
-const havePermissionAsync = new Promise((resolve, reject) => {
-  // Call resolve on behalf of passed
-  setTimeout(() => resolve(), 1000);
-});
-
-@Secured('admin', noMatch)
+@Secured('admin')
 class TestSecuredString extends React.Component {
   render() {
     <Alert message="user Passed!" type="success" showIcon />;
   }
 }
-
-@Secured(['user', 'admin'], noMatch)
-class TestSecuredArray extends React.Component {
-  render() {
-    <Alert
-      message="Use Array as a parameter passed!"
-      type="success"
-      showIcon
-    />;
-  }
-}
-
-@Secured(havePermission, noMatch)
-class TestSecuredFunction extends React.Component {
-  render() {
-    <Alert
-      message="Use function as a parameter passed!"
-      type="success"
-      showIcon
-    />;
-  }
-}
-
-@Secured(havePermissionAsync, noMatch)
-class TestSecuredPromise extends React.Component {
-  render() {
-    <Alert
-      message="Use Promise as a parameter passed!"
-      type="success"
-      showIcon
-    />;
-  }
-}
-
 ReactDOM.render(
   <div>
     <TestSecuredString />
-    <TestSecuredArray />
-    <TestSecuredFunction />
-    <TestSecuredPromise />
   </div>,
   mountNode,
 );

+ 6 - 1
src/routes/Dashboard/Monitor.js

@@ -13,7 +13,12 @@ const { Secured } = Authorized;
 
 const targetTime = new Date().getTime() + 3900000;
 
-@Secured('admin')
+// use permission as a parameter
+const havePermissionAsync = new Promise((resolve) => {
+  // Call resolve on behalf of passed
+  setTimeout(() => resolve(), 1000);
+});
+@Secured(havePermissionAsync)
 @connect(({ monitor, loading }) => ({
   monitor,
   loading: loading.models.monitor,