flat: 暂存

This commit is contained in:
史典卓
2025-04-03 09:26:57 +08:00
parent 994ec60616
commit d021d47c93
2 changed files with 129 additions and 107 deletions

View File

@@ -1,14 +1,14 @@
import React, { Fragment, useEffect, useRef, useState } from 'react';
import { FormattedMessage, useAccess } from '@umijs/max';
import { Button, FormInstance, message, Modal } from 'antd';
import { Button, FormInstance, message } from 'antd';
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
import { AlignLeftOutlined, DeleteOutlined, FormOutlined, PlusOutlined } from '@ant-design/icons';
import { AlignLeftOutlined, FormOutlined, PlusOutlined } from '@ant-design/icons';
import EditCompanyListRow from './edit';
import {
addCmsIndustryIndustryt,
delCmsIndustryList,
exportCmsIndustry,
getCmsIndustryTreeList,
getCmsIndustryTreeList,
updateCmsIndustryIndustryt,
} from '@/services/classify/industry';
import { getDictValueEnum } from '@/services/system/dict';
@@ -23,7 +23,8 @@ interface IndustryItem {
children?: IndustryItem[];
}
const handleRemoveOne = async (id: string) => { // 参数改为id
const handleRemoveOne = async (id: string) => {
// 参数改为id
const hide = message.loading('正在删除');
try {
const resp = await delCmsIndustryList(id);
@@ -41,7 +42,8 @@ const handleRemoveOne = async (id: string) => { // 参数改为id
}
};
const handleExport = async (values: any) => { // 简化类型定义
const handleExport = async (values: any) => {
// 简化类型定义
const hide = message.loading('正在导出');
try {
await exportCmsIndustry(values);
@@ -57,13 +59,13 @@ const handleExport = async (values: any) => { // 简化类型定义
// 处理树形数据的函数(移到组件外部)
function processTreeData(data: any[]): IndustryItem[] {
return data.map(item => ({
return data.map((item) => ({
id: item.id,
industryName: item.label,
orderNum: item.sort || 0,
status: item.status || '0',
key: item.id, // ProTable需要的唯一key
children: item.children ? processTreeData(item.children) : []
children: item.children ? processTreeData(item.children) : undefined,
}));
}
@@ -72,7 +74,7 @@ function ManagementList() {
const formTableRef = useRef<FormInstance>();
const actionRef = useRef<ActionType>();
const [currentRow, setCurrentRow] = useState<IndustryItem>(); // 使用新类型
const [currentRow, setCurrentRow] = useState<IndustryItem>(); // 使用新类型
const [modalVisible, setModalVisible] = useState<boolean>(false);
const [industryStatusEnum, setIndustryStatusEnum] = useState<any>([]);
@@ -82,7 +84,8 @@ function ManagementList() {
});
}, []);
const columns: ProColumns<IndustryItem>[] = [ // 使用新类型
const columns: ProColumns<IndustryItem>[] = [
// 使用新类型
{
title: '行业名称',
dataIndex: 'industryName',
@@ -110,7 +113,7 @@ function ManagementList() {
title: '操作',
hideInSearch: true,
align: 'center',
dataIndex: 'id', // 改为id
dataIndex: 'id', // 改为id
width: 300,
render: (id, record) => [
<Button
@@ -139,28 +142,28 @@ function ManagementList() {
>
</Button>,
<Button
type="link"
size="small"
danger
key="batchRemove"
icon={<DeleteOutlined />}
hidden={!access.hasPerms('area:subway:List')}
onClick={async () => {
Modal.confirm({
title: '删除',
content: '确定删除该项吗?',
onOk: async () => {
const success = await handleRemoveOne(id.toString());
if (success && actionRef.current) {
actionRef.current.reload();
}
},
});
}}
>
</Button>,
// <Button
// type="link"
// size="small"
// danger
// key="batchRemove"
// icon={<DeleteOutlined />}
// hidden={!access.hasPerms('area:subway:List')}
// onClick={async () => {
// Modal.confirm({
// title: '删除',
// content: '确定删除该项吗?',
// onOk: async () => {
// const success = await handleRemoveOne(id.toString());
// if (success && actionRef.current) {
// actionRef.current.reload();
// }
// },
// });
// }}
// >
// 删除
// </Button>,
],
},
];
@@ -171,7 +174,7 @@ function ManagementList() {
<ProTable<IndustryItem>
actionRef={actionRef}
formRef={formTableRef}
rowKey="id" // 改为id
rowKey="id" // 改为id
columns={columns}
search={false}
defaultExpandAllRows={true}
@@ -219,7 +222,8 @@ function ManagementList() {
open={modalVisible}
onSubmit={async (values) => {
let resData;
if (values.id) { // 改为id
if (values.id) {
// 改为id
resData = await updateCmsIndustryIndustryt(values);
} else {
resData = await addCmsIndustryIndustryt(values);
@@ -238,8 +242,10 @@ function ManagementList() {
industryStatusEnum={industryStatusEnum}
values={currentRow}
mode={
currentRow?.id // 改为id
? access.hasPerms('area:business:List.update') ? 'edit' : 'view'
currentRow?.id // 改为id
? access.hasPerms('area:business:List.update')
? 'edit'
: 'view'
: 'create'
}
/>
@@ -247,4 +253,4 @@ function ManagementList() {
);
}
export default ManagementList;
export default ManagementList;

View File

@@ -1,13 +1,14 @@
import React, { Fragment, useEffect, useRef, useState } from 'react';
import { FormattedMessage, useAccess } from '@umijs/max';
import { Button, FormInstance, message, Modal } from 'antd';
import { Button, FormInstance, message } from 'antd';
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
import { DeleteOutlined, FormOutlined, PlusOutlined } from '@ant-design/icons';
import { PlusOutlined } from '@ant-design/icons';
import EditCompanyListRow from './edit';
import { addCmsCompanyList, delCmsCompanyList, putCmsCompanyList } from '@/services/company/list';
import { exportCmsJobTitleList, getCmsJobTitleList } from '@/services/classify/jobs';
import { getDictValueEnum } from '@/services/system/dict';
import DictTag from '@/components/DictTag';
declare namespace API {
namespace ClassifyJobs {
interface Params {
@@ -17,6 +18,7 @@ declare namespace API {
jobName?: string;
status?: string;
}
interface Jobs {
jobId: number;
parentId: number;
@@ -25,14 +27,14 @@ declare namespace API {
status?: string;
createTime?: string;
parentName?: string;
children?: Jobs[];
children?: Jobs[];
depth?: number; // 添加这行
}
}
}
// params类型
type JobListParams = API.ClassifyJobs.Params & {
tree?:boolean;
tree?: boolean;
};
const handleRemoveOne = async (jobId: string) => {
@@ -67,14 +69,21 @@ const handleExport = async (values: API.ClassifyJobs.Params) => {
return false;
}
};
const buildTree = (data: API.ClassifyJobs.Jobs[], parentId: number = 0,depth = 0): API.ClassifyJobs.Jobs[] => {
const buildTree = (
data: API.ClassifyJobs.Jobs[],
parentId: number = 0,
depth = 0,
): API.ClassifyJobs.Jobs[] => {
return data
.filter(item => item.parentId === parentId)
.map(item => ({
...item,
depth,
children: buildTree(data, item.jobId,depth + 1),
}));
.filter((item) => item.parentId === parentId)
.map((item) => {
const child = buildTree(data, item.jobId, depth + 1);
return {
...item,
depth,
children: child.length ? child : undefined,
};
});
};
const ManagementList: React.FC = () => {
@@ -97,16 +106,22 @@ const ManagementList: React.FC = () => {
{
title: '岗位名称',
dataIndex: 'jobName',
align: 'center',
render: (text, record) => (
<span style={{ paddingLeft: `${(record.depth || 0) * 20}px`,display:'inline-block' ,
width:'100%'}}>
<span
style={{
paddingLeft: `${(record.depth || 0) * 20}px`,
display: 'inline-block',
width: '100%',
}}
>
{text}
</span>
),
},
{title: '父级岗位',
{
title: '父级岗位',
dataIndex: 'parentName',
valueType: 'text',
hideInSearch: true,
@@ -129,55 +144,55 @@ const ManagementList: React.FC = () => {
return <DictTag enums={jobsStatusEnum} value={record.status} />;
},
},
{
title: '操作',
hideInSearch: true,
align: 'center',
dataIndex: 'jobId',
width: 300,
render: (_, record) => [
<Button
type="link"
size="small"
key="edit"
icon={<FormOutlined />}
hidden={!access.hasPerms('system:job:edit')}
onClick={() => {
setModalVisible(true);
setCurrentRow(record);
}}
>
</Button>,
// <Button
// type="link"
// size="small"
// danger
// key="delete"
// icon={<DeleteOutlined />}
// hidden={!access.hasPerms('system:job:remove')}
// onClick={async () => {
// Modal.confirm({
// title: '删除',
// content: '确定删除该项吗?',
// okText: '确认',
// cancelText: '取消',
// onOk: async () => {
// if(record.jobId){
// const success = await handleRemoveOne(record.jobId.toString());
// if (success && actionRef.current) {
// actionRef.current.reload();
// }
// }
// },
// });
// }}
// >
// 删除
// </Button>,
],
},
// {
// title: '操作',
// hideInSearch: true,
// align: 'center',
// dataIndex: 'jobId',
// width: 300,
// render: (_, record) => [
// <Button
// type="link"
// size="small"
// key="edit"
// icon={<FormOutlined />}
// hidden={!access.hasPerms('system:job:edit')}
// onClick={() => {
// setModalVisible(true);
// setCurrentRow(record);
// }}
// >
// 编辑
// </Button>,
// // <Button
// // type="link"
// // size="small"
// // danger
// // key="delete"
// // icon={<DeleteOutlined />}
// // hidden={!access.hasPerms('system:job:remove')}
// // onClick={async () => {
// // Modal.confirm({
// // title: '删除',
// // content: '确定删除该项吗?',
// // okText: '确认',
// // cancelText: '取消',
// // onOk: async () => {
// // if(record.jobId){
// // const success = await handleRemoveOne(record.jobId.toString());
//
// // if (success && actionRef.current) {
// // actionRef.current.reload();
// // }
// // }
// // },
// // });
// // }}
// // >
// // 删除
// // </Button>,
// ],
// },
];
return (
<Fragment>
@@ -194,8 +209,10 @@ const ManagementList: React.FC = () => {
labelWidth: 120,
}}
request={async (params) => {
const res = await getCmsJobTitleList({ ...params, tree: false ,
pageSize:1000
const res = await getCmsJobTitleList({
...params,
tree: false,
pageSize: 1000,
});
const treeData = buildTree(res.rows);
console.log('完整树形结构:', JSON.stringify(treeData, null, 2));
@@ -209,10 +226,9 @@ const ManagementList: React.FC = () => {
expandable={{
childrenColumnName: 'children',
defaultExpandAllRows: true,
indentSize:30,
rowExpandable: (record) => !!record.children?.length
indentSize: 30,
rowExpandable: (record) => !!record.children?.length,
}}
toolBarRender={() => [
<Button
type="primary"
@@ -270,6 +286,6 @@ const ManagementList: React.FC = () => {
></EditCompanyListRow>
</Fragment>
);
}
};
export default ManagementList;