Commit 8576f971 authored by superman's avatar superman

1.3.6-3

parent 04f979a1
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -63,9 +63,9 @@ export default class EditItem extends Component {
const {params:{id}} = this.props;
if (id) {
this.fetchItem(id);
if (id !== 'ROLE_ADMIN') {
this.fetchResourceList();
}
}
if (id !== 'ROLE_ADMIN') {
this.fetchResourceList(1);
}
};
......@@ -76,9 +76,11 @@ export default class EditItem extends Component {
history.replace('/admin/authorities/' + item.id);
return;
}
if (item && item.permissions && resources) {
// if (item && item.permissions && resources) {
if (resources) {
this.analysisCheckedKeys(nextProps);
}
// }
};
fetchItem(id) {
......@@ -88,7 +90,8 @@ export default class EditItem extends Component {
});
};
fetchResourceList() {
fetchResourceList(a) {
console.log('fetchResourceList', a);
this.props.dispatch({
type: 'FETCH_RESOURCE_LIST',
query: {s: 100}
......@@ -102,15 +105,21 @@ export default class EditItem extends Component {
if (this.props.params.id) {
data.id = this.props.params.id;
}
if (!data.id) {
data.status = 1;
}
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 (data.id) {
//创建的时候是不能分配权限的
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) {
......@@ -119,11 +128,11 @@ export default class EditItem extends Component {
}
})
}
if(data.name){
if(!/^ROLE_/g.test(data.name)){
if (data.name) {
if (!/^ROLE_/g.test(data.name)) {
data.name = 'ROLE_' + data.name;
}
data.name = (data.name+'').toUpperCase();
data.name = (data.name + '').toUpperCase();
}
console.log(data);
this.props.dispatch({
......@@ -133,7 +142,8 @@ export default class EditItem extends Component {
}
analysisCheckedKeys(props) {
const {item:{permissions}, resources, isEdit} = props;
const {item, resources, isEdit} = props;
const permissions = item && item.permissions || null;
//对权限资源分组
const resourcesCategoryMap = {};
const checkedKeys = [];
......@@ -176,6 +186,7 @@ export default class EditItem extends Component {
resourcesCategoryMap,
checkedKeys
});
// console.log('analysisCheckedKeys', resourcesCategoryMap, checkedKeys);
}
......@@ -205,6 +216,8 @@ export default class EditItem extends Component {
/>
);
// console.log('params=>', params, this.state);
return (
<Layout header={header}>
<Spin spinning={loading}>
......@@ -229,19 +242,22 @@ export default class EditItem extends Component {
item.description || NULL
}
</Form.Item>
<Form.Item label="状态" {...smallFormItemLayout}>
{
isEdit ?
<Select
placeholder="请选择状态" {...getFieldProps('status', {initialValue: enableStatusToString(item.status)})} >
<Select.Option value="1">系统</Select.Option>
<Select.Option value="5">禁用</Select.Option>
<Select.Option value="9">启用</Select.Option>
</Select>
:
(typeof item.status !== 'undefined' ? enableStatusToString(item.status) : NULL)
}
</Form.Item>
{
!isCreate &&
<Form.Item label="状态" {...smallFormItemLayout}>
{
isEdit ?
<Select
placeholder="请选择状态" {...getFieldProps('status', {initialValue: enableStatusToString(item.status)})} >
<Select.Option value="1">系统</Select.Option>
<Select.Option value="5">禁用</Select.Option>
<Select.Option value="9">启用</Select.Option>
</Select>
:
(typeof item.status !== 'undefined' ? enableStatusToString(item.status) : NULL)
}
</Form.Item>
}
{
!isCreate &&
<Form.Item label="创建时间" {...smallFormItemLayout}>
......@@ -260,48 +276,49 @@ export default class EditItem extends Component {
</Col>
{
params.id !== 'ROLE_ADMIN' &&
<Col span="12">
<Tree checkable={isEdit}
defaultExpandAll={true}
checkedKeys={this.state.checkedKeys}
onCheck={(checkedKeys)=> {
this.setState({checkedKeys});
}}>
{
Object.keys(this.state.resourcesCategoryMap).map((key, index)=>
<Tree.TreeNode className="resource-category" key={'c-' + key}
title={key}>
{
this.state.resourcesCategoryMap[key].map(res=>
res.action &&
<Tree.TreeNode className="resource-item"
key={
res.action.length === 1 ?
('a-' + res.controllerName + '-' + res.action[0].value) :
('r-' + res.id)
}
title={
res.description + (
res.action.length === 1 ? ' - ' + res.action[0].label : ''
)
}>
{
res.action.length > 1 && res.action.map(action=>
<Tree.TreeNode className="resource-action"
key={'a-' + res.controllerName + '-' + action.value}
title={action.label}/>
)
}
</Tree.TreeNode>
)
}
</Tree.TreeNode>
)
}
</Tree>
</Col>
(params.id && params.id !== 'ROLE_ADMIN') ?
<Col span="12">
<Tree checkable={isEdit}
defaultExpandAll={true}
checkedKeys={this.state.checkedKeys}
onCheck={(checkedKeys)=> {
this.setState({checkedKeys});
}}>
{
Object.keys(this.state.resourcesCategoryMap).map((key, index)=>
<Tree.TreeNode className="resource-category" key={'c-' + key}
title={key}>
{
this.state.resourcesCategoryMap[key].map(res=>
res.action &&
<Tree.TreeNode className="resource-item"
key={
res.action.length === 1 ?
('a-' + res.controllerName + '-' + res.action[0].value) :
('r-' + res.id)
}
title={
res.description + (
res.action.length === 1 ? ' - ' + res.action[0].label : ''
)
}>
{
res.action.length > 1 && res.action.map(action=>
<Tree.TreeNode className="resource-action"
key={'a-' + res.controllerName + '-' + action.value}
title={action.label}/>
)
}
</Tree.TreeNode>
)
}
</Tree.TreeNode>
)
}
</Tree>
</Col>
: null
}
</Row>
</Form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment