<template>
|
<div class="personal-attendance-report">
|
<div class="report-header">
|
<h4>考勤统计报表</h4>
|
<div class="header-actions">
|
<el-select v-model="reportPeriod" @change="handlePeriodChange" size="small">
|
<el-option label="本月" value="month" />
|
<el-option label="本季度" value="quarter" />
|
<el-option label="本年度" value="year" />
|
</el-select>
|
<el-button
|
size="small"
|
@click="exportReport"
|
icon="el-icon-download"
|
>
|
导出报表
|
</el-button>
|
</div>
|
</div>
|
|
<!-- 统计概览 -->
|
<el-row :gutter="20" class="stats-overview">
|
<el-col :span="6">
|
<el-card shadow="hover" class="stat-card">
|
<div class="stat-content">
|
<div class="stat-icon attendance-icon">
|
<i class="el-icon-date"></i>
|
</div>
|
<div class="stat-info">
|
<div class="stat-value">{{ overview.totalDays }}</div>
|
<div class="stat-label">总出勤天数</div>
|
</div>
|
</div>
|
</el-card>
|
</el-col>
|
<el-col :span="6">
|
<el-card shadow="hover" class="stat-card">
|
<div class="stat-content">
|
<div class="stat-icon present-icon">
|
<i class="el-icon-success"></i>
|
</div>
|
<div class="stat-info">
|
<div class="stat-value">{{ overview.presentDays }}</div>
|
<div class="stat-label">正常出勤</div>
|
</div>
|
</div>
|
</el-card>
|
</el-col>
|
<el-col :span="6">
|
<el-card shadow="hover" class="stat-card">
|
<div class="stat-content">
|
<div class="stat-icon abnormal-icon">
|
<i class="el-icon-warning"></i>
|
</div>
|
<div class="stat-info">
|
<div class="stat-value">{{ overview.abnormalDays }}</div>
|
<div class="stat-label">异常天数</div>
|
</div>
|
</div>
|
</el-card>
|
</el-col>
|
<el-col :span="6">
|
<el-card shadow="hover" class="stat-card">
|
<div class="stat-content">
|
<div class="stat-icon rate-icon">
|
<i class="el-icon-data-analysis"></i>
|
</div>
|
<div class="stat-info">
|
<div class="stat-value">{{ overview.attendanceRate }}%</div>
|
<div class="stat-label">出勤率</div>
|
</div>
|
</div>
|
</el-card>
|
</el-col>
|
</el-row>
|
|
<!-- 图表区域 -->
|
<el-row :gutter="20" class="charts-section">
|
<el-col :span="12">
|
<el-card header="出勤趋势" shadow="never">
|
<div id="attendanceTrendChart" class="chart-container"></div>
|
</el-card>
|
</el-col>
|
<el-col :span="12">
|
<el-card header="考勤分布" shadow="never">
|
<div id="attendanceDistributionChart" class="chart-container"></div>
|
</el-card>
|
</el-col>
|
</el-row>
|
|
<!-- 详细统计表格 -->
|
<el-card header="详细统计" class="detail-table-card" shadow="never">
|
<el-table :data="detailedStats" border style="width: 100%">
|
<el-table-column prop="month" label="月份" />
|
<el-table-column prop="workDays" label="应出勤天数" />
|
<el-table-column prop="actualDays" label="实际出勤" />
|
<el-table-column prop="lateTimes" label="迟到次数" >
|
<template #default="scope">
|
<el-tag v-if="scope.row.lateTimes > 0" type="warning" size="small">
|
{{ scope.row.lateTimes }}
|
</el-tag>
|
<span v-else>{{ scope.row.lateTimes }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="leaveEarlyTimes" label="早退次数" >
|
<template #default="scope">
|
<el-tag v-if="scope.row.leaveEarlyTimes > 0" type="warning" size="small">
|
{{ scope.row.leaveEarlyTimes }}
|
</el-tag>
|
<span v-else>{{ scope.row.leaveEarlyTimes }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="absenceDays" label="缺勤天数" >
|
<template #default="scope">
|
<el-tag v-if="scope.row.absenceDays > 0" type="danger" size="small">
|
{{ scope.row.absenceDays }}
|
</el-tag>
|
<span v-else>{{ scope.row.absenceDays }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="businessTripDays" label="出差天数" >
|
<template #default="scope">
|
<el-tag v-if="scope.row.businessTripDays > 0" type="primary" size="small">
|
{{ scope.row.businessTripDays }}
|
</el-tag>
|
<span v-else>{{ scope.row.businessTripDays }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="attendanceRate" label="出勤率" >
|
<template #default="scope">
|
<el-progress
|
:percentage="scope.row.attendanceRate"
|
:show-text="false"
|
:color="getProgressColor(scope.row.attendanceRate)"
|
/>
|
<span>{{ scope.row.attendanceRate }}%</span>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-card>
|
|
<!-- 异常记录 -->
|
<el-card header="异常记录" class="abnormal-records-card" shadow="never">
|
<el-table :data="abnormalRecords" border style="width: 100%">
|
<el-table-column prop="date" label="日期" />
|
<el-table-column prop="type" label="异常类型" >
|
<template #default="scope">
|
<el-tag :type="getAbnormalType(scope.row.type)" size="small">
|
{{ scope.row.type }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column prop="description" label="描述" min-width="200" />
|
<el-table-column prop="duration" label="时长" />
|
<el-table-column prop="status" label="状态" >
|
<template #default="scope">
|
<el-tag
|
:type="scope.row.status === '已处理' ? 'success' : 'warning'"
|
size="small"
|
>
|
{{ scope.row.status }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" >
|
<template #default="scope">
|
<el-button type="text" size="mini" @click="viewAbnormalDetail(scope.row)">
|
查看
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-card>
|
</div>
|
</template>
|
|
<script>
|
import * as echarts from 'echarts'
|
|
export default {
|
name: 'PersonalAttendanceReport',
|
props: {
|
stats: {
|
type: Object,
|
default: () => ({})
|
},
|
attendanceData: {
|
type: Array,
|
default: () => []
|
}
|
},
|
data() {
|
return {
|
reportPeriod: 'month',
|
overview: {
|
totalDays: 0,
|
presentDays: 0,
|
abnormalDays: 0,
|
attendanceRate: 0
|
},
|
detailedStats: [],
|
abnormalRecords: [],
|
trendChart: null,
|
distributionChart: null
|
}
|
},
|
mounted() {
|
this.initData()
|
this.$nextTick(() => {
|
this.initCharts()
|
})
|
},
|
beforeDestroy() {
|
// 销毁图表实例
|
if (this.trendChart) {
|
this.trendChart.dispose()
|
}
|
if (this.distributionChart) {
|
this.distributionChart.dispose()
|
}
|
},
|
methods: {
|
initData() {
|
// 初始化概览数据
|
this.overview = {
|
totalDays: this.stats.totalDays || 22,
|
presentDays: this.stats.presentDays || 20,
|
abnormalDays: this.stats.abnormalDays || 2,
|
attendanceRate: this.stats.attendanceRate || 90.9
|
}
|
|
// 初始化详细统计
|
this.detailedStats = [
|
{ month: '2024-12', workDays: 22, actualDays: 20, lateTimes: 2,
|
leaveEarlyTimes: 1, absenceDays: 0, businessTripDays: 3, attendanceRate: 90.9 },
|
{ month: '2024-11', workDays: 21, actualDays: 19, lateTimes: 1,
|
leaveEarlyTimes: 0, absenceDays: 1, businessTripDays: 2, attendanceRate: 90.5 },
|
{ month: '2024-10', workDays: 23, actualDays: 22, lateTimes: 0,
|
leaveEarlyTimes: 0, absenceDays: 0, businessTripDays: 1, attendanceRate: 95.7 }
|
]
|
|
// 初始化异常记录
|
this.abnormalRecords = [
|
{ date: '2024-12-15', type: '迟到', description: '早上迟到30分钟', duration: '30分钟', status: '已处理' },
|
{ date: '2024-12-08', type: '早退', description: '下午提前1小时离开', duration: '1小时', status: '已处理' },
|
{ date: '2024-11-20', type: '缺勤', description: '病假', duration: '1天', status: '已处理' }
|
]
|
},
|
|
initCharts() {
|
this.initTrendChart()
|
this.initDistributionChart()
|
this.setupChartResize()
|
},
|
|
initTrendChart() {
|
const chartDom = document.getElementById('attendanceTrendChart')
|
if (!chartDom) return
|
|
this.trendChart = echarts.init(chartDom)
|
const option = {
|
tooltip: {
|
trigger: 'axis',
|
formatter: function(params) {
|
let result = params[0].axisValue + '<br/>'
|
params.forEach(param => {
|
result += `${param.seriesName}: ${param.value}<br/>`
|
})
|
return result
|
}
|
},
|
legend: {
|
data: ['出勤天数', '异常天数', '出勤率'],
|
bottom: 10
|
},
|
grid: {
|
left: '3%',
|
right: '4%',
|
bottom: '15%',
|
top: '10%',
|
containLabel: true
|
},
|
xAxis: {
|
type: 'category',
|
data: ['10月', '11月', '12月']
|
},
|
yAxis: [
|
{
|
type: 'value',
|
name: '天数',
|
min: 0,
|
max: 30
|
},
|
{
|
type: 'value',
|
name: '出勤率(%)',
|
min: 0,
|
max: 100,
|
axisLabel: {
|
formatter: '{value}%'
|
}
|
}
|
],
|
series: [
|
{
|
name: '出勤天数',
|
type: 'bar',
|
barWidth: '30%',
|
data: [22, 19, 20],
|
itemStyle: {
|
color: '#409EFF'
|
}
|
},
|
{
|
name: '异常天数',
|
type: 'bar',
|
barWidth: '30%',
|
data: [1, 2, 2],
|
itemStyle: {
|
color: '#F56C6C'
|
}
|
},
|
{
|
name: '出勤率',
|
type: 'line',
|
yAxisIndex: 1,
|
data: [95.7, 90.5, 90.9],
|
itemStyle: {
|
color: '#67C23A'
|
},
|
lineStyle: {
|
width: 3
|
}
|
}
|
]
|
}
|
this.trendChart.setOption(option)
|
},
|
|
initDistributionChart() {
|
const chartDom = document.getElementById('attendanceDistributionChart')
|
if (!chartDom) return
|
|
this.distributionChart = echarts.init(chartDom)
|
const option = {
|
tooltip: {
|
trigger: 'item',
|
formatter: '{a} <br/>{b}: {c} ({d}%)'
|
},
|
legend: {
|
orient: 'vertical',
|
right: 10,
|
top: 'center',
|
data: ['正常出勤', '迟到', '早退', '缺勤', '出差']
|
},
|
series: [
|
{
|
name: '考勤分布',
|
type: 'pie',
|
radius: ['40%', '70%'],
|
center: ['40%', '50%'],
|
avoidLabelOverlap: false,
|
itemStyle: {
|
borderColor: '#fff',
|
borderWidth: 2
|
},
|
label: {
|
show: false,
|
position: 'center'
|
},
|
emphasis: {
|
label: {
|
show: true,
|
fontSize: 18,
|
fontWeight: 'bold'
|
}
|
},
|
labelLine: {
|
show: false
|
},
|
data: [
|
{ value: 20, name: '正常出勤', itemStyle: { color: '#67C23A' } },
|
{ value: 2, name: '迟到', itemStyle: { color: '#E6A23C' } },
|
{ value: 1, name: '早退', itemStyle: { color: '#F56C6C' } },
|
{ value: 0, name: '缺勤', itemStyle: { color: '#909399' } },
|
{ value: 3, name: '出差', itemStyle: { color: '#409EFF' } }
|
]
|
}
|
]
|
}
|
this.distributionChart.setOption(option)
|
},
|
|
setupChartResize() {
|
// 监听窗口变化,重新渲染图表
|
const handleResize = () => {
|
if (this.trendChart) {
|
this.trendChart.resize()
|
}
|
if (this.distributionChart) {
|
this.distributionChart.resize()
|
}
|
}
|
|
window.addEventListener('resize', handleResize)
|
this.$once('hook:beforeDestroy', () => {
|
window.removeEventListener('resize', handleResize)
|
})
|
},
|
|
handlePeriodChange(period) {
|
this.reportPeriod = period
|
this.updateChartData()
|
},
|
|
updateChartData() {
|
// 根据选择的周期更新图表数据
|
let data
|
switch (this.reportPeriod) {
|
case 'month':
|
data = this.getMonthlyData()
|
break
|
case 'quarter':
|
data = this.getQuarterlyData()
|
break
|
case 'year':
|
data = this.getYearlyData()
|
break
|
default:
|
data = this.getMonthlyData()
|
}
|
|
this.updateCharts(data)
|
},
|
|
getMonthlyData() {
|
// 模拟月度数据
|
return {
|
xAxis: ['10月', '11月', '12月'],
|
attendance: [22, 19, 20],
|
abnormal: [1, 2, 2],
|
rate: [95.7, 90.5, 90.9]
|
}
|
},
|
|
getQuarterlyData() {
|
// 模拟季度数据
|
return {
|
xAxis: ['Q1', 'Q2', 'Q3', 'Q4'],
|
attendance: [65, 62, 58, 61],
|
abnormal: [5, 8, 6, 4],
|
rate: [92.8, 88.6, 90.2, 93.5]
|
}
|
},
|
|
getYearlyData() {
|
// 模拟年度数据
|
return {
|
xAxis: ['2022', '2023', '2024'],
|
attendance: [240, 248, 252],
|
abnormal: [25, 18, 15],
|
rate: [90.2, 92.5, 94.1]
|
}
|
},
|
|
updateCharts(data) {
|
if (this.trendChart) {
|
const option = this.trendChart.getOption()
|
option.xAxis[0].data = data.xAxis
|
option.series[0].data = data.attendance
|
option.series[1].data = data.abnormal
|
option.series[2].data = data.rate
|
this.trendChart.setOption(option)
|
}
|
},
|
|
getProgressColor(rate) {
|
if (rate >= 95) return '#67C23A'
|
if (rate >= 90) return '#E6A23C'
|
if (rate >= 80) return '#F56C6C'
|
return '#909399'
|
},
|
|
getAbnormalType(type) {
|
const typeMap = {
|
'迟到': 'warning',
|
'早退': 'warning',
|
'缺勤': 'danger',
|
'请假': 'info'
|
}
|
return typeMap[type] || 'info'
|
},
|
|
viewAbnormalDetail(record) {
|
this.$message.info(`查看异常记录: ${record.date} - ${record.type}`)
|
// 这里可以打开详情对话框
|
},
|
|
exportReport() {
|
this.$message.success('报表导出功能开发中')
|
// 这里可以实现导出PDF或Excel功能
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.personal-attendance-report {
|
padding: 20px;
|
background: #fff;
|
border-radius: 8px;
|
}
|
|
.report-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 24px;
|
padding-bottom: 16px;
|
border-bottom: 1px solid #ebeef5;
|
}
|
|
.report-header h4 {
|
margin: 0;
|
color: #303133;
|
font-size: 20px;
|
font-weight: 600;
|
}
|
|
.header-actions {
|
display: flex;
|
gap: 12px;
|
align-items: center;
|
}
|
|
.stats-overview {
|
margin-bottom: 24px;
|
}
|
|
.stat-card {
|
border-radius: 8px;
|
transition: all 0.3s ease;
|
}
|
|
.stat-card:hover {
|
transform: translateY(-2px);
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
}
|
|
.stat-content {
|
display: flex;
|
align-items: center;
|
padding: 16px;
|
}
|
|
.stat-icon {
|
width: 60px;
|
height: 60px;
|
border-radius: 50%;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
margin-right: 16px;
|
font-size: 24px;
|
color: white;
|
}
|
|
.attendance-icon {
|
background: linear-gradient(135deg, #409EFF, #79BBFF);
|
}
|
|
.present-icon {
|
background: linear-gradient(135deg, #67C23A, #95D475);
|
}
|
|
.abnormal-icon {
|
background: linear-gradient(135deg, #E6A23C, #EEBD6D);
|
}
|
|
.rate-icon {
|
background: linear-gradient(135deg, #F56C6C, #F89898);
|
}
|
|
.stat-info {
|
flex: 1;
|
}
|
|
.stat-value {
|
font-size: 28px;
|
font-weight: bold;
|
color: #303133;
|
margin-bottom: 4px;
|
}
|
|
.stat-label {
|
color: #909399;
|
font-size: 14px;
|
}
|
|
.charts-section {
|
margin-bottom: 24px;
|
}
|
|
.chart-container {
|
width: 100%;
|
height: 300px;
|
}
|
|
.detail-table-card,
|
.abnormal-records-card {
|
margin-bottom: 20px;
|
}
|
|
/* 响应式设计 */
|
@media (max-width: 1200px) {
|
.stats-overview .el-col {
|
margin-bottom: 16px;
|
}
|
}
|
|
@media (max-width: 768px) {
|
.personal-attendance-report {
|
padding: 12px;
|
}
|
|
.report-header {
|
flex-direction: column;
|
align-items: flex-start;
|
gap: 12px;
|
}
|
|
.header-actions {
|
width: 100%;
|
justify-content: space-between;
|
}
|
|
.stat-content {
|
padding: 12px;
|
}
|
|
.stat-icon {
|
width: 50px;
|
height: 50px;
|
font-size: 20px;
|
margin-right: 12px;
|
}
|
|
.stat-value {
|
font-size: 24px;
|
}
|
|
.chart-container {
|
height: 250px;
|
}
|
}
|
|
/* 动画效果 */
|
.fade-enter-active, .fade-leave-active {
|
transition: opacity 0.3s;
|
}
|
.fade-enter, .fade-leave-to {
|
opacity: 0;
|
}
|
|
/* 表格样式优化 */
|
.el-table {
|
border-radius: 4px;
|
overflow: hidden;
|
}
|
|
.el-table::before {
|
display: none;
|
}
|
|
/* 卡片标题样式 */
|
.el-card__header {
|
background: #f8f9fa;
|
border-bottom: 1px solid #ebeef5;
|
font-weight: 600;
|
color: #303133;
|
}
|
</style>
|