Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
shuniu-admin-react
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
superman
shuniu-admin-react
Commits
613ea9d4
Commit
613ea9d4
authored
Aug 09, 2016
by
superman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2
parent
712bedf8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
140 deletions
+94
-140
index.css
dist/index.css
+1
-1
index.js
dist/index.js
+36
-36
EditItem.jsx
src/containers/Authority/EditItem.jsx
+55
-91
List.jsx
src/containers/Resource/List.jsx
+2
-12
No files found.
dist/index.css
View file @
613ea9d4
This diff is collapsed.
Click to expand it.
dist/index.js
View file @
613ea9d4
This diff is collapsed.
Click to expand it.
src/containers/Authority/EditItem.jsx
View file @
613ea9d4
...
...
@@ -51,11 +51,8 @@ export default class EditItem extends Component {
constructor
()
{
super
(...
arguments
);
this
.
state
=
{
isEdit
:
false
,
permissions
:
{},
expandedKeys
:[],
autoExpandParent
:
true
,
checkedKeys
:[]
resourcesCategoryMap
:{},
checkedKeys
:
[]
}
}
...
...
@@ -66,12 +63,10 @@ export default class EditItem extends Component {
};
componentWillReceiveProps
(
nextProps
)
{
const
state
=
{
isEdit
:
nextProps
.
isEdit
};
if
(
nextProps
.
item
&&
nextProps
.
item
.
permissions
&&
nextProps
.
resources
)
{
state
.
permissions
=
nextProps
.
item
.
permissions
;
console
.
log
(
'
state.permissions'
,
state
.
permissions
);
this
.
analysisCheckedKeys
(
nextProps
)
;
console
.
log
(
'
analysisCheckedKeys'
);
}
this
.
setState
(
state
);
};
fetchItem
(
id
)
{
...
...
@@ -93,7 +88,14 @@ export default class EditItem extends Component {
let
data
=
{};
data
=
this
.
props
.
form
.
getFieldsValue
();
data
.
id
=
this
.
props
.
params
.
id
;
data
.
permissions
=
JSON
.
stringify
(
this
.
state
.
permissions
);
const
permissions
=
{};
this
.
state
.
checkedKeys
.
forEach
(
key
=>
{
const
[
ka
,
cn
,
mask
]
=
key
.
split
(
'-'
);
if
(
ka
===
'a'
&&
mask
){
permissions
[
cn
]
=
(
permissions
[
cn
]
||
0
)
+
parseInt
(
mask
,
10
);
}
});
data
.
permissions
=
JSON
.
stringify
(
permissions
);
if
(
isNaN
(
data
.
status
))
{
ENABLE_STATUS_LIST
.
forEach
(
item
=>
{
if
(
item
.
text
===
data
.
status
)
{
...
...
@@ -108,28 +110,55 @@ export default class EditItem extends Component {
});
}
handleExpand
(
expandedKeys
){
console
.
log
(
'onExpand'
,
arguments
);
this
.
setState
({
expandedKeys
,
autoExpandParent
:
false
analysisCheckedKeys
(
props
)
{
const
{
item
:{
permissions
},
resources
,
isEdit
}
=
props
;
//对权限资源分组
const
resourcesCategoryMap
=
{};
const
checkedKeys
=
[];
resources
&&
resources
.
forEach
(
res
=>
{
if
(
res
.
actionMask
&&
res
.
status
==
9
)
{
const
category
=
res
.
category
||
'其他'
;
const
map
=
resourcesCategoryMap
[
category
]
||
[];
//角色拥有权限
const
permisMask
=
permissions
&&
permissions
[
res
.
controllerName
]
||
0
;
const
permisAction
=
permisMask
&&
resourceActions
(
permisMask
)
||
[];
const
permisActionMap
=
{};
if
(
permisAction
.
length
)
{
permisAction
.
forEach
(
pac
=>
{
permisActionMap
[
pac
.
mask
]
=
pac
;
});
}
if
(
isEdit
)
{
res
.
action
=
resourceActions
(
res
.
actionMask
);
res
.
action
.
forEach
(
ac
=>
{
if
(
permisActionMap
[
ac
.
mask
])
{
ac
.
checked
=
true
;
checkedKeys
.
push
([
'a'
,
res
.
controllerName
,
ac
.
mask
].
join
(
'-'
));
}
});
}
else
{
res
.
action
=
permisAction
;
}
if
(
isEdit
||
permisAction
.
length
)
{
map
.
push
(
res
);
resourcesCategoryMap
[
category
]
=
map
;
}
}
});
}
handleCheck
(
checkedKeys
){
this
.
setState
({
resourcesCategoryMap
,
checkedKeys
});
}
render
()
{
const
{
item
,
resources
,
loading
,
form
:{
getFieldProps
},
location
:{
query
}}
=
this
.
props
;
const
{
isEdit
}
=
this
.
state
;
const
{
item
,
resources
,
loading
,
form
:{
getFieldProps
},
location
:{
query
},
isEdit
}
=
this
.
props
;
const
operation
=
(
<
div
style=
{
{
textAlign
:
'right'
}
}
>
...
...
@@ -166,53 +195,6 @@ export default class EditItem extends Component {
/>
);
//对权限资源分组
const
resourcesCategoryMap
=
{};
//角色权限
const
{
permissions
}
=
this
.
state
;
const
checkedKeys
=
[];
resources
.
forEach
(
res
=>
{
if
(
res
.
actionMask
&&
res
.
status
==
9
)
{
const
category
=
res
.
category
||
'其他'
;
const
map
=
resourcesCategoryMap
[
category
]
||
[];
//角色拥有权限
const
permisMask
=
permissions
[
res
.
controllerName
];
const
permisAction
=
permisMask
&&
resourceActions
(
permisMask
)
||
[];
const
permisActionMap
=
{};
if
(
permisAction
.
length
)
{
permisAction
.
forEach
(
pac
=>
{
permisActionMap
[
pac
.
mask
]
=
pac
;
});
}
if
(
isEdit
)
{
res
.
action
=
resourceActions
(
res
.
actionMask
);
res
.
action
.
forEach
(
ac
=>
{
if
(
permisActionMap
[
ac
.
mask
])
{
ac
.
checked
=
true
;
checkedKeys
.
push
([
'a'
,
res
.
controllerName
,
ac
.
mask
].
join
(
'-'
));
}
});
}
else
{
res
.
action
=
permisAction
;
}
if
(
isEdit
||
permisAction
.
length
)
{
map
.
push
(
res
);
resourcesCategoryMap
[
category
]
=
map
;
}
}
});
console
.
log
(
permissions
,
'选中的:'
,
checkedKeys
);
return
(
<
Layout
header=
{
header
}
>
<
Spin
spinning=
{
loading
}
>
...
...
@@ -289,31 +271,13 @@ export default class EditItem extends Component {
<
Tree
checkable=
{
isEdit
}
defaultExpandAll=
{
true
}
checkedKeys=
{
this
.
state
.
checkedKeys
}
onClick=
{
(
cks
)
=>
{
const
cs
=
{};
cks
.
forEach
(
key
=>
{
const
[
ac
,
cn
,
mask
]
=
key
.
split
(
'-'
);
if
(
ac
===
'a'
&&
typeof
mask
!==
'undefined'
){
let
_mask
=
parseInt
(
mask
,
10
);
cs
[
cn
]
=
(
cs
[
cn
]
||
0
)
+
_mask
;
}
});
console
.
log
(
cs
);
this
.
setState
({
checkedKeys
:
cks
,
permissions
:
cs
,
})
}
}
>
onCheck=
{
(
checkedKeys
)
=>
{
this
.
setState
({
checkedKeys
});}
}
>
{
Object
.
keys
(
resourcesCategoryMap
).
map
((
key
,
index
)
=>
Object
.
keys
(
this
.
state
.
resourcesCategoryMap
).
map
((
key
,
index
)
=>
<
Tree
.
TreeNode
className=
"resource-category"
key=
{
'c-'
+
key
}
title=
{
key
}
>
{
resourcesCategoryMap
[
key
].
map
(
res
=>
this
.
state
.
resourcesCategoryMap
[
key
].
map
(
res
=>
<
Tree
.
TreeNode
className=
"resource-item"
key=
{
res
.
action
.
length
===
1
?
...
...
src/containers/Resource/List.jsx
View file @
613ea9d4
...
...
@@ -116,8 +116,8 @@ export default class List extends Component {
width
:
180
,
},
{
title
:
'权限值'
,
dataIndex
:
'action
Name
'
,
key
:
'action
Name
'
,
dataIndex
:
'action
Mask
'
,
key
:
'action
Mask
'
,
width
:
80
,
className
:
'tac'
},
{
...
...
@@ -140,16 +140,6 @@ export default class List extends Component {
render
:
(
status
)
=>
(
<
span
>
{
enableStatusToString
(
status
)
}
</
span
>
)
},
{
title
:
'操作'
,
key
:
'operation'
,
width
:
120
,
className
:
'tac'
,
render
:
(
text
,
item
)
=>
(
<
span
onClick=
{
e
=>
{
e
.
stopPropagation
();
e
.
preventDefault
();}
}
>
</
span
>
)
}
];
...
...
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