feat: 增加日志
This commit is contained in:
parent
125722c87d
commit
45fab652a0
|
|
@ -460,8 +460,17 @@ def create_app():
|
|||
@app.get("/api/logs", tags=["Log"], description="日志列表", response_model=TableResponse)
|
||||
async def log_list(p:dict = Depends(pagination_query), user: DB.User = Depends(get_current_user)):
|
||||
page, page_size = p["page"], p["page_size"]
|
||||
users = await DB.User.all()
|
||||
res = await DB.WorkLogs.all().order_by('-id').limit(page_size).offset((page - 1) * page_size)
|
||||
return TableResponse(data=[x.json() for x in res], total=len(res))
|
||||
count = await DB.WorkLogs.all().count()
|
||||
data = []
|
||||
for l in res:
|
||||
u = next((x for x in users if x.id == l.user_id), None)
|
||||
obj = l.json()
|
||||
if u:
|
||||
obj["user"] = u.username
|
||||
data.append(obj)
|
||||
return TableResponse(data=data, total=count)
|
||||
|
||||
return app
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
import { Collapse, Modal } from "antd"
|
||||
import { useState } from "react"
|
||||
|
||||
const LogDetail = ({ record }) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const items = record?.result?.logs?.map((e, i) => ({
|
||||
key: i + '',
|
||||
label: e?.title,
|
||||
children: <p style={e?.result?.err ? { color: 'red' } : {}}> {e?.result?.err || e?.result?.out }</p>
|
||||
}))
|
||||
|
||||
|
||||
console.log(items)
|
||||
|
||||
return <>
|
||||
<a onClick={() => setOpen(true)}>查看</a>
|
||||
<Modal width={800} open={open} onCancel={() => setOpen(false)} title="日志详情">
|
||||
<Collapse items={items}/>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
|
||||
export default LogDetail;
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
import { ProTable } from "@ant-design/pro-components";
|
||||
import { Card } from "antd";
|
||||
import { Card, Space, Typography } from "antd";
|
||||
import { useRef } from "react";
|
||||
import { formatSeconds } from "../Flow";
|
||||
import { tableList } from "../../api/log";
|
||||
import LogDetail from "./Detail";
|
||||
|
||||
const LogPage = () => {
|
||||
const actionRef = useRef(null);
|
||||
|
|
@ -22,21 +23,21 @@ const LogPage = () => {
|
|||
}
|
||||
},
|
||||
{
|
||||
dataIndex: 'last_user',
|
||||
dataIndex: 'user',
|
||||
title: '执行用户',
|
||||
},
|
||||
{
|
||||
dataIndex: 'last_run_time',
|
||||
dataIndex: 'create_time',
|
||||
title: '执行时间',
|
||||
render: (_, record) => record?.last_run_time ? new Date(record?.last_run_time * 1000).toLocaleString() : '-'
|
||||
render: (_, record) => record?.create_time ? new Date(record?.create_time * 1000).toLocaleString() : '-'
|
||||
},
|
||||
{
|
||||
dataIndex: 'time',
|
||||
title: '执行耗时',
|
||||
render: (_, record) => record?.time ? formatSeconds(record?.time) : '-',
|
||||
render: (_, record) => record?.result?.time ? formatSeconds(record?.result?.time) : '-',
|
||||
},
|
||||
{
|
||||
dataIndex: 'last_status',
|
||||
dataIndex: 'status',
|
||||
title: '执行结果',
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
|
|
@ -53,14 +54,17 @@ const LogPage = () => {
|
|||
width: 60,
|
||||
fixed: 'right',
|
||||
render: (_, record) => [
|
||||
<a>查看</a>
|
||||
<LogDetail record={record} key='detail' />
|
||||
]
|
||||
}
|
||||
];
|
||||
const onRequest = async (params) => {
|
||||
const res = await tableList(params)
|
||||
console.log(res);
|
||||
return {};
|
||||
const onRequest = async ({current: page, pageSize: page_size,...params}) => {
|
||||
const res = await tableList({ page, page_size, ...params })
|
||||
let index = (page - 1) * page_size + 1;
|
||||
res?.data?.forEach((e, i) => {
|
||||
e.index = index + i
|
||||
});
|
||||
return res;
|
||||
}
|
||||
return <Card title="操作日志">
|
||||
<ProTable
|
||||
|
|
|
|||
Loading…
Reference in New Issue