添加查看详情功能
This commit is contained in:
@@ -6,11 +6,17 @@ import {
|
||||
ProFormRadio,
|
||||
ProFormSelect,
|
||||
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';
|
||||
|
||||
interface IndustryDetail extends API.ClassifyIndustry.IndustryRow {
|
||||
parentName: string;
|
||||
}
|
||||
|
||||
export type ListFormProps = {
|
||||
onCancel: (flag?: boolean, formVars?: unknown) => void;
|
||||
@@ -19,17 +25,30 @@ export type ListFormProps = {
|
||||
values?: Partial<API.ClassifyIndustry.IndustryRow>;
|
||||
// industryStatusEnum: DictOptionType[];
|
||||
industryStatusEnum: DictValueEnumObj;
|
||||
mode?: 'view' | 'edit' | 'create';
|
||||
};
|
||||
|
||||
const listEdit: React.FC<ListFormProps> = (props) => {
|
||||
const [form] = Form.useForm();
|
||||
const { industryStatusEnum } = props;
|
||||
const { industryStatusEnum, mode = props.values ? 'edit' : 'create',values } = props;
|
||||
useEffect(() => {
|
||||
form.resetFields();
|
||||
if (props.values) {
|
||||
form.setFieldsValue(props.values);
|
||||
if (values) {
|
||||
form.setFieldsValue(values);
|
||||
}
|
||||
}, [form, props]);
|
||||
}, [form,values?.industryId]);
|
||||
|
||||
const getSafeDetailData = (
|
||||
data?: Partial<API.ClassifyIndustry.IndustryRow>
|
||||
): 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 handleCancel = () => {
|
||||
props.onCancel();
|
||||
@@ -39,13 +58,45 @@ const listEdit: React.FC<ListFormProps> = (props) => {
|
||||
const handleFinish = async (values: Record<string, any>) => {
|
||||
props.onSubmit(values as API.ClassifyIndustry.IndustryRow);
|
||||
};
|
||||
|
||||
// check
|
||||
if (mode === 'view') {
|
||||
return (
|
||||
<ModalForm<{
|
||||
name: string;
|
||||
company: string;
|
||||
}>
|
||||
title={`${props.values ? '编辑' : '新增'}行业`}
|
||||
<ModalForm
|
||||
title="行业详情"
|
||||
open={props.open}
|
||||
width={800}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
onCancel: () => handleCancel(),
|
||||
footer: null,
|
||||
}}
|
||||
submitter={false}
|
||||
>
|
||||
<ProDescriptions<IndustryDetail>
|
||||
column={1}
|
||||
dataSource={getSafeDetailData(values)}
|
||||
loading={!values}
|
||||
>
|
||||
<ProDescriptions.Item label="行业ID" dataIndex="industryId" />
|
||||
<ProDescriptions.Item label="行业名称" dataIndex="industryName" />
|
||||
<ProDescriptions.Item label="显示顺序" dataIndex="orderNum" />
|
||||
<ProDescriptions.Item
|
||||
label="父行业"
|
||||
dataIndex="parentName"
|
||||
valueType="text"// 假设API返回中有parentName字段
|
||||
/>
|
||||
<ProDescriptions.Item
|
||||
label="行业状态"
|
||||
dataIndex="status"
|
||||
valueEnum={industryStatusEnum}
|
||||
/>
|
||||
</ProDescriptions>
|
||||
</ModalForm>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<ModalForm
|
||||
title={`${values ? '编辑' : '新增'}行业`}
|
||||
form={form}
|
||||
autoFocusFirstInput
|
||||
open={props.open}
|
||||
|
||||
Reference in New Issue
Block a user