From 994ec60616f6ac3725e0e26e2e681fb770ed5632 Mon Sep 17 00:00:00 2001 From: yy <3078169442@qq.com> Date: Wed, 2 Apr 2025 19:07:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E8=81=8C=E4=BD=8D=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=92=8C=E8=A1=8C=E4=B8=9A=E7=AE=A1=E7=90=86=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E8=BD=AC=E4=B8=BA=E6=A0=91=E5=BD=A2=E8=A1=A8=E6=A0=BC=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .hintrc | 8 ++ src/global.less | 10 +- src/pages/Classify/Industry/edit.tsx | 176 ++++++++++++------------ src/pages/Classify/Industry/index.tsx | 156 ++++++++++++---------- src/pages/Classify/Jobs/edit.tsx | 127 ++++++++++++++---- src/pages/Classify/Jobs/index.tsx | 185 +++++++++++++++++--------- src/pages/Company/List/edit.tsx | 5 +- src/services/classify/industry.ts | 4 +- src/types/classify/jobs.d.ts | 1 + src/typings.d.ts | 24 ++++ 10 files changed, 442 insertions(+), 254 deletions(-) diff --git a/.hintrc b/.hintrc index aa8de6b..1a5323d 100644 --- a/.hintrc +++ b/.hintrc @@ -1,5 +1,13 @@ { "extends": [ "development" + ], + "hints": { + "no-inline-styles": "off" + }, + "browserslist": [ + "defaults", + "not ie 11", + "not ie <= 11" ] } \ No newline at end of file diff --git a/src/global.less b/src/global.less index 6d5ad58..de3e0f1 100644 --- a/src/global.less +++ b/src/global.less @@ -20,7 +20,15 @@ body, .ant-pro-sider.ant-layout-sider.ant-pro-sider-fixed { left: unset; } - +.ant-table-row { + &-level-1 .ant-table-cell:first-child { + padding-left: 24px !important; + } + &-level-2 .ant-table-cell:first-child { + padding-left: 48px !important; + } + // 可根据需要添加更多层级 +} canvas { display: block; } diff --git a/src/pages/Classify/Industry/edit.tsx b/src/pages/Classify/Industry/edit.tsx index fc57f4d..e9e39b5 100644 --- a/src/pages/Classify/Industry/edit.tsx +++ b/src/pages/Classify/Industry/edit.tsx @@ -4,50 +4,56 @@ import { ProForm, ProFormDigit, ProFormRadio, - ProFormSelect, + ProFormTreeSelect, ProFormText, ProDescriptions, } from '@ant-design/pro-components'; import { Form } from 'antd'; import { DictValueEnumObj } from '@/components/DictTag'; import { FormattedMessage } from '@@/exports'; -import { getCmsIndustryTree } from '@/services/classify/industry'; -import { values } from 'lodash'; +import { getCmsIndustryTreeList } from '@/services/classify/industry'; // 修改导入为 getCmsIndustryTreeList -interface IndustryDetail extends API.ClassifyIndustry.IndustryRow { - parentName: string; +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: API.ClassifyIndustry.IndustryRow) => Promise; + onSubmit: (values: any) => Promise; open: boolean; - values?: Partial; - // industryStatusEnum: DictOptionType[]; + 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; + const { industryStatusEnum, mode = props.values ? 'edit' : 'create', values } = props; + useEffect(() => { form.resetFields(); if (values) { - form.setFieldsValue(values); + form.setFieldsValue({ + ...values, + parentId: values?.parentId ?? 0 + }); } - }, [form,values?.industryId]); + }, [form, values?.id]); - const getSafeDetailData = ( - data?: Partial - ): IndustryDetail => { - return{ - industryId: data?.industryId ?? 0, - industryName: data?.industryName ?? '', - orderNum: data?.orderNum ?? 0, - parentId: data?.parentId ?? 0, - parentName: (data as any)?.parentName ?? '无', // 或通过 parentId 映射 - status: data?.status ?? '0',} + 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 = () => { @@ -56,34 +62,51 @@ const listEdit: React.FC = (props) => { }; const handleFinish = async (values: Record) => { - props.onSubmit(values as API.ClassifyIndustry.IndustryRow); + const submitValues = { + ...values, + parentId: values.parentId === 0 ? undefined : values.parentId + }; + props.onSubmit(submitValues); }; -// check -if (mode === 'view') { - return ( - handleCancel(), - footer: null, - }} - submitter={false} + + // 获取行业树数据 + 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 ( - ); }; -export default listEdit; +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 195ba1c..bbdd68d 100644 --- a/src/pages/Classify/Industry/index.tsx +++ b/src/pages/Classify/Industry/index.tsx @@ -8,17 +8,25 @@ import { addCmsIndustryIndustryt, delCmsIndustryList, exportCmsIndustry, - getCmsIndustryList, + getCmsIndustryTreeList, updateCmsIndustryIndustryt, } from '@/services/classify/industry'; import { getDictValueEnum } from '@/services/system/dict'; import DictTag from '@/components/DictTag'; -const handleRemoveOne = async (industryId: string) => { +// 定义行业数据类型(替代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('正在删除'); - if (!industryId) return true; try { - const resp = await delCmsIndustryList(industryId); + const resp = await delCmsIndustryList(id); hide(); if (resp.code === 200) { message.success('删除成功,即将刷新'); @@ -33,7 +41,7 @@ const handleRemoveOne = async (industryId: string) => { } }; -const handleExport = async (values: API.ClassifyIndustry.Params) => { +const handleExport = async (values: any) => { // 简化类型定义 const hide = message.loading('正在导出'); try { await exportCmsIndustry(values); @@ -47,12 +55,24 @@ const handleExport = async (values: API.ClassifyIndustry.Params) => { } }; +// 处理树形数据的函数(移到组件外部) +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 [currentRow, setCurrentRow] = useState(); // 使用新类型 const [modalVisible, setModalVisible] = useState(false); const [industryStatusEnum, setIndustryStatusEnum] = useState([]); @@ -62,9 +82,7 @@ function ManagementList() { }); }, []); - const editSubmit = () => {}; - - const columns: ProColumns[] = [ + const columns: ProColumns[] = [ // 使用新类型 { title: '行业名称', dataIndex: 'industryName', @@ -92,9 +110,9 @@ function ManagementList() { title: '操作', hideInSearch: true, align: 'center', - dataIndex: 'industryId', + dataIndex: 'id', // 改为id width: 300, - render: (industryId, record) => [ + render: (id, record) => [ , + }} + > + 详情 + , , + render: (_, record) => [ , + // , ], }, ]; @@ -144,28 +190,41 @@ function ManagementList() { rowKey="jobId" key="index" columns={columns} - request={(params) => - getCmsJobTitleList({ ...params } as API.ClassifyJobs.Params).then((res) => { - const result = { - data: res.rows, - total: res.total, - success: true, - }; - return result; - }) - } + 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={() => [ - // , + ,