|
@@ -1,10 +1,5 @@
|
|
|
<template>
|
|
|
- <section
|
|
|
- v-loading.body="fileLoading"
|
|
|
- v-loading.fullscreen="loading"
|
|
|
- element-loading-text="请稍后..."
|
|
|
- class="content"
|
|
|
- >
|
|
|
+ <section element-loading-text="请稍后..." class="content">
|
|
|
<div class="part-box">
|
|
|
<h2 class="part-box-title">课程列表</h2>
|
|
|
|
|
@@ -53,7 +48,7 @@
|
|
|
type="primary"
|
|
|
plain
|
|
|
icon="icon icon-import"
|
|
|
- @click="impCourse"
|
|
|
+ @click="importCourse"
|
|
|
>导入</el-button
|
|
|
>
|
|
|
<el-button
|
|
@@ -197,69 +192,13 @@
|
|
|
</el-dialog>
|
|
|
|
|
|
<!-- 导入弹窗 -->
|
|
|
- <el-dialog
|
|
|
- title="导入课程"
|
|
|
- width="520px"
|
|
|
- :visible.sync="impDialog"
|
|
|
- :modal="false"
|
|
|
- append-to-body
|
|
|
- custom-class="side-dialog"
|
|
|
- >
|
|
|
- <el-form>
|
|
|
- <el-form-item style="margin-left: 20px">
|
|
|
- <el-upload
|
|
|
- ref="upload"
|
|
|
- class="form_left"
|
|
|
- accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
- :action="uploadAction"
|
|
|
- :headers="uploadHeaders"
|
|
|
- :data="uploadData"
|
|
|
- :before-upload="beforeUpload"
|
|
|
- :on-progress="uploadProgress"
|
|
|
- :on-success="uploadSuccess"
|
|
|
- :on-error="uploadError"
|
|
|
- :file-list="fileList"
|
|
|
- :auto-upload="false"
|
|
|
- :multiple="false"
|
|
|
- >
|
|
|
- <el-button
|
|
|
- slot="trigger"
|
|
|
- size="small"
|
|
|
- type="primary"
|
|
|
- icon="icon icon-search-white"
|
|
|
- >
|
|
|
- 选择文件
|
|
|
- </el-button>
|
|
|
- <el-button
|
|
|
- size="small"
|
|
|
- type="primary"
|
|
|
- icon="icon icon-save-white"
|
|
|
- @click="submitUpload"
|
|
|
- >
|
|
|
- 确认上传
|
|
|
- </el-button>
|
|
|
- <el-button
|
|
|
- size="small"
|
|
|
- type="primary"
|
|
|
- icon="icon icon-delete-white"
|
|
|
- @click="removeFile"
|
|
|
- >
|
|
|
- 清空文件
|
|
|
- </el-button>
|
|
|
- <el-button
|
|
|
- size="small"
|
|
|
- type="primary"
|
|
|
- icon="icon icon-export-white"
|
|
|
- :loading="tempDownloading"
|
|
|
- @click="exportFile"
|
|
|
- >
|
|
|
- 下载模板
|
|
|
- </el-button>
|
|
|
- <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
|
|
|
- </el-upload>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- </el-dialog>
|
|
|
+ <import-file-dialog
|
|
|
+ ref="ImportCourseDialog"
|
|
|
+ dialog-title="导入课程"
|
|
|
+ :template-url="courseTemplateUrl"
|
|
|
+ :upload-url="uploadCourseUrl"
|
|
|
+ @uploaded="uploadSuccess"
|
|
|
+ ></import-file-dialog>
|
|
|
|
|
|
<!-- 导入错误信息列表 -->
|
|
|
<el-dialog title="错误提示" :visible.sync="errDialog" append-to-body>
|
|
@@ -283,9 +222,11 @@ import { ENABLE_TYPE, LEVEL_TYPE } from "../constants/constants.js";
|
|
|
import { mapState } from "vuex";
|
|
|
import { courseExportApi } from "../api";
|
|
|
import { downloadByApi } from "@/plugins/download";
|
|
|
+import ImportFileDialog from "@/components/ImportFileDialog.vue";
|
|
|
|
|
|
export default {
|
|
|
name: "Course",
|
|
|
+ components: { ImportFileDialog },
|
|
|
data() {
|
|
|
return {
|
|
|
formSearch: {
|
|
@@ -309,20 +250,15 @@ export default {
|
|
|
pageSize: 10,
|
|
|
total: 10,
|
|
|
|
|
|
- impDialog: false,
|
|
|
- uploadAction: QUESTION_API + "/course/import",
|
|
|
+ uploadCourseUrl: `${QUESTION_API}/course/import`,
|
|
|
+ courseTemplateUrl: `${QUESTION_API}/course/importTemplate`,
|
|
|
uploadHeaders: {},
|
|
|
- uploadData: {},
|
|
|
errMessages: [],
|
|
|
errDialog: false,
|
|
|
- fileLoading: false,
|
|
|
- loading: false,
|
|
|
- fileList: [],
|
|
|
|
|
|
courseDialog: false,
|
|
|
relationDialog: false,
|
|
|
downloading: false,
|
|
|
- tempDownloading: false,
|
|
|
|
|
|
rules: {
|
|
|
name: [
|
|
@@ -708,103 +644,22 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
//导入
|
|
|
- impCourse() {
|
|
|
- this.impDialog = true;
|
|
|
- this.initUpload();
|
|
|
- },
|
|
|
- initUpload() {
|
|
|
- this.fileList = [];
|
|
|
- },
|
|
|
- beforeUpload(file) {
|
|
|
- console.log(file);
|
|
|
- },
|
|
|
- uploadProgress() {
|
|
|
- console.log("uploadProgress");
|
|
|
+ importCourse() {
|
|
|
+ this.$refs.ImportCourseDialog.open();
|
|
|
},
|
|
|
uploadSuccess(response) {
|
|
|
- if (!response.hasError) {
|
|
|
+ const { hasError, failRecords } = response.data;
|
|
|
+ if (!hasError) {
|
|
|
this.$notify({
|
|
|
message: "上传成功",
|
|
|
type: "success",
|
|
|
});
|
|
|
- this.fileLoading = false;
|
|
|
- this.impDialog = false;
|
|
|
this.searchForm();
|
|
|
} else {
|
|
|
- this.fileLoading = false;
|
|
|
- this.impDialog = false;
|
|
|
- this.errMessages = response.failRecords;
|
|
|
+ this.errMessages = failRecords;
|
|
|
this.errDialog = true;
|
|
|
}
|
|
|
},
|
|
|
- uploadError(response) {
|
|
|
- var json = JSON.parse(response.message);
|
|
|
- if (response.status == 500) {
|
|
|
- this.$notify({
|
|
|
- message: json.desc,
|
|
|
- type: "error",
|
|
|
- });
|
|
|
- }
|
|
|
- this.fileLoading = false;
|
|
|
- },
|
|
|
- //确定上传
|
|
|
- submitUpload() {
|
|
|
- if (!this.checkUpload()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- this.$refs.upload.submit();
|
|
|
- this.fileLoading = true;
|
|
|
- },
|
|
|
- checkUpload() {
|
|
|
- var fileList = this.$refs.upload.uploadFiles;
|
|
|
- if (fileList.length == 0) {
|
|
|
- this.$notify({
|
|
|
- message: "上传文件不能为空",
|
|
|
- type: "error",
|
|
|
- });
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (fileList.length > 1) {
|
|
|
- this.$notify({
|
|
|
- message: "每次只能上传一个文件",
|
|
|
- type: "error",
|
|
|
- });
|
|
|
- return false;
|
|
|
- }
|
|
|
- for (let file of fileList) {
|
|
|
- if (!file.name.endsWith(".xlsx")) {
|
|
|
- this.$notify({
|
|
|
- message: "上传文件必须为xlsx格式",
|
|
|
- type: "error",
|
|
|
- });
|
|
|
- this.initUpload();
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- },
|
|
|
- //清空文件
|
|
|
- removeFile() {
|
|
|
- // this.fileList = [];
|
|
|
- this.$refs.upload.clearFiles();
|
|
|
- },
|
|
|
- //下载模板
|
|
|
- async exportFile() {
|
|
|
- if (this.tempDownloading) return;
|
|
|
- this.tempDownloading = true;
|
|
|
-
|
|
|
- const res = await downloadByApi(() => {
|
|
|
- return this.$httpWithMsg.get(`${QUESTION_API}/course/importTemplate`, {
|
|
|
- responseType: "blob",
|
|
|
- });
|
|
|
- }).catch((e) => {
|
|
|
- this.$message.error(e || "下载失败,请重新尝试!");
|
|
|
- });
|
|
|
- this.tempDownloading = false;
|
|
|
-
|
|
|
- if (!res) return;
|
|
|
- this.$message.success("下载成功!");
|
|
|
- },
|
|
|
},
|
|
|
};
|
|
|
</script>
|