assistant-todo/src/app/ui/task/four/TreeTable.tsx

148 lines
4.7 KiB
TypeScript
Raw Normal View History

2024-04-12 06:43:55 -04:00
'use client'
import React, {useEffect, useState} from 'react';
2024-04-23 03:38:51 -04:00
import {ConfigProvider, Table} from 'antd';
2024-04-19 05:44:44 -04:00
import type {TableColumnsType, TableProps} from 'antd';
import {getTaskTreeResult, taskPriorityList, taskStateList, taskTreeResult} from "@/app/lib/task/project/data";
2024-04-12 06:43:55 -04:00
import {DataType, ResponseVO, ResultPage} from "@/app/lib/definitions";
2024-04-24 01:54:59 -04:00
import OperationButton from "@/app/ui/task/OperationButton";
2024-04-23 01:19:26 -04:00
import dayjs from "dayjs";
2024-04-24 01:54:59 -04:00
import "@/app/ui/task/four/detailForm.modules.css"
2024-04-12 06:43:55 -04:00
type TableRowSelection<T> = TableProps<T>['rowSelection'];
const columns: TableColumnsType<DataType> = [
{
title: '任务编码',
dataIndex: 'code',
key: 'code',
width: '10%',
},
{
title: '任务名称',
dataIndex: 'name',
key: 'name',
width: '20%',
},
2024-04-23 01:19:26 -04:00
// {
// title: '任务描述',
// dataIndex: 'description',
// // width: '30%',
// key: 'description',
// },
2024-04-12 06:43:55 -04:00
{
title: '任务状态',
dataIndex: 'state',
width: '10%',
key: 'state',
},
2024-04-19 05:44:44 -04:00
// {
// title: '优先级',
// dataIndex: 'priority',
// width: '10%',
// key: 'priority',
// },
2024-04-23 01:19:26 -04:00
{
title: '期望开始时间',
dataIndex: 'expectedStartTime',
width: '10%',
key: 'expectedStartTime',
},
2024-04-12 06:43:55 -04:00
{
title: '操作',
dataIndex: 'action',
width: '10%',
key: 'action',
},
];
// rowSelection objects indicates the need for row selection
const rowSelection: TableRowSelection<DataType> = {
onChange: (selectedRowKeys, selectedRows) => {
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
},
onSelect: (record, selected, selectedRows) => {
console.log(record, selected, selectedRows);
},
onSelectAll: (selected, selectedRows, changeRows) => {
console.log(selected, selectedRows, changeRows);
},
};
2024-04-16 04:11:21 -04:00
2024-04-19 05:44:44 -04:00
interface TableSearchType {
search?: any
2024-04-23 03:38:51 -04:00
priority:string
2024-04-19 05:44:44 -04:00
}
const TreeTable: React.FC<TableSearchType> = (props) => {
function recursionActionChild(children: DataType[]) {
if (children.length === 0) {
2024-04-16 04:11:21 -04:00
return;
}
for (let item of children) {
2024-04-19 05:44:44 -04:00
item.key = item.id;
item.action = (
<OperationButton itemId={item.id} pid={item.pid} pPid={item.pPid} refreshDate={refreshDate}/>)
item.state = taskStateList.find(taskState => taskState.code === item.state?.toString())?.name;
item.priority = taskPriorityList.find(taskPriority => taskPriority.code === item.priority?.toString())?.name;
2024-04-23 01:19:26 -04:00
if (item.expectedStartTime) {
item.expectedStartTime = dayjs(item.expectedStartTime).format('YYYY-MM-DD HH:mm:ss')
}
2024-04-19 05:44:44 -04:00
if (item.children && item.children.length > 0) {
2024-04-23 01:19:26 -04:00
if (item.children && item.children.length > 0) {
recursionActionChild(item.children)
} else {
item.children = undefined
}
2024-04-16 04:11:21 -04:00
}
}
}
2024-04-12 06:43:55 -04:00
// const [checkStrictly, setCheckStrictly] = useState(false);
const [data, setData] = useState<DataType[]>([]);
const [pageNumber, setPageNumber] = useState<number>(1);
2024-04-23 01:19:26 -04:00
const [pageSize, setPageSize] = useState<number>(100);
2024-04-19 05:44:44 -04:00
const refreshDate = (): void => {
getTaskTreeResult(JSON.stringify({
pageSize,
pageNumber,
2024-04-23 01:19:26 -04:00
data: props.search
2024-04-19 05:44:44 -04:00
})).then((result: ResponseVO<ResultPage<DataType>>) => {
if (result.status.success) {
2024-04-12 06:43:55 -04:00
recursionActionChild(result.data.content);
setData(result.data.content)
}
})
2024-04-16 04:11:21 -04:00
}
useEffect(() => {
refreshDate();
2024-04-23 01:19:26 -04:00
}, [props.search]);
2024-04-12 06:43:55 -04:00
return (
<>
2024-04-23 03:38:51 -04:00
<ConfigProvider
theme={{
components: {
Table: {
headerBg:taskPriorityList.find((item)=>item.code===props.priority)?.color
/* 这里是你的组件 token */
},
},
}}
>
<Table
columns={columns}
// rowSelection={{ ...rowSelection, checkStrictly}}
dataSource={data}
pagination={{ pageSize: 5 }}
scroll={{ y: 280 }}
/>
</ConfigProvider>
2024-04-12 06:43:55 -04:00
{/*<Space align="center" style={{ marginBottom: 16 }}>*/}
{/* CheckStrictly: <Switch checked={checkStrictly} onChange={setCheckStrictly} />*/}
{/*</Space>*/}
2024-04-17 22:38:47 -04:00
{/*<ColorPicker defaultValue="#1677ff" showText/>*/}
2024-04-12 06:43:55 -04:00
</>
);
};
export default TreeTable;