feat: 获取工作
This commit is contained in:
parent
c865132e1a
commit
2009f2b478
|
|
@ -8,7 +8,7 @@ import models.db as DB
|
||||||
import nodes as F
|
import nodes as F
|
||||||
from tortoise.transactions import in_transaction
|
from tortoise.transactions import in_transaction
|
||||||
from fastapi import FastAPI, Depends, HTTPException
|
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 models.schemas.user import LoginRequest, LoginResponse
|
||||||
from core.config import load_init_config, save_init_config
|
from core.config import load_init_config, save_init_config
|
||||||
from core.db import init_tortoise, close_tortoise
|
from core.db import init_tortoise, close_tortoise
|
||||||
|
|
@ -346,10 +346,10 @@ def create_app():
|
||||||
return BaseResponse()
|
return BaseResponse()
|
||||||
|
|
||||||
@app.get(
|
@app.get(
|
||||||
"/api/tasks",
|
"/api/flows",
|
||||||
tags=["Flow"],
|
tags=["Flow"],
|
||||||
description="任务列表",
|
description="任务列表",
|
||||||
response_model=BaseResponse,
|
response_model=TableResponse,
|
||||||
)
|
)
|
||||||
async def task_list():
|
async def task_list():
|
||||||
global_tasks = app.state.tasks
|
global_tasks = app.state.tasks
|
||||||
|
|
@ -365,7 +365,7 @@ def create_app():
|
||||||
obj["is_running"] = work.uuid in global_tasks
|
obj["is_running"] = work.uuid in global_tasks
|
||||||
obj["status"] = global_status[work.uuid] if work.uuid in global_status else {}
|
obj["status"] = global_status[work.uuid] if work.uuid in global_status else {}
|
||||||
res.append(obj)
|
res.append(obj)
|
||||||
return BaseResponse(data=res)
|
return TableResponse(data=res, total=len(res))
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,12 @@ class BaseResponse(BaseModel):
|
||||||
success: bool = True
|
success: bool = True
|
||||||
message: str | None = None
|
message: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class TableResponse(BaseResponse):
|
||||||
|
data: list = []
|
||||||
|
total: int = 0
|
||||||
|
|
||||||
|
|
||||||
class InitConfigRequest(BaseModel):
|
class InitConfigRequest(BaseModel):
|
||||||
db_type: str = "sqlite"
|
db_type: str = "sqlite"
|
||||||
admin_password: str = "admin"
|
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 { 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 { useAuth } from "../../context/AuthContext";
|
||||||
import { LoadingOutlined } from "@ant-design/icons";
|
import { LoadingOutlined } from "@ant-design/icons";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { tableList } from "../../api/flow";
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const run = async record => {
|
const run = async record => {
|
||||||
|
|
||||||
|
}
|
||||||
|
const stop = async record => {
|
||||||
|
|
||||||
}
|
}
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
dataIndex: 'id',
|
dataIndex: 'index',
|
||||||
title: "序号",
|
title: "序号",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataIndex: 'title',
|
dataIndex: 'title',
|
||||||
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',
|
dataIndex: 'status',
|
||||||
title: "状态",
|
title: "状态",
|
||||||
render: (_, record) => {
|
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,
|
width: user?.level === 0 ? 120 : 60,
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
render: (_, record) => [
|
render: (_, record) => [
|
||||||
<Popconfirm key='1' title="运行工作" onConfirm={() => run(record)}>
|
!record?.is_running && (
|
||||||
<Button type="link" style={{ padding: '0 0', border: 'none' }}>进入</Button>
|
<Popconfirm key='1' title="运行工作" onConfirm={() => run(record)}>
|
||||||
</Popconfirm>,
|
<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='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>,
|
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 (
|
return (
|
||||||
<Card title="工作台">
|
<Card title="工作台">
|
||||||
<ProTable
|
<ProTable
|
||||||
|
|
@ -59,7 +92,7 @@ export default () => {
|
||||||
scroll={{ x: 'max-content' }}
|
scroll={{ x: 'max-content' }}
|
||||||
options={false}
|
options={false}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={[{ id: 1 }]}
|
request={onRequest}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</Card>
|
</Card>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue