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
77d714f2
Commit
77d714f2
authored
Sep 12, 2018
by
陈帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix authority parse error
parent
1dd1fb4f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
8 deletions
+33
-8
src/components/Exception/index.d.ts
src/components/Exception/index.d.ts
+1
-0
src/components/Exception/index.en-US.md
src/components/Exception/index.en-US.md
+2
-1
src/components/Exception/index.js
src/components/Exception/index.js
+4
-2
src/components/Exception/index.zh-CN.md
src/components/Exception/index.zh-CN.md
+1
-0
src/pages/Authorized.js
src/pages/Authorized.js
+3
-2
src/utils/authority.js
src/utils/authority.js
+11
-3
src/utils/utils.js
src/utils/utils.js
+11
-0
No files found.
src/components/Exception/index.d.ts
View file @
77d714f2
...
...
@@ -9,6 +9,7 @@ export interface IExceptionProps {
style
?:
React
.
CSSProperties
;
className
?:
string
;
backText
?:
React
.
ReactNode
;
redirect
?:
string
;
}
export
default
class
Exception
extends
React
.
Component
<
IExceptionProps
,
any
>
{}
src/components/Exception/index.en-US.md
View file @
77d714f2
...
...
@@ -16,4 +16,5 @@ title | title | ReactNode | -
desc | supplementary description | ReactNode | -
img | the url of background image | string | -
actions | suggested operations, a default 'Home' link will show if not set | ReactNode | -
linkElement | to specify the element of link | string
\|
ReactElement | 'a'
\ No newline at end of file
linkElement | to specify the element of link | string
\|
ReactElement | 'a'
redirect | redirect path | string | '/'
\ No newline at end of file
src/components/Exception/index.js
View file @
77d714f2
...
...
@@ -7,6 +7,7 @@ import styles from './index.less';
class
Exception
extends
React
.
PureComponent
{
static
defaultProps
=
{
backText
:
'
back to home
'
,
redirect
:
'
/
'
,
};
constructor
(
props
)
{
...
...
@@ -24,6 +25,7 @@ class Exception extends React.PureComponent {
desc
,
img
,
actions
,
redirect
,
...
rest
}
=
this
.
props
;
const
pageType
=
type
in
config
?
type
:
'
404
'
;
...
...
@@ -44,8 +46,8 @@ class Exception extends React.PureComponent {
createElement
(
linkElement
,
{
to
:
'
/
'
,
href
:
'
/
'
,
to
:
redirect
,
href
:
redirect
,
},
<
Button
type
=
"
primary
"
>
{
backText
}
<
/Button
>
)}
...
...
src/components/Exception/index.zh-CN.md
View file @
77d714f2
...
...
@@ -18,3 +18,4 @@ order: 5
| img | 背景图片地址 | string| -|
| actions | 建议操作,配置此属性时默认的『返回首页』按钮不生效| ReactNode| -|
| linkElement | 定义链接的元素 | string
\|
ReactElement | 'a' |
| redirect | 返回按钮的跳转地址 | string | '/'
src/pages/Authorized.js
View file @
77d714f2
...
...
@@ -15,12 +15,13 @@ export default ({ children }) => {
type
=
"
403
"
desc
=
{
formatMessage
({
id
:
'
app.exception.description.403
'
})}
linkElement
=
{
Link
}
backText
=
{
formatMessage
({
id
:
'
app.exception.back
'
})}
redirect
=
"
/user/login
"
backText
=
"
back to login
"
/>
);
// if Authority === ['guest'] redirect to /user/login
// You can implement the logic here.
if
(
Authority
.
join
(
''
)
===
'
guest
'
)
{
if
(
Authority
===
'
guest
'
||
Authority
.
join
(
''
)
===
'
guest
'
)
{
noMatch
=
<
Redirect
to
=
"
/user/login
"
/>
;
}
return
(
...
...
src/utils/authority.js
View file @
77d714f2
import
{
isJsonString
}
from
'
@/utils/utils
'
;
// 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'];
const
authorityString
=
localStorage
.
getItem
(
'
antd-pro-authority
'
);
let
authority
;
try
{
if
(
isJsonString
(
authorityString
))
{
authority
=
JSON
.
parse
(
authorityString
);
}
catch
(
e
)
{
}
else
{
authority
=
[
authorityString
];
}
return
authority
||
[
'
admin
'
];
}
export
function
setAuthority
(
authority
)
{
return
localStorage
.
setItem
(
'
antd-pro-authority
'
,
JSON
.
stringify
(
authority
));
let
authorityString
;
if
(
isJsonString
(
authority
))
{
authorityString
=
JSON
.
stringify
(
authority
);
}
else
{
authorityString
=
[
authority
];
}
return
localStorage
.
setItem
(
'
antd-pro-authority
'
,
authorityString
);
}
src/utils/utils.js
View file @
77d714f2
...
...
@@ -181,3 +181,14 @@ export function formatWan(val) {
export
function
isAntdPro
()
{
return
window
.
location
.
hostname
===
'
preview.pro.ant.design
'
;
}
export
function
isJsonString
(
str
)
{
try
{
if
(
typeof
JSON
.
parse
(
str
)
===
'
object
'
)
{
return
true
;
}
}
catch
(
e
)
{
return
false
;
}
return
false
;
}
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