feat: 创建工作

This commit is contained in:
李如威 2025-09-22 17:46:31 +08:00
parent ab5f99144c
commit 7e9f0eece2
5 changed files with 26 additions and 14 deletions

View File

@ -330,7 +330,7 @@ def create_app():
await work.save() await work.save()
work_content.work_id = work.id work_content.work_id = work.id
await work_content.save() await work_content.save()
return BaseResponse() return BaseResponse(data=work.uuid)
@app.put("/api/flows", tags=["Flow"], description="任务修改", response_model=BaseResponse) @app.put("/api/flows", tags=["Flow"], description="任务修改", response_model=BaseResponse)
async def update_flow(work_uuid: str, body: WorkRequest, user: DB.User = Depends(get_current_user)): async def update_flow(work_uuid: str, body: WorkRequest, user: DB.User = Depends(get_current_user)):

View File

@ -20,6 +20,9 @@ export const flowUpdate = async (id, data = {}) => {
return request("/api/flows?work_uuid=" + id, "PUT", data) return request("/api/flows?work_uuid=" + id, "PUT", data)
} }
export const flowCreate = async (data = {}) => {
return request("/api/flows", "POST", data)
}

View File

@ -54,13 +54,13 @@ const ClientPage = () => {
] ]
return <Card title="节点管理" extra={<Create onFinish={() => actionRef?.current?.reload()} />}> return <Card title="节点管理">
<ProTable <ProTable
headerTitle={<Create onFinish={() => actionRef?.current?.reload()} />}
actionRef={actionRef} actionRef={actionRef}
rowKey='id' rowKey='id'
search={false} search={false}
scroll={{ x: 'max-content' }} scroll={{ x: 'max-content' }}
options={false}
columns={columns} columns={columns}
request={onRequest} request={onRequest}
/> />

View File

@ -14,7 +14,7 @@ import {
ReactFlowProvider, ReactFlowProvider,
} from '@xyflow/react'; } from '@xyflow/react';
import '@xyflow/react/dist/style.css'; import '@xyflow/react/dist/style.css';
import { flowDetail, flowUpdate } from "../../api/flow"; import { flowCreate, flowDetail, flowUpdate } from "../../api/flow";
import EditNode from "./components/EditNode"; import EditNode from "./components/EditNode";
import CustomNode from "./components/CustomNode"; import CustomNode from "./components/CustomNode";
import { ProForm, ProFormText, ProFormTextArea } from "@ant-design/pro-components"; import { ProForm, ProFormText, ProFormTextArea } from "@ant-design/pro-components";
@ -55,6 +55,7 @@ const nodeTypes = {
const FlowDetail = () => { const FlowDetail = () => {
const { modal, message } = App.useApp(); const { modal, message } = App.useApp();
const { work_uuid } = useParams() const { work_uuid } = useParams()
const isCreate = work_uuid === 'create';
const navigate = useNavigate(); const navigate = useNavigate();
const formRef = useRef(null); const formRef = useRef(null);
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes); const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
@ -100,6 +101,7 @@ const FlowDetail = () => {
} }
const loadDetail = async () => { const loadDetail = async () => {
try { try {
if (isCreate) return;
const res = await flowDetail(work_uuid); const res = await flowDetail(work_uuid);
const { data: { content: { content: infoList } } } = res; const { data: { content: { content: infoList } } } = res;
if (res?.success) { if (res?.success) {
@ -138,8 +140,8 @@ const FlowDetail = () => {
try { try {
await formRef.current.validateFields(); await formRef.current.validateFields();
modal.confirm({ modal.confirm({
title: "保存", title: isCreate ? "创建" : "保存",
content: "确认保存修改内容?", content: isCreate ? "创建工作?" : "确认保存修改内容?",
onOk: async () => { onOk: async () => {
const content = []; const content = [];
nodes.forEach(e => { nodes.forEach(e => {
@ -152,13 +154,18 @@ const FlowDetail = () => {
uuid: e.id uuid: e.id
}) })
}); });
const res = await flowUpdate(record.uuid, { const reqParams = {
content, content,
...formRef.current.getFieldsValue() ...formRef.current.getFieldsValue()
}) }
const res = await (isCreate ? flowCreate(reqParams) : flowUpdate(record.uuid, reqParams))
if (res?.success) { if (res?.success) {
message.success("保存成功"); if (isCreate) {
navigate("/flow/detail/" + res?.data);
} else {
message.success("操作成功");
loadDetail(); loadDetail();
}
} else { } else {
message.error(res.message); message.error(res.message);
} }
@ -179,7 +186,7 @@ const FlowDetail = () => {
<Col span={18} > <Col span={18} >
<Card title="工作" extra={<Space> <Card title="工作" extra={<Space>
<Button onClick={() => navigate("/flow")}>取消</Button> <Button onClick={() => navigate("/flow")}>取消</Button>
<Button type='primary' onClick={() => onSave()}>保存</Button> <Button type='primary' onClick={() => onSave()}>{isCreate ? '创建':'保存'}</Button>
</Space>}> </Space>}>
<div style={{ height: 'calc(100vh - 220px)', width: '100%' }}> <div style={{ height: 'calc(100vh - 220px)', width: '100%' }}>
<ReactFlow <ReactFlow

View File

@ -1,7 +1,7 @@
import { ProTable } from "@ant-design/pro-components" import { ProTable } from "@ant-design/pro-components"
import { Button, Card, Flex, Modal, Popconfirm, Space, Steps, Typography } from "antd" import { Button, Card, Popconfirm, Space, Typography } from "antd"
import { useAuth } from "../../context/AuthContext"; import { useAuth } from "../../context/AuthContext";
import { LoadingOutlined } from "@ant-design/icons"; import { LoadingOutlined, PlusOutlined } from "@ant-design/icons";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { tableList, flowRun, flowStop } from "../../api/flow"; import { tableList, flowRun, flowStop } from "../../api/flow";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
@ -169,11 +169,13 @@ export default () => {
return ( return (
<Card title="工作台"> <Card title="工作台">
<ProTable <ProTable
headerTitle={(
<Button icon={<PlusOutlined />} type='primary' onClick={() => navigate("/flow/detail/create")}>创建</Button>
)}
actionRef={actionRef} actionRef={actionRef}
rowKey='id' rowKey='id'
search={false} search={false}
scroll={{ x: 'max-content' }} scroll={{ x: 'max-content' }}
options={false}
columns={columns} columns={columns}
request={onRequest} request={onRequest}
/> />