Skip to content

Commit 2140f05

Browse files
committed
add node
1 parent 8709b27 commit 2140f05

File tree

10 files changed

+106
-110
lines changed

10 files changed

+106
-110
lines changed

antd-pro/config/routes.ts

-7
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ export default [
9393
},
9494
],
9595
},
96-
{
97-
name: 'test',
98-
icon: 'bug',
99-
path: '/test',
100-
component: './test',
101-
access: 'hasAuthentication',
102-
},
10396
{
10497
path: '/',
10598
redirect: '/welcome',

antd-pro/src/pages/table/index.tsx

+41-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { list, save, del } from '@/services/api/table';
1+
import { list, save, del, resort } from '@/services/api/table';
22
import { PlusOutlined } from '@ant-design/icons';
33
import type { ActionType, ProColumns } from '@ant-design/pro-components';
4-
import { ModalForm, PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
4+
import { ModalForm, PageContainer, ProFormSelect, ProFormText, ProFormDigit } from '@ant-design/pro-components';
55
import { Button, Form, message, Popconfirm } from 'antd';
6-
import { MyTable } from 'coding-components';
6+
import { MyTable } from './MyTable';
77
import React, { useRef, useState } from 'react';
88

99
const TablePage: React.FC = () => {
@@ -50,20 +50,24 @@ const TablePage: React.FC = () => {
5050
dataIndex: 'id',
5151
sorter: true,
5252
search: false,
53+
width: 100,
5354
},
5455
{
5556
title: "服务名称",
5657
dataIndex: 'name',
5758
sorter: true,
59+
width: 100,
5860
},
5961
{
6062
title: "地址",
6163
dataIndex: 'url',
6264
search: false,
65+
width: 100,
6366
},
6467
{
6568
title: "状态",
6669
dataIndex: 'state',
70+
width: 100,
6771
filters: [
6872
{
6973
text: '禁用',
@@ -85,10 +89,17 @@ const TablePage: React.FC = () => {
8589
},
8690
},
8791
},
92+
{
93+
title: "排序",
94+
dataIndex: 'sort',
95+
search: false,
96+
width: 100,
97+
},
8898
{
8999
title: "操作",
90100
dataIndex: 'option',
91101
valueType: 'option',
102+
width: 100,
92103
render: (_, record) => [
93104
<a
94105
key="config"
@@ -123,9 +134,23 @@ const TablePage: React.FC = () => {
123134
return (
124135
<PageContainer>
125136
<MyTable
137+
sortable={true}
138+
dragSortKey="id"
139+
onDragSortEnd={
140+
async (beforeIndex: number, afterIndex: number,oldDataSource: any[], newDataSource: any[], rowKey: string) => {
141+
console.log(beforeIndex, afterIndex, oldDataSource, newDataSource, rowKey);
142+
const beforeId = oldDataSource[beforeIndex][rowKey];
143+
const afterId = oldDataSource[afterIndex][rowKey];
144+
const body = {
145+
beforeId: beforeId,
146+
afterId: afterId,
147+
};
148+
resort(body)
149+
}
150+
}
126151
headerTitle="服务节点配置"
127152
actionRef={actionRef}
128-
rowKey="key"
153+
rowKey="id"
129154
toolBarRender={() => [
130155
<Button
131156
type="primary"
@@ -138,7 +163,6 @@ const TablePage: React.FC = () => {
138163
</Button>,
139164
]}
140165
request={async (params, sort, filter) => {
141-
console.log(params, sort, filter);
142166
const res = await list({
143167
...params,
144168
sort: Buffer.from(JSON.stringify(sort)).toString('base64'),
@@ -225,6 +249,18 @@ const TablePage: React.FC = () => {
225249
]}
226250
name="state"
227251
/>
252+
253+
<ProFormDigit
254+
label="排序"
255+
rules={[
256+
{
257+
required: true,
258+
message: "请输入排序",
259+
},
260+
]}
261+
placeholder="请输入排序"
262+
name="sort" />
263+
228264
</ModalForm>
229265

230266
</PageContainer>

antd-pro/src/pages/test/index.tsx

-89
This file was deleted.

antd-pro/src/services/api/table.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ import {get, post} from "@/services/api/index";
44

55

66
export async function list(
7-
params: {
8-
// query
9-
/** 当前的页码 */
10-
current?: number;
11-
/** 页面的容量 */
12-
pageSize?: number;
13-
}
7+
params: any
148
) {
159
return get('/api/node/list', params);
1610
}
@@ -20,6 +14,10 @@ export async function save(body: any) {
2014
return post('/api/node/save', body);
2115
}
2216

17+
export async function resort(body: any) {
18+
return post('/api/node/resort', body);
19+
}
20+
2321

2422
export async function del(body: {
2523
id:string,

components-server/components-server/src/main/java/com/codingapi/server/controller/NodeController.java

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.codingapi.springboot.framework.dto.response.MultiResponse;
99
import com.codingapi.springboot.framework.dto.response.Response;
1010
import lombok.AllArgsConstructor;
11+
import org.springframework.data.domain.Sort;
1112
import org.springframework.web.bind.annotation.*;
1213

1314
@RestController
@@ -21,9 +22,16 @@ public class NodeController {
2122

2223
@GetMapping("/list")
2324
public MultiResponse<Node> list(SearchRequest request) {
25+
request.addSort(Sort.by("sort").ascending());
2426
return MultiResponse.of(nodeRepository.searchRequest(request));
2527
}
2628

29+
@PostMapping("/resort")
30+
public Response resort(@RequestBody SortRequest sortRequest) {
31+
nodeRepository.reSort(sortRequest);
32+
return Response.buildSuccess();
33+
}
34+
2735
@PostMapping("/save")
2836
public Response save(@RequestBody Node node) {
2937
nodeService.save(node);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.codingapi.server.controller;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Setter
7+
@Getter
8+
public class SortRequest {
9+
10+
private Object beforeId;
11+
private Object afterId;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codingapi.server.domain;
2+
3+
public interface ISort {
4+
5+
void setSort(Integer sort);
6+
7+
Integer getSort();
8+
}

components-server/components-server/src/main/java/com/codingapi/server/domain/Node.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@NoArgsConstructor
2020
@ToString
2121
@Entity
22-
public class Node implements Cloneable {
22+
public class Node implements ISort,Cloneable {
2323

2424
@Id
2525
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -33,6 +33,10 @@ public class Node implements Cloneable {
3333
@JsonSerialize(using = EnumSerializer.class)
3434
private State state;
3535

36+
37+
private Integer sort;
38+
39+
3640
@SneakyThrows
3741
public void swap(Node target) {
3842
Node old = (Node) this.clone();

components-server/components-server/src/main/java/com/codingapi/server/repository/NodeRepository.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import com.codingapi.server.domain.Node;
44
import com.codingapi.springboot.fast.jpa.repository.FastRepository;
55

6-
public interface NodeRepository extends FastRepository<Node, Integer> {
6+
public interface NodeRepository extends FastRepository<Node, Integer>,SortRepository<Node,Integer> {
77

88
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.codingapi.server.repository;
2+
3+
import com.codingapi.server.controller.SortRequest;
4+
import com.codingapi.server.domain.ISort;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.data.repository.NoRepositoryBean;
7+
8+
@NoRepositoryBean
9+
public interface SortRepository<T extends ISort, ID> extends JpaRepository<T, ID> {
10+
11+
12+
default void reSort(SortRequest request) {
13+
T after = this.getReferenceById((ID) request.getAfterId());
14+
T before = this.getReferenceById((ID) request.getBeforeId());
15+
16+
Integer beforeSort = before.getSort();
17+
Integer afterSort = after.getSort();
18+
19+
before.setSort(afterSort);
20+
after.setSort(beforeSort);
21+
22+
save(before);
23+
save(after);
24+
}
25+
26+
}

0 commit comments

Comments
 (0)