Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
7f4d070e
提交
7f4d070e
authored
7月 10, 2019
作者:
zhenxianyimeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
部门更新和新增modal框
上级
f3abed3a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
216 行增加
和
2 行删除
+216
-2
deptmentList.js
admin-web/src/models/admin/deptmentList.js
+37
-1
DeptmentList.js
admin-web/src/pages/Admin/DeptmentList.js
+155
-1
admin.js
admin-web/src/services/admin.js
+24
-0
没有找到文件。
admin-web/src/models/admin/deptmentList.js
浏览文件 @
7f4d070e
import
{
message
}
from
'antd'
;
import
{
message
}
from
'antd'
;
import
{
deptTreePage
}
from
'../../services/admin'
;
import
{
deptTreePage
,
deptTreeAll
,
addDeptment
,
updateDeptment
}
from
'../../services/admin'
;
const
buildSelectTree
=
list
=>
{
return
list
.
map
(
item
=>
{
let
children
=
[];
if
(
item
.
children
)
{
children
=
buildSelectTree
(
item
.
children
);
}
return
{
title
:
item
.
name
,
value
:
`
${
item
.
name
}
-
${
item
.
id
}
`
,
key
:
item
.
id
,
children
,
};
});
};
export
default
{
export
default
{
namespace
:
'deptmentList'
,
namespace
:
'deptmentList'
,
...
@@ -13,6 +28,27 @@ export default {
...
@@ -13,6 +28,27 @@ export default {
},
},
effects
:
{
effects
:
{
*
add
({
payload
},
{
call
,
put
})
{
const
{
onSuccess
,
body
}
=
payload
;
const
response
=
yield
call
(
addDeptment
,
body
);
if
(
response
&&
response
.
code
===
0
)
{
onSuccess
&&
onSuccess
();
}
},
*
update
({
payload
},
{
call
,
put
})
{
const
{
onSuccess
,
body
}
=
payload
;
const
response
=
yield
call
(
updateDeptment
,
body
);
if
(
response
&&
response
.
code
===
0
)
{
onSuccess
&&
onSuccess
();
}
},
*
getDeptmentAll
({
payload
},
{
call
,
put
})
{
const
result
=
yield
call
(
deptTreeAll
,
payload
);
yield
put
({
type
:
'treeSuccess'
,
payload
:
result
.
data
,
});
},
*
getDeptmentList
({
payload
},
{
call
,
put
})
{
*
getDeptmentList
({
payload
},
{
call
,
put
})
{
const
result
=
yield
call
(
deptTreePage
,
payload
);
const
result
=
yield
call
(
deptTreePage
,
payload
);
let
deptmentData
=
{};
let
deptmentData
=
{};
...
...
admin-web/src/pages/Admin/DeptmentList.js
浏览文件 @
7f4d070e
import
React
,
{
PureComponent
,
Fragment
}
from
'react'
;
import
React
,
{
PureComponent
,
Fragment
}
from
'react'
;
import
{
Button
,
Card
,
Table
,
Form
,
Divider
}
from
'antd'
;
import
{
Button
,
Card
,
Table
,
Form
,
Divider
,
Modal
,
Input
,
TreeSelect
,
message
}
from
'antd'
;
import
PageHeaderWrapper
from
'@/components/PageHeaderWrapper'
;
import
PageHeaderWrapper
from
'@/components/PageHeaderWrapper'
;
import
{
connect
}
from
'dva'
;
import
{
connect
}
from
'dva'
;
import
styles
from
'./DeptmentList.less'
;
import
styles
from
'./DeptmentList.less'
;
import
PaginationHelper
from
'../../../helpers/PaginationHelper'
;
import
PaginationHelper
from
'../../../helpers/PaginationHelper'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
const
FormItem
=
Form
.
Item
;
// 添加 form 表单
const
CreateForm
=
Form
.
create
()(
props
=>
{
const
{
modalVisible
,
form
,
handleAdd
,
handleModalVisible
,
modalType
,
initValues
,
selectTree
,
}
=
props
;
const
okHandle
=
()
=>
{
form
.
validateFields
((
err
,
fieldsValue
)
=>
{
if
(
err
)
return
;
let
pid
=
fieldsValue
.
pid
;
if
(
fieldsValue
.
pid
)
{
pid
=
pid
.
split
(
'-'
)[
1
];
fieldsValue
.
pid
=
pid
;
}
form
.
resetFields
();
handleAdd
({
fields
:
fieldsValue
,
modalType
,
initValues
,
});
});
};
const
selectStyle
=
{
width
:
200
,
};
function
onTypeChange
(
event
)
{
initValues
.
type
=
parseInt
(
event
.
target
.
value
);
}
// 给 type 赋予初始值
initValues
.
type
=
initValues
.
type
||
1
;
const
title
=
modalType
===
'add'
?
'添加部门'
:
'编辑部门'
;
const
okText
=
modalType
===
'add'
?
'添加'
:
'编辑'
;
return
(
<
Modal
destroyOnClose
title
=
{
title
}
visible
=
{
modalVisible
}
onOk
=
{
okHandle
}
okText
=
{
okText
}
onCancel
=
{()
=>
handleModalVisible
()}
>
<
FormItem
labelCol
=
{{
span
:
5
}}
wrapperCol
=
{{
span
:
15
}}
label
=
"部门名称"
>
{
form
.
getFieldDecorator
(
'name'
,
{
initialValue
:
initValues
.
name
,
rules
:
[{
required
:
true
,
message
:
'请输入部门名称!'
,
min
:
2
}],
})(
<
Input
placeholder
=
"部门名称"
/>
)}
<
/FormItem
>
<
FormItem
labelCol
=
{{
span
:
5
}}
wrapperCol
=
{{
span
:
15
}}
label
=
"部门排序"
>
{
form
.
getFieldDecorator
(
'sort'
,
{
initialValue
:
initValues
.
sort
,
})(
<
Input
placeholder
=
"部门排序"
/>
)}
<
/FormItem
>
<
FormItem
labelCol
=
{{
span
:
5
}}
wrapperCol
=
{{
span
:
15
}}
label
=
"父级部门"
>
{
form
.
getFieldDecorator
(
'pid'
,
{
rules
:
[{
required
:
true
,
message
:
'请选择父级编号!'
}],
initialValue
:
initValues
.
pid
===
0
?
`根节点-
${
initValues
.
pid
}
`
:
initValues
.
pid
?
`
${
initValues
.
name
}
-
${
initValues
.
pid
}
`
:
undefined
,
})(
<
TreeSelect
showSearch
style
=
{{
width
:
300
}}
dropdownStyle
=
{{
maxHeight
:
400
,
overflow
:
'auto'
}}
treeData
=
{
selectTree
}
placeholder
=
"选择父级部门"
/>
)}
<
/FormItem
>
<
/Modal
>
);
});
@
connect
(({
deptmentList
,
loading
})
=>
({
@
connect
(({
deptmentList
,
loading
})
=>
({
deptmentList
,
deptmentList
,
...
@@ -13,6 +98,12 @@ import moment from 'moment';
...
@@ -13,6 +98,12 @@ import moment from 'moment';
}))
}))
@
Form
.
create
()
@
Form
.
create
()
export
default
class
DepetmentList
extends
PureComponent
{
export
default
class
DepetmentList
extends
PureComponent
{
state
=
{
modalVisible
:
false
,
modalType
:
'add'
,
//add or update
initValues
:
{},
};
componentDidMount
()
{
componentDidMount
()
{
const
{
dispatch
}
=
this
.
props
;
const
{
dispatch
}
=
this
.
props
;
dispatch
({
dispatch
({
...
@@ -23,8 +114,70 @@ export default class DepetmentList extends PureComponent {
...
@@ -23,8 +114,70 @@ export default class DepetmentList extends PureComponent {
});
});
}
}
handleModalVisible
=
(
flag
,
modalType
,
initValues
)
=>
{
this
.
setState
({
modalVisible
:
!!
flag
,
initValues
:
initValues
||
{},
modalType
:
modalType
||
'add'
,
});
if
(
flag
)
{
//query treeSelect
const
{
dispatch
}
=
this
.
props
;
dispatch
({
type
:
'deptmentList/getDeptmentAll'
,
payload
:
{},
});
}
};
handleAdd
=
({
fields
,
modalType
,
initValues
})
=>
{
const
{
dispatch
}
=
this
.
props
;
if
(
modalType
===
'add'
)
{
dispatch
({
type
:
'deptmentList/add'
,
payload
:
{
body
:
{
...
fields
,
},
onSuccess
:
()
=>
{
message
.
success
(
'添加成功'
);
this
.
handleModalVisible
();
},
onFail
:
response
=>
{
message
.
warn
(
'添加失败'
+
response
.
message
);
},
},
});
}
else
{
dispatch
({
type
:
'deptmentList/update'
,
payload
:
{
body
:
{
...
initValues
,
...
fields
,
},
onSuccess
:
()
=>
{
message
.
success
(
'更新成功成功'
);
this
.
handleModalVisible
();
},
onFail
:
response
=>
{
message
.
warn
(
'更新失败'
+
response
.
message
);
},
},
});
}
};
render
()
{
render
()
{
const
{
deptmentData
,
deptmentList
}
=
this
.
props
;
const
{
deptmentData
,
deptmentList
}
=
this
.
props
;
const
{
selectTree
}
=
deptmentList
;
const
{
modalVisible
,
modalType
,
initValues
}
=
this
.
state
;
const
parentMethods
=
{
handleAdd
:
this
.
handleAdd
,
handleModalVisible
:
this
.
handleModalVisible
,
modalType
,
initValues
,
};
const
columns
=
[
const
columns
=
[
{
{
title
:
'部门名称'
,
title
:
'部门名称'
,
...
@@ -80,6 +233,7 @@ export default class DepetmentList extends PureComponent {
...
@@ -80,6 +233,7 @@ export default class DepetmentList extends PureComponent {
rowKey
=
"id"
rowKey
=
"id"
/>
/>
<
/Card
>
<
/Card
>
<
CreateForm
{...
parentMethods
}
selectTree
=
{
selectTree
}
modalVisible
=
{
modalVisible
}
/
>
<
/PageHeaderWrapper
>
<
/PageHeaderWrapper
>
);
);
}
}
...
...
admin-web/src/services/admin.js
浏览文件 @
7f4d070e
...
@@ -56,12 +56,36 @@ export async function adminRoleAssign(params) {
...
@@ -56,12 +56,36 @@ export async function adminRoleAssign(params) {
}
}
// deptment
// deptment
export
async
function
addDeptment
(
params
)
{
return
request
(
'/admin-api/admins/dept/add'
,
{
method
:
'POST'
,
body
:
{
...
params
,
},
});
}
export
async
function
updateDeptment
(
params
)
{
return
request
(
'/admin-api/admins/dept/update'
,
{
method
:
'POST'
,
body
:
{
...
params
,
},
});
}
export
async
function
deptTreePage
(
params
)
{
export
async
function
deptTreePage
(
params
)
{
return
request
(
`/admin-api/admins/dept/tree/page?
${
stringify
(
params
)}
`
,
{
return
request
(
`/admin-api/admins/dept/tree/page?
${
stringify
(
params
)}
`
,
{
method
:
'GET'
,
method
:
'GET'
,
});
});
}
}
export
async
function
deptTreeAll
()
{
return
request
(
'/admin-api/admins/dept/tree/all'
,
{
method
:
'GET'
,
});
}
// resource
// resource
export
async
function
addResource
(
params
)
{
export
async
function
addResource
(
params
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论