可正常保存流程
This commit is contained in:
parent
42ad69abb5
commit
2c39b79515
@ -78,7 +78,7 @@ ModuleName/ # 模块结构
|
|||||||
|
|
||||||
// 标准 CRUD 接口
|
// 标准 CRUD 接口
|
||||||
export const getList = (params?: Query) =>
|
export const getList = (params?: Query) =>
|
||||||
request.get<Response[]>('/api/v1/xxx', { params });
|
request.get<Page<Response>>('/api/v1/xxx/page', { params }); // 列表接口统一使用 /page 后缀
|
||||||
|
|
||||||
export const create = (data: Request) =>
|
export const create = (data: Request) =>
|
||||||
request.post<Response>('/api/v1/xxx', data);
|
request.post<Response>('/api/v1/xxx', data);
|
||||||
@ -105,8 +105,24 @@ ModuleName/ # 模块结构
|
|||||||
- 资源使用复数形式(users, roles)
|
- 资源使用复数形式(users, roles)
|
||||||
- 特殊操作使用动词(export, import)
|
- 特殊操作使用动词(export, import)
|
||||||
|
|
||||||
|
3. 列表数据获取规范:
|
||||||
|
- API 路径必须以 `/page` 结尾,例如:`/api/v1/workflow-definitions/page`
|
||||||
|
- 服务层方法定义示例:
|
||||||
|
```typescript
|
||||||
|
export const getDefinitions = (params?: WorkflowDefinitionQuery) =>
|
||||||
|
request.get<Page<WorkflowDefinitionResponse>>(`${DEFINITION_URL}/page`, { params });
|
||||||
|
```
|
||||||
|
- 组件中获取列表数据:
|
||||||
|
```typescript
|
||||||
|
const response = await getDefinitions();
|
||||||
|
if (response) {
|
||||||
|
setList(response.content); // 使用 response.content 获取列表数据
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- 分页数据结构统一使用 `Page<T>` 类型
|
||||||
|
- 列表数据必须位于返回结果的 `content` 字段中
|
||||||
|
|
||||||
4. 类型处理规则:
|
## 4. 类型处理规则:
|
||||||
- request 工具的泛型参数 T 表示业务数据类型
|
- request 工具的泛型参数 T 表示业务数据类型
|
||||||
- 响应拦截器负责从 Response<T> 中提取 data
|
- 响应拦截器负责从 Response<T> 中提取 data
|
||||||
- 服务方法直接使用业务数据类型作为泛型参数
|
- 服务方法直接使用业务数据类型作为泛型参数
|
||||||
|
|||||||
@ -1,24 +1,38 @@
|
|||||||
import React from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Card, Table, Button, Space, Tag, Popconfirm, message } from 'antd';
|
import { Card, Table, Button, Space, Tag, Popconfirm, message } from 'antd';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { useTableData } from '@/hooks/useTableData';
|
|
||||||
import { getDefinitions, deleteDefinition, publishDefinition, disableDefinition, enableDefinition } from '../service';
|
import { getDefinitions, deleteDefinition, publishDefinition, disableDefinition, enableDefinition } from '../service';
|
||||||
import { WorkflowDefinitionResponse, WorkflowStatus } from '../types';
|
import { WorkflowDefinitionResponse, WorkflowStatus } from '../types';
|
||||||
|
|
||||||
const Definition: React.FC = () => {
|
const Definition: React.FC = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { list, loading, pagination, handleTableChange, refresh } = useTableData({
|
const [loading, setLoading] = useState(false);
|
||||||
service: {
|
const [list, setList] = useState<WorkflowDefinitionResponse[]>([]);
|
||||||
list: getDefinitions
|
|
||||||
|
const loadData = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const response = await getDefinitions();
|
||||||
|
if (response) {
|
||||||
|
setList(response.content);
|
||||||
}
|
}
|
||||||
});
|
} catch (error) {
|
||||||
|
message.error('加载数据失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handlePublish = async (id: number) => {
|
const handlePublish = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
await publishDefinition(id);
|
await publishDefinition(id);
|
||||||
message.success('发布成功');
|
message.success('发布成功');
|
||||||
refresh();
|
loadData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('发布失败');
|
message.error('发布失败');
|
||||||
}
|
}
|
||||||
@ -28,7 +42,7 @@ const Definition: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
await disableDefinition(id);
|
await disableDefinition(id);
|
||||||
message.success('禁用成功');
|
message.success('禁用成功');
|
||||||
refresh();
|
loadData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('禁用失败');
|
message.error('禁用失败');
|
||||||
}
|
}
|
||||||
@ -38,7 +52,7 @@ const Definition: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
await enableDefinition(id);
|
await enableDefinition(id);
|
||||||
message.success('启用成功');
|
message.success('启用成功');
|
||||||
refresh();
|
loadData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('启用失败');
|
message.error('启用失败');
|
||||||
}
|
}
|
||||||
@ -48,7 +62,7 @@ const Definition: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
await deleteDefinition(id);
|
await deleteDefinition(id);
|
||||||
message.success('删除成功');
|
message.success('删除成功');
|
||||||
refresh();
|
loadData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('删除失败');
|
message.error('删除失败');
|
||||||
}
|
}
|
||||||
@ -154,8 +168,6 @@ const Definition: React.FC = () => {
|
|||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={list}
|
dataSource={list}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
pagination={pagination}
|
|
||||||
onChange={handleTableChange}
|
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@ -19,7 +19,7 @@ const LOG_URL = '/api/v1/workflow-logs';
|
|||||||
|
|
||||||
// 工作流定义相关接口
|
// 工作流定义相关接口
|
||||||
export const getDefinitions = (params?: WorkflowDefinitionQuery) =>
|
export const getDefinitions = (params?: WorkflowDefinitionQuery) =>
|
||||||
request.get<Page<WorkflowDefinitionResponse>>(`${DEFINITION_URL}`, { params });
|
request.get<Page<WorkflowDefinitionResponse>>(`${DEFINITION_URL}/page`, { params });
|
||||||
|
|
||||||
export const getDefinition = (id: number) =>
|
export const getDefinition = (id: number) =>
|
||||||
request.get<WorkflowDefinitionResponse>(`${DEFINITION_URL}/${id}`);
|
request.get<WorkflowDefinitionResponse>(`${DEFINITION_URL}/${id}`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user