提交代码

This commit is contained in:
zlwu committed 2025-09-07 20:32:52 +08:00
1 parent edaf8dbacf
commit 9c3741562d
13 files changed
+1574 -9

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
import request from '@/utils/request'
export interface StudentStatisticsBo {
startTime: string
endTime: string
collegeId?: number
majorId?: number
classId?: number
}
export interface StatisticsChartData {
name: string
dormDeductionCount: number
dormViolationCount: number
dormViolationDeduction: number
teachingViolationCount: number
teachingViolationDeduction: number
}
export interface StatisticsDetailData {
id: number
name: string
parentName: string
dormDeductionCount: number
dormViolationCount: number
dormViolationDeduction: number
teachingViolationCount: number
teachingViolationDeduction: number
totalDeduction: number
}
export interface StudentStatisticsVo {
dimension: string
chartData: StatisticsChartData[]
detailData: StatisticsDetailData[]
}
export interface CascadeOptionVo {
id: number
label: string
value: string
sort: number
}
// 获取统计数据
export function getStatistics(data: StudentStatisticsBo) {
return request({
url: '/xg/studentStatistics/statistics',
method: 'post',
data: data
})
}
// 导出统计数据
export function exportStatistics(data: StudentStatisticsBo) {
return request({
url: '/xg/studentStatistics/export',
method: 'post',
data: data,
responseType: 'blob'
})
}
// 获取二级学院列表
export function getColleges() {
return request({
url: '/xg/studentStatistics/colleges',
method: 'get'
})
}
// 根据学院ID获取专业列表
export function getMajorsByCollegeId(collegeId: number) {
return request({
url: `/xg/studentStatistics/majors/${collegeId}`,
method: 'get'
})
}
// 根据专业ID获取班级列表
export function getClassesByMajorId(majorId: number) {
return request({
url: `/xg/studentStatistics/classes/${majorId}`,
method: 'get'
})
}
@@ -0,0 +1,426 @@
<template>
<div class="p-2 page-container">
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
<div v-show="showSearch" class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :model="queryParams" label-width="120px">
<el-row :gutter="20">
<el-col :span="6">
<el-form-item label="统计开始时间" prop="startTime" required>
<el-date-picker
v-model="queryParams.startTime"
type="datetime"
placeholder="选择开始时间"
value-format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="统计结束时间" prop="endTime" required>
<el-date-picker
v-model="queryParams.endTime"
type="datetime"
placeholder="选择结束时间"
value-format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="二级学院" prop="collegeId">
<el-select v-model="queryParams.collegeId" placeholder="请选择学院" clearable style="width: 100%" @change="onCollegeChange">
<el-option v-for="item in collegeOptions" :key="item.id" :label="item.label" :value="item.id" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="专业" prop="majorId">
<el-select
v-model="queryParams.majorId"
placeholder="请选择专业"
clearable
style="width: 100%"
:disabled="!queryParams.collegeId"
@change="onMajorChange"
>
<el-option v-for="item in majorOptions" :key="item.id" :label="item.label" :value="item.id" />
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="6">
<el-form-item label="班级" prop="classId">
<el-select v-model="queryParams.classId" placeholder="请选择班级" clearable style="width: 100%" :disabled="!queryParams.majorId">
<el-option v-for="item in classOptions" :key="item.id" :label="item.label" :value="item.id" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="18">
<el-form-item class="search-btn-container">
<el-button type="primary" icon="Search" @click="handleQuery" :loading="loading">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
<!-- <el-button type="success" icon="Download" @click="handleExport" :loading="exportLoading" v-if="statisticsData">导出</el-button> -->
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-card>
</div>
</transition>
<!-- 无数据提示 -->
<el-card shadow="never" v-if="!statisticsData && !loading">
<el-empty description="暂无数据" style="padding: 60px 0">
<template #description>
<p style="color: #909399; font-size: 14px">请设置统计时间范围和筛选条件,然后点击【搜索】按钮查看统计数据</p>
</template>
</el-empty>
</el-card>
<!-- 统计图表 -->
<el-card shadow="never" v-if="statisticsData">
<template #header>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<div class="card-header">
<span>{{ getChartTitle() }}</span>
</div>
</el-col>
<right-toolbar :showSearch="showSearch" @update:showSearch="showSearch = $event" @queryTable="handleQuery"></right-toolbar>
</el-row>
</template>
<div ref="chartRef" style="height: 400px"></div>
</el-card>
<!-- 统计明细 -->
<el-card shadow="never" v-if="statisticsData">
<template #header>
<div class="card-header">
<span>明细数据</span>
</div>
</template>
<el-table :data="statisticsData.detailData" style="width: 100%" border>
<el-table-column prop="name" label="名称" width="200" />
<el-table-column prop="parentName" label="上级" width="150" v-if="statisticsData.dimension !== 'college'" />
<el-table-column prop="dormDeductionCount" label="宿舍扣分总数" min-width="120" align="center">
<template #default="scope">
{{ scope.row.dormDeductionCount && scope.row.dormDeductionCount !== 0 ? `-${scope.row.dormDeductionCount}` : '0' }}
</template>
</el-table-column>
<el-table-column prop="dormViolationCount" label="宿舍违纪记录总数" min-width="140" align="center" />
<el-table-column prop="dormViolationDeduction" label="宿舍违纪记录扣分总数" min-width="160" align="center">
<template #default="scope">
{{
scope.row.dormViolationDeduction && scope.row.dormViolationDeduction !== 0 ? `-${scope.row.dormViolationDeduction.toFixed(2)}` : '0.00'
}}
</template>
</el-table-column>
<el-table-column prop="teachingViolationCount" label="教学区违纪记录总数" min-width="160" align="center" />
<el-table-column prop="teachingViolationDeduction" label="教学区违纪记录扣分总数" min-width="180" align="center">
<template #default="scope">
{{
scope.row.teachingViolationDeduction && scope.row.teachingViolationDeduction !== 0
? `-${scope.row.teachingViolationDeduction.toFixed(2)}`
: '0.00'
}}
</template>
</el-table-column>
<el-table-column prop="totalDeduction" label="违纪合计扣分" min-width="140" align="center">
<template #default="scope">
{{ scope.row.totalDeduction && scope.row.totalDeduction !== 0 ? `-${scope.row.totalDeduction.toFixed(2)}` : '0.00' }}
</template>
</el-table-column>
</el-table>
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, nextTick, getCurrentInstance, ComponentInternalInstance } from 'vue';
import { ElMessage } from 'element-plus';
import * as echarts from 'echarts';
import {
getStatistics,
exportStatistics,
getColleges,
getMajorsByCollegeId,
getClassesByMajorId,
type StudentStatisticsBo,
type StudentStatisticsVo,
type CascadeOptionVo
} from '@/api/xg/studentStatistics';
defineOptions({
name: 'StudentStatistics'
});
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const queryFormRef = ref();
const chartRef = ref<HTMLDivElement>();
const loading = ref(false);
const exportLoading = ref(false);
const showSearch = ref(true);
// 查询参数
const queryParams = reactive<StudentStatisticsBo>({
startTime: '',
endTime: '',
collegeId: undefined,
majorId: undefined,
classId: undefined
});
// 级联选择器选项
const collegeOptions = ref<CascadeOptionVo[]>([]);
const majorOptions = ref<CascadeOptionVo[]>([]);
const classOptions = ref<CascadeOptionVo[]>([]);
// 统计数据
const statisticsData = ref<StudentStatisticsVo>();
// 图表实例
let chart: echarts.ECharts | null = null;
/** 设置默认时间范围(当前月第一天到最后一天) */
const setDefaultTimeRange = () => {
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth();
// 当前月第一天 00:00:00
const firstDay = new Date(year, month, 1);
const startTime = `${firstDay.getFullYear()}-${String(firstDay.getMonth() + 1).padStart(2, '0')}-${String(firstDay.getDate()).padStart(2, '0')} 00:00:00`;
// 当前月最后一天 23:59:59
const lastDay = new Date(year, month + 1, 0);
const endTime = `${lastDay.getFullYear()}-${String(lastDay.getMonth() + 1).padStart(2, '0')}-${String(lastDay.getDate()).padStart(2, '0')} 23:59:59`;
queryParams.startTime = startTime;
queryParams.endTime = endTime;
};
/** 查询学院列表 */
const getCollegeList = async () => {
try {
const res = await getColleges();
collegeOptions.value = res.data || [];
} catch (error) {
console.error('获取学院列表失败:', error);
}
};
/** 学院变化事件 */
const onCollegeChange = async (collegeId?: number) => {
queryParams.majorId = undefined;
queryParams.classId = undefined;
majorOptions.value = [];
classOptions.value = [];
if (collegeId) {
try {
const res = await getMajorsByCollegeId(collegeId);
majorOptions.value = res.data || [];
} catch (error) {
console.error('获取专业列表失败:', error);
}
}
};
/** 专业变化事件 */
const onMajorChange = async (majorId?: number) => {
queryParams.classId = undefined;
classOptions.value = [];
if (majorId) {
try {
const res = await getClassesByMajorId(majorId);
classOptions.value = res.data || [];
} catch (error) {
console.error('获取班级列表失败:', error);
}
}
};
/** 搜索按钮操作 */
const handleQuery = async () => {
if (!queryParams.startTime || !queryParams.endTime) {
ElMessage.warning('请填写统计开始时间和结束时间');
return;
}
loading.value = true;
try {
const res = await getStatistics(queryParams);
statisticsData.value = res.data;
// 渲染图表
await nextTick();
renderChart();
} catch (error) {
console.error('获取统计数据失败:', error);
ElMessage.error('获取统计数据失败');
} finally {
loading.value = false;
}
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
// 重置为默认时间范围
setDefaultTimeRange();
queryParams.collegeId = undefined;
queryParams.majorId = undefined;
queryParams.classId = undefined;
majorOptions.value = [];
classOptions.value = [];
statisticsData.value = undefined;
if (chart) {
chart.clear();
}
};
/** 导出按钮操作 */
const handleExport = async () => {
exportLoading.value = true;
try {
await exportStatistics(queryParams);
ElMessage.success('导出成功');
} catch (error) {
console.error('导出失败:', error);
ElMessage.error('导出失败');
} finally {
exportLoading.value = false;
}
};
/** 获取图表标题 */
const getChartTitle = () => {
if (!statisticsData.value) return '';
const dimension = statisticsData.value.dimension;
switch (dimension) {
case 'college':
return '二级学院统计';
case 'major':
return '专业统计';
case 'class':
return '班级统计';
case 'classDetail':
return '班级详情统计';
default:
return '统计图表';
}
};
/** 渲染图表 */
const renderChart = () => {
if (!chartRef.value || !statisticsData.value) return;
// 销毁现有图表
if (chart) {
chart.dispose();
}
// 创建新图表
chart = echarts.init(chartRef.value);
const chartData = statisticsData.value.chartData || [];
const names = chartData.map((item) => item.name);
const option = {
title: {
text: getChartTitle(),
left: 'center'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
data: ['宿舍扣分总数', '宿舍违纪记录总数', '宿舍违纪记录扣分总数', '教学区违纪记录总数', '教学区违纪记录扣分总数'],
top: 30
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
top: '15%',
containLabel: true
},
xAxis: {
type: 'category',
data: names,
axisTick: {
alignWithLabel: true
}
},
yAxis: {
type: 'value'
},
series: [
{
name: '宿舍扣分总数',
type: 'bar',
data: chartData.map((item) => item.dormDeductionCount)
},
{
name: '宿舍违纪记录总数',
type: 'bar',
data: chartData.map((item) => item.dormViolationCount)
},
{
name: '宿舍违纪记录扣分总数',
type: 'bar',
data: chartData.map((item) => item.dormViolationDeduction)
},
{
name: '教学区违纪记录总数',
type: 'bar',
data: chartData.map((item) => item.teachingViolationCount)
},
{
name: '教学区违纪记录扣分总数',
type: 'bar',
data: chartData.map((item) => item.teachingViolationDeduction)
}
]
};
chart.setOption(option);
// 监听窗口大小变化
window.addEventListener('resize', () => {
chart?.resize();
});
};
onMounted(() => {
// 设置默认时间范围
setDefaultTimeRange();
// 获取学院列表
getCollegeList();
});
</script>
<style scoped>
.page-container {
background-color: #f5f5f5;
}
.search-btn-container {
text-align: left;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
</style>
@@ -51,6 +51,12 @@
<el-option v-for="type in disciplineTypeOptions" :key="type.id" :label="type.typeName" :value="type.id" />
</el-select>
</el-form-item>
<!-- 违纪处分类型说明显示 -->
<el-form-item label="类型说明" v-if="selectedDisciplineType && selectedDisciplineType.remark">
<div class="discipline-type-remark">
<el-text type="info" size="small">{{ selectedDisciplineType.remark }}</el-text>
</div>
</el-form-item>
<el-form-item label="违纪处分日期" prop="disciplineDate">
<el-date-picker
v-model="form.disciplineDate"
@@ -253,7 +259,7 @@
<script setup name="DisciplineRecordForm" lang="ts">
import { ref, reactive, computed, toRefs, getCurrentInstance } from 'vue';
import { UploadFilled, Document, Loading, Download, Delete } from '@element-plus/icons-vue';
import { ElMessage, ElMessageBox, ElLoading, FormInstance } from 'element-plus';
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus';
import { getToken } from '@/utils/auth';
import { globalHeaders } from '@/utils/request';
import ImagePreview from '@/components/ImagePreview/index.vue';
@@ -271,7 +277,7 @@ const emit = defineEmits(['success']);
const { proxy } = getCurrentInstance() as any;
const { student_discipline_status } = toRefs<any>(proxy?.useDict('student_discipline_status'));
const disciplineRecordFormRef = ref<FormInstance>();
const disciplineRecordFormRef = ref<any>();
const buttonLoading = ref(false);
// 学生选择器相关状态
@@ -281,6 +287,9 @@ const studentLoading = ref(false);
// 违纪处分类型选项
const disciplineTypeOptions = ref<DisciplineTypeVO[]>([]);
// 选中的违纪处分类型信息
const selectedDisciplineType = ref<DisciplineTypeVO | null>(null);
// 附件上传相关状态
const attachmentList = ref<any[]>([]);
@@ -307,16 +316,12 @@ const initFormData: DisciplineRecordFormType = {
disciplineContent: undefined,
scoreDeduction: undefined,
status: '1', // 默认生效
approvalStatus: undefined,
approvalBy: undefined,
approvalTime: undefined,
approvalRemark: undefined,
attachmentOssIds: undefined
};
const form = ref<DisciplineRecordFormType>({ ...initFormData });
const rules = reactive({
const rules = reactive<any>({
studentId: [{ required: true, message: '学生不能为空', trigger: 'change' }],
disciplineTypeId: [{ required: true, message: '违纪处分类型不能为空', trigger: 'change' }],
disciplineDate: [{ required: true, message: '违纪处分日期不能为空', trigger: 'blur' }],
@@ -383,6 +388,14 @@ const openDialog = async (id?: string | number, title?: string) => {
// 处理附件数据
await handleAttachmentData();
// 设置选中的违纪处分类型(用于显示类型说明)
if (form.value.disciplineTypeId) {
const selectedType = disciplineTypeOptions.value.find((type) => type.id === form.value.disciplineTypeId);
if (selectedType) {
selectedDisciplineType.value = selectedType;
}
}
}
};
@@ -390,6 +403,7 @@ const openDialog = async (id?: string | number, title?: string) => {
const resetForm = () => {
form.value = { ...initFormData };
attachmentList.value = [];
selectedDisciplineType.value = null;
disciplineRecordFormRef.value?.resetFields();
};
@@ -478,12 +492,18 @@ const loadDisciplineTypes = async () => {
const handleDisciplineTypeChange = (typeId: string | number) => {
if (!typeId) {
form.value.disciplineTypeName = undefined;
selectedDisciplineType.value = null;
return;
}
const selectedType = disciplineTypeOptions.value.find((type) => type.id === typeId);
if (selectedType) {
form.value.disciplineTypeName = selectedType.typeName;
selectedDisciplineType.value = selectedType;
// 自动填充最低扣分(如果有的话)
if (selectedType.minScore !== undefined && selectedType.minScore !== null) {
form.value.scoreDeduction = Number(selectedType.minScore);
}
}
};
@@ -972,6 +992,17 @@ defineExpose({
box-sizing: border-box;
}
/* 违纪处分类型说明显示 */
.discipline-type-remark {
padding: 8px 12px;
background: #f0f9ff;
border: 1px solid #bfdbfe;
border-radius: 4px;
font-size: 13px;
line-height: 1.5;
color: #1e40af;
}
.student-name-text {
font-weight: 500;
color: #303133;