feat: 获取工作
This commit is contained in:
parent
c865132e1a
commit
2009f2b478
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -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 <Space>
|
||||
<Typography.Text>{record?.work_title}</Typography.Text>
|
||||
<Typography.Text type="secondary">({record?.work_desc})</Typography.Text>
|
||||
</Space>
|
||||
}
|
||||
},
|
||||
{
|
||||
dataIndex: 'status',
|
||||
title: "状态",
|
||||
render: (_, record) => {
|
||||
return <RunningStatus record={record} />
|
||||
if (record?.is_running) {
|
||||
return <RunningStatus record={record} />
|
||||
}
|
||||
return "空闲"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -43,14 +57,33 @@ export default () => {
|
|||
width: user?.level === 0 ? 120 : 60,
|
||||
fixed: 'right',
|
||||
render: (_, record) => [
|
||||
<Popconfirm key='1' title="运行工作" onConfirm={() => run(record)}>
|
||||
<Button type="link" style={{ padding: '0 0', border: 'none' }}>进入</Button>
|
||||
</Popconfirm>,
|
||||
!record?.is_running && (
|
||||
<Popconfirm key='1' title="运行工作" onConfirm={() => run(record)}>
|
||||
<Button type="link" style={{ padding: '0 0', border: 'none' }}>运行</Button>
|
||||
</Popconfirm>
|
||||
),
|
||||
record?.is_running && (
|
||||
<Popconfirm key='1' title="暂停工作" onConfirm={() => stop(record)}>
|
||||
<Button type="link" danger style={{ padding: '0 0', border: 'none' }}>暂停</Button>
|
||||
</Popconfirm>
|
||||
),
|
||||
user?.level === 0 && <Button key='2' type="link" style={{ padding: '0 0', border: 'none' }}>编辑</Button>,
|
||||
user?.level === 0 && <Button key='3' type="link" danger style={{ padding: '0 0', border: 'none' }}>删除</Button>,
|
||||
]
|
||||
}
|
||||
];
|
||||
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 (
|
||||
<Card title="工作台">
|
||||
<ProTable
|
||||
|
|
@ -59,7 +92,7 @@ export default () => {
|
|||
scroll={{ x: 'max-content' }}
|
||||
options={false}
|
||||
columns={columns}
|
||||
dataSource={[{ id: 1 }]}
|
||||
request={onRequest}
|
||||
/>
|
||||
|
||||
</Card>
|
||||
|
|
|
|||
Loading…
Reference in New Issue