diff --git a/backend/app/main.py b/backend/app/main.py index d172408..724ceda 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -8,7 +8,7 @@ import models.db as DB import nodes as F from tortoise.transactions import in_transaction from fastapi import FastAPI, Depends, HTTPException -from models.schemas.system import InitStatusResponse, InitConfigRequest, BaseResponse +from models.schemas.system import InitStatusResponse, InitConfigRequest, BaseResponse, TableResponse from models.schemas.user import LoginRequest, LoginResponse from core.config import load_init_config, save_init_config from core.db import init_tortoise, close_tortoise @@ -346,10 +346,10 @@ def create_app(): return BaseResponse() @app.get( - "/api/tasks", + "/api/flows", tags=["Flow"], description="任务列表", - response_model=BaseResponse, + response_model=TableResponse, ) async def task_list(): global_tasks = app.state.tasks @@ -365,7 +365,7 @@ def create_app(): obj["is_running"] = work.uuid in global_tasks obj["status"] = global_status[work.uuid] if work.uuid in global_status else {} res.append(obj) - return BaseResponse(data=res) + return TableResponse(data=res, total=len(res)) return app diff --git a/backend/app/models/schemas/system.py b/backend/app/models/schemas/system.py index f2f37f4..d123c03 100644 --- a/backend/app/models/schemas/system.py +++ b/backend/app/models/schemas/system.py @@ -6,6 +6,12 @@ class BaseResponse(BaseModel): success: bool = True message: str | None = None + +class TableResponse(BaseResponse): + data: list = [] + total: int = 0 + + class InitConfigRequest(BaseModel): db_type: str = "sqlite" admin_password: str = "admin" diff --git a/frontend/src/api/flow.js b/frontend/src/api/flow.js new file mode 100644 index 0000000..bd1aba0 --- /dev/null +++ b/frontend/src/api/flow.js @@ -0,0 +1,12 @@ +import { request } from "./base"; + +export const tableList = async (data = {}) => { + return request("/api/flows?" + new URLSearchParams(data).toString(), "GET") +} + +export const run = async (data = {}) => { + return request("/api/current_user", "POST", data) +} + + + diff --git a/frontend/src/pages/Flow/index.jsx b/frontend/src/pages/Flow/index.jsx index 4985733..86ab949 100644 --- a/frontend/src/pages/Flow/index.jsx +++ b/frontend/src/pages/Flow/index.jsx @@ -1,27 +1,41 @@ import { ProTable } from "@ant-design/pro-components" -import { Button, Card, Modal, Popconfirm, Space, Steps } from "antd" +import { Button, Card, Flex, Modal, Popconfirm, Space, Steps, Typography } from "antd" import { useAuth } from "../../context/AuthContext"; import { LoadingOutlined } from "@ant-design/icons"; import { useState } from "react"; +import { tableList } from "../../api/flow"; + export default () => { const { user } = useAuth(); const run = async record => { + } + const stop = async record => { + } const columns = [ { - dataIndex: 'id', + dataIndex: 'index', title: "序号", }, { dataIndex: 'title', title: "工作流", + render: (_, record) => { + return + {record?.work_title} + ({record?.work_desc}) + + } }, { dataIndex: 'status', title: "状态", render: (_, record) => { - return + if (record?.is_running) { + return + } + return "空闲" } }, { @@ -43,14 +57,33 @@ export default () => { width: user?.level === 0 ? 120 : 60, fixed: 'right', render: (_, record) => [ - run(record)}> - - , + !record?.is_running && ( + run(record)}> + + + ), + record?.is_running && ( + stop(record)}> + + + ), user?.level === 0 && , user?.level === 0 && , ] } ]; + const onRequest = async (params) => { + console.log(params); + try { + const res = await tableList(); + res?.data?.forEach((e, i) => { + e.index = i + 1 + (params?.current - 1) * params?.pageSize; + }) + return res + } catch (error) { + return {} + } + } return ( { scroll={{ x: 'max-content' }} options={false} columns={columns} - dataSource={[{ id: 1 }]} + request={onRequest} />