Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
a7981496
Commit
a7981496
authored
Feb 01, 2018
by
jim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix#862 determine if the target is instantiated
parent
5c08dabd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
20 deletions
+40
-20
src/components/Authorized/Authorized.js
src/components/Authorized/Authorized.js
+1
-5
src/components/Authorized/AuthorizedRoute.js
src/components/Authorized/AuthorizedRoute.js
+16
-4
src/components/Authorized/CheckPermissions.js
src/components/Authorized/CheckPermissions.js
+5
-1
src/components/Authorized/PromiseRender.js
src/components/Authorized/PromiseRender.js
+17
-5
src/components/Authorized/Secured.js
src/components/Authorized/Secured.js
+1
-5
No files found.
src/components/Authorized/Authorized.js
View file @
a7981496
...
...
@@ -5,11 +5,7 @@ class Authorized extends React.Component {
render
()
{
const
{
children
,
authority
,
noMatch
=
null
}
=
this
.
props
;
const
childrenRender
=
typeof
children
===
'
undefined
'
?
null
:
children
;
return
CheckPermissions
(
authority
,
childrenRender
,
noMatch
);
return
CheckPermissions
(
authority
,
childrenRender
,
noMatch
);
}
}
...
...
src/components/Authorized/AuthorizedRoute.js
View file @
a7981496
...
...
@@ -4,16 +4,28 @@ import Authorized from './Authorized';
class
AuthorizedRoute
extends
React
.
Component
{
render
()
{
const
{
component
:
Component
,
render
,
authority
,
redirectPath
,
...
rest
}
=
this
.
props
;
const
{
component
:
Component
,
render
,
authority
,
redirectPath
,
...
rest
}
=
this
.
props
;
return
(
<
Authorized
authority
=
{
authority
}
noMatch
=
{
<
Route
{...
rest
}
render
=
{()
=>
<
Redirect
to
=
{{
pathname
:
redirectPath
}}
/>} /
>
}
noMatch
=
{
<
Route
{...
rest
}
render
=
{()
=>
<
Redirect
to
=
{{
pathname
:
redirectPath
}}
/>
}
/>
}
>
<
Route
{...
rest
}
render
=
{
props
=>
(
Component
?
<
Component
{...
props
}
/> : render
(
props
))
}
render
=
{
props
=>
(
Component
?
<
Component
{...
props
}
/> : render
(
props
)
)
}
/
>
<
/Authorized
>
);
...
...
src/components/Authorized/CheckPermissions.js
View file @
a7981496
...
...
@@ -3,7 +3,11 @@ import PromiseRender from './PromiseRender';
import
{
CURRENT
}
from
'
./index
'
;
function
isPromise
(
obj
)
{
return
!!
obj
&&
(
typeof
obj
===
'
object
'
||
typeof
obj
===
'
function
'
)
&&
typeof
obj
.
then
===
'
function
'
;
return
(
!!
obj
&&
(
typeof
obj
===
'
object
'
||
typeof
obj
===
'
function
'
)
&&
typeof
obj
.
then
===
'
function
'
);
}
/**
...
...
src/components/Authorized/PromiseRender.js
View file @
a7981496
...
...
@@ -6,22 +6,34 @@ export default class PromiseRender extends React.PureComponent {
component
:
null
,
};
componentDidMount
()
{
const
ok
=
this
.
checkIsInstantiation
(
this
.
props
.
ok
);
const
error
=
this
.
checkIsInstantiation
(
this
.
props
.
error
);
this
.
props
.
promise
.
then
(()
=>
{
this
.
setState
({
component
:
this
.
props
.
ok
,
component
:
ok
,
});
})
.
catch
(()
=>
{
this
.
setState
({
component
:
()
=>
this
.
props
.
error
,
component
:
error
,
});
});
}
// 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
checkIsInstantiation
=
(
target
)
=>
{
if
(
!
React
.
isValidElement
(
target
))
{
return
target
;
}
return
()
=>
target
;
};
render
()
{
const
C
=
this
.
state
.
component
;
return
C
?
(
<
C
{...
this
.
props
}
/
>
const
C
omponent
=
this
.
state
.
component
;
return
C
omponent
?
(
<
C
omponent
{...
this
.
props
}
/
>
)
:
(
<
div
style
=
{{
...
...
src/components/Authorized/Secured.js
View file @
a7981496
...
...
@@ -38,11 +38,7 @@ const authorize = (authority, error) => {
throw
new
Error
(
'
authority is required
'
);
}
return
function
decideAuthority
(
targer
)
{
return
()
=>
CheckPermissions
(
authority
,
targer
,
classError
||
Exception403
);
return
()
=>
CheckPermissions
(
authority
,
targer
,
classError
||
Exception403
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment