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
0f15cfc9
Commit
0f15cfc9
authored
Sep 12, 2018
by
afc163
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix authority reading and add test case
parent
5bcf895a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
25 deletions
+31
-25
src/utils/authority.js
src/utils/authority.js
+12
-14
src/utils/authority.test.js
src/utils/authority.test.js
+19
-0
src/utils/utils.js
src/utils/utils.js
+0
-11
No files found.
src/utils/authority.js
View file @
0f15cfc9
import
{
isJsonString
}
from
'
@/utils/utils
'
;
// use localStorage to store the authority info, which might be sent from server in actual project.
// use localStorage to store the authority info, which might be sent from server in actual project.
export
function
getAuthority
()
{
export
function
getAuthority
(
str
)
{
// return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
// return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
const
authorityString
=
localStorage
.
getItem
(
'
antd-pro-authority
'
);
const
authorityString
=
typeof
str
===
'
undefined
'
?
localStorage
.
getItem
(
'
antd-pro-authority
'
)
:
str
;
// authorityString could be admin, "admin", ["admin"]
let
authority
;
let
authority
;
if
(
isJsonString
(
authorityString
))
{
try
{
authority
=
JSON
.
parse
(
authorityString
);
authority
=
JSON
.
parse
(
authorityString
);
}
else
{
}
catch
(
e
)
{
authority
=
[
authorityString
];
authority
=
authorityString
;
}
if
(
typeof
authority
===
'
string
'
)
{
return
[
authority
];
}
}
return
authority
||
[
'
admin
'
];
return
authority
||
[
'
admin
'
];
}
}
export
function
setAuthority
(
authority
)
{
export
function
setAuthority
(
authority
)
{
let
authorityString
;
const
proAuthority
=
typeof
authority
===
'
string
'
?
[
authority
]
:
authority
;
if
(
isJsonString
(
authority
))
{
return
localStorage
.
setItem
(
'
antd-pro-authority
'
,
JSON
.
stringify
(
proAuthority
));
authorityString
=
JSON
.
stringify
(
authority
);
}
else
{
authorityString
=
[
authority
];
}
return
localStorage
.
setItem
(
'
antd-pro-authority
'
,
authorityString
);
}
}
src/utils/authority.test.js
0 β 100644
View file @
0f15cfc9
import
{
getAuthority
}
from
'
./authority
'
;
describe
(
'
getAuthority should be strong
'
,
()
=>
{
it
(
'
empty
'
,
()
=>
{
expect
(
getAuthority
(
null
)).
toEqual
([
'
admin
'
]);
// default value
});
it
(
'
string
'
,
()
=>
{
expect
(
getAuthority
(
'
admin
'
)).
toEqual
([
'
admin
'
]);
});
it
(
'
array with double quotes
'
,
()
=>
{
expect
(
getAuthority
(
'
"admin"
'
)).
toEqual
([
'
admin
'
]);
});
it
(
'
array with single item
'
,
()
=>
{
expect
(
getAuthority
(
'
["admin"]
'
)).
toEqual
([
'
admin
'
]);
});
it
(
'
array with multiple items
'
,
()
=>
{
expect
(
getAuthority
(
'
["admin", "guest"]
'
)).
toEqual
([
'
admin
'
,
'
guest
'
]);
});
});
src/utils/utils.js
View file @
0f15cfc9
...
@@ -181,14 +181,3 @@ export function formatWan(val) {
...
@@ -181,14 +181,3 @@ export function formatWan(val) {
export
function
isAntdPro
()
{
export
function
isAntdPro
()
{
return
window
.
location
.
hostname
===
'
preview.pro.ant.design
'
;
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