后端查看效果,不用拉取
This commit is contained in:
@@ -15,14 +15,14 @@ export default {
|
|||||||
// localhost:8000/api/** -> https://preview.pro.ant.design/api/**
|
// localhost:8000/api/** -> https://preview.pro.ant.design/api/**
|
||||||
'/api/': {
|
'/api/': {
|
||||||
// 要代理的地址
|
// 要代理的地址
|
||||||
target: 'http://39.98.44.136:8080',
|
target: 'https://qd.zhaopinzao8dian.com/api',
|
||||||
// 配置了这个可以从 http 代理到 https
|
// 配置了这个可以从 http 代理到 https
|
||||||
// 依赖 origin 的功能可能需要这个,比如 cookie
|
// 依赖 origin 的功能可能需要这个,比如 cookie
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
pathRewrite: { '^/api': '' },
|
pathRewrite: { '^/api': '' },
|
||||||
},
|
},
|
||||||
'/profile/avatar/': {
|
'/profile/avatar/': {
|
||||||
target: 'http://39.98.44.136:8080',
|
target: 'https://qd.zhaopinzao8dian.com/api',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
"@amap/amap-jsapi-loader": "^1.0.1",
|
"@amap/amap-jsapi-loader": "^1.0.1",
|
||||||
"@ant-design/charts": "^2.3.0",
|
"@ant-design/charts": "^2.3.0",
|
||||||
"@ant-design/icons": "^5.5.0",
|
"@ant-design/icons": "^5.5.0",
|
||||||
|
"@ant-design/maps": "^1.0.0",
|
||||||
"@ant-design/plots": "^2.3.2",
|
"@ant-design/plots": "^2.3.2",
|
||||||
"@ant-design/pro-components": "^2.8.7",
|
"@ant-design/pro-components": "^2.8.7",
|
||||||
"@ant-design/use-emotion-css": "1.0.4",
|
"@ant-design/use-emotion-css": "1.0.4",
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ export async function render(oldRender: () => void) {
|
|||||||
const checkRegion = 5 * 60 * 1000;
|
const checkRegion = 5 * 60 * 1000;
|
||||||
export const request = {
|
export const request = {
|
||||||
...errorConfig,
|
...errorConfig,
|
||||||
baseURL: process.env.NODE_ENV === 'development' ? '' : 'http://39.98.44.136:8080',
|
baseURL: process.env.NODE_ENV === 'development' ? '' : 'https://qd.zhaopinzao8dian.com/api',
|
||||||
// baseURL: 'http://39.98.44.136:8080',
|
// baseURL: 'http://39.98.44.136:8080',
|
||||||
requestInterceptors: [
|
requestInterceptors: [
|
||||||
(url: any, options: { headers: any }) => {
|
(url: any, options: { headers: any }) => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState, useMemo } from 'react';
|
import React, { useEffect, useState, useMemo, useRef } from 'react';
|
||||||
import { Card, Select, Button, Space, Spin, Empty, Row, Col, message, DatePicker } from 'antd';
|
import { Card, Select, Button, Space, Spin, Empty, Row, Col, message, DatePicker, Tabs } from 'antd';
|
||||||
import { Line } from '@ant-design/charts';
|
import { Line, Heatmap } from '@ant-design/charts';
|
||||||
import { getIndustryTrend } from '@/services/analysis/industry';
|
import { getIndustryTrend, getIndustryAreaTrend, getSalaryTrend } from '@/services/analysis/industry';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { useRequest } from '@umijs/max';
|
import { useRequest } from '@umijs/max';
|
||||||
import {
|
import {
|
||||||
@@ -9,16 +9,37 @@ import {
|
|||||||
AnalysisType,
|
AnalysisType,
|
||||||
IndustryTrendState,
|
IndustryTrendState,
|
||||||
IndustryDataItem,
|
IndustryDataItem,
|
||||||
ChartConfig
|
ChartConfig,
|
||||||
} from '@/types/analysis/industry';
|
} from '@/types/analysis/industry';
|
||||||
import {
|
import { formatQuarter, formatDateForDisplay, convertApiData, convertSalaryData } from './utils';
|
||||||
formatQuarter,
|
|
||||||
formatDateForDisplay,
|
|
||||||
convertApiData
|
|
||||||
} from './utils';
|
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
const { RangePicker } = DatePicker;
|
const { RangePicker } = DatePicker;
|
||||||
|
const { TabPane } = Tabs;
|
||||||
|
|
||||||
|
const flattenAreaData = (apiResponse: any) => {
|
||||||
|
if (!apiResponse || typeof apiResponse !== 'object') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const flattenedData = [];
|
||||||
|
|
||||||
|
for (const month in apiResponse) {
|
||||||
|
if (apiResponse.hasOwnProperty(month)) {
|
||||||
|
const areas = apiResponse[month];
|
||||||
|
|
||||||
|
areas.forEach((area) => {
|
||||||
|
flattenedData.push({
|
||||||
|
name: area.name,
|
||||||
|
time: area.time,
|
||||||
|
value: parseInt(area.data) || 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flattenedData;
|
||||||
|
};
|
||||||
|
|
||||||
const IndustryTrendPage: React.FC = () => {
|
const IndustryTrendPage: React.FC = () => {
|
||||||
const [params, setParams] = useState<IndustryTrendState>({
|
const [params, setParams] = useState<IndustryTrendState>({
|
||||||
@@ -26,13 +47,20 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
type: '岗位发布数量',
|
type: '岗位发布数量',
|
||||||
startTime: dayjs().subtract(5, 'month').format('YYYY-MM'),
|
startTime: dayjs().subtract(5, 'month').format('YYYY-MM'),
|
||||||
endTime: dayjs().format('YYYY-MM'),
|
endTime: dayjs().format('YYYY-MM'),
|
||||||
selectedIndustry: ''
|
selectedIndustry: '',
|
||||||
|
selectedSalaryRange: '',
|
||||||
|
analysisCategory: 'industry', // 默认显示行业分析
|
||||||
});
|
});
|
||||||
|
|
||||||
const [allData, setAllData] = useState<IndustryDataItem[]>([]);
|
const [allData, setAllData] = useState<IndustryDataItem[]>([]);
|
||||||
|
const [areaData, setAreaData] = useState<any[]>([]);
|
||||||
|
const [salaryData, setSalaryData] = useState<any[]>([]);
|
||||||
const [availableIndustries, setAvailableIndustries] = useState<string[]>([]);
|
const [availableIndustries, setAvailableIndustries] = useState<string[]>([]);
|
||||||
|
const [availableSalaryRanges, setAvailableSalaryRanges] = useState<string[]>([]);
|
||||||
|
const heatmapRef = useRef(null);
|
||||||
|
|
||||||
const { loading, run: fetchData } = useRequest(
|
// 获取行业趋势数据
|
||||||
|
const { loading: industryLoading, run: fetchIndustryData } = useRequest(
|
||||||
async () => {
|
async () => {
|
||||||
let { startTime, endTime, timeDimension, type } = params;
|
let { startTime, endTime, timeDimension, type } = params;
|
||||||
|
|
||||||
@@ -45,7 +73,7 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
timeDimension,
|
timeDimension,
|
||||||
type,
|
type,
|
||||||
startTime,
|
startTime,
|
||||||
endTime
|
endTime,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -54,82 +82,105 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
const formattedData = convertApiData(data);
|
const formattedData = convertApiData(data);
|
||||||
setAllData(formattedData);
|
setAllData(formattedData);
|
||||||
|
|
||||||
const industries = Array.from(
|
const industries = Array.from(new Set(formattedData.map((item: any) => item.category)))
|
||||||
new Set(formattedData.map((item: { category: any; }) => item.category))
|
.filter(Boolean)
|
||||||
).filter(Boolean).sort();
|
.sort();
|
||||||
|
|
||||||
setAvailableIndustries(industries);
|
setAvailableIndustries(industries);
|
||||||
|
|
||||||
if (industries.length > 0 && !industries.includes(params.selectedIndustry)) {
|
if (industries.length > 0 && !industries.includes(params.selectedIndustry)) {
|
||||||
setParams(p => ({ ...p, selectedIndustry: industries[0] }));
|
setParams((p) => ({ ...p, selectedIndustry: industries[0] }));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: () => message.error('数据加载失败')
|
onError: (error) => {
|
||||||
}
|
message.error('行业数据加载失败');
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleTimeDimensionChange = (value: TimeDimension) => {
|
// 获取地区趋势数据
|
||||||
const now = dayjs();
|
const { loading: areaLoading, run: fetchAreaData } = useRequest(
|
||||||
let newStartTime = '';
|
async () => {
|
||||||
|
let { startTime, endTime, timeDimension, type } = params;
|
||||||
|
|
||||||
if (value === '月') {
|
if (timeDimension === '季度') {
|
||||||
newStartTime = now.subtract(5, 'month').format('YYYY-MM');
|
startTime = formatQuarter(startTime);
|
||||||
} else if (value === '季度') {
|
endTime = formatQuarter(endTime);
|
||||||
newStartTime = now.subtract(6, 'quarter').format('YYYY-Q');
|
|
||||||
} else {
|
|
||||||
newStartTime = now.subtract(5, 'year').format('YYYY');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setParams(p => ({
|
return await getIndustryAreaTrend({
|
||||||
...p,
|
timeDimension,
|
||||||
timeDimension: value,
|
type,
|
||||||
startTime: newStartTime,
|
startTime,
|
||||||
endTime: value === '月' ? now.format('YYYY-MM') :
|
endTime,
|
||||||
value === '季度' ? now.format('YYYY-Q') :
|
});
|
||||||
now.format('YYYY'),
|
},
|
||||||
selectedIndustry: ''
|
{
|
||||||
}));
|
manual: true,
|
||||||
};
|
onSuccess: (res) => {
|
||||||
|
const formattedData = flattenAreaData(res);
|
||||||
|
setAreaData(formattedData);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
message.error('地区数据加载失败');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const handleDateRangeChange = (dates: any, dateStrings: [string, string]) => {
|
// 获取薪资趋势数据
|
||||||
if (dates && dates[0] && dates[1]) {
|
const { loading: salaryLoading, run: fetchSalaryData } = useRequest(
|
||||||
setParams(p => ({
|
async () => {
|
||||||
...p,
|
let { startTime, endTime, timeDimension, type } = params;
|
||||||
startTime: dateStrings[0],
|
|
||||||
endTime: dateStrings[1]
|
if (timeDimension === '季度') {
|
||||||
}));
|
startTime = formatQuarter(startTime);
|
||||||
|
endTime = formatQuarter(endTime);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const disabledDate = (current: dayjs.Dayjs) => {
|
return await getSalaryTrend({
|
||||||
const now = dayjs();
|
timeDimension,
|
||||||
|
type,
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
{
|
||||||
|
manual: true,
|
||||||
|
onSuccess: (data) => {
|
||||||
|
const formattedData = convertSalaryData(data);
|
||||||
|
setSalaryData(formattedData);
|
||||||
|
|
||||||
if (params.timeDimension === '月') {
|
const ranges = Array.from(new Set(formattedData.map((item: any) => item.category)))
|
||||||
return current.isAfter(now.endOf('month'));
|
.filter(Boolean)
|
||||||
} else if (params.timeDimension === '季度') {
|
.sort();
|
||||||
return current.isAfter(now.endOf('quarter'));
|
|
||||||
} else {
|
setAvailableSalaryRanges(ranges);
|
||||||
return current.isAfter(now.endOf('year'));
|
|
||||||
|
if (ranges.length > 0 && !ranges.includes(params.selectedSalaryRange)) {
|
||||||
|
setParams((p) => ({ ...p, selectedSalaryRange: ranges[0] }));
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
onError: (error) => {
|
||||||
const currentIndustryData = useMemo(() => {
|
message.error('薪资数据加载失败');
|
||||||
if (!params.selectedIndustry || allData.length === 0) return [];
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// 根据分析类别获取当前数据
|
||||||
|
const currentData = useMemo(() => {
|
||||||
|
if (params.analysisCategory === 'industry') {
|
||||||
return allData
|
return allData
|
||||||
.filter(item => item.category === params.selectedIndustry)
|
.filter((item) => item.category === params.selectedIndustry)
|
||||||
.map(item => ({
|
.map((item) => ({
|
||||||
...item,
|
...item,
|
||||||
originalDate: item.date,
|
originalDate: item.date,
|
||||||
date: formatDateForDisplay(item.date, params.timeDimension)
|
date: formatDateForDisplay(item.date, params.timeDimension),
|
||||||
}))
|
}))
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
if (params.timeDimension === '季度') {
|
if (params.timeDimension === '季度') {
|
||||||
// 处理中文季度格式,如 "2024-第一季度" -> ["2024", "第一"]
|
|
||||||
const [yearA, quarterA] = a.originalDate.split('-');
|
const [yearA, quarterA] = a.originalDate.split('-');
|
||||||
const [yearB, quarterB] = b.originalDate.split('-');
|
const [yearB, quarterB] = b.originalDate.split('-');
|
||||||
|
|
||||||
// 转换中文季度为数字("第一" -> 1, "第二" -> 2...)
|
|
||||||
const quarterToNumber = (q: string) => {
|
const quarterToNumber = (q: string) => {
|
||||||
if (q.includes('第一')) return 1;
|
if (q.includes('第一')) return 1;
|
||||||
if (q.includes('第二')) return 2;
|
if (q.includes('第二')) return 2;
|
||||||
@@ -147,34 +198,236 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
return dayjs(a.originalDate).valueOf() - dayjs(b.originalDate).valueOf();
|
return dayjs(a.originalDate).valueOf() - dayjs(b.originalDate).valueOf();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [allData, params.selectedIndustry, params.timeDimension]);
|
} else if (params.analysisCategory === 'salary') {
|
||||||
|
return salaryData
|
||||||
|
.filter((item) => item.category === params.selectedSalaryRange)
|
||||||
|
.map((item) => ({
|
||||||
|
...item,
|
||||||
|
originalDate: item.date,
|
||||||
|
date: formatDateForDisplay(item.date, params.timeDimension),
|
||||||
|
}))
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (params.timeDimension === '季度') {
|
||||||
|
const [yearA, quarterA] = a.originalDate.split('-');
|
||||||
|
const [yearB, quarterB] = b.originalDate.split('-');
|
||||||
|
|
||||||
|
const quarterToNumber = (q: string) => {
|
||||||
|
if (q.includes('第一')) return 1;
|
||||||
|
if (q.includes('第二')) return 2;
|
||||||
|
if (q.includes('第三')) return 3;
|
||||||
|
if (q.includes('第四')) return 4;
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
return yearA === yearB
|
||||||
|
? quarterToNumber(quarterA) - quarterToNumber(quarterB)
|
||||||
|
: parseInt(yearA) - parseInt(yearB);
|
||||||
|
} else if (params.timeDimension === '年') {
|
||||||
|
return parseInt(a.originalDate) - parseInt(b.originalDate);
|
||||||
|
} else {
|
||||||
|
return dayjs(a.originalDate).valueOf() - dayjs(b.originalDate).valueOf();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}, [allData, salaryData, params]);
|
||||||
|
|
||||||
|
// 热力图配置
|
||||||
|
const heatmapConfig = useMemo(() => {
|
||||||
|
const sortedData = [...areaData].sort((a, b) => {
|
||||||
|
if (params.timeDimension === '年') {
|
||||||
|
return parseInt(a.time) - parseInt(b.time);
|
||||||
|
} else if (params.timeDimension === '季度') {
|
||||||
|
const [yearA, quarterA] = a.time.split('-Q');
|
||||||
|
const [yearB, quarterB] = b.time.split('-Q');
|
||||||
|
return yearA === yearB
|
||||||
|
? parseInt(quarterA) - parseInt(quarterB)
|
||||||
|
: parseInt(yearA) - parseInt(yearB);
|
||||||
|
} else {
|
||||||
|
return dayjs(a.time).valueOf() - dayjs(b.time).valueOf();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 计算最大值和阈值
|
||||||
|
const maxValue = Math.max(...sortedData.map((item) => item.value), 1);
|
||||||
|
const hotThreshold = maxValue * 0.8; // 热门阈值(前20%)
|
||||||
|
const growthThreshold = maxValue * 0.5; // 增长阈值(前50%)
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: sortedData,
|
||||||
|
height: 300,
|
||||||
|
autoFit: false,
|
||||||
|
xField: 'name',
|
||||||
|
yField: 'time',
|
||||||
|
colorField: 'value',
|
||||||
|
mark: 'cell',
|
||||||
|
style: {
|
||||||
|
inset: 1,
|
||||||
|
fillOpacity: 0.9,
|
||||||
|
},
|
||||||
|
cellSize: [100, 40],
|
||||||
|
color: ['#5B8FF9', '#5AD8A6', '#5D7092', '#F6BD16', '#E8684A'],
|
||||||
|
label: {
|
||||||
|
text: (d: { value: number }) => {
|
||||||
|
if (d.value >= 10000) return (d.value / 10000).toFixed(0) + 'w';
|
||||||
|
if (d.value >= 1000) return (d.value / 1000).toFixed(0) + 'k';
|
||||||
|
return d.value;
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fill: '#fff',
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
textShadow: '0 0 3px rgba(0,0,0,0.7)',
|
||||||
|
},
|
||||||
|
position: 'inside',
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
title: {
|
||||||
|
text: '区域',
|
||||||
|
style: { fontSize: 12 },
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
autoRotate: true,
|
||||||
|
style: {
|
||||||
|
fontSize: 11,
|
||||||
|
fill: '#666',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
title: {
|
||||||
|
text: '时间',
|
||||||
|
style: { fontSize: 12 },
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
formatter: (text) => {
|
||||||
|
if (params.timeDimension === '年') return `${text}年`;
|
||||||
|
if (params.timeDimension === '季度') return text.replace('-Q', '年Q');
|
||||||
|
return text.replace('-', '年').replace('-', '月');
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fontSize: 11,
|
||||||
|
fill: '#666',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
sortable: false,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
title: (d) => `${d.name} - ${d.time}`,
|
||||||
|
field: 'value',
|
||||||
|
valueFormatter: (v) => {
|
||||||
|
if (v >= 10000) return (v / 10000).toFixed(1) + '万';
|
||||||
|
if (v >= 1000) return (v / 1000).toFixed(1) + '千';
|
||||||
|
return v;
|
||||||
|
},
|
||||||
|
pointerEvents: 'none',
|
||||||
|
domStyles: {
|
||||||
|
'g2-tooltip': {
|
||||||
|
padding: '8px 12px',
|
||||||
|
borderRadius: '4px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
interactions: [{ type: 'element-active' }],
|
||||||
|
legend: {
|
||||||
|
position: 'bottom',
|
||||||
|
layout: 'horizontal',
|
||||||
|
slidable: true,
|
||||||
|
title: false,
|
||||||
|
itemName: {
|
||||||
|
style: {
|
||||||
|
fill: '#666',
|
||||||
|
fontSize: 12,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [areaData, params.timeDimension]);
|
||||||
|
|
||||||
|
const handleTimeDimensionChange = (value: TimeDimension) => {
|
||||||
|
const now = dayjs();
|
||||||
|
let newStartTime = '';
|
||||||
|
|
||||||
|
if (value === '月') {
|
||||||
|
newStartTime = now.subtract(5, 'month').format('YYYY-MM');
|
||||||
|
} else if (value === '季度') {
|
||||||
|
newStartTime = now.subtract(6, 'quarter').format('YYYY-Q');
|
||||||
|
} else {
|
||||||
|
newStartTime = now.subtract(5, 'year').format('YYYY');
|
||||||
|
}
|
||||||
|
|
||||||
|
setParams((p) => ({
|
||||||
|
...p,
|
||||||
|
timeDimension: value,
|
||||||
|
startTime: newStartTime,
|
||||||
|
endTime:
|
||||||
|
value === '月'
|
||||||
|
? now.format('YYYY-MM')
|
||||||
|
: value === '季度'
|
||||||
|
? now.format('YYYY-Q')
|
||||||
|
: now.format('YYYY'),
|
||||||
|
selectedIndustry: params.analysisCategory === 'industry' ? '' : p.selectedIndustry,
|
||||||
|
selectedSalaryRange: params.analysisCategory === 'salary' ? '' : p.selectedSalaryRange,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDateRangeChange = (dates: any, dateStrings: [string, string]) => {
|
||||||
|
if (dates && dates[0] && dates[1]) {
|
||||||
|
setParams((p) => ({
|
||||||
|
...p,
|
||||||
|
startTime: dateStrings[0],
|
||||||
|
endTime: dateStrings[1],
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const disabledDate = (current: dayjs.Dayjs) => {
|
||||||
|
const now = dayjs();
|
||||||
|
|
||||||
|
if (params.timeDimension === '月') {
|
||||||
|
return current.isAfter(now.endOf('month'));
|
||||||
|
} else if (params.timeDimension === '季度') {
|
||||||
|
return current.isAfter(now.endOf('quarter'));
|
||||||
|
} else {
|
||||||
|
return current.isAfter(now.endOf('year'));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getPickerValue = () => {
|
const getPickerValue = () => {
|
||||||
try {
|
try {
|
||||||
return [
|
return [
|
||||||
dayjs(params.startTime, params.timeDimension === '年' ? 'YYYY' :
|
dayjs(
|
||||||
params.timeDimension === '季度' ? 'YYYY-Q' : 'YYYY-MM'),
|
params.startTime,
|
||||||
dayjs(params.endTime, params.timeDimension === '年' ? 'YYYY' :
|
params.timeDimension === '年'
|
||||||
params.timeDimension === '季度' ? 'YYYY-Q' : 'YYYY-MM')
|
? 'YYYY'
|
||||||
|
: params.timeDimension === '季度'
|
||||||
|
? 'YYYY-Q'
|
||||||
|
: 'YYYY-MM',
|
||||||
|
),
|
||||||
|
dayjs(
|
||||||
|
params.endTime,
|
||||||
|
params.timeDimension === '年'
|
||||||
|
? 'YYYY'
|
||||||
|
: params.timeDimension === '季度'
|
||||||
|
? 'YYYY-Q'
|
||||||
|
: 'YYYY-MM',
|
||||||
|
),
|
||||||
];
|
];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('日期解析错误:', e);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const chartConfig: ChartConfig = {
|
const chartConfig: ChartConfig = {
|
||||||
data: currentIndustryData,
|
data: currentData,
|
||||||
height: 180,
|
height: 180,
|
||||||
xField: 'date',
|
xField: 'date',
|
||||||
yField: 'value',
|
yField: 'value',
|
||||||
seriesField: 'category',
|
seriesField: 'category',
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'cat',
|
type: 'cat',
|
||||||
|
|
||||||
label: {
|
label: {
|
||||||
formatter: (text: string) => text,
|
formatter: (text: string) => text,
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
@@ -205,7 +458,10 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
{list.map((item, index) => {
|
{list.map((item, index) => {
|
||||||
const { name, value, color } = item;
|
const { name, value, color } = item;
|
||||||
return (
|
return (
|
||||||
<div key={index} style={{ margin: '4px 0', display: 'flex', justifyContent: 'space-between' }}>
|
<div
|
||||||
|
key={index}
|
||||||
|
style={{ margin: '4px 0', display: 'flex', justifyContent: 'space-between' }}
|
||||||
|
>
|
||||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
@@ -219,7 +475,10 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
></span>
|
></span>
|
||||||
<span>{name}</span>
|
<span>{name}</span>
|
||||||
</div>
|
</div>
|
||||||
<b>{value}{params.type === '招聘增长率' ? '%' : ''}</b>
|
<b>
|
||||||
|
{value}
|
||||||
|
{params.type === '招聘增长率' ? '%' : ''}
|
||||||
|
</b>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -233,31 +492,71 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
tooltip: {
|
tooltip: {
|
||||||
showTitle: undefined,
|
showTitle: undefined,
|
||||||
title: undefined,
|
title: undefined,
|
||||||
customContent: undefined
|
customContent: undefined,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchData();
|
if (params.analysisCategory === 'industry') {
|
||||||
}, [params.timeDimension, params.startTime, params.endTime, params.type]);
|
fetchIndustryData();
|
||||||
|
fetchAreaData();
|
||||||
|
} else if (params.analysisCategory === 'salary') {
|
||||||
|
fetchSalaryData();
|
||||||
|
fetchAreaData();
|
||||||
|
}
|
||||||
|
}, [params.timeDimension, params.startTime, params.endTime, params.type, params.analysisCategory]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ padding: 16 }}>
|
<div style={{ padding: 16 }}>
|
||||||
<Card title="行业趋势分析" style={{ marginBottom: 24 }}>
|
<Card title="趋势分析" style={{ marginBottom: 24 }}>
|
||||||
|
<Tabs
|
||||||
|
activeKey={params.analysisCategory}
|
||||||
|
onChange={(key) => setParams(p => ({
|
||||||
|
...p,
|
||||||
|
analysisCategory: key as 'industry' | 'salary' | 'area',
|
||||||
|
selectedIndustry: key === 'industry' && availableIndustries.length > 0 ? availableIndustries[0] : p.selectedIndustry,
|
||||||
|
selectedSalaryRange: key === 'salary' && availableSalaryRanges.length > 0 ? availableSalaryRanges[0] : p.selectedSalaryRange
|
||||||
|
}))}
|
||||||
|
>
|
||||||
|
<TabPane tab="行业趋势" key="industry" />
|
||||||
|
<TabPane tab="薪资趋势" key="salary" />
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
<div style={{ marginBottom: 24 }}>
|
<div style={{ marginBottom: 24 }}>
|
||||||
<Space size="middle" wrap>
|
<Space size="middle" wrap>
|
||||||
|
{params.analysisCategory === 'industry' && (
|
||||||
<Select
|
<Select
|
||||||
value={params.selectedIndustry}
|
value={params.selectedIndustry}
|
||||||
onChange={(value) => setParams(p => ({ ...p, selectedIndustry: value }))}
|
onChange={(value) => setParams((p) => ({ ...p, selectedIndustry: value }))}
|
||||||
style={{ width: 150 }}
|
style={{ width: 150 }}
|
||||||
loading={loading}
|
loading={industryLoading}
|
||||||
placeholder="选择行业"
|
placeholder="选择行业"
|
||||||
disabled={availableIndustries.length === 0}
|
disabled={availableIndustries.length === 0}
|
||||||
>
|
>
|
||||||
{availableIndustries.map(industry => (
|
{availableIndustries.map((industry) => (
|
||||||
<Option key={industry} value={industry}>{industry}</Option>
|
<Option key={industry} value={industry}>
|
||||||
|
{industry}
|
||||||
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{params.analysisCategory === 'salary' && (
|
||||||
|
<Select
|
||||||
|
value={params.selectedSalaryRange}
|
||||||
|
onChange={(value) => setParams((p) => ({ ...p, selectedSalaryRange: value }))}
|
||||||
|
style={{ width: 150 }}
|
||||||
|
loading={salaryLoading}
|
||||||
|
placeholder="选择薪资区间"
|
||||||
|
disabled={availableSalaryRanges.length === 0}
|
||||||
|
>
|
||||||
|
{availableSalaryRanges.map((range) => (
|
||||||
|
<Option key={range} value={range}>
|
||||||
|
{range}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
)}
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
value={params.timeDimension}
|
value={params.timeDimension}
|
||||||
@@ -270,19 +569,24 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
<RangePicker
|
<RangePicker
|
||||||
picker={params.timeDimension === '月' ? 'month' :
|
picker={
|
||||||
params.timeDimension === '季度' ? 'quarter' : 'year'}
|
params.timeDimension === '月'
|
||||||
|
? 'month'
|
||||||
|
: params.timeDimension === '季度'
|
||||||
|
? 'quarter'
|
||||||
|
: 'year'
|
||||||
|
}
|
||||||
value={getPickerValue()}
|
value={getPickerValue()}
|
||||||
onChange={handleDateRangeChange}
|
onChange={handleDateRangeChange}
|
||||||
style={{ width: 180 }}
|
style={{ width: 180 }}
|
||||||
disabled={loading}
|
disabled={industryLoading || areaLoading || salaryLoading}
|
||||||
allowClear={false}
|
allowClear={false}
|
||||||
disabledDate={disabledDate}
|
disabledDate={disabledDate}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
value={params.type}
|
value={params.type}
|
||||||
onChange={(value) => setParams(p => ({ ...p, type: value }))}
|
onChange={(value) => setParams((p) => ({ ...p, type: value }))}
|
||||||
style={{ width: 100 }}
|
style={{ width: 100 }}
|
||||||
>
|
>
|
||||||
<Option value="岗位发布数量">岗位数量</Option>
|
<Option value="岗位发布数量">岗位数量</Option>
|
||||||
@@ -291,89 +595,76 @@ const IndustryTrendPage: React.FC = () => {
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={() => fetchData()}
|
onClick={() => {
|
||||||
loading={loading}
|
if (params.analysisCategory === 'industry') {
|
||||||
|
fetchIndustryData();
|
||||||
|
fetchAreaData();
|
||||||
|
} else if (params.analysisCategory === 'salary') {
|
||||||
|
fetchSalaryData();
|
||||||
|
fetchAreaData();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
loading={industryLoading || areaLoading || salaryLoading}
|
||||||
>
|
>
|
||||||
查询
|
查询
|
||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Row gutter={[16, 16]}>
|
||||||
|
{params.analysisCategory !== 'area' && (
|
||||||
|
<Col span={24}>
|
||||||
<Card
|
<Card
|
||||||
title={`${params.selectedIndustry || '请选择行业'}趋势 (${params.type})`}
|
title={
|
||||||
|
params.analysisCategory === 'industry'
|
||||||
|
? `${params.selectedIndustry || '请选择行业'}趋势 (${params.type})`
|
||||||
|
: `${params.selectedSalaryRange || '请选择薪资区间'}趋势 (${params.type})`
|
||||||
|
}
|
||||||
style={{ marginBottom: 24 }}
|
style={{ marginBottom: 24 }}
|
||||||
bodyStyle={{ padding: '24px 12px' }}
|
bodyStyle={{ padding: '24px 12px', height: 210 }}
|
||||||
>
|
>
|
||||||
<Spin spinning={loading}>
|
<Spin spinning={params.analysisCategory === 'industry' ? industryLoading : salaryLoading}>
|
||||||
{currentIndustryData.length > 0 ? (
|
{currentData.length > 0 ? (
|
||||||
<Line {...chartConfig} />
|
<Line {...chartConfig} />
|
||||||
) : (
|
) : (
|
||||||
<Empty
|
<Empty
|
||||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||||
description={
|
description={
|
||||||
loading ? '数据加载中...' :
|
industryLoading || salaryLoading
|
||||||
params.selectedIndustry ? '当前时间段无数据' : '请先选择行业'
|
? '数据加载中...'
|
||||||
|
: params.analysisCategory === 'industry'
|
||||||
|
? params.selectedIndustry
|
||||||
|
? '当前时间段无数据'
|
||||||
|
: '请先选择行业'
|
||||||
|
: params.selectedSalaryRange
|
||||||
|
? '当前时间段无数据'
|
||||||
|
: '请先选择薪资区间'
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Spin>
|
</Spin>
|
||||||
</Card>
|
</Card>
|
||||||
|
</Col>
|
||||||
|
)}
|
||||||
|
|
||||||
<Row gutter={[16, 16]}>
|
<Col span={24}>
|
||||||
<Col xs={24} sm={12} md={8} lg={8} xl={6}>
|
|
||||||
<Card
|
<Card
|
||||||
title="区域分析"
|
title="区域分析"
|
||||||
bodyStyle={{
|
bodyStyle={{
|
||||||
padding: 12,
|
padding: 12,
|
||||||
height: 300,
|
height: 400,
|
||||||
display: 'flex',
|
position: 'relative',
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center'
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Empty description="热力地图预留位置" />
|
{areaLoading ? (
|
||||||
</Card>
|
<Spin tip="数据加载中..." size="large" />
|
||||||
</Col>
|
) : areaData.length > 0 ? (
|
||||||
<Col xs={24} sm={12} md={8} lg={8} xl={6}>
|
<div style={{ height: '100%', width: '100%' }}>
|
||||||
<Card
|
<Heatmap {...heatmapConfig} />
|
||||||
title="薪资趋势"
|
</div>
|
||||||
bodyStyle={{
|
) : (
|
||||||
padding: 12,
|
<Empty description="暂无区域数据" />
|
||||||
height: 300,
|
)}
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Empty description="薪资分析预留位置" />
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
<Col xs={24} sm={12} md={8} lg={8} xl={6}>
|
|
||||||
<Card
|
|
||||||
title="经验要求"
|
|
||||||
bodyStyle={{
|
|
||||||
padding: 12,
|
|
||||||
height: 300,
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Empty description="经验分析预留位置" />
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
<Col xs={24} sm={12} md={8} lg={8} xl={6}>
|
|
||||||
<Card
|
|
||||||
title="技能需求"
|
|
||||||
bodyStyle={{
|
|
||||||
padding: 12,
|
|
||||||
height: 300,
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Empty description="技能分析预留位置" />
|
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
import { TimeDimension, QuarterFormat, DateFormatter, QuarterFormatter, ApiDataConverter, IndustryDataItem, AreaDataItem } from '@/types/analysis/industry';
|
||||||
import { TimeDimension, QuarterFormat, DateFormatter, QuarterFormatter, ApiDataConverter, IndustryDataItem } from '@/types/analysis/industry';
|
|
||||||
|
|
||||||
export const formatQuarter: QuarterFormatter = (dateStr: string): QuarterFormat => {
|
export const formatQuarter: QuarterFormatter = (dateStr: string): QuarterFormat => {
|
||||||
if (dateStr.includes('第')) return dateStr as QuarterFormat;
|
if (dateStr.includes('第')) return dateStr as QuarterFormat;
|
||||||
@@ -78,3 +77,85 @@ export const convertApiData: ApiDataConverter = (apiData: any) => {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const convertAreaApiData = (apiData: any): AreaDataItem[] => {
|
||||||
|
if (!apiData?.data) {
|
||||||
|
console.warn('convertAreaApiData: apiData.data 为空');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result: AreaDataItem[] = [];
|
||||||
|
|
||||||
|
// 处理嵌套的月份数据
|
||||||
|
if (typeof apiData.data === 'object' && !Array.isArray(apiData.data)) {
|
||||||
|
Object.entries(apiData.data).forEach(([time, items]) => {
|
||||||
|
if (Array.isArray(items)) {
|
||||||
|
items.forEach((item: any) => {
|
||||||
|
if (!item) return;
|
||||||
|
const uniqueName = items.filter((i: any) => i.name === item.name).length > 1
|
||||||
|
? `${item.name}_${index}`
|
||||||
|
: item.name;
|
||||||
|
result.push({
|
||||||
|
name: item.name || '未知区域',
|
||||||
|
value: Number(item.data) || 0,
|
||||||
|
time: item.time || time,
|
||||||
|
x:uniqueName,
|
||||||
|
y:time,
|
||||||
|
category: item.name,
|
||||||
|
originalData: item
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (Array.isArray(apiData.data)) {
|
||||||
|
return apiData.data.map((item: any) => ({
|
||||||
|
name: item.name || '未知区域',
|
||||||
|
value: Number(item.data) || 0,
|
||||||
|
time: item.time || '未知时间',
|
||||||
|
x: item.name,
|
||||||
|
y: item.time,
|
||||||
|
category: item.name,
|
||||||
|
originalData: item
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
} catch (error) {
|
||||||
|
console.error('数据转换错误:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const convertSalaryData: ApiDataConverter = (apiData: any) => {
|
||||||
|
if (!apiData) return [];
|
||||||
|
try {
|
||||||
|
if (Array.isArray(apiData)) {
|
||||||
|
return apiData.map(item => ({
|
||||||
|
date: item.time || item.date,
|
||||||
|
category: item.name || item.category || '未知薪资区间',
|
||||||
|
value: Number(item.data || item.value) || 0
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if (typeof apiData === 'object') {
|
||||||
|
const result: IndustryDataItem[] = [];
|
||||||
|
Object.entries(apiData).forEach(([date, items]) => {
|
||||||
|
if (Array.isArray(items)) {
|
||||||
|
items.forEach((item: any) => {
|
||||||
|
result.push({
|
||||||
|
date,
|
||||||
|
category: item.name || item.category || '未知薪资区间',
|
||||||
|
value: Number(item.data || item.value) || 0
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
} catch (error) {
|
||||||
|
console.error('薪资数据转换错误:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -6,3 +6,27 @@ export async function getIndustryTrend(params?: API.Analysis.IndustryParams) {
|
|||||||
params
|
params
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
export async function getIndustryAreaTrend(params: any) {
|
||||||
|
try {
|
||||||
|
const response = await request('/api/cms/statics/industryArea', {
|
||||||
|
method: 'GET',
|
||||||
|
params,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('接口原始响应:', response); // 调试日志
|
||||||
|
return response; // 兼容不同后端响应格式
|
||||||
|
} catch (error) {
|
||||||
|
console.error('接口请求异常:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getSalaryTrend(params?: API.Analysis.IndustryParams) {
|
||||||
|
return request<API.Analysis.IndustryResult>('/api/cms/statics/salary', {
|
||||||
|
method: 'GET',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
19
src/types/analysis/industry.d.ts
vendored
19
src/types/analysis/industry.d.ts
vendored
@@ -4,18 +4,25 @@ import { ReactNode } from 'react';
|
|||||||
export type TimeDimension = '月' | '季度' | '年';
|
export type TimeDimension = '月' | '季度' | '年';
|
||||||
export type AnalysisType = '岗位发布数量' | '招聘增长率';
|
export type AnalysisType = '岗位发布数量' | '招聘增长率';
|
||||||
export type QuarterFormat = `${number}-${'Q1'|'Q2'|'Q3'|'Q4'|'第一季度'|'第二季度'|'第三季度'|'第四季度'}`;
|
export type QuarterFormat = `${number}-${'Q1'|'Q2'|'Q3'|'Q4'|'第一季度'|'第二季度'|'第三季度'|'第四季度'}`;
|
||||||
|
export type AnalysisCategory = 'industry' | 'area' | 'salary';
|
||||||
|
export type SalaryRange = '3k-5k' | '5k-8k' | '8k-10k' | '10k+';
|
||||||
|
|
||||||
export interface IndustryDataItem {
|
export interface IndustryDataItem {
|
||||||
date: string;
|
date: string;
|
||||||
category: string;
|
category: string;
|
||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
export interface AreaDataItem {
|
||||||
|
name: string;
|
||||||
|
value: number;
|
||||||
|
time: string;
|
||||||
|
}
|
||||||
export interface IndustryTrendParams {
|
export interface IndustryTrendParams {
|
||||||
timeDimension: TimeDimension;
|
timeDimension: TimeDimension;
|
||||||
type: AnalysisType;
|
type: AnalysisType;
|
||||||
startTime: string;
|
startTime: string;
|
||||||
endTime: string;
|
endTime: string;
|
||||||
|
selectedIndustry: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IndustryTrendState extends IndustryTrendParams {
|
export interface IndustryTrendState extends IndustryTrendParams {
|
||||||
@@ -80,7 +87,15 @@ export interface ChartConfig {
|
|||||||
}>;
|
}>;
|
||||||
legend?: boolean;
|
legend?: boolean;
|
||||||
}
|
}
|
||||||
|
export interface IndustryTrendState {
|
||||||
|
timeDimension: TimeDimension;
|
||||||
|
type: AnalysisType;
|
||||||
|
startTime: string;
|
||||||
|
endTime: string;
|
||||||
|
selectedIndustry: string;
|
||||||
|
selectedSalaryRange: string;
|
||||||
|
analysisCategory: AnalysisCategory; // 新增分析类别
|
||||||
|
}
|
||||||
export type DateFormatter = (dateStr: string, dimension: TimeDimension) => string;
|
export type DateFormatter = (dateStr: string, dimension: TimeDimension) => string;
|
||||||
export type QuarterFormatter = (dateStr: string) => QuarterFormat;
|
export type QuarterFormatter = (dateStr: string) => QuarterFormat;
|
||||||
export type ApiDataConverter = (apiData: any) => IndustryDataItem[];
|
export type ApiDataConverter = (apiData: any) => IndustryDataItem[];
|
||||||
Reference in New Issue
Block a user