xiatian 3 年之前
父节点
当前提交
d8e225ae3c

+ 207 - 0
src/modules/questions/views/CourseProperty.vue

@@ -76,6 +76,17 @@
               @click="closeCoursePropertys"
               ><i class="el-icon-close"></i> 禁用</el-button
             >
+            <el-button
+              size="small"
+              type="primary"
+              icon="el-icon-upload2"
+              @click="impCourseProperty"
+            >
+              导入
+            </el-button>
+            <el-button size="small" type="primary" @click="exportCourseProperty"
+              ><i class="el-icon-download"></i>导出</el-button
+            >
           </el-form-item>
         </el-row>
       </el-form>
@@ -224,12 +235,86 @@
         </el-row>
       </el-form>
     </el-dialog>
+    <!-- 导入弹窗 -->
+    <el-dialog title="导入窗口" width="520px" :visible.sync="impDialog">
+      <el-form>
+        <el-row>
+          <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="el-icon-search"
+              >
+                选择文件
+              </el-button>
+              &nbsp;
+              <el-button
+                size="small"
+                type="primary"
+                icon="el-icon-check"
+                @click="submitUpload"
+              >
+                确认上传
+              </el-button>
+              <el-button
+                size="small"
+                type="primary"
+                icon="el-icon-refresh"
+                @click="removeFile"
+              >
+                清空文件
+              </el-button>
+              <el-button
+                size="small"
+                type="primary"
+                icon="el-icon-download"
+                @click="exportFile"
+              >
+                下载模板
+              </el-button>
+              <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
+            </el-upload>
+          </el-form-item>
+        </el-row>
+      </el-form>
+    </el-dialog>
+
+    <!-- 导入错误信息列表 -->
+    <el-dialog title="错误提示" :visible.sync="errDialog">
+      <div
+        v-for="errMessage in errMessages"
+        :key="errMessage.lineNum"
+        class="text-danger"
+      >
+        第{{ errMessage.lineNum }}行:{{ errMessage.msg }}
+      </div>
+      <span slot="footer" class="dialog-footer">
+        <el-button @click="errDialog = false">确定</el-button>
+      </span>
+    </el-dialog>
   </section>
 </template>
 
 <script>
 import { CORE_API, QUESTION_API } from "@/constants/constants";
 import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
+import { mapState } from "vuex";
 export default {
   components: { LinkTitlesCustom },
   data() {
@@ -238,6 +323,16 @@ export default {
         name: "",
         courseId: "",
       },
+
+      impDialog: false,
+      uploadAction: QUESTION_API + "/courseProperty/import",
+      uploadHeaders: {},
+      uploadData: {},
+      errMessages: [],
+      errDialog: false,
+      fileLoading: false,
+      fileList: [],
+
       courseList: [],
       loading: false,
       tableData: [],
@@ -260,6 +355,9 @@ export default {
     };
   },
   computed: {
+    ...mapState({
+      user: (state) => state.user,
+    }),
     selectedIds() {
       var selectedIdsStr = "";
       for (let id of this.selectedList) {
@@ -292,9 +390,118 @@ export default {
   },
   created() {
     this.initValue();
+    this.uploadHeaders = {
+      key: this.user.key,
+      token: this.user.token,
+    };
   },
 
   methods: {
+    exportCourseProperty() {
+      var key = this.user.key;
+      var token = this.user.token;
+      window.open(
+        QUESTION_API +
+          "/courseProperty/export?$key=" +
+          key +
+          "&$token=" +
+          token +
+          "&name=" +
+          this.formSearch.name +
+          "&courseId=" +
+          this.formSearch.courseId
+      );
+    },
+    //导入
+    impCourseProperty() {
+      this.impDialog = true;
+      this.initUpload();
+    },
+    initUpload() {
+      this.fileList = [];
+    },
+    beforeUpload(file) {
+      console.log(file);
+    },
+    uploadProgress() {
+      console.log("uploadProgress");
+    },
+    uploadSuccess(response) {
+      if (!response.hasError) {
+        this.$notify({
+          message: "上传成功",
+          type: "success",
+        });
+        this.fileLoading = false;
+        this.impDialog = false;
+        this.searchCourProperty();
+      } else {
+        this.fileLoading = false;
+        this.impDialog = false;
+        this.errMessages = response.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();
+    },
+    //下载模板
+    exportFile() {
+      window.location.href =
+        QUESTION_API +
+        "/courseProperty/importTemplate?$key=" +
+        this.user.key +
+        "&$token=" +
+        this.user.token;
+    },
     //查询所有课程属性
     searchFrom() {
       this.currentPage = 1;

+ 5 - 1
src/modules/questions/views/EditPaper.vue

@@ -520,7 +520,11 @@
                         content.firstProperty.code
                       }})</span
                     ><br />
-                    <span v-if="content.secondProperty != null"
+                    <span
+                      v-if="
+                        content.secondProperty != null &&
+                        content.secondProperty.code
+                      "
                       >二级属性:{{ content.secondProperty.name }}({{
                         content.secondProperty.code
                       }})</span

+ 2 - 2
src/modules/questions/views/PropertyInfo.vue

@@ -164,7 +164,7 @@
 </template>
 
 <script>
-import { QUESTION_API } from "@/constants/constants";
+import { CORE_API, QUESTION_API } from "@/constants/constants";
 import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
 export default {
   components: { LinkTitlesCustom },
@@ -281,7 +281,7 @@ export default {
       this.courseList = [];
       if (query) {
         this.courseLoading = true;
-        this.$http.get(QUESTION_API + "/course/" + query).then((response) => {
+        this.$http.get(CORE_API + "/course/" + query).then((response) => {
           var courseBean = response.data;
           this.courseList.push(courseBean);
         });