Skip to content

Commit a80591d

Browse files
committed
add user page
1 parent a61e2db commit a80591d

8 files changed

Lines changed: 295 additions & 21 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.codingapi.example.controller;
2+
3+
import com.codingapi.example.entity.User;
4+
import com.codingapi.example.repository.UserRepository;
5+
import com.codingapi.example.service.UserService;
6+
import com.codingapi.springboot.framework.dto.request.IdRequest;
7+
import com.codingapi.springboot.framework.dto.request.SearchRequest;
8+
import com.codingapi.springboot.framework.dto.response.MultiResponse;
9+
import com.codingapi.springboot.framework.dto.response.Response;
10+
import lombok.AllArgsConstructor;
11+
import org.springframework.web.bind.annotation.*;
12+
13+
@RestController
14+
@RequestMapping("/api/user")
15+
@AllArgsConstructor
16+
public class UserController {
17+
18+
private final UserService userService;
19+
20+
private final UserRepository userRepository;
21+
22+
@GetMapping("/list")
23+
public MultiResponse<User> list(SearchRequest request){
24+
return MultiResponse.of(userRepository.searchRequest(request));
25+
}
26+
27+
@PostMapping("/save")
28+
public Response save(@RequestBody User request){
29+
userService.save(request);
30+
return Response.buildSuccess();
31+
}
32+
33+
@PostMapping("/remove")
34+
public Response remove(@RequestBody IdRequest request){
35+
userService.remove(request.getLongId());
36+
return Response.buildSuccess();
37+
}
38+
39+
}

flow-engine-example/src/main/java/com/codingapi/example/entity/User.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public static User admin(PasswordEncoder passwordEncoder){
3939
}
4040

4141

42+
public void encodePassword(PasswordEncoder passwordEncoder){
43+
this.password = passwordEncoder.encode(password);
44+
}
45+
46+
4247
public List<String> getRoles() {
4348
return List.of(ADMIN_ROLE);
4449
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.codingapi.example.service;
2+
3+
import com.codingapi.example.entity.User;
4+
import com.codingapi.example.repository.UserRepository;
5+
import lombok.AllArgsConstructor;
6+
import org.springframework.security.crypto.password.PasswordEncoder;
7+
import org.springframework.stereotype.Service;
8+
9+
@Service
10+
@AllArgsConstructor
11+
public class UserService {
12+
13+
private final UserRepository userRepository;
14+
private final PasswordEncoder passwordEncoder;
15+
16+
public void save(User user) {
17+
user.encodePassword(passwordEncoder);
18+
userRepository.save(user);
19+
}
20+
21+
public void remove(long id) {
22+
userRepository.deleteById(id);
23+
}
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { httpClient } from "."
2+
3+
export const list = (request: any) => {
4+
return httpClient.page('/api/user/list', request, {}, {}, []);
5+
}
6+
7+
export const remove = (id:string) => {
8+
return httpClient.post('/api/user/remove',{id});
9+
}
10+
11+
export const save = (body:any) => {
12+
return httpClient.post('/api/user/save',body);
13+
}

frontend/apps/app-pc/src/config/routers.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
import { createHashRouter, type RouteObject } from "react-router";
1+
import {createHashRouter} from "react-router";
22
import LoginPage from "@/pages/login";
33
import HomePage from "@/pages/home";
44
import DesignPage from "@/pages/desgin";
55
import TodoPage from "@/pages/todo";
6+
import UserPage from "@/pages/user.tsx";
67

78

8-
const routers:RouteObject[] = [
9+
export const routers = [
910
{
1011
path:'/login',
11-
element:<LoginPage/>
12+
element:<LoginPage/>,
13+
name:'登陆界面',
14+
},
15+
{
16+
path:'/user',
17+
element:<UserPage/>,
18+
name: '用户界面'
1219
},
1320
{
1421
path:'/design',
15-
element:<DesignPage/>
22+
element:<DesignPage/>,
23+
name: '流程设计'
1624
},
1725
{
1826
path:'/todo',
19-
element:<TodoPage/>
27+
element:<TodoPage/>,
28+
name: '待办中心'
2029
},
2130
{
2231
path:'/',
23-
element:<HomePage/>
32+
element:<HomePage/>,
33+
name: '系统主页'
2434
}
2535
]
2636

frontend/apps/app-pc/src/pages/home.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import React from "react";
22
import { useNavigate } from "react-router";
33
import { Button, Flex, Space } from "antd";
4+
import {routers} from "@/config/routers.tsx";
45

56
const HomePage: React.FC = () => {
67

78
const navigate = useNavigate();
89

10+
const routerButtons = routers.filter(item=>item.path!=='/');
11+
912
return (
1013
<div>
11-
<Flex justify="center"><h1>Home Page</h1></Flex>
14+
<Flex justify="center"><h1>Flow-Engine Home Page</h1></Flex>
1215
<Space>
13-
<Button
14-
onClick={() => {
15-
navigate("/login")
16-
}}>login</Button>
17-
<Button
18-
onClick={() => {
19-
navigate("/design")
20-
}}>design</Button>
21-
<Button
22-
onClick={() => {
23-
navigate('/todo');
24-
}}
25-
>todo</Button>
16+
{routerButtons.map((item)=>{
17+
return (
18+
<Button
19+
onClick={() => {
20+
navigate(item.path)
21+
}}>
22+
{item.name}
23+
</Button>
24+
)
25+
})}
2626
</Space>
2727
</div>
2828
)
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from '@/pages/design-list';
2-
export * from '@/pages/design-panel';
2+
export * from '@/pages/design-panel';
3+
export * from '@/components/table';

0 commit comments

Comments
 (0)