From 3580385967bed56d78e14a9b03e3d90e5885eca1 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Sun, 26 Oct 2025 14:22:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=A1=8C=E4=B8=9A?= =?UTF-8?q?=E5=88=86=E7=B1=BBCascader=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 IndustryCascader 组件,支持多级行业分类选择 - 集成 IndustryContext 全局行业数据管理 - 支持懒加载和搜索功能 - 提供清晰的行业选择路径展示 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Community/components/IndustryCascader.js | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/views/Community/components/IndustryCascader.js diff --git a/src/views/Community/components/IndustryCascader.js b/src/views/Community/components/IndustryCascader.js new file mode 100644 index 00000000..abd742ec --- /dev/null +++ b/src/views/Community/components/IndustryCascader.js @@ -0,0 +1,75 @@ +// src/views/Community/components/IndustryCascader.js +import React, { useState } from 'react'; +import { Card, Form, Cascader } from 'antd'; +import { useIndustry } from '../../../contexts/IndustryContext'; +import { logger } from '../../../utils/logger'; + +const IndustryCascader = ({ onFilterChange, loading }) => { + const [industryCascaderValue, setIndustryCascaderValue] = useState([]); + + // 使用全局行业数据 + const { industryData, loadIndustryData, loading: industryLoading } = useIndustry(); + + // Cascader 获得焦点时加载数据 + const handleCascaderFocus = async () => { + if (!industryData || industryData.length === 0) { + logger.debug('IndustryCascader', 'Cascader 获得焦点,开始加载行业数据'); + await loadIndustryData(); + } + }; + + // Cascader 选择变化 + const handleIndustryCascaderChange = (value, selectedOptions) => { + setIndustryCascaderValue(value); + + if (value && value.length > 0) { + // value[0] = 分类体系名称 + // value[1...n] = 行业代码(一级~四级) + const industryCode = value[value.length - 1]; // 最后一级的 code + const classification = value[0]; // 分类体系名称 + + onFilterChange('industry_classification', classification); + onFilterChange('industry_code', industryCode); + + logger.debug('IndustryCascader', 'Cascader 选择变化', { + value, + classification, + industryCode, + path: selectedOptions.map(o => o.label).join(' > ') + }); + } else { + // 清空 + onFilterChange('industry_classification', ''); + onFilterChange('industry_code', ''); + } + }; + + return ( + +
+ + labels.join(' > ')} + showSearch={{ + filter: (inputValue, path) => + path.some(option => option.label.toLowerCase().includes(inputValue.toLowerCase())) + }} + style={{ width: '100%' }} + /> + +
+
+ ); +}; + +export default IndustryCascader;