feat: 添加修改行业分类不展示的问题

This commit is contained in:
zdl
2025-10-24 13:30:52 +08:00
parent 801113b7e5
commit 3f881d000b
2 changed files with 160 additions and 41 deletions

View File

@@ -1,6 +1,6 @@
// src/views/Community/components/EventFilters.js
import React, { useState, useEffect } from 'react';
import { Card, Row, Col, DatePicker, Button, Select, Form, Input, Cascader } from 'antd';
import { Card, Row, Col, DatePicker, Button, Select, Form, Cascader } from 'antd';
import { FilterOutlined } from '@ant-design/icons';
import moment from 'moment';
import locale from 'antd/es/date-picker/locale/zh_CN';
@@ -12,7 +12,9 @@ const { Option } = Select;
const EventFilters = ({ filters, onFilterChange, loading }) => {
const [form] = Form.useForm();
const [industryOptions, setIndustryOptions] = useState([]);
// 使用全局行业数据
const { industryData, loading: industryLoading, loadIndustryData } = useIndustry();
// 初始化表单值
useEffect(() => {
@@ -25,25 +27,14 @@ const EventFilters = ({ filters, onFilterChange, loading }) => {
form.setFieldsValue(initialValues);
}, [filters, form]);
// 加载申银万国行业分类树形数据
const loadIndustryClassifications = async () => {
try {
const response = await industryService.getClassifications();
if (response.success && response.data) {
setIndustryOptions(response.data);
logger.debug('EventFilters', '申银万国行业分类加载成功', {
count: response.data?.length || 0
});
}
} catch (error) {
logger.error('EventFilters', 'loadIndustryClassifications', error);
// Cascader 获得焦点时确保数据已加载
const handleCascaderFocus = async () => {
if (!industryData || industryData.length === 0) {
logger.debug('EventFilters', 'Cascader 获得焦点,触发数据加载');
await loadIndustryData();
}
};
useEffect(() => {
loadIndustryClassifications();
}, []);
const handleDateRangeChange = (dates) => {
if (dates && dates.length === 2) {
const dateRange = `${dates[0].format('YYYY-MM-DD')}${dates[1].format('YYYY-MM-DD')}`;
@@ -92,14 +83,14 @@ const EventFilters = ({ filters, onFilterChange, loading }) => {
};
// 行业级联选择变化
const handleIndustryChange = (value, selectedOptions) => {
const handleIndustryChange = (value) => {
if (!value || value.length === 0) {
onFilterChange('industry_code', '');
return;
}
// 获取选中的节点
const selectedNode = findNodeByPath(industryOptions, value);
const selectedNode = findNodeByPath(industryData || [], value);
if (!selectedNode) {
// 如果找不到节点,使用最后一个值
@@ -163,17 +154,20 @@ const EventFilters = ({ filters, onFilterChange, loading }) => {
{/* 行业分类级联选择器 - 替换原来的 5 个独立 Select */}
<Row gutter={16}>
<Col span={24}>
<Form.Item label="申银万国行业分类" name="industry_cascade">
<Form.Item label="行业" name="industry_cascade">
<Cascader
options={industryOptions}
options={industryData || []}
onChange={handleIndustryChange}
placeholder="请选择行业(支持选择任意级别)"
onFocus={handleCascaderFocus}
placeholder={industryLoading ? "加载中..." : "请选择行业(支持选择任意级别)"}
changeOnSelect
expandTrigger="hover"
showSearch={{
filter: (inputValue, path) =>
path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1)
}}
disabled={loading}
disabled={loading || industryLoading}
loading={industryLoading}
allowClear
style={{ width: '100%' }}
displayRender={(labels) => labels.join(' / ')}