1+ import React from "react" ;
2+ import { type ActionType , Table , type TableProps } from "@flow-engine/flow-design" ;
3+ import { Button , Form , Input , message , Modal , Popconfirm , Space , Switch } from "antd" ;
4+ import { list , remove , save } from "@/api/user.ts" ;
5+
6+ const UserPage = ( ) => {
7+ const actionType = React . useRef < ActionType > ( null ) ;
8+ const [ visible , setVisible ] = React . useState ( false ) ;
9+ const [ form ] = Form . useForm ( ) ;
10+
11+ const columns : TableProps < any > [ 'columns' ] = [
12+ {
13+ dataIndex : 'id' ,
14+ title : '编号' ,
15+ } ,
16+ {
17+ dataIndex : 'name' ,
18+ title : '姓名' ,
19+ } ,
20+ {
21+ dataIndex : 'account' ,
22+ title : '账户' ,
23+ } ,
24+ {
25+ dataIndex : 'flowManager' ,
26+ title : '角色' ,
27+ render : ( value , record ) => {
28+ return value ? '流程管理员' : '普通用户'
29+ }
30+ } ,
31+ {
32+ dataIndex : 'flowOperatorId' ,
33+ title : '流程委托人' ,
34+ render : ( value , record ) => {
35+ if ( ! value ) {
36+ return '无'
37+ }
38+ return value
39+ }
40+ } ,
41+ {
42+ dataIndex : 'option' ,
43+ title : '操作' ,
44+ render : ( value , record ) => {
45+ return (
46+ < Space >
47+ < a onClick = { ( ) => {
48+ form . setFieldsValue ( {
49+ ...record ,
50+ password : ''
51+ } ) ;
52+ setVisible ( true ) ;
53+ } } > 编辑</ a >
54+ { record . account !== 'admin' && (
55+ < Popconfirm
56+ title = { "确认要删除该用户吗?" }
57+ onConfirm = { ( ) => {
58+ remove ( record . id ) . then ( ( ) => {
59+ message . success ( "用户已删除" ) ;
60+ actionType . current ?. reload ( ) ;
61+ } )
62+ } }
63+ >
64+ < a > 删除</ a >
65+ </ Popconfirm >
66+ ) }
67+ </ Space >
68+ )
69+ }
70+ }
71+ ] ;
72+
73+ return (
74+ < div >
75+ < Table
76+ rowKey = { "id" }
77+ actionType = { actionType }
78+ toolBarRender = { ( ) => {
79+ return [
80+ < Button
81+ key = { "create" }
82+ type = { 'primary' }
83+ onClick = { ( ) => {
84+ form . resetFields ( ) ;
85+ setVisible ( true ) ;
86+ } } > 创建用户</ Button >
87+ ]
88+ } }
89+ columns = { columns }
90+ request = { ( request ) => {
91+ return list ( request ) ;
92+ } }
93+ />
94+
95+ < Modal
96+ width = { "60%" }
97+ title = { "编辑用户" }
98+ open = { visible }
99+ onCancel = { ( ) => {
100+ setVisible ( false ) ;
101+ } }
102+ onOk = { ( ) => {
103+ form . submit ( ) ;
104+ } }
105+ >
106+ < Form
107+ form = { form }
108+ onFinish = { ( values ) => {
109+ save ( values ) . then ( ( ) => {
110+ message . success ( "用户已保存" ) ;
111+ actionType . current ?. reload ( ) ;
112+ setVisible ( false ) ;
113+ } )
114+ } }
115+ >
116+ < Form . Item
117+ name = "id"
118+ hidden = { true }
119+ >
120+ < Input />
121+ </ Form . Item >
122+
123+ < Form . Item
124+ name = "name"
125+ label = { "名称" }
126+ rules = { [
127+ {
128+ message : '名称不能为空' ,
129+ required : true ,
130+ }
131+ ] }
132+ >
133+ < Input />
134+ </ Form . Item >
135+
136+
137+ < Form . Item
138+ name = "account"
139+ label = { "登陆账号" }
140+ rules = { [
141+ {
142+ message : '登陆账号不能为空' ,
143+ required : true ,
144+ }
145+ ] }
146+ >
147+ < Input />
148+ </ Form . Item >
149+
150+ < Form . Item
151+ name = "password"
152+ label = { "登陆密码" }
153+ rules = { [
154+ {
155+ message : '登陆密码不能为空' ,
156+ required : true ,
157+ }
158+ ] }
159+ >
160+ < Input />
161+ </ Form . Item >
162+
163+ < Form . Item
164+ name = "flowManager"
165+ label = { "流程管理员" }
166+ >
167+ < Switch />
168+ </ Form . Item >
169+
170+ < Form . Item
171+ name = "flowOperatorId"
172+ label = { "流程委托人" }
173+ >
174+ < Input />
175+ </ Form . Item >
176+ </ Form >
177+ </ Modal >
178+ </ div >
179+ )
180+ }
181+
182+ export default UserPage ;
0 commit comments