Files
shihezi-admin/src/pages/Management/List/index.tsx

344 lines
9.8 KiB
TypeScript
Raw Normal View History

2025-03-28 15:30:35 +08:00
import React, { Fragment, useEffect, useRef, useState } from 'react';
import { FormattedMessage, history, useAccess } from '@umijs/max';
2025-01-20 17:42:05 +08:00
2025-03-28 15:30:35 +08:00
import {
addCmsJobList,
delCmsJobIds,
exportCmsJob,
getCmsJobList,
updateCmsJobList,
} from '@/services/Management/list';
import { Button, FormInstance, message, Modal, Switch } from 'antd';
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
import {
AlignLeftOutlined,
BarChartOutlined,
DeleteOutlined,
FormOutlined,
PlusOutlined,
} from '@ant-design/icons';
2025-03-28 15:30:35 +08:00
import EditManageRow from './edit';
import { getDictValueEnum } from '@/services/system/dict';
import DictTag from '@/components/DictTag';
const handleExport = async (values: API.ManagementList.ListParams) => {
const hide = message.loading('正在导出');
try {
await exportCmsJob(values);
hide();
message.success('导出成功');
return true;
} catch (error) {
hide();
message.error('导出失败,请重试');
return false;
}
};
2025-01-20 17:42:05 +08:00
const handleRemoveOne = async (jobId: string) => {
const hide = message.loading('正在删除');
if (!jobId) return true;
try {
const resp = await delCmsJobIds(jobId);
hide();
if (resp.code === 200) {
message.success('删除成功,即将刷新');
} else {
message.error(resp.msg);
}
return true;
} catch (error) {
hide();
message.error('删除失败,请重试');
return false;
}
};
2024-11-26 16:43:31 +08:00
function ManagementList() {
const access = useAccess();
const formTableRef = useRef<FormInstance>();
const actionRef = useRef<ActionType>();
2025-03-28 15:30:35 +08:00
const [educationEnum, setEducationEnum] = useState<any>([]);
const [experienceEnum, setExperienceEnum] = useState<any>([]);
const [areaEnum, setAreaEnum] = useState<any>([]);
const [isPublishEnum, setIsPublishEnum] = useState<any>([]);
const [hotEnum, setHotEnum] = useState<any>([]);
const [currentRow, setCurrentRow] = useState<API.ManagementList.Manage>();
const [modalVisible, setModalVisible] = useState<boolean>(false);
2025-03-31 17:43:40 +08:00
const [mode, setMode] = useState<'view' | 'edit' | 'create'>('create');
2025-01-20 17:42:05 +08:00
useEffect(() => {
2025-03-28 15:30:35 +08:00
getDictValueEnum('education', true, true).then((data) => {
setEducationEnum(data);
});
getDictValueEnum('experience', true, true).then((data) => {
setExperienceEnum(data);
});
getDictValueEnum('area', true, true).then((data) => {
setAreaEnum(data);
});
getDictValueEnum('is_publish', true).then((data) => {
setIsPublishEnum(data);
});
2025-01-20 17:42:05 +08:00
// getDictValueEnum('job_hot',true).then((data) => {
// setHotEnum(data)
// })
2025-03-28 15:30:35 +08:00
}, []);
async function changeRelease(record: API.ManagementList.Manage) {
let resData = await updateCmsJobList({
jobId: record.jobId,
isPublish: record.isPublish === 1 ? 0 : 1,
});
if (resData.code === 200) {
message.success('修改成功');
if (actionRef.current) {
actionRef.current.reload();
}
}
}
2025-01-20 17:42:05 +08:00
const columns: ProColumns<API.ManagementList.Manage>[] = [
2024-11-26 16:43:31 +08:00
{
2025-01-20 17:42:05 +08:00
title: '岗位名称',
dataIndex: 'jobTitle',
valueType: 'text',
align: 'center',
2025-03-28 15:30:35 +08:00
},
{
title: '最小薪资',
dataIndex: 'minSalary',
valueType: 'text',
align: 'center',
},
{
title: '最大薪资',
2025-01-20 17:42:05 +08:00
dataIndex: 'maxSalary',
valueType: 'text',
align: 'center',
},
{
title: '单位名称',
dataIndex: 'companyName',
valueType: 'text',
align: 'center',
},
{
title: '学历要求',
dataIndex: 'education',
valueType: 'select',
align: 'center',
valueEnum: educationEnum,
render: (_, record) => {
2025-03-28 15:30:35 +08:00
return <DictTag enums={educationEnum} value={record.education} />;
2025-01-20 17:42:05 +08:00
},
},
{
title: '经验要求',
dataIndex: 'experience',
valueType: 'select',
align: 'center',
valueEnum: experienceEnum,
render: (_, record) => {
2025-03-28 15:30:35 +08:00
return <DictTag enums={experienceEnum} value={record.experience} />;
2025-01-20 17:42:05 +08:00
},
},
// {
// title: '是否热门',
// dataIndex: 'isHot',
// valueType: 'select',
// align: 'center',
// valueEnum: hotEnum,
// render: (_, record) => {
// return (<DictTag enums={hotEnum} value={record.isHot} />);
// },
// },
{
2025-03-28 15:30:35 +08:00
title: '是否发布',
dataIndex: 'isPublish',
valueType: 'select',
2025-01-20 17:42:05 +08:00
align: 'center',
2025-03-28 15:30:35 +08:00
valueEnum: isPublishEnum,
render: (text, record) => (
<Switch checked={record.isPublish === 1} onChange={changeRelease.bind(null, record)} />
),
2025-01-20 17:42:05 +08:00
},
{
title: '招聘人数',
dataIndex: 'vacancies',
2024-11-26 16:43:31 +08:00
valueType: 'text',
2025-01-20 17:42:05 +08:00
align: 'center',
2024-11-26 16:43:31 +08:00
hideInSearch: true,
},
2025-01-20 17:42:05 +08:00
{
title: '浏览量',
dataIndex: 'view',
valueType: 'text',
align: 'center',
hideInSearch: true,
},
{
title: '操作',
hideInSearch: true,
align: 'center',
dataIndex: 'jobId',
width: 300,
render: (jobId, record) => [
2025-03-31 17:43:40 +08:00
<div key="first-row" style={{ marginBottom: 8, display: 'flex', justifyContent: 'center' }}>
<Button
type="link"
size="small"
key="view"
icon={<AlignLeftOutlined />}
hidden={!access.hasPerms('area:business:List.view')}
onClick={() => {
setCurrentRow(record);
setModalVisible(true);
setMode('view'); // 新增状态控制模式
}}
>
</Button>
<Button
type="link"
size="small"
key="edit"
icon={<BarChartOutlined />}
hidden={!access.hasPerms('area:business:List.update')}
onClick={() => history.push(`/management/see-matching/index/${record.jobId}`)}
>
</Button>
2025-03-31 17:43:40 +08:00
</div>,
<div key="second-row" style={{ display: 'flex', justifyContent: 'space-evenly' }}>
<Button
type="link"
size="small"
key="edit"
icon={<FormOutlined />}
hidden={!access.hasPerms('area:business:List.update')}
onClick={() => {
setModalVisible(true);
setCurrentRow(record);
}}
>
</Button>
<Button
type="link"
size="small"
danger
key="batchRemove"
icon={<DeleteOutlined />}
hidden={!access.hasPerms('area:subway:List')}
onClick={async () => {
Modal.confirm({
title: '删除',
content: '确定删除该项吗?',
okText: '确认',
cancelText: '取消',
onOk: async () => {
const success = await handleRemoveOne(jobId as string);
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
2025-01-20 17:42:05 +08:00
}
},
});
}}
>
</Button>
</div>,
2025-03-28 15:30:35 +08:00
],
},
];
2024-11-26 16:43:31 +08:00
return (
<Fragment>
<div style={{ width: '100%', float: 'right' }}>
2025-01-20 17:42:05 +08:00
<ProTable<API.ManagementList.Manage>
2024-11-26 16:43:31 +08:00
// params 是需要自带的参数
// 这个参数优先级更高,会覆盖查询表单的参数
actionRef={actionRef}
formRef={formTableRef}
2025-01-20 17:42:05 +08:00
rowKey="jobId"
key="index"
2024-11-26 16:43:31 +08:00
columns={columns}
request={(params) =>
2025-01-20 17:42:05 +08:00
getCmsJobList({ ...params } as API.ManagementList.ListParams).then((res) => {
2025-03-28 15:30:35 +08:00
console.log(params);
2024-11-26 16:43:31 +08:00
const result = {
data: res.rows,
total: res.total,
success: true,
};
return result;
})
}
toolBarRender={() => [
<Button
type="primary"
key="add"
2025-01-20 17:42:05 +08:00
hidden={!access.hasPerms('manage:List:add')}
2024-11-26 16:43:31 +08:00
onClick={async () => {
setCurrentRow(undefined);
setModalVisible(true);
2025-03-31 17:43:40 +08:00
setMode('create');
2024-11-26 16:43:31 +08:00
}}
>
<PlusOutlined />
</Button>,
2025-03-28 15:30:35 +08:00
<Button
type="primary"
key="export"
hidden={!access.hasPerms('system:user:export')}
onClick={async () => {
const searchVal = formTableRef.current && formTableRef.current.getFieldsValue();
handleExport(searchVal as API.ManagementList.ListParams);
}}
>
<PlusOutlined />
<FormattedMessage id="pages.searchTable.export" defaultMessage="导出" />
</Button>,
2024-11-26 16:43:31 +08:00
]}
/>
</div>
<EditManageRow
open={modalVisible}
2025-03-31 17:43:40 +08:00
mode={mode}
2025-03-28 15:30:35 +08:00
onSubmit={async (values) => {
let resData;
if (values.jobId) {
resData = await updateCmsJobList(values);
} else {
resData = await addCmsJobList(values);
}
if (resData.code === 200) {
setModalVisible(false);
setCurrentRow(undefined);
if (values.jobId) {
message.success('修改成功');
} else {
message.success('新增成功');
}
if (actionRef.current) {
actionRef.current.reload();
}
}
2024-11-26 16:43:31 +08:00
}}
2025-03-28 15:30:35 +08:00
values={currentRow}
2024-11-26 16:43:31 +08:00
onCancel={() => {
setModalVisible(false);
setCurrentRow(undefined);
}}
2025-03-28 15:30:35 +08:00
educationEnum={educationEnum}
experienceEnum={experienceEnum}
areaEnum={areaEnum}
2024-11-26 16:43:31 +08:00
></EditManageRow>
</Fragment>
2025-03-28 15:30:35 +08:00
);
2024-11-26 16:43:31 +08:00
}
2025-03-28 15:30:35 +08:00
export default ManagementList;