diff --git a/frontend/src/api/teachOffice/elective.js b/frontend/src/api/teachOffice/elective.js index 05fd5664..0b039c45 100644 --- a/frontend/src/api/teachOffice/elective.js +++ b/frontend/src/api/teachOffice/elective.js @@ -46,6 +46,19 @@ export function batchStopElective(bhList) { }) } +/** 导入选修课 Excel POST /jys/elective/import(multipart,字段名 file) */ +export function importElective(file) { + const formData = new FormData() + formData.append('file', file) + return request({ + url: '/jys/elective/import', + method: 'post', + data: formData, + headers: { 'Content-Type': 'multipart/form-data' }, + timeout: 60000 + }) +} + // 下载选修班列表(Excel) export function exportElectiveList(query) { return request({ diff --git a/frontend/src/views/teachOffice/elective/index.vue b/frontend/src/views/teachOffice/elective/index.vue index 9feeeb0d..481c1e86 100644 --- a/frontend/src/views/teachOffice/elective/index.vue +++ b/frontend/src/views/teachOffice/elective/index.vue @@ -74,10 +74,7 @@ 下载选修班列表 学员名单Word 学员名单Excel - 选择文件 - {{ fileName }} - - 上传数据 + 数据导入 @@ -233,6 +230,29 @@ 确定 + + + importVisible = val" + > + + + 选择文件 + {{ fileName }} + + + 请选择填写完成的选修课数据模板文件上传 + + + 取消 + 上传数据 + + @@ -240,6 +260,7 @@ import { listElective, addElective, + importElective, batchOpenElective, batchCancelOpenElective, batchStopElective, @@ -278,6 +299,8 @@ export default { selectedRows: [], // ==================== 文件上传 ==================== + importVisible: false, + importing: false, selectedFile: null, // ==================== 新建选修课弹窗 ==================== @@ -436,6 +459,13 @@ export default { }, // ==================== 文件上传 ==================== + handleOpenImport() { + this.selectedFile = null + this.importVisible = true + this.$nextTick(() => { + if (this.$refs.fileInputRef) this.$refs.fileInputRef.value = '' + }) + }, handleSelectFile() { this.$refs.fileInputRef && this.$refs.fileInputRef.click() }, @@ -447,7 +477,14 @@ export default { this.$message.warning('请先选择文件') return } - this.$message.warning('后端暂未提供该接口') + this.importing = true + importElective(this.selectedFile).then(res => { + this.$message.success((res && res.msg) || '导入成功') + this.importVisible = false + this.loadList() + }).catch(() => {}).finally(() => { + this.importing = false + }) }, // ==================== 表格多选 ==================== @@ -628,19 +665,6 @@ export default { .el-button + .el-button { margin-left: 0; } - - .file-name { - max-width: 180px; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - font-size: 12px; - color: #999; - - &.has-file { - color: #303133; - } - } } } @@ -663,4 +687,37 @@ export default { margin-top: 16px; } } + +// ==================== 数据导入弹窗 ==================== +.import-dialog { + .import-body { + display: flex; + flex-direction: column; + gap: 14px; + } + + .import-file-row { + display: flex; + align-items: center; + gap: 12px; + + .file-name { + max-width: 240px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 12px; + color: #999; + + &.has-file { + color: #303133; + } + } + } + + .import-tip { + font-size: 12px; + color: #909399; + } +} diff --git a/frontend/src/views/teachOffice/subject/index.vue b/frontend/src/views/teachOffice/subject/index.vue index fb0684ed..44f4316f 100644 --- a/frontend/src/views/teachOffice/subject/index.vue +++ b/frontend/src/views/teachOffice/subject/index.vue @@ -52,27 +52,6 @@ - - - - - 数据导入 - 选择填写完成的课程科目模板并上传 - - - - - 选择文件 - {{ fileName }} - - - - 覆盖已存在课程科目 - 上传数据 - - - - @@ -81,6 +60,7 @@ 新建课程科目 删除所选 【课程科目数据文件模板】下载 + 数据导入 + + + importVisible = val" + > + + + 选择文件 + {{ fileName }} + + + 覆盖已存在课程科目 + + 下载课程科目数据文件模板 + + + + 取消 + 上传数据 + + @@ -333,6 +339,7 @@ export default { selectedRows: [], // ==================== 文件上传 ==================== + importVisible: false, selectedFile: null, coverExist: false, @@ -508,6 +515,14 @@ export default { }, // ==================== 文件上传(后端暂未提供) ==================== + handleOpenImport() { + this.selectedFile = null + this.coverExist = false + this.importVisible = true + this.$nextTick(() => { + if (this.$refs.fileInputRef) this.$refs.fileInputRef.value = '' + }) + }, handleSelectFile() { this.$refs.fileInputRef && this.$refs.fileInputRef.click() }, @@ -518,6 +533,10 @@ export default { }, handleUpload() { + if (!this.selectedFile) { + this.$message.warning('请先选择文件') + return + } this.$message.warning('后端暂未提供该接口') }, @@ -627,37 +646,31 @@ export default { } -// ==================== 4. 文件上传区域 ==================== -.upload-card { - margin-bottom: 16px; +// ==================== 4. 数据导入弹窗 ==================== +.import-dialog { + .import-body { + display: flex; + flex-direction: column; + gap: 14px; + } - .upload-row { + .import-file-row { display: flex; align-items: center; - justify-content: space-between; - flex-wrap: wrap; gap: 12px; - .upload-left { - display: flex; - align-items: center; - gap: 12px; + .file-name { + font-size: 12px; + color: #999; - .file-name { - font-size: 12px; - color: #999; - - &.has-file { - color: #303133; - } + &.has-file { + color: #303133; } } + } - .upload-right { - display: flex; - align-items: center; - gap: 12px; - } + .import-tip { + margin-top: -4px; } }
选择填写完成的课程科目模板并上传