wuzhen update

This commit is contained in:
wuzhen committed 2025-08-01 08:37:16 +08:00
commit 679a9cf070
26 files changed
+3639 -260

No files matched your search

@@ -187,6 +187,15 @@ export function exportStudent(query?: StudentQuery): AxiosPromise<any> {
}) as any;
}
// 下载导入模板
export function downloadImportTemplate(): AxiosPromise<any> {
return request({
url: '/studentMsg/studentMsg/importTemplate',
method: 'post',
responseType: 'blob'
});
}
// 学生状态修改
export function changeStudentStatus(studentId: string | number, status: string): AxiosPromise<R<any>> {
// 实际使用时连接后端接口
@@ -73,3 +73,14 @@ export const getPersonalInfo = (userId?: number): AxiosPromise<StudentMsgForm> =
params: { userId }
});
};
/**
* 下载导入模板
*/
export const downloadImportTemplate = () => {
return request({
url: '/studentMsg/studentMsg/importTemplate',
method: 'post',
responseType: 'blob'
});
};
@@ -99,7 +99,7 @@
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item icon="Download" @click="importTemplate">下载模板</el-dropdown-item>
<el-dropdown-item icon="Top" @click="handleImport">导入数据</el-dropdown-item>
<el-dropdown-item icon="Top" :disabled="!showAddButton" @click="handleImport">导入数据</el-dropdown-item>
<el-dropdown-item icon="Download" @click="handleExport">导出数据</el-dropdown-item>
</el-dropdown-menu>
</template>
@@ -1428,10 +1428,11 @@
:limit="1"
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport"
:action="getImportUrl()"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:on-error="handleFileError"
:auto-upload="false"
drag
>
@@ -1441,7 +1442,11 @@
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<template #tip>
<div class="text-center el-upload__tip">
<div class="el-upload__tip"><el-checkbox v-model="upload.updateSupport" />是否更新已经存在的学生数据</div>
<div class="el-upload__tip" style="color: red">不更新已经存在的学生数据,仅更新新增的学生数据</div>
<div class="el-upload__tip" style="color: #409eff; margin-top: 5px">
<el-icon style="margin-right: 4px"><InfoFilled /></el-icon>
请先选择左侧班级节点,导入的学生将归属到该班级
</div>
<span>仅允许导入xls、xlsx格式文件。</span>
<el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
</div>
@@ -1459,15 +1464,17 @@
<script setup lang="ts">
import api from '@/api/xg/xsjcxx/studentMsg/index';
import { downloadImportTemplate } from '@/api/xg/xsjcxx/studentMsg/studentMsg/index';
import { StudentForm, StudentQuery, StudentVO } from '@/api/xg/xsjcxx/studentMsg/types';
import { StudentMsgForm } from '@/api/xg/xsjcxx/studentMsg/studentMsg/types';
import { useRouter } from 'vue-router';
import { getCurrentInstance, ref, reactive, toRefs, watchEffect, onMounted, computed } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { ElMessage, ElMessageBox } from 'element-plus';
import { to } from 'await-to-js';
import { globalHeaders } from '@/utils/request';
// import type { UploadInstance } from 'element-plus';
// import type { FormInstance, TreeInstance } from 'element-plus';
import { Plus, ArrowDown } from '@element-plus/icons-vue';
import { Plus, ArrowDown, InfoFilled } from '@element-plus/icons-vue';
import service from '@/utils/request';
interface ComponentInternalInstance {
proxy?: any;
@@ -1638,9 +1645,9 @@ const upload = reactive({
// 是否更新已经存在的数据
updateSupport: false,
// 设置上传的请求头部
headers: { Authorization: 'Bearer ' },
headers: globalHeaders(),
// 上传的地址
url: '/api/studentMsg/student/importData'
url: import.meta.env.VITE_APP_BASE_API + '/studentMsg/studentMsg/importData'
});
const initFormData: StudentMsgForm = {
@@ -2172,6 +2179,10 @@ const handleSelectionChange = (selection: StudentVO[]) => {
/** 导入按钮操作 */
const handleImport = () => {
if (!showAddButton.value) {
ElMessage.warning('请先选择班级节点后再导入数据');
return;
}
upload.title = '学生导入';
upload.open = true;
};
@@ -2213,7 +2224,8 @@ const handleExport = () => {
/** 下载模板操作 */
const importTemplate = () => {
proxy?.download('studentMsg/studentMsg/importTemplate', {}, `student_template_${new Date().getTime()}.xlsx`);
// 直接用GET方式下载,避免axios方式导致500错误
proxy?.download('studentMsg/studentMsg/importTemplate', {}, `学生信息导入模板_${new Date().getTime()}.xlsx`);
};
/**文件上传中处理 */
@@ -2226,14 +2238,62 @@ const handleFileSuccess = (response: any) => {
upload.open = false;
upload.isUploading = false;
uploadRef.value?.clearFiles();
// 关闭所有loading消息
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 handleFileError = (error: any) => {
upload.isUploading = false;
uploadRef.value?.clearFiles();
// 关闭所有loading消息
ElMessage.closeAll();
console.error('文件上传失败:', error);
ElMessage.error('导入失败,请检查文件格式或网络连接');
};
/** 获取导入URL */
const getImportUrl = () => {
const baseUrl = upload.url;
const params = new URLSearchParams();
params.append('updateSupport', 'false');
// 添加deptId参数(当前选中的部门节点ID)
if (currentSelectedNode.value && currentSelectedNode.value.id) {
params.append('deptId', currentSelectedNode.value.id.toString());
}
return `${baseUrl}?${params.toString()}`;
};
/** 提交上传文件 */
const submitFileForm = () => {
// 检查是否选择了部门节点
if (!currentSelectedNode.value || !currentSelectedNode.value.id) {
ElMessage.warning('请先选择左侧的班级节点');
return;
}
// 显示导入loading效果
ElMessage({
message: '正在导入数据,请耐心等待...',
type: 'info',
duration: 0,
zIndex: 4000
});
// 设置上传中状态
upload.isUploading = true;
// 提交文件上传
uploadRef.value?.submit();
};