2025-05-26 11:28:13 +08:00
|
|
|
import React, { useEffect, useState, useMemo } from 'react';
|
2025-05-26 12:19:08 +08:00
|
|
|
import { Card, Select, Button, Space, Spin, Empty, Row, Col, message, DatePicker } from 'antd';
|
2025-05-26 11:28:13 +08:00
|
|
|
import { Line } from '@ant-design/charts';
|
|
|
|
|
import { getIndustryTrend } from '@/services/analysis/industry';
|
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
import { useRequest } from '@umijs/max';
|
2025-05-26 13:35:01 +08:00
|
|
|
import {
|
|
|
|
|
TimeDimension,
|
|
|
|
|
AnalysisType,
|
|
|
|
|
IndustryTrendState,
|
|
|
|
|
IndustryDataItem,
|
|
|
|
|
ChartConfig
|
|
|
|
|
} from '@/types/analysis/industry';
|
|
|
|
|
import {
|
|
|
|
|
formatQuarter,
|
|
|
|
|
formatDateForDisplay,
|
|
|
|
|
convertApiData
|
|
|
|
|
} from './utils';
|
2025-05-26 11:28:13 +08:00
|
|
|
|
|
|
|
|
const { Option } = Select;
|
2025-05-26 12:19:08 +08:00
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
|
2025-05-26 11:28:13 +08:00
|
|
|
const IndustryTrendPage: React.FC = () => {
|
2025-05-26 13:35:01 +08:00
|
|
|
const [params, setParams] = useState<IndustryTrendState>({
|
|
|
|
|
timeDimension: '月',
|
|
|
|
|
type: '岗位发布数量',
|
2025-05-26 12:19:08 +08:00
|
|
|
startTime: dayjs().subtract(5, 'month').format('YYYY-MM'),
|
2025-05-26 11:28:13 +08:00
|
|
|
endTime: dayjs().format('YYYY-MM'),
|
2025-05-26 12:19:08 +08:00
|
|
|
selectedIndustry: ''
|
2025-05-26 11:28:13 +08:00
|
|
|
});
|
2025-05-26 12:19:08 +08:00
|
|
|
|
2025-05-26 11:28:13 +08:00
|
|
|
const [allData, setAllData] = useState<IndustryDataItem[]>([]);
|
2025-05-26 12:19:08 +08:00
|
|
|
const [availableIndustries, setAvailableIndustries] = useState<string[]>([]);
|
2025-05-26 13:35:01 +08:00
|
|
|
|
2025-05-26 12:19:08 +08:00
|
|
|
const { loading, run: fetchData } = useRequest(
|
|
|
|
|
async () => {
|
2025-05-26 13:35:01 +08:00
|
|
|
let { startTime, endTime, timeDimension, type } = params;
|
|
|
|
|
|
|
|
|
|
if (timeDimension === '季度') {
|
|
|
|
|
startTime = formatQuarter(startTime);
|
|
|
|
|
endTime = formatQuarter(endTime);
|
2025-05-26 12:19:08 +08:00
|
|
|
}
|
2025-05-26 13:35:01 +08:00
|
|
|
|
|
|
|
|
return await getIndustryTrend({
|
|
|
|
|
timeDimension,
|
|
|
|
|
type,
|
|
|
|
|
startTime,
|
|
|
|
|
endTime
|
|
|
|
|
});
|
2025-05-26 12:19:08 +08:00
|
|
|
},
|
2025-05-26 11:28:13 +08:00
|
|
|
{
|
|
|
|
|
manual: true,
|
2025-05-26 12:19:08 +08:00
|
|
|
onSuccess: (data) => {
|
|
|
|
|
const formattedData = convertApiData(data);
|
2025-05-26 11:28:13 +08:00
|
|
|
setAllData(formattedData);
|
2025-05-26 13:35:01 +08:00
|
|
|
|
2025-05-26 12:19:08 +08:00
|
|
|
const industries = Array.from(
|
2025-05-26 13:35:01 +08:00
|
|
|
new Set(formattedData.map((item: { category: any; }) => item.category))
|
2025-05-26 12:19:08 +08:00
|
|
|
).filter(Boolean).sort();
|
|
|
|
|
|
|
|
|
|
setAvailableIndustries(industries);
|
2025-05-26 13:35:01 +08:00
|
|
|
|
2025-05-26 12:19:08 +08:00
|
|
|
if (industries.length > 0 && !industries.includes(params.selectedIndustry)) {
|
|
|
|
|
setParams(p => ({ ...p, selectedIndustry: industries[0] }));
|
|
|
|
|
}
|
2025-05-26 13:35:01 +08:00
|
|
|
},
|
|
|
|
|
onError: () => message.error('数据加载失败')
|
2025-05-26 11:28:13 +08:00
|
|
|
}
|
|
|
|
|
);
|
2025-05-26 12:19:08 +08:00
|
|
|
|
2025-05-26 13:35:01 +08:00
|
|
|
const handleTimeDimensionChange = (value: TimeDimension) => {
|
2025-05-26 12:19:08 +08:00
|
|
|
const now = dayjs();
|
|
|
|
|
let newStartTime = '';
|
2025-05-26 13:35:01 +08:00
|
|
|
|
|
|
|
|
if (value === '月') {
|
|
|
|
|
newStartTime = now.subtract(6, 'month').format('YYYY-MM');
|
|
|
|
|
} else if (value === '季度') {
|
|
|
|
|
newStartTime = now.subtract(6, 'quarter').format('YYYY-Q');
|
|
|
|
|
} else {
|
|
|
|
|
newStartTime = now.subtract(5, 'year').format('YYYY');
|
2025-05-26 11:28:13 +08:00
|
|
|
}
|
2025-05-26 13:35:01 +08:00
|
|
|
|
2025-05-26 12:19:08 +08:00
|
|
|
setParams(p => ({
|
|
|
|
|
...p,
|
|
|
|
|
timeDimension: value,
|
|
|
|
|
startTime: newStartTime,
|
|
|
|
|
endTime: value === '月' ? now.format('YYYY-MM') :
|
|
|
|
|
value === '季度' ? now.format('YYYY-Q') :
|
|
|
|
|
now.format('YYYY'),
|
|
|
|
|
selectedIndustry: ''
|
|
|
|
|
}));
|
2025-05-26 11:28:13 +08:00
|
|
|
};
|
2025-05-26 13:35:01 +08:00
|
|
|
|
2025-05-26 12:19:08 +08:00
|
|
|
const handleDateRangeChange = (dates: any, dateStrings: [string, string]) => {
|
|
|
|
|
if (dates && dates[0] && dates[1]) {
|
|
|
|
|
setParams(p => ({
|
|
|
|
|
...p,
|
|
|
|
|
startTime: dateStrings[0],
|
|
|
|
|
endTime: dateStrings[1]
|
|
|
|
|
}));
|
|
|
|
|
}
|
2025-05-26 11:28:13 +08:00
|
|
|
};
|
2025-05-26 13:35:01 +08:00
|
|
|
|
2025-05-26 11:28:13 +08:00
|
|
|
const currentIndustryData = useMemo(() => {
|
2025-05-26 12:19:08 +08:00
|
|
|
if (!params.selectedIndustry || allData.length === 0) return [];
|
|
|
|
|
|
|
|
|
|
return allData
|
2025-05-26 11:28:13 +08:00
|
|
|
.filter(item => item.category === params.selectedIndustry)
|
|
|
|
|
.map(item => ({
|
2025-05-26 12:19:08 +08:00
|
|
|
...item,
|
2025-05-26 13:35:01 +08:00
|
|
|
date: formatDateForDisplay(item.date, params.timeDimension)
|
2025-05-26 11:28:13 +08:00
|
|
|
}))
|
2025-05-26 13:35:01 +08:00
|
|
|
.sort((a, b) => {
|
|
|
|
|
const dateA = a.date.includes('第')
|
|
|
|
|
? parseInt(a.date.split('第')[1])
|
|
|
|
|
: dayjs(a.date).valueOf();
|
|
|
|
|
const dateB = b.date.includes('第')
|
|
|
|
|
? parseInt(b.date.split('第')[1])
|
|
|
|
|
: dayjs(b.date).valueOf();
|
|
|
|
|
return dateA - dateB;
|
|
|
|
|
});
|
2025-05-26 12:19:08 +08:00
|
|
|
}, [allData, params.selectedIndustry, params.timeDimension]);
|
2025-05-26 13:35:01 +08:00
|
|
|
|
2025-05-26 12:19:08 +08:00
|
|
|
const getPickerValue = () => {
|
|
|
|
|
try {
|
|
|
|
|
return [
|
|
|
|
|
dayjs(params.startTime, params.timeDimension === '年' ? 'YYYY' :
|
|
|
|
|
params.timeDimension === '季度' ? 'YYYY-Q' : 'YYYY-MM'),
|
|
|
|
|
dayjs(params.endTime, params.timeDimension === '年' ? 'YYYY' :
|
|
|
|
|
params.timeDimension === '季度' ? 'YYYY-Q' : 'YYYY-MM')
|
|
|
|
|
];
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('日期解析错误:', e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-26 13:35:01 +08:00
|
|
|
const chartConfig: ChartConfig = {
|
2025-05-26 11:28:13 +08:00
|
|
|
data: currentIndustryData,
|
|
|
|
|
height: 180,
|
|
|
|
|
xField: 'date',
|
|
|
|
|
yField: 'value',
|
|
|
|
|
seriesField: 'category',
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'cat',
|
|
|
|
|
label: {
|
2025-05-26 13:35:01 +08:00
|
|
|
formatter: (text: string) => text,
|
2025-05-26 11:28:13 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
label: {
|
|
|
|
|
formatter: (val: string) => `${val}${params.type === '招聘增长率' ? '%' : '个'}`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
tooltip: false,
|
|
|
|
|
point: {
|
|
|
|
|
size: 4,
|
|
|
|
|
shape: 'circle',
|
|
|
|
|
},
|
|
|
|
|
animation: {
|
|
|
|
|
appear: {
|
|
|
|
|
animation: 'path-in',
|
|
|
|
|
duration: 1000,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-05-26 12:19:08 +08:00
|
|
|
smooth: true,
|
2025-05-26 11:28:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-05-26 12:19:08 +08:00
|
|
|
fetchData();
|
|
|
|
|
}, [params.timeDimension, params.startTime, params.endTime, params.type]);
|
2025-05-26 11:28:13 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div style={{ padding: 16 }}>
|
2025-05-26 12:19:08 +08:00
|
|
|
<Card title="行业趋势分析" style={{ marginBottom: 24 }}>
|
|
|
|
|
<div style={{ marginBottom: 24 }}>
|
2025-05-26 11:28:13 +08:00
|
|
|
<Space size="middle" wrap>
|
|
|
|
|
<Select
|
|
|
|
|
value={params.selectedIndustry}
|
2025-05-26 12:19:08 +08:00
|
|
|
onChange={(value) => setParams(p => ({ ...p, selectedIndustry: value }))}
|
|
|
|
|
style={{ width: 150 }}
|
2025-05-26 11:28:13 +08:00
|
|
|
loading={loading}
|
|
|
|
|
placeholder="选择行业"
|
2025-05-26 12:19:08 +08:00
|
|
|
disabled={availableIndustries.length === 0}
|
2025-05-26 11:28:13 +08:00
|
|
|
>
|
2025-05-26 12:19:08 +08:00
|
|
|
{availableIndustries.map(industry => (
|
2025-05-26 11:28:13 +08:00
|
|
|
<Option key={industry} value={industry}>{industry}</Option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
|
|
|
|
|
<Select
|
|
|
|
|
value={params.timeDimension}
|
2025-05-26 12:19:08 +08:00
|
|
|
onChange={handleTimeDimensionChange}
|
2025-05-26 11:28:13 +08:00
|
|
|
style={{ width: 100 }}
|
|
|
|
|
>
|
|
|
|
|
<Option value="月">按月</Option>
|
|
|
|
|
<Option value="季度">按季度</Option>
|
|
|
|
|
<Option value="年">按年</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
|
2025-05-26 12:19:08 +08:00
|
|
|
<RangePicker
|
|
|
|
|
picker={params.timeDimension === '月' ? 'month' :
|
|
|
|
|
params.timeDimension === '季度' ? 'quarter' : 'year'}
|
|
|
|
|
value={getPickerValue()}
|
|
|
|
|
onChange={handleDateRangeChange}
|
|
|
|
|
style={{ width: 180 }}
|
|
|
|
|
disabled={loading}
|
|
|
|
|
allowClear={false}
|
|
|
|
|
/>
|
|
|
|
|
|
2025-05-26 11:28:13 +08:00
|
|
|
<Select
|
|
|
|
|
value={params.type}
|
2025-05-26 12:19:08 +08:00
|
|
|
onChange={(value) => setParams(p => ({ ...p, type: value }))}
|
|
|
|
|
style={{ width: 100 }}
|
2025-05-26 11:28:13 +08:00
|
|
|
>
|
|
|
|
|
<Option value="岗位发布数量">岗位数量</Option>
|
|
|
|
|
<Option value="招聘增长率">增长率</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
2025-05-26 12:19:08 +08:00
|
|
|
onClick={() => fetchData()}
|
2025-05-26 11:28:13 +08:00
|
|
|
loading={loading}
|
|
|
|
|
>
|
|
|
|
|
查询
|
|
|
|
|
</Button>
|
|
|
|
|
</Space>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Card
|
2025-05-26 12:19:08 +08:00
|
|
|
title={`${params.selectedIndustry || '请选择行业'}趋势 (${params.type})`}
|
2025-05-26 11:28:13 +08:00
|
|
|
style={{ marginBottom: 24 }}
|
2025-05-26 13:35:01 +08:00
|
|
|
bodyStyle={{ padding: '24px 12px' }}
|
2025-05-26 11:28:13 +08:00
|
|
|
>
|
|
|
|
|
<Spin spinning={loading}>
|
|
|
|
|
{currentIndustryData.length > 0 ? (
|
|
|
|
|
<Line {...chartConfig} />
|
|
|
|
|
) : (
|
2025-05-26 12:19:08 +08:00
|
|
|
<Empty
|
|
|
|
|
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
|
|
|
description={
|
|
|
|
|
loading ? '数据加载中...' :
|
|
|
|
|
params.selectedIndustry ? '当前时间段无数据' : '请先选择行业'
|
|
|
|
|
}
|
|
|
|
|
/>
|
2025-05-26 11:28:13 +08:00
|
|
|
)}
|
|
|
|
|
</Spin>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Row gutter={[16, 16]}>
|
2025-05-26 13:35:01 +08:00
|
|
|
<Col xs={24} sm={12} md={8} lg={8} xl={6}>
|
|
|
|
|
<Card
|
|
|
|
|
title="区域分析"
|
|
|
|
|
bodyStyle={{
|
|
|
|
|
padding: 12,
|
|
|
|
|
height: 300,
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center'
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-05-26 11:28:13 +08:00
|
|
|
<Empty description="热力地图预留位置" />
|
|
|
|
|
</Card>
|
|
|
|
|
</Col>
|
2025-05-26 13:35:01 +08:00
|
|
|
<Col xs={24} sm={12} md={8} lg={8} xl={6}>
|
|
|
|
|
<Card
|
|
|
|
|
title="薪资趋势"
|
|
|
|
|
bodyStyle={{
|
|
|
|
|
padding: 12,
|
|
|
|
|
height: 300,
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center'
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-05-26 11:28:13 +08:00
|
|
|
<Empty description="薪资分析预留位置" />
|
|
|
|
|
</Card>
|
|
|
|
|
</Col>
|
2025-05-26 13:35:01 +08:00
|
|
|
<Col xs={24} sm={12} md={8} lg={8} xl={6}>
|
|
|
|
|
<Card
|
|
|
|
|
title="经验要求"
|
|
|
|
|
bodyStyle={{
|
|
|
|
|
padding: 12,
|
|
|
|
|
height: 300,
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center'
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-05-26 11:28:13 +08:00
|
|
|
<Empty description="经验分析预留位置" />
|
|
|
|
|
</Card>
|
|
|
|
|
</Col>
|
2025-05-26 13:35:01 +08:00
|
|
|
<Col xs={24} sm={12} md={8} lg={8} xl={6}>
|
|
|
|
|
<Card
|
|
|
|
|
title="技能需求"
|
|
|
|
|
bodyStyle={{
|
|
|
|
|
padding: 12,
|
|
|
|
|
height: 300,
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center'
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-05-26 11:28:13 +08:00
|
|
|
<Empty description="技能分析预留位置" />
|
|
|
|
|
</Card>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-26 13:35:01 +08:00
|
|
|
|
|
|
|
|
|
2025-05-26 11:28:13 +08:00
|
|
|
export default IndustryTrendPage;
|