<script lang="ts" setup>
|
import type { EchartsUIType } from '@vben/plugins/echarts';
|
|
import type { HrmStatisticsApi } from '#/api/hrm/statistics';
|
|
import { computed, onMounted, ref } from 'vue';
|
|
import { ContentWrap, Page } from '@vben/common-ui';
|
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
|
import { Spin, Table } from 'ant-design-vue';
|
|
import { getTenureStatistics } from '#/api/hrm/statistics';
|
|
import {
|
getAgeDistributionOption,
|
getContractWarningChartOption,
|
getDeptDistributionOption,
|
getDeptTenureOption,
|
getEducationDistributionOption,
|
getGenderDistributionOption,
|
getHireResignTrendOption,
|
getMarriageDistributionOption,
|
getPoliticalDistributionOption,
|
getPostDistributionOption,
|
getStatusDistributionOption,
|
getTenureDistributionOption,
|
} from './chartOptions';
|
|
defineOptions({ name: 'HrmHumanStatistics' });
|
|
const loading = ref(true);
|
const statistics = ref<HrmStatisticsApi.EmployeeStatistics>();
|
|
const statusChartRef = ref<EchartsUIType>();
|
const trendChartRef = ref<EchartsUIType>();
|
const tenureChartRef = ref<EchartsUIType>();
|
const ageChartRef = ref<EchartsUIType>();
|
const deptDistChartRef = ref<EchartsUIType>();
|
const deptTenureChartRef = ref<EchartsUIType>();
|
const postChartRef = ref<EchartsUIType>();
|
const educationChartRef = ref<EchartsUIType>();
|
const genderChartRef = ref<EchartsUIType>();
|
const marriageChartRef = ref<EchartsUIType>();
|
const politicalChartRef = ref<EchartsUIType>();
|
const contractChartRef = ref<EchartsUIType>();
|
|
const { renderEcharts: renderStatusChart } = useEcharts(statusChartRef);
|
const { renderEcharts: renderTrendChart } = useEcharts(trendChartRef);
|
const { renderEcharts: renderTenureChart } = useEcharts(tenureChartRef);
|
const { renderEcharts: renderAgeChart } = useEcharts(ageChartRef);
|
const { renderEcharts: renderDeptDistChart } = useEcharts(deptDistChartRef);
|
const { renderEcharts: renderDeptTenureChart } = useEcharts(deptTenureChartRef);
|
const { renderEcharts: renderPostChart } = useEcharts(postChartRef);
|
const { renderEcharts: renderEducationChart } = useEcharts(educationChartRef);
|
const { renderEcharts: renderGenderChart } = useEcharts(genderChartRef);
|
const { renderEcharts: renderMarriageChart } = useEcharts(marriageChartRef);
|
const { renderEcharts: renderPoliticalChart } = useEcharts(politicalChartRef);
|
const { renderEcharts: renderContractChart } = useEcharts(contractChartRef);
|
|
/** 顶部指标卡 */
|
const summaryCards = computed(() => {
|
const data = statistics.value;
|
if (!data) {
|
return [];
|
}
|
return [
|
{
|
label: '在岗人数',
|
value: data.totalCount ?? 0,
|
unit: '人',
|
desc: `在职 ${data.activeCount ?? 0} · 试用 ${data.probationCount ?? 0}`,
|
},
|
{
|
label: '平均工龄',
|
value: data.averageTenureYears ?? 0,
|
unit: '年',
|
desc: '仅统计在岗员工',
|
},
|
{
|
label: '平均年龄',
|
value: data.averageAge ?? 0,
|
unit: '岁',
|
desc: '仅统计在岗员工',
|
},
|
{
|
label: '本年入职',
|
value: data.thisYearHireCount ?? 0,
|
unit: '人',
|
desc: '按入职日期统计',
|
},
|
{
|
label: '本年离职',
|
value: data.thisYearResignCount ?? 0,
|
unit: '人',
|
desc: '按离职日期统计',
|
},
|
{
|
label: '离职员工',
|
value: data.resignedCount ?? 0,
|
unit: '人',
|
desc: '员工档案累计',
|
},
|
];
|
});
|
|
/** 工龄排行表格列 */
|
const topTenureColumns = [
|
{ title: '排名', dataIndex: 'rank', width: 80 },
|
{ title: '姓名', dataIndex: 'name' },
|
{ title: '部门', dataIndex: 'deptName' },
|
{ title: '入职日期', dataIndex: 'hireDate', width: 140 },
|
{ title: '工龄(年)', dataIndex: 'tenureYears', width: 120 },
|
];
|
|
/** 工龄排行数据,补充排名列 */
|
const topTenureData = computed(() =>
|
(statistics.value?.topTenureEmployees ?? []).map((item, index) => ({
|
...item,
|
rank: index + 1,
|
})),
|
);
|
|
async function loadStatistics() {
|
loading.value = true;
|
try {
|
const data = await getTenureStatistics();
|
statistics.value = data;
|
await Promise.all([
|
renderStatusChart(getStatusDistributionOption(data.statusDistribution ?? [])),
|
renderTrendChart(getHireResignTrendOption(data.hireResignTrend ?? [])),
|
renderTenureChart(
|
getTenureDistributionOption(data.tenureDistribution ?? []),
|
),
|
renderAgeChart(getAgeDistributionOption(data.ageDistribution ?? [])),
|
renderDeptDistChart(
|
getDeptDistributionOption(data.deptDistribution ?? []),
|
),
|
renderDeptTenureChart(getDeptTenureOption(data.deptTenureList ?? [])),
|
renderPostChart(getPostDistributionOption(data.postDistribution ?? [])),
|
renderEducationChart(
|
getEducationDistributionOption(data.educationDistribution ?? []),
|
),
|
renderGenderChart(
|
getGenderDistributionOption(data.genderDistribution ?? []),
|
),
|
renderMarriageChart(
|
getMarriageDistributionOption(data.marriageDistribution ?? []),
|
),
|
renderPoliticalChart(
|
getPoliticalDistributionOption(data.politicalDistribution ?? []),
|
),
|
renderContractChart(
|
getContractWarningChartOption(data.contractWarning ?? []),
|
),
|
]);
|
} finally {
|
loading.value = false;
|
}
|
}
|
|
onMounted(() => {
|
loadStatistics();
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<Spin :spinning="loading" tip="加载中...">
|
<div class="flex flex-col gap-4">
|
<!-- 指标卡 -->
|
<div class="grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6">
|
<div
|
v-for="card in summaryCards"
|
:key="card.label"
|
class="rounded-lg border border-border bg-background p-4"
|
>
|
<div class="text-sm text-muted-foreground">{{ card.label }}</div>
|
<div class="mt-1 flex items-baseline gap-1">
|
<span class="text-2xl font-semibold">{{ card.value }}</span>
|
<span class="text-sm text-muted-foreground">{{ card.unit }}</span>
|
</div>
|
<div class="mt-1 text-xs text-muted-foreground">{{ card.desc }}</div>
|
</div>
|
</div>
|
|
<!-- 人员概况:状态构成 + 近 12 个月入离职趋势 -->
|
<ContentWrap>
|
<div class="grid grid-cols-1 gap-4 xl:grid-cols-3">
|
<EchartsUI ref="statusChartRef" height="320px" />
|
<div class="xl:col-span-2">
|
<EchartsUI ref="trendChartRef" height="320px" />
|
</div>
|
</div>
|
</ContentWrap>
|
|
<!-- 人员结构:工龄 / 年龄 / 部门人数 -->
|
<ContentWrap>
|
<div class="grid grid-cols-1 gap-4 xl:grid-cols-3">
|
<EchartsUI ref="tenureChartRef" height="320px" />
|
<EchartsUI ref="ageChartRef" height="320px" />
|
<EchartsUI ref="deptDistChartRef" height="320px" />
|
</div>
|
</ContentWrap>
|
|
<!-- 部门平均工龄 + 岗位分布 -->
|
<ContentWrap>
|
<div class="grid grid-cols-1 gap-4 xl:grid-cols-2">
|
<EchartsUI ref="deptTenureChartRef" height="340px" />
|
<EchartsUI ref="postChartRef" height="340px" />
|
</div>
|
</ContentWrap>
|
|
<!-- 人员画像:学历 / 性别 / 婚姻 / 政治面貌 -->
|
<ContentWrap>
|
<div class="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
|
<EchartsUI ref="educationChartRef" height="320px" />
|
<EchartsUI ref="genderChartRef" height="320px" />
|
<EchartsUI ref="marriageChartRef" height="320px" />
|
<EchartsUI ref="politicalChartRef" height="320px" />
|
</div>
|
</ContentWrap>
|
|
<!-- 合同风险 -->
|
<ContentWrap>
|
<div class="grid grid-cols-1 gap-4 xl:grid-cols-3">
|
<div class="xl:col-span-2">
|
<EchartsUI ref="contractChartRef" height="320px" />
|
</div>
|
<div class="flex flex-col justify-center gap-3">
|
<div class="rounded-lg border border-border bg-background p-4">
|
<div class="text-sm text-muted-foreground">在岗未签有效合同</div>
|
<div class="mt-1 flex items-baseline gap-1">
|
<span class="text-2xl font-semibold">
|
{{ statistics?.noContractCount ?? 0 }}
|
</span>
|
<span class="text-sm text-muted-foreground">人</span>
|
</div>
|
<div class="mt-1 text-xs text-muted-foreground">
|
在岗员工中没有当前生效合同的员工数
|
</div>
|
</div>
|
<div class="text-xs text-muted-foreground">
|
口径:仅统计在岗员工的当前生效合同,已解除/已终止合同不计入;无固定期限合同不计入到期天数。
|
</div>
|
</div>
|
</div>
|
</ContentWrap>
|
|
<!-- 工龄排行 -->
|
<ContentWrap title="工龄排行 TOP 10">
|
<Table
|
:columns="topTenureColumns"
|
:data-source="topTenureData"
|
:pagination="false"
|
row-key="id"
|
size="small"
|
/>
|
</ContentWrap>
|
</div>
|
</Spin>
|
</Page>
|
</template>
|