fix(xg): 操行分导入改为直接提交已选文件
continuous-integration/drone/tag Build is passing

导入弹窗位于班级循环内时,确定导入没有请求后台接口。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-11-24 16:37:35 +08:00
1 parent 7f9d3830ad
commit 73d80507d9
2 files changed
+124 -123

No files matched your search

+14
View File
@@ -124,6 +124,20 @@ export function conductScoreCheckPermission(query: any) {
});
}
// 导入操行分数据
export function conductScoreImportData(data: FormData, params: { academicYear: number; semester: number; classId: string }) {
return request({
url: '/xg/conduct-score/importData',
method: 'post',
params,
data,
headers: {
repeatSubmit: false
},
timeout: 300000
});
}
// 获取学生详细记录(按月份)
export function conductScoreGetStudentRecords(studentId: any, academicYear: any, semester: any, tenantId: any) {
return request({
@@ -155,70 +155,6 @@
</template>
</el-dialog>
<!-- 导入数据弹窗 -->
<el-dialog
v-model="importModalVisible"
title="导入操行分数据"
width="500px"
append-to-body
:close-on-click-modal="false"
destroy-on-close
>
<div class="mb-4">
<div class="text-sm text-gray-600 mb-2">
<strong>当前录入条件:</strong>
{{ queryParams.academicYear - 1 }}-{{ queryParams.academicYear }}学年
{{ queryParams.semester === 1 ? '第一学期' : '第二学期' }}
{{ queryParams.month }}月
{{ activeTab ? `(${classTabs.find((tab) => tab.classId.toString() === activeTab)?.className})` : '' }}
</div>
<div class="text-sm text-red-600 mb-3">
<el-icon class="mr-1"><InfoFilled /></el-icon>
如果学生已有该月份的分数记录,将被Excel中的数据覆盖
</div>
</div>
<el-upload
ref="importUploadRef"
:limit="1"
accept=".xlsx, .xls"
:headers="importUpload.headers"
:action="getImportUrl()"
:disabled="importUpload.isUploading"
:on-progress="handleImportFileUploadProgress"
:on-success="handleImportFileSuccess"
:on-error="handleImportFileError"
:auto-upload="false"
drag
>
<el-icon class="el-icon--upload">
<i-ep-upload-filled />
</el-icon>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<template #tip>
<div class="text-center el-upload__tip">
<div class="el-upload__tip" style="color: #409eff; margin-bottom: 5px">模板包含5列:月份、学号、学生姓名、分数、备注</div>
<div class="el-upload__tip" style="color: red">仅处理班主任负责班级的学生数据,学号不存在或姓名不匹配的数据将被跳过</div>
<span>仅允许导入xls、xlsx格式文件。</span>
<el-link
type="primary"
:underline="false"
style="font-size: 12px; vertical-align: baseline; margin-left: 10px"
@click="handleImportTemplate"
>
下载模板
</el-link>
</div>
</template>
</el-upload>
<template #footer>
<div class="dialog-footer">
<el-button @click="importModalVisible = false">取消</el-button>
<el-button type="primary" @click="submitImportFile" :loading="importUpload.isUploading">确定导入</el-button>
</div>
</template>
</el-dialog>
<el-table
v-if="currentClassStudents && currentClassStudents.length > 0"
v-loading="tabLoading"
@@ -319,19 +255,75 @@
<!-- 调试信息(开发环境显示) -->
<div v-else style="padding: 20px; text-align: center; color: #909399">正在加载班级数据...</div>
<!-- 导入数据弹窗放在班级循环外,避免每个 Tab 各生成一个上传组件 -->
<el-dialog
v-model="importModalVisible"
title="导入操行分数据"
width="500px"
append-to-body
:close-on-click-modal="false"
destroy-on-close
@closed="handleImportDialogClosed"
>
<div class="mb-4">
<div class="text-sm text-gray-600 mb-2">
<strong>当前录入条件:</strong>
{{ queryParams.academicYear - 1 }}-{{ queryParams.academicYear }}学年
{{ queryParams.semester === 1 ? '第一学期' : '第二学期' }}
{{ queryParams.month }}月
{{ activeTab ? `(${classTabs.find((tab) => tab.classId.toString() === activeTab)?.className})` : '' }}
</div>
<div class="text-sm text-red-600 mb-3">
<el-icon class="mr-1"><InfoFilled /></el-icon>
如果学生已有该月份的分数记录,将被Excel中的数据覆盖
</div>
</div>
<el-upload
ref="importUploadRef"
:limit="1"
accept=".xlsx, .xls"
:disabled="importUpload.isUploading"
:auto-upload="false"
:on-change="handleImportFileChange"
:on-remove="handleImportFileRemove"
drag
>
<el-icon class="el-icon--upload">
<i-ep-upload-filled />
</el-icon>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<template #tip>
<div class="text-center el-upload__tip">
<div class="el-upload__tip" style="color: #409eff; margin-bottom: 5px">模板包含5列:月份、学号、学生姓名、分数、备注</div>
<div class="el-upload__tip" style="color: red">仅处理班主任负责班级的学生数据,学号不存在或姓名不匹配的数据将被跳过</div>
<span>仅允许导入xls、xlsx格式文件。</span>
<el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline; margin-left: 10px" @click="handleImportTemplate">
下载模板
</el-link>
</div>
</template>
</el-upload>
<template #footer>
<div class="dialog-footer">
<el-button @click="importModalVisible = false">取消</el-button>
<el-button type="primary" @click="submitImportFile" :loading="importUpload.isUploading">确定导入</el-button>
</div>
</template>
</el-dialog>
</div>
</div>
</template>
<script setup lang="ts" name="ConductScoreInput">
import { ref, reactive, onMounted, computed, getCurrentInstance, toRefs, nextTick } from 'vue';
import { ref, reactive, onMounted, computed, getCurrentInstance, toRefs } from 'vue';
import ElMessage from 'element-plus/es/components/message/index';
import ElMessageBox from 'element-plus/es/components/message-box/index';
import { ArrowDown, InfoFilled } from '@element-plus/icons-vue';
import { globalHeaders } from '@/utils/request';
// API接口
import { conductScoreClassStudents, conductScoreBatchAdd, conductScoreBatchUpdate } from '@/api/xg/conductScore';
import { conductScoreClassStudents, conductScoreBatchAdd, conductScoreBatchUpdate, conductScoreImportData } from '@/api/xg/conductScore';
// 获取当前实例
const { proxy } = getCurrentInstance() as any;
@@ -849,10 +841,9 @@ const batchModalForm = reactive({
// 导入数据相关
const importModalVisible = ref(false);
const importUploadRef = ref<any>();
const importFileList = ref<any[]>([]);
const importUpload = reactive({
isUploading: false,
headers: globalHeaders(),
url: ''
isUploading: false
});
const confirmBatchModalSave = () => {
@@ -992,6 +983,7 @@ const handleImportData = () => {
ElMessage.warning('请先选择要导入数据的班级');
return;
}
importFileList.value = [];
importModalVisible.value = true;
};
@@ -999,74 +991,69 @@ const handleImportTemplate = () => {
proxy?.download('xg/conduct-score/importTemplate', {}, `操行分导入模板_${new Date().getTime()}.xlsx`);
};
const getImportUrl = () => {
const baseUrl = import.meta.env.VITE_APP_BASE_API + '/xg/conduct-score/importData';
const params = new URLSearchParams();
params.append('academicYear', queryParams.academicYear.toString());
params.append('semester', queryParams.semester.toString());
// 如果选择了特定班级,则只导入该班级数据
if (activeTab.value) {
params.append('classId', activeTab.value);
}
return `${baseUrl}?${params.toString()}`;
const handleImportFileChange = (_uploadFile, fileList) => {
importFileList.value = fileList;
};
const handleImportFileUploadProgress = () => {
importUpload.isUploading = true;
const handleImportFileRemove = (_uploadFile, fileList) => {
importFileList.value = fileList;
};
const handleImportFileSuccess = (response) => {
importModalVisible.value = false;
importUpload.isUploading = false;
importUploadRef.value[0]?.clearFiles();
ElMessage.closeAll();
ElMessageBox.alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {
dangerouslyUseHTMLString: true
});
// 刷新数据
getList();
const handleImportDialogClosed = () => {
importFileList.value = [];
};
const handleImportFileError = (error) => {
importUpload.isUploading = false;
importUploadRef.value[0]?.clearFiles();
ElMessage.closeAll();
console.error('文件上传失败:', error);
ElMessage.error('导入失败,请检查文件格式或网络连接');
};
const submitImportFile = () => {
if (!importUploadRef.value || !importUploadRef.value[0]) {
ElMessage.error('上传组件未初始化');
const submitImportFile = async () => {
if (importUpload.isUploading) {
return;
}
ElMessage({
const rawFile = [...importFileList.value].reverse().find((file) => file?.raw)?.raw;
if (!rawFile) {
ElMessage.warning('请先选择要导入的文件');
return;
}
if (queryParams.academicYear == null || queryParams.semester == null) {
ElMessage.warning('请先选择学年和学期');
return;
}
if (!activeTab.value) {
ElMessage.warning('请先选择要导入数据的班级');
return;
}
const formData = new FormData();
formData.append('file', rawFile);
importUpload.isUploading = true;
const loadingMessage = ElMessage({
message: '正在导入数据,请耐心等待...',
type: 'info',
duration: 0,
zIndex: 4000
});
importUpload.isUploading = true;
// 使用 nextTick 确保组件已完全挂载
nextTick(() => {
try {
importUploadRef.value[0]?.submit();
} catch (error) {
console.error('Submit error:', error);
ElMessage.error('上传失败:' + error.message);
importUpload.isUploading = false;
}
});
try {
const response: any = await conductScoreImportData(formData, {
academicYear: queryParams.academicYear,
semester: queryParams.semester,
classId: activeTab.value
});
importUploadRef.value?.clearFiles?.();
importFileList.value = [];
importModalVisible.value = false;
ElMessageBox.alert(
"<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + (response?.msg || '导入完成') + '</div>',
'导入结果',
{ dangerouslyUseHTMLString: true }
);
getList();
} catch (error) {
console.error('文件上传失败:', error);
} finally {
loadingMessage.close();
importUpload.isUploading = false;
}
};
// 生命周期