Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
sage-front-framework
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
郁骅焌
sage-front-framework
Commits
8d5f01e8
提交
8d5f01e8
authored
5月 09, 2020
作者:
郁骅焌
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
角色管理修改
上级
ebf75992
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
140 行增加
和
14 行删除
+140
-14
index.jsx
src/pages/demo/crud/index.jsx
+1
-3
CreateForm.jsx
src/pages/role/components/CreateForm.jsx
+53
-0
UpdateForm.jsx
src/pages/role/components/UpdateForm.jsx
+53
-0
index.jsx
src/pages/role/index.jsx
+33
-11
没有找到文件。
src/pages/demo/crud/index.jsx
浏览文件 @
8d5f01e8
...
@@ -11,9 +11,7 @@ import UpdateForm from './components/UpdateForm'
...
@@ -11,9 +11,7 @@ import UpdateForm from './components/UpdateForm'
// 详情数据
// 详情数据
const
initDetail
=
{
const
initDetail
=
{
id
:
null
,
id
:
null
field1
:
''
,
field2
:
''
,
}
}
const
CrudList
=
()
=>
{
const
CrudList
=
()
=>
{
...
...
src/pages/role/components/CreateForm.jsx
0 → 100644
浏览文件 @
8d5f01e8
import
React
,
{
useState
,
useRef
,
useEffect
,
useImperativeHandle
}
from
'react'
import
{
Form
,
Input
,
InputNumber
,
Select
,
AutoComplete
}
from
'antd'
import
{
SageForm
}
from
'@/components/Common'
const
CreateForm
=
(
props
,
ref
)
=>
{
const
formRef
=
useRef
()
const
onFinish
=
(
values
)
=>
{
if
(
props
.
onFinish
)
{
props
.
onFinish
(
values
)
}
}
const
onFinishFailed
=
({
values
})
=>
{
console
.
log
(
values
)
}
// 表单字段设置
const
formFields
=
[
{
name
:
'roleName'
,
label
:
'角色名'
,
type
:
'input'
,
rules
:
[{
required
:
true
}]
},
{
name
:
'remarks'
,
label
:
'备注'
,
type
:
'textarea'
}
]
// 暴露外部方法
useImperativeHandle
(
ref
,
()
=>
({
submit
:
()
=>
formRef
.
current
.
submit
(),
validateFields
:
(
nameList
)
=>
formRef
.
current
.
validateFields
(
nameList
),
getFieldsValue
:
(
nameList
)
=>
formRef
.
current
.
getFieldsValue
(
nameList
),
setFieldsValue
:
(
values
)
=>
formRef
.
current
.
setFieldsValue
(
values
),
resetFields
:
(
fields
)
=>
formRef
.
current
.
resetFields
(
fields
)
}))
return
(
<
SageForm
ref=
{
formRef
}
formFields=
{
formFields
}
onFinish=
{
onFinish
}
onFinishFailed=
{
onFinishFailed
}
/>
)
}
export
default
React
.
forwardRef
(
CreateForm
)
src/pages/role/components/UpdateForm.jsx
0 → 100644
浏览文件 @
8d5f01e8
import
React
,
{
useState
,
useRef
,
useEffect
,
useImperativeHandle
}
from
'react'
import
{
Form
,
Input
,
InputNumber
,
Select
,
AutoComplete
}
from
'antd'
import
{
SageForm
}
from
'@/components/Common'
const
UpdateForm
=
(
props
,
ref
)
=>
{
const
formRef
=
useRef
()
const
onFinish
=
(
values
)
=>
{
if
(
props
.
onFinish
)
{
props
.
onFinish
(
values
)
}
}
const
onFinishFailed
=
({
values
})
=>
{
console
.
log
(
values
)
}
// 表单字段设置
const
formFields
=
[
{
name
:
'roleName'
,
label
:
'角色名'
,
type
:
'input'
,
rules
:
[{
required
:
true
}]
},
{
name
:
'remarks'
,
label
:
'备注'
,
type
:
'textarea'
}
]
// 暴露外部方法
useImperativeHandle
(
ref
,
()
=>
({
submit
:
()
=>
formRef
.
current
.
submit
(),
validateFields
:
(
nameList
)
=>
formRef
.
current
.
validateFields
(
nameList
),
getFieldsValue
:
(
nameList
)
=>
formRef
.
current
.
getFieldsValue
(
nameList
),
setFieldsValue
:
(
values
)
=>
formRef
.
current
.
setFieldsValue
(
values
),
resetFields
:
(
fields
)
=>
formRef
.
current
.
resetFields
(
fields
)
}))
return
(
<
SageForm
ref=
{
formRef
}
formFields=
{
formFields
}
onFinish=
{
onFinish
}
onFinishFailed=
{
onFinishFailed
}
/>
)
}
export
default
React
.
forwardRef
(
UpdateForm
)
src/pages/role/index.jsx
浏览文件 @
8d5f01e8
...
@@ -5,6 +5,9 @@ import { SageLayoutLR, SageTable, SageModal, SageForm, SageButton, sageMessage,
...
@@ -5,6 +5,9 @@ import { SageLayoutLR, SageTable, SageModal, SageForm, SageButton, sageMessage,
import
{
MenuTree
}
from
'@/components/Business'
import
{
MenuTree
}
from
'@/components/Business'
import
{
PlusOutlined
,
CheckOutlined
}
from
'@ant-design/icons'
;
import
{
PlusOutlined
,
CheckOutlined
}
from
'@ant-design/icons'
;
import
{
queryRule
,
updateRule
,
addRule
,
removeRule
,
getRuleDetail
}
from
'./service'
;
import
{
queryRule
,
updateRule
,
addRule
,
removeRule
,
getRuleDetail
}
from
'./service'
;
import
CreateForm
from
'./components/CreateForm'
import
UpdateForm
from
'./components/UpdateForm'
const
initDetail
=
{
const
initDetail
=
{
id
:
null
,
id
:
null
,
...
@@ -17,12 +20,14 @@ const TableList = () => {
...
@@ -17,12 +20,14 @@ const TableList = () => {
// 状态
// 状态
const
[
detail
,
setDetail
]
=
useState
(
initDetail
)
// 详情
const
[
detail
,
setDetail
]
=
useState
(
initDetail
)
// 详情
const
[
status
,
setStatus
]
=
useState
(
''
)
// 状态 1、add 2、update 3、detail
const
[
status
,
setStatus
]
=
useState
(
''
)
// 状态 1、add 2、update 3、detail
const
[
modalLoading
,
setModalLoading
]
=
useState
(
false
)
// 窗口loading
const
[
role
,
setRole
]
=
useState
({})
// 菜单分配对象
const
[
role
,
setRole
]
=
useState
({})
// 菜单分配对象
// ref对象
// ref对象
const
tableRef
=
useRef
();
const
tableRef
=
useRef
();
const
modalRef
=
useRef
();
const
modalRef
=
useRef
();
const
formRef
=
useRef
();
const
createFormRef
=
useRef
();
const
updateFormRef
=
useRef
();
const
menutreeRef
=
useRef
();
const
menutreeRef
=
useRef
();
// 查询条件
// 查询条件
...
@@ -69,7 +74,7 @@ const TableList = () => {
...
@@ -69,7 +74,7 @@ const TableList = () => {
modalRef
.
current
.
setTitle
(
'编辑角色'
)
modalRef
.
current
.
setTitle
(
'编辑角色'
)
modalRef
.
current
.
setVisible
(
true
)
modalRef
.
current
.
setVisible
(
true
)
f
ormRef
.
current
.
setFieldsValue
({
updateF
ormRef
.
current
.
setFieldsValue
({
roleName
:
roleData
.
roleName
,
roleName
:
roleData
.
roleName
,
remarks
:
roleData
.
remarks
remarks
:
roleData
.
remarks
})
})
...
@@ -149,8 +154,8 @@ const TableList = () => {
...
@@ -149,8 +154,8 @@ const TableList = () => {
setDetail
(
initDetail
)
setDetail
(
initDetail
)
modalRef
.
current
.
setTitle
(
'新增角色'
)
modalRef
.
current
.
setTitle
(
'新增角色'
)
modalRef
.
current
.
setVisible
(
true
)
modalRef
.
current
.
setVisible
(
true
)
if
(
f
ormRef
.
current
)
{
if
(
createF
ormRef
.
current
)
{
formRef
.
current
.
setFieldsValue
(
initDetail
)
createFormRef
.
current
.
resetFields
(
)
}
}
}
}
}
}
...
@@ -169,15 +174,20 @@ const TableList = () => {
...
@@ -169,15 +174,20 @@ const TableList = () => {
// 窗口确认按钮
// 窗口确认按钮
const
onOk
=
async
()
=>
{
const
onOk
=
async
()
=>
{
if
(
formRef
.
current
)
{
if
(
status
===
'add'
&&
createFormRef
.
current
)
{
formRef
.
current
.
submit
();
createFormRef
.
current
.
submit
();
}
if
(
status
===
'update'
&&
updateFormRef
.
current
)
{
updateFormRef
.
current
.
submit
();
}
}
}
}
// 表单提交成功
// 表单提交成功
const
onFinish
=
async
(
values
)
=>
{
const
onFinish
=
async
(
values
)
=>
{
const
formData
=
Object
.
assign
({},
values
)
const
formData
=
Object
.
assign
({},
values
)
let
res
=
null
let
res
=
null
setModalLoading
(
true
)
switch
(
status
)
{
switch
(
status
)
{
case
'add'
:
case
'add'
:
res
=
await
addRule
(
formData
)
res
=
await
addRule
(
formData
)
...
@@ -189,6 +199,7 @@ const TableList = () => {
...
@@ -189,6 +199,7 @@ const TableList = () => {
default
:
default
:
break
;
break
;
}
}
setModalLoading
(
false
)
if
(
res
.
isSuccess
)
{
if
(
res
.
isSuccess
)
{
sageMessage
.
success
(
'保存成功'
)
sageMessage
.
success
(
'保存成功'
)
...
@@ -242,12 +253,23 @@ const TableList = () => {
...
@@ -242,12 +253,23 @@ const TableList = () => {
<
SageModal
<
SageModal
ref=
{
modalRef
}
ref=
{
modalRef
}
onOk=
{
onOk
}
onOk=
{
onOk
}
confirmLoading=
{
modalLoading
}
>
>
<
SageForm
{
ref=
{
formRef
}
status
===
'add'
?
initialValues=
{
detail
}
<
CreateForm
onFinish=
{
onFinish
}
ref=
{
createFormRef
}
/>
onFinish=
{
onFinish
}
/>
:
null
}
{
status
===
'update'
?
<
UpdateForm
ref=
{
updateFormRef
}
detail=
{
detail
}
onFinish=
{
onFinish
}
/>
:
null
}
</
SageModal
>
</
SageModal
>
</
PageHeaderWrapper
>
</
PageHeaderWrapper
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论