diff --git a/src/pages/Classify/Industry/edit.tsx b/src/pages/Classify/Industry/edit.tsx index e9e39b5..bcaffd0 100644 --- a/src/pages/Classify/Industry/edit.tsx +++ b/src/pages/Classify/Industry/edit.tsx @@ -1,189 +1,190 @@ -import React, { useEffect } from 'react'; -import { - ModalForm, - ProForm, - ProFormDigit, - ProFormRadio, - ProFormTreeSelect, - ProFormText, - ProDescriptions, -} from '@ant-design/pro-components'; -import { Form } from 'antd'; -import { DictValueEnumObj } from '@/components/DictTag'; -import { FormattedMessage } from '@@/exports'; -import { getCmsIndustryTreeList } from '@/services/classify/industry'; // 修改导入为 getCmsIndustryTreeList - -interface IndustryDetail { - id?: number; - industryName?: string; - orderNum?: number; - status?: string; - parentId?: number; - parentName?: string; -} - -export type ListFormProps = { - onCancel: (flag?: boolean, formVars?: unknown) => void; - onSubmit: (values: any) => Promise; - open: boolean; - values?: Partial; - industryStatusEnum: DictValueEnumObj; - mode?: 'view' | 'edit' | 'create'; -}; - -const listEdit: React.FC = (props) => { - const [form] = Form.useForm(); - const { industryStatusEnum, mode = props.values ? 'edit' : 'create', values } = props; - - useEffect(() => { - form.resetFields(); - if (values) { - form.setFieldsValue({ - ...values, - parentId: values?.parentId ?? 0 - }); - } - }, [form, values?.id]); - - const getSafeDetailData = (data?: Partial): IndustryDetail => { - return { - id: data?.id ?? 0, - industryName: data?.industryName ?? '', - orderNum: data?.orderNum ?? 0, - parentId: data?.parentId ?? 0, - parentName: data?.parentName ?? '顶级节点', - status: data?.status ?? '0', - }; - }; - - const handleCancel = () => { - props.onCancel(); - form.resetFields(); - }; - - const handleFinish = async (values: Record) => { - const submitValues = { - ...values, - parentId: values.parentId === 0 ? undefined : values.parentId - }; - props.onSubmit(submitValues); - }; - - // 获取行业树数据 - const fetchIndustryTree = async () => { - const res = await getCmsIndustryTreeList(); - return [ - { - id: 0, - label: '顶级节点', - value: 0, - children: res.data || [] - } - ]; - }; - - if (mode === 'view') { - return ( - handleCancel(), - footer: null, - }} - submitter={false} - > - - column={1} - dataSource={getSafeDetailData(values)} - loading={!values} - > - - - - record.parentId === 0 ? '顶级节点' : text} - /> - - - - ); - } - - return ( - handleCancel(), - }} - submitTimeout={2000} - onFinish={handleFinish} - > - - ); -}; - +import React, { useEffect } from 'react'; +import { + ModalForm, + ProForm, + ProFormDigit, + ProFormRadio, + ProFormTreeSelect, + ProFormText, + ProDescriptions, +} from '@ant-design/pro-components'; +import { Form } from 'antd'; +import { DictValueEnumObj } from '@/components/DictTag'; +import { FormattedMessage } from '@@/exports'; +import { getCmsIndustryTreeList } from '@/services/classify/industry'; // 修改导入为 getCmsIndustryTreeList + +interface IndustryDetail { + id?: number; + industryName?: string; + orderNum?: number; + status?: string; + parentId?: number; + parentName?: string; +} + +export type ListFormProps = { + onCancel: (flag?: boolean, formVars?: unknown) => void; + onSubmit: (values: any) => Promise; + open: boolean; + values?: Partial; + industryStatusEnum: DictValueEnumObj; + mode?: 'view' | 'edit' | 'create'; +}; + +const listEdit: React.FC = (props) => { + const [form] = Form.useForm(); + const { industryStatusEnum, mode = props.values ? 'edit' : 'create', values } = props; + + useEffect(() => { + form.resetFields(); + if (values) { + form.setFieldsValue({ + ...values, + parentId: values?.parentId ?? 0 + }); + } + }, [form, values?.id]); + + const getSafeDetailData = (data?: Partial): IndustryDetail => { + return { + id: data?.id ?? 0, + industryName: data?.industryName ?? '', + orderNum: data?.orderNum ?? 0, + parentId: data?.parentId ?? 0, + parentName: data?.parentName ?? '顶级节点', + status: data?.status ?? '0', + }; + }; + + const handleCancel = () => { + props.onCancel(); + form.resetFields(); + }; + + const handleFinish = async (values: Record) => { + const submitValues = { + ...values, + parentId: values.parentId === 0 ? undefined : values.parentId + }; + props.onSubmit(submitValues); + }; + + // 获取行业树数据 + const fetchIndustryTree = async () => { + const res = await getCmsIndustryTreeList(); + return [ + { + id: 0, + label: '顶级节点', + value: 0, + children: res.data || [] + } + ]; + }; + + if (mode === 'view') { + return ( + handleCancel(), + footer: null, + }} + submitter={false} + > + + column={1} + dataSource={getSafeDetailData(values)} + loading={!values} + > + + + + record.parentId === 0 ? '顶级节点' : text} + /> + + + + ); + } + + return ( + handleCancel(), + }} + submitTimeout={2000} + onFinish={handleFinish} + > + + ); +}; + export default listEdit; \ No newline at end of file diff --git a/src/pages/Classify/Industry/index.tsx b/src/pages/Classify/Industry/index.tsx index bbdd68d..5f2fa62 100644 --- a/src/pages/Classify/Industry/index.tsx +++ b/src/pages/Classify/Industry/index.tsx @@ -1,250 +1,256 @@ -import React, { Fragment, useEffect, useRef, useState } from 'react'; -import { FormattedMessage, useAccess } from '@umijs/max'; -import { Button, FormInstance, message, Modal } from 'antd'; -import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components'; -import { AlignLeftOutlined, DeleteOutlined, FormOutlined, PlusOutlined } from '@ant-design/icons'; -import EditCompanyListRow from './edit'; -import { - addCmsIndustryIndustryt, - delCmsIndustryList, - exportCmsIndustry, - getCmsIndustryTreeList, - updateCmsIndustryIndustryt, -} from '@/services/classify/industry'; -import { getDictValueEnum } from '@/services/system/dict'; -import DictTag from '@/components/DictTag'; - -// 定义行业数据类型(替代API.ClassifyIndustry.IndustryRow) -interface IndustryItem { - id: number; - industryName: string; - orderNum?: number; - status?: string; - children?: IndustryItem[]; -} - -const handleRemoveOne = async (id: string) => { // 参数改为id - const hide = message.loading('正在删除'); - try { - const resp = await delCmsIndustryList(id); - hide(); - if (resp.code === 200) { - message.success('删除成功,即将刷新'); - } else { - message.error(resp.msg); - } - return true; - } catch (error) { - hide(); - message.error('删除失败,请重试'); - return false; - } -}; - -const handleExport = async (values: any) => { // 简化类型定义 - const hide = message.loading('正在导出'); - try { - await exportCmsIndustry(values); - hide(); - message.success('导出成功'); - return true; - } catch (error) { - hide(); - message.error('导出失败,请重试'); - return false; - } -}; - -// 处理树形数据的函数(移到组件外部) -function processTreeData(data: any[]): IndustryItem[] { - 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) : [] - })); -} - -function ManagementList() { - const access = useAccess(); - const formTableRef = useRef(); - const actionRef = useRef(); - - const [currentRow, setCurrentRow] = useState(); // 使用新类型 - const [modalVisible, setModalVisible] = useState(false); - const [industryStatusEnum, setIndustryStatusEnum] = useState([]); - - useEffect(() => { - getDictValueEnum('sys_industry_status', true).then((data) => { - setIndustryStatusEnum(data); - }); - }, []); - - const columns: ProColumns[] = [ // 使用新类型 - { - title: '行业名称', - dataIndex: 'industryName', - valueType: 'text', - align: 'center', - }, - { - title: '显示顺序', - dataIndex: 'orderNum', - valueType: 'text', - hideInSearch: true, - align: 'center', - }, - { - title: '状态', - dataIndex: 'status', - align: 'center', - valueType: 'select', - valueEnum: industryStatusEnum, - render: (_, record) => { - return ; - }, - }, - { - title: '操作', - hideInSearch: true, - align: 'center', - dataIndex: 'id', // 改为id - width: 300, - render: (id, record) => [ - , - , - , - ], - }, - ]; - - return ( - -
- - actionRef={actionRef} - formRef={formTableRef} - rowKey="id" // 改为id - columns={columns} - search={false} - defaultExpandAllRows={true} - childrenColumnName="children" - pagination={false} - request={async () => { - try { - const res = await getCmsIndustryTreeList(); - return { - data: processTreeData(res.data || []), - success: true, - }; - } catch (error) { - console.error('获取数据失败:', error); - return { data: [], success: false }; - } - }} - toolBarRender={() => [ - , - , - ]} - /> -
- { - let resData; - if (values.id) { // 改为id - resData = await updateCmsIndustryIndustryt(values); - } else { - resData = await addCmsIndustryIndustryt(values); - } - if (resData.code === 200) { - setModalVisible(false); - setCurrentRow(undefined); - message.success(values.id ? '修改成功' : '新增成功'); - actionRef.current?.reload(); - } - }} - onCancel={() => { - setModalVisible(false); - setCurrentRow(undefined); - }} - industryStatusEnum={industryStatusEnum} - values={currentRow} - mode={ - currentRow?.id // 改为id - ? access.hasPerms('area:business:List.update') ? 'edit' : 'view' - : 'create' - } - /> -
- ); -} - -export default ManagementList; \ No newline at end of file +import React, { Fragment, useEffect, useRef, useState } from 'react'; +import { FormattedMessage, useAccess } from '@umijs/max'; +import { Button, FormInstance, message } from 'antd'; +import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components'; +import { AlignLeftOutlined, FormOutlined, PlusOutlined } from '@ant-design/icons'; +import EditCompanyListRow from './edit'; +import { + addCmsIndustryIndustryt, + delCmsIndustryList, + exportCmsIndustry, + getCmsIndustryTreeList, + updateCmsIndustryIndustryt, +} from '@/services/classify/industry'; +import { getDictValueEnum } from '@/services/system/dict'; +import DictTag from '@/components/DictTag'; + +// 定义行业数据类型(替代API.ClassifyIndustry.IndustryRow) +interface IndustryItem { + id: number; + industryName: string; + orderNum?: number; + status?: string; + children?: IndustryItem[]; +} + +const handleRemoveOne = async (id: string) => { + // 参数改为id + const hide = message.loading('正在删除'); + try { + const resp = await delCmsIndustryList(id); + hide(); + if (resp.code === 200) { + message.success('删除成功,即将刷新'); + } else { + message.error(resp.msg); + } + return true; + } catch (error) { + hide(); + message.error('删除失败,请重试'); + return false; + } +}; + +const handleExport = async (values: any) => { + // 简化类型定义 + const hide = message.loading('正在导出'); + try { + await exportCmsIndustry(values); + hide(); + message.success('导出成功'); + return true; + } catch (error) { + hide(); + message.error('导出失败,请重试'); + return false; + } +}; + +// 处理树形数据的函数(移到组件外部) +function processTreeData(data: any[]): IndustryItem[] { + 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) : undefined, + })); +} + +function ManagementList() { + const access = useAccess(); + const formTableRef = useRef(); + const actionRef = useRef(); + + const [currentRow, setCurrentRow] = useState(); // 使用新类型 + const [modalVisible, setModalVisible] = useState(false); + const [industryStatusEnum, setIndustryStatusEnum] = useState([]); + + useEffect(() => { + getDictValueEnum('sys_industry_status', true).then((data) => { + setIndustryStatusEnum(data); + }); + }, []); + + const columns: ProColumns[] = [ + // 使用新类型 + { + title: '行业名称', + dataIndex: 'industryName', + valueType: 'text', + align: 'center', + }, + { + title: '显示顺序', + dataIndex: 'orderNum', + valueType: 'text', + hideInSearch: true, + align: 'center', + }, + { + title: '状态', + dataIndex: 'status', + align: 'center', + valueType: 'select', + valueEnum: industryStatusEnum, + render: (_, record) => { + return ; + }, + }, + { + title: '操作', + hideInSearch: true, + align: 'center', + dataIndex: 'id', // 改为id + width: 300, + render: (id, record) => [ + , + , + // , + ], + }, + ]; + + return ( + +
+ + actionRef={actionRef} + formRef={formTableRef} + rowKey="id" // 改为id + columns={columns} + search={false} + defaultExpandAllRows={true} + childrenColumnName="children" + pagination={false} + request={async () => { + try { + const res = await getCmsIndustryTreeList(); + return { + data: processTreeData(res.data || []), + success: true, + }; + } catch (error) { + console.error('获取数据失败:', error); + return { data: [], success: false }; + } + }} + toolBarRender={() => [ + , + , + ]} + /> +
+ { + let resData; + if (values.id) { + // 改为id + resData = await updateCmsIndustryIndustryt(values); + } else { + resData = await addCmsIndustryIndustryt(values); + } + if (resData.code === 200) { + setModalVisible(false); + setCurrentRow(undefined); + message.success(values.id ? '修改成功' : '新增成功'); + actionRef.current?.reload(); + } + }} + onCancel={() => { + setModalVisible(false); + setCurrentRow(undefined); + }} + industryStatusEnum={industryStatusEnum} + values={currentRow} + mode={ + currentRow?.id // 改为id + ? access.hasPerms('area:business:List.update') + ? 'edit' + : 'view' + : 'create' + } + /> +
+ ); +} + +export default ManagementList; diff --git a/src/pages/Classify/Jobs/edit.tsx b/src/pages/Classify/Jobs/edit.tsx index 7095c16..ee8b64c 100644 --- a/src/pages/Classify/Jobs/edit.tsx +++ b/src/pages/Classify/Jobs/edit.tsx @@ -1,159 +1,159 @@ -import React,{ useEffect,useState } from 'react'; -import { - ModalForm, - ProForm, - ProFormDigit, - ProFormText, - ProFormTextArea, - ProFormTreeSelect, - ProFormSelect -} from '@ant-design/pro-components'; -import { Form } from 'antd'; -import { getCmsJobTitleList } from '@/services/classify/jobs'; -import { getDictValueEnum } from '@/services/system/dict'; - - - -// tree -type JobListParams = API.ClassifyJobs.Params; - -export type ListFormProps = { - onCancel: (flag?: boolean, formVals?: unknown) => void; - onSubmit: (values: any) => Promise; - open: boolean; - values?: Partial; - // jobGroupOptions: DictOptionType[]; - // statusOptions: DictValueEnumObj; -}; - -const listEdit: React.FC = (props) => { - const [form] = Form.useForm(); - const [treeData, setTreeData] = useState([]); - const [statusOptions, setStatusOptions] = useState>({}); - const [loading, setLoading] = useState(false); - - const buildTree = (data: API.ClassifyJobs.Job[], parentId: number = 0): API.ClassifyJobs.Job[] => { - return data - .filter(item => item.parentId === parentId) - .map(item => ({ - ...item, - children: buildTree(data, item.jobId), - })); - }; - - useEffect(() => { - const fetchData = async () => { - const res = await getCmsJobTitleList({ - tree: false, - // 明确传递所有必要参数 - pageSize: 1000, // 确保获取全部数据 - current: 1 - } as JobListParams); - setLoading(true); - try { - // 获取状态枚举 - const statusData = await getDictValueEnum('sys_jobs_status', true); - setStatusOptions(statusData); - // 获取岗位数据 - const res = await getCmsJobTitleList({ tree: false } as JobListParams); - console.log('原始数据:', res.rows); - - const treeData = buildTree(res.rows || []); - console.log('转换后的树形数据:', treeData); - setTreeData(treeData); - - // 设置表单初始值 - if (props.values) { - form.setFieldsValue({ - ...props.values, - parentId: props.values.parentId || undefined, - }); - } - } catch (error) { - console.error('数据加载失败:', error); - } finally { - setLoading(false); - } -}; -fetchData(); -}, []); - - const handleCancel = () => { - props.onCancel(); - form.resetFields(); - }; - - - const handleFinish = async (values: Record) => { - await props.onSubmit(values); - }; - - return ( - handleCancel(), - }} - submitTimeout={2000} - onFinish={handleFinish} - > - - ); -}; - -export default listEdit; - - - +import React,{ useEffect,useState } from 'react'; +import { + ModalForm, + ProForm, + ProFormDigit, + ProFormText, + ProFormTextArea, + ProFormTreeSelect, + ProFormSelect +} from '@ant-design/pro-components'; +import { Form } from 'antd'; +import { getCmsJobTitleList } from '@/services/classify/jobs'; +import { getDictValueEnum } from '@/services/system/dict'; + + + +// tree +type JobListParams = API.ClassifyJobs.Params; + +export type ListFormProps = { + onCancel: (flag?: boolean, formVals?: unknown) => void; + onSubmit: (values: any) => Promise; + open: boolean; + values?: Partial; + // jobGroupOptions: DictOptionType[]; + // statusOptions: DictValueEnumObj; +}; + +const listEdit: React.FC = (props) => { + const [form] = Form.useForm(); + const [treeData, setTreeData] = useState([]); + const [statusOptions, setStatusOptions] = useState>({}); + const [loading, setLoading] = useState(false); + + const buildTree = (data: API.ClassifyJobs.Jobs[], parentId: number = 0): API.ClassifyJobs.Jobs[] => { + return data + .filter(item => item.parentId === parentId) + .map(item => ({ + ...item, + children: buildTree(data, item.jobId), + })); + }; + + useEffect(() => { + const fetchData = async () => { + const res = await getCmsJobTitleList({ + tree: false, + // 明确传递所有必要参数 + pageSize: 1000, // 确保获取全部数据 + current: 1 + } as JobListParams); + setLoading(true); + try { + // 获取状态枚举 + const statusData = await getDictValueEnum('sys_jobs_status', true); + setStatusOptions(statusData); + // 获取岗位数据 + const res = await getCmsJobTitleList({ tree: false } as JobListParams); + console.log('原始数据:', res.rows); + + const treeData = buildTree(res.rows || []); + console.log('转换后的树形数据:', treeData); + setTreeData(treeData); + + // 设置表单初始值 + if (props.values) { + form.setFieldsValue({ + ...props.values, + parentId: props.values.parentId || undefined, + }); + } + } catch (error) { + console.error('数据加载失败:', error); + } finally { + setLoading(false); + } +}; +fetchData(); +}, []); + + const handleCancel = () => { + props.onCancel(); + form.resetFields(); + }; + + + const handleFinish = async (values: Record) => { + await props.onSubmit(values); + }; + + return ( + handleCancel(), + }} + submitTimeout={2000} + onFinish={handleFinish} + > + + ); +}; + +export default listEdit; + + + diff --git a/src/pages/Classify/Jobs/index.tsx b/src/pages/Classify/Jobs/index.tsx index 2bb56bc..eee5f72 100644 --- a/src/pages/Classify/Jobs/index.tsx +++ b/src/pages/Classify/Jobs/index.tsx @@ -1,275 +1,250 @@ -import React, { Fragment, useEffect, useRef, useState } from 'react'; -import { FormattedMessage, useAccess } from '@umijs/max'; -import { Button, FormInstance, message, Modal } from 'antd'; -import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components'; -import { DeleteOutlined, FormOutlined, 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 { - tree?: boolean; - pageSize?: number; - current?: number; - jobName?: string; - status?: string; - } - interface Jobs { - jobId: number; - parentId: number; - jobName: string; - orderNum?: number; - status?: string; - createTime?: string; - parentName?: string; - children?: Jobs[]; - depth?: number; // 添加这行 - } - } -} -// params类型 -type JobListParams = API.ClassifyJobs.Params & { - tree?:boolean; -}; - -const handleRemoveOne = async (jobId: string) => { - const hide = message.loading('正在删除'); - if (!jobId) return true; - try { - const resp = await delCmsCompanyList(jobId); - hide(); - if (resp.code === 200) { - message.success('删除成功,即将刷新'); - } else { - message.error(resp.msg); - } - return true; - } catch (error) { - hide(); - message.error('删除失败,请重试'); - return false; - } -}; - -const handleExport = async (values: API.ClassifyJobs.Params) => { - const hide = message.loading('正在导出'); - try { - await exportCmsJobTitleList(values); - hide(); - message.success('导出成功'); - return true; - } catch (error) { - hide(); - message.error('导出失败,请重试'); - return false; - } -}; -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), - })); -}; - -const ManagementList: React.FC = () => { - const access = useAccess(); - - const formTableRef = useRef(); - const actionRef = useRef(); - - const [currentRow, setCurrentRow] = useState(); - const [modalVisible, setModalVisible] = useState(false); - const [jobsStatusEnum, setJobsStatusEnum] = useState([]); - - useEffect(() => { - getDictValueEnum('sys_jobs_status', true).then(setJobsStatusEnum); - }, []); - - const editSubmit = () => {}; - - const columns: ProColumns[] = [ - { - title: '岗位名称', - dataIndex: 'jobName', - - align: 'center', - render: (text, record) => ( - - {text} - - ), - }, - {title: '父级岗位', - dataIndex: 'parentName', - valueType: 'text', - hideInSearch: true, - align: 'center', - }, - { - title: '显示顺序', - dataIndex: 'orderNum', - valueType: 'text', - hideInSearch: true, - align: 'center', - }, - { - title: '状态', - dataIndex: 'status', - align: 'center', - valueType: 'select', - valueEnum: jobsStatusEnum, - render: (_, record) => { - return ; - }, - }, - { - title: '操作', - hideInSearch: true, - align: 'center', - dataIndex: 'jobId', - width: 300, - render: (_, record) => [ - , - // , - ], - }, - ]; - return ( - -
- - // params 是需要自带的参数 - // 这个参数优先级更高,会覆盖查询表单的参数 - actionRef={actionRef} - formRef={formTableRef} - rowKey="jobId" - key="index" - columns={columns} - search={{ - labelWidth: 120, - }} - request={async (params) => { - const res = await getCmsJobTitleList({ ...params, tree: false , - pageSize:1000 - }); - const treeData = buildTree(res.rows); - console.log('完整树形结构:', JSON.stringify(treeData, null, 2)); - return { - data: treeData, - total: res.total, - success: true, - }; - }} - pagination={false} - expandable={{ - childrenColumnName: 'children', - defaultExpandAllRows: true, - indentSize:30, - rowExpandable: (record) => !!record.children?.length - }} - - toolBarRender={() => [ - , - , - ]} - /> -
- { - let resData; - if (values.jobId) { - resData = await putCmsCompanyList(values); - } else { - resData = await addCmsCompanyList(values); - } - if (resData.code === 200) { - setModalVisible(false); - setCurrentRow(undefined); - if (values.jobId) { - message.success('修改成功'); - } else { - message.success('新增成功'); - } - if (actionRef.current) { - actionRef.current.reload(); - } - } - }} - onCancel={() => { - setModalVisible(false); - setCurrentRow(undefined); - }} - values={currentRow} - > -
- ); -} - -export default ManagementList; +import React, { Fragment, useEffect, useRef, useState } from 'react'; +import { FormattedMessage, useAccess } from '@umijs/max'; +import { Button, FormInstance, message, Modal } from 'antd'; +import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components'; +import { DeleteOutlined, FormOutlined, 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'; + + +const handleRemoveOne = async (jobId: string) => { + const hide = message.loading('正在删除'); + if (!jobId) return true; + try { + const resp = await delCmsCompanyList(jobId); + hide(); + if (resp.code === 200) { + message.success('删除成功,即将刷新'); + } else { + message.error(resp.msg); + } + return true; + } catch (error) { + hide(); + message.error('删除失败,请重试'); + return false; + } +}; + +const handleExport = async (values: API.ClassifyJobs.Params) => { + const hide = message.loading('正在导出'); + try { + await exportCmsJobTitleList(values); + hide(); + message.success('导出成功'); + return true; + } catch (error) { + hide(); + message.error('导出失败,请重试'); + return false; + } +}; +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), + })); +}; + +const ManagementList: React.FC = () => { + const access = useAccess(); + + const formTableRef = useRef(); + const actionRef = useRef(); + + const [currentRow, setCurrentRow] = useState(); + const [modalVisible, setModalVisible] = useState(false); + const [jobsStatusEnum, setJobsStatusEnum] = useState([]); + + useEffect(() => { + getDictValueEnum('sys_jobs_status', true).then(setJobsStatusEnum); + }, []); + + const editSubmit = () => {}; + + const columns: ProColumns[] = [ + { + title: '岗位名称', + dataIndex: 'jobName', + + align: 'center', + render: (text, record) => ( + + {text} + + ), + }, + {title: '父级岗位', + dataIndex: 'parentName', + valueType: 'text', + hideInSearch: true, + align: 'center', + }, + { + title: '显示顺序', + dataIndex: 'orderNum', + valueType: 'text', + hideInSearch: true, + align: 'center', + }, + { + title: '状态', + dataIndex: 'status', + align: 'center', + valueType: 'select', + valueEnum: jobsStatusEnum, + render: (_, record) => { + return ; + }, + }, + { + title: '操作', + hideInSearch: true, + align: 'center', + dataIndex: 'jobId', + width: 300, + render: (_, record) => [ + , + // , + ], + }, + ]; + return ( + +
+ + // params 是需要自带的参数 + // 这个参数优先级更高,会覆盖查询表单的参数 + actionRef={actionRef} + formRef={formTableRef} + rowKey="jobId" + key="index" + columns={columns} + search={{ + labelWidth: 120, + }} + request={async (params) => { + const res = await getCmsJobTitleList({ ...params, tree: false , + pageSize:1000 + }); + const treeData = buildTree(res.rows); + console.log('完整树形结构:', JSON.stringify(treeData, null, 2)); + return { + data: treeData, + total: res.total, + success: true, + }; + }} + pagination={false} + expandable={{ + childrenColumnName: 'children', + defaultExpandAllRows: true, + indentSize:30, + rowExpandable: (record) => !!record.children?.length + }} + + toolBarRender={() => [ + , + , + ]} + /> +
+ { + let resData; + if (values.jobId) { + resData = await putCmsCompanyList(values); + } else { + resData = await addCmsCompanyList(values); + } + if (resData.code === 200) { + setModalVisible(false); + setCurrentRow(undefined); + if (values.jobId) { + message.success('修改成功'); + } else { + message.success('新增成功'); + } + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + onCancel={() => { + setModalVisible(false); + setCurrentRow(undefined); + }} + values={currentRow} + > +
+ ); +} + +export default ManagementList; diff --git a/src/pages/Management/List/edit.tsx b/src/pages/Management/List/edit.tsx index bbd447a..15e0870 100644 --- a/src/pages/Management/List/edit.tsx +++ b/src/pages/Management/List/edit.tsx @@ -1,207 +1,207 @@ -import { - ModalForm, - ProForm, - ProFormDigit, - ProFormSelect, - ProFormText, - ProFormTextArea, - ProDescriptions, -} from '@ant-design/pro-components'; -import { Form } from 'antd'; -import React, { useEffect } from 'react'; -import { DictValueEnumObj } from '@/components/DictTag'; -import { getCmsCompanyList } from '@/services/company/list'; - -export type ListFormProps = { - onCancel: (flag?: boolean, formVals?: unknown) => void; - onSubmit: (values: API.ManagementList.Manage) => Promise; - open: boolean; - values?: Partial; - educationEnum: DictValueEnumObj; - experienceEnum: DictValueEnumObj; - areaEnum: DictValueEnumObj; - mode?: 'view' | 'edit' | 'create'; -}; - -const waitTime = (time: number = 100) => { - return new Promise((resolve) => { - setTimeout(() => { - resolve(true); - }, time); - }); -}; - -const listEdit: React.FC = (props) => { - const [form] = Form.useForm<{ name: string; company: string; companyName: number }>(); - const { educationEnum, experienceEnum, areaEnum } = props; - const { mode = props.values ? 'edit' : 'create' } = props; - useEffect(() => { - form.resetFields(); - if (props.values) { - form.setFieldsValue({ - ...props.values, - jobLocationAreaCode: String(props.values.jobLocationAreaCode || ''), - }); - } - }, [form, props.values?.jobID]); - - const handleCancel = () => { - props.onCancel(); - form.resetFields(); - }; - - const handleFinish = async (values: Record) => { - props.onSubmit(values as API.ManagementList.Manage); - }; - - const handleChange = (_: string, value: any) => { - form.setFieldValue('companyName', value.label); - }; - if (mode === 'view') { - return ( - handleCancel(), - footer: null, - }} - submitter={false} - > - - column={2} - dataSource={props.values || {}} - > - - - - - - - - - - - - - ); - } - return ( - - title={mode === 'edit' ? '编辑岗位' : '新建岗位'} - form={form} - autoFocusFirstInput - open={props.open} - modalProps={{ - destroyOnClose: true, - onCancel: () => handleCancel(), - }} - submitTimeout={2000} - onFinish={handleFinish} - > - - - - - - - - - - - - - - - - - - - - - - ); -}; - -export default listEdit; +import { + ModalForm, + ProForm, + ProFormDigit, + ProFormSelect, + ProFormText, + ProFormTextArea, + ProDescriptions, +} from '@ant-design/pro-components'; +import { Form } from 'antd'; +import React, { useEffect } from 'react'; +import { DictValueEnumObj } from '@/components/DictTag'; +import { getCmsCompanyList } from '@/services/company/list'; + +export type ListFormProps = { + onCancel: (flag?: boolean, formVals?: unknown) => void; + onSubmit: (values: API.ManagementList.Manage) => Promise; + open: boolean; + values?: Partial; + educationEnum: DictValueEnumObj; + experienceEnum: DictValueEnumObj; + areaEnum: DictValueEnumObj; + mode?: 'view' | 'edit' | 'create'; +}; + +const waitTime = (time: number = 100) => { + return new Promise((resolve) => { + setTimeout(() => { + resolve(true); + }, time); + }); +}; + +const listEdit: React.FC = (props) => { + const [form] = Form.useForm(); + const { educationEnum, experienceEnum, areaEnum } = props; + const { mode = props.values ? 'edit' : 'create' } = props; + useEffect(() => { + if(props.open){ + form.resetFields(); + if (props.values) { + form.setFieldsValue({ + ...props.values, + jobLocationAreaCode: String(props.values.jobLocationAreaCode || ''), + }); + } + } + }, [form, props.values?.jobId,props.open]); + + const handleCancel = () => { + props.onCancel(); + form.resetFields(); + }; + + const handleFinish = async (values: Record) => { + props.onSubmit(values as API.ManagementList.Manage); + }; + + const handleChange = (_: string, value: any) => { + form.setFieldValue('companyName', value.label); + }; + if (mode === 'view') { + return ( + handleCancel(), + footer: null, + }} + submitter={false} + > + + column={2} + dataSource={props.values || {}} + > + + + + + + + + + + + + + ); + } + return ( + + + title={mode === 'edit' ? '编辑岗位' : '新建岗位'} + form={form} + autoFocusFirstInput + open={props.open} + modalProps={{ + destroyOnClose: true, + onCancel: () => handleCancel(), + }} + submitTimeout={2000} + onFinish={handleFinish} + > + + + + + + + + + + + + + + + + + + + + + + ); +}; + +export default listEdit; diff --git a/src/types/Management/list.d.ts b/src/types/Management/list.d.ts index 128a5c9..2f5dd52 100644 --- a/src/types/Management/list.d.ts +++ b/src/types/Management/list.d.ts @@ -1,72 +1,72 @@ -declare namespace API.ManagementList { - export interface Manage { - applyNum: number; - companyId: number; - companyName: string; - education: string; - experience: string; - isApply: number; - isCollection: number; - isHot: number; - jobId: number; - jobLocation: string; - jobLocationAreaCode: number; - jobTitle: string; - latitude: number; - longitude: number; - maxSalary: number; - minSalary: number; - postingDate: string; - vacancies: number; - view: number; - release: number; - isPublish: number; - } - - export interface AddParams { - applyNum?: number; - companyId?: number; - companyName?: string; - education?: string; - experience?: string; - isApply?: number; - isCollection?: number; - isHot?: number; - jobId?: number; - jobLocation?: string; - jobLocationAreaCode?: number; - jobTitle?: string; - latitude?: number; - longitude?: number; - maxSalary?: number; - minSalary?: number; - postingDate?: string; - vacancies?: number; - view?: number; - release?: number; - isPublish?: number; - } - - export interface ListParams { - createTime?: string; - updateTime?: string; - remark?: string; - pageSize?: number; - current?: number; - } - - export interface ManageIdResult { - code: number; - msg: string; - data: Manage; - rows: Array; - total: number; - } - - export interface ManagePageResult { - code: number; - msg: string; - total: number; - rows: Array; - } -} +declare namespace API.ManagementList { + export interface Manage { + applyNum?: number; + companyId?: number; + companyName?: string; + education?: string; + experience?: string; + isApply?: number; + isCollection?: number; + isHot?: number; + jobId?: number; + jobLocation?: string; + jobLocationAreaCode?: string; + jobTitle?: string; + latitude?: number; + longitude?: number; + maxSalary?: number; + minSalary?: number; + postingDate?: string; + vacancies?: number; + view?: number; + release?: number; + isPublish?: number; + } + + export interface AddParams { + applyNum?: number; + companyId?: number; + companyName?: string; + education?: string; + experience?: string; + isApply?: number; + isCollection?: number; + isHot?: number; + jobId?: number; + jobLocation?: string; + jobLocationAreaCode?: string; + jobTitle?: string; + latitude?: number; + longitude?: number; + maxSalary?: number; + minSalary?: number; + postingDate?: string; + vacancies?: number; + view?: number; + release?: number; + isPublish?: number; + } + + export interface ListParams { + createTime?: string; + updateTime?: string; + remark?: string; + pageSize?: number; + current?: number; + } + + export interface ManageIdResult { + code: number; + msg: string; + data: Manage; + rows: Array; + total: number; + } + + export interface ManagePageResult { + code: number; + msg: string; + total: number; + rows: Array; + } +} diff --git a/src/types/classify/jobs.d.ts b/src/types/classify/jobs.d.ts index 0a4edde..89b4c21 100644 --- a/src/types/classify/jobs.d.ts +++ b/src/types/classify/jobs.d.ts @@ -1,26 +1,33 @@ -declare namespace API.ClassifyJobs { - export interface Result { - total: number; - rows: Jobs[]; - code: number; - msg: string; - } - - export interface Jobs { - [x: string]: number; - createTime?: any; - jobId: number; - parentId: number; - jobName: string; - orderNum: number; - status: string; - } - - export interface Params { - jobId?: number; - parentId?: number; - jobName?: string; - orderNum?: number; - status?: string; - } -} +declare namespace API.ClassifyJobs { + export interface Result { + total: number; + rows: Jobs[]; + code: number; + msg: string; + } + + export interface Jobs { + createTime?: string; + jobId: number; + parentId: number; + jobName: string; + orderNum: number; + status: string; + children?:Jobs[]; + depth?: number; + parentName?: string; + } + export interface JobTreeNode extends Jobs { + children: JobTreeNode[]; + depth: number; + } + + export interface Params { + jobId?: number; + parentId?: number; + jobName?: string; + orderNum?: number; + status?: string; + tree?:boolean; + } +} diff --git a/src/typings.d.ts b/src/typings.d.ts index 092a1df..0aaad1e 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -1,44 +1,32 @@ -declare module 'slash2'; -declare module '*.css'; -declare module '*.less'; -declare module '*.scss'; -declare module '*.sass'; -declare module '*.svg'; -declare module '*.png'; -declare module '*.jpg'; -declare module '*.jpeg'; -declare module '*.gif'; -declare module '*.bmp'; -declare module '*.tiff'; -declare module 'omit.js'; -declare module 'numeral'; -declare module '@antv/data-set'; -declare module 'mockjs'; -declare module 'react-fittext'; -declare module 'bizcharts-plugin-slider'; - -declare const REACT_APP_ENV: 'test' | 'dev' | 'pre' | false; -declare namespace API { - namespace ClassifyJobs { - interface Params { - tree?: boolean; - pageSize?: number; - current?: number; - jobName?: string; - status?: string; - [key: string]: any; // 允许其他未定义属性 - } - - // 表格和表单使用的职业数据 - interface Job { - jobId: number; - parentId: number; - jobName: string; - orderNum?: number; - status?: string; - createTime?: string; - parentName?: string; - children?: Job[]; - } - } +declare module 'slash2'; +declare module '*.css'; +declare module '*.less'; +declare module '*.scss'; +declare module '*.sass'; +declare module '*.svg'; +declare module '*.png'; +declare module '*.jpg'; +declare module '*.jpeg'; +declare module '*.gif'; +declare module '*.bmp'; +declare module '*.tiff'; +declare module 'omit.js'; +declare module 'numeral'; +declare module '@antv/data-set'; +declare module 'mockjs'; +declare module 'react-fittext'; +declare module 'bizcharts-plugin-slider'; + +declare const REACT_APP_ENV: 'test' | 'dev' | 'pre' | false; +declare namespace API { + namespace ClassifyJobs { + interface Params { + tree?: boolean; + pageSize?: number; + current?: number; + jobName?: string; + status?: string; + [key: string]: any; // 允许其他未定义属性 + } + } } \ No newline at end of file