Michael Wang il y a 4 ans
Parent
commit
8065361636

+ 51 - 2
src/api/examwork-course.js

@@ -3,6 +3,7 @@ import { pickBy } from "lodash-es";
 import { object2QueryString } from "@/utils/utils";
 
 export function searchCourses({
+  id = "",
   examId = "",
   code = "",
   hasPaper = "",
@@ -10,11 +11,59 @@ export function searchCourses({
   pageSize = 10,
 }) {
   const data = pickBy(
-    { examId, code, hasPaper, pageNumber, pageSize },
+    { id, examId, code, hasPaper, pageNumber, pageSize },
     (v) => v !== ""
   );
-  if (data.examId)
+  if (data.examId || data.id)
     return httpApp.post(
       "/api/admin/exam/course/query?" + object2QueryString(data)
     );
 }
+
+export function searchPapers({ examId = "", courseCode = "" }) {
+  const data = pickBy({ examId, courseCode }, (v) => v !== "");
+  return httpApp.post(
+    "/api/admin/exam/paper/query?" + object2QueryString(data)
+  );
+}
+
+export function saveCourse({
+  examId = "",
+  courseCode = "",
+  objectiveShuffle = "",
+  optionShuffle = "",
+}) {
+  const data = pickBy(
+    {
+      examId,
+      courseCode,
+      objectiveShuffle,
+      optionShuffle,
+    },
+    (v) => v !== ""
+  );
+  return httpApp.post("/api/admin/exam/course/save", data);
+}
+
+export function savePaper({ id = "", weight = "", audioPlayCount = "" }) {
+  const data = pickBy(
+    {
+      id,
+      weight,
+      audioPlayCount,
+    },
+    (v) => v !== ""
+  );
+  return httpApp.post("/api/admin/exam/paper/save", data);
+}
+
+/**
+ *
+ * @param {Object[]} papers
+ * @param {String} papers.id
+ * @param {Number} papers.weight
+ * @param {Number} papers.audioPlayCount
+ */
+export function savePapers(papers) {
+  return httpApp.post("/api/admin/exam/paper/save", papers);
+}

+ 12 - 4
src/features/examwork/CourseManagement/CourseManagement.vue

@@ -79,17 +79,25 @@
       :examId="form.examId"
       @reload="searchForm"
     />
+
+    <CoursePaperDialog
+      ref="theDialog2"
+      :course="selectedCourse"
+      @reload="searchForm"
+    />
   </div>
 </template>
 
 <script>
 import { searchCourses } from "@/api/examwork-course";
 import PaperImportDialog from "./PaperImportDialog";
+import CoursePaperDialog from "./CoursePaperDialog";
 
 export default {
   name: "CourseManagement",
   components: {
     PaperImportDialog,
+    CoursePaperDialog,
   },
   computed: {},
   data() {
@@ -106,7 +114,7 @@ export default {
       currentPage: 1,
       pageSize: 10,
       total: 10,
-      selectedActivity: {},
+      selectedCourse: {},
     };
   },
   async created() {},
@@ -148,9 +156,9 @@ export default {
       }
       this.$refs.theDialog.openDialog();
     },
-    edit(activity) {
-      this.selectedActivity = activity;
-      this.$refs.theDialog.openDialog();
+    edit(course) {
+      this.selectedCourse = course;
+      this.$refs.theDialog2.openDialog();
     },
   },
 };

+ 173 - 0
src/features/examwork/CourseManagement/CoursePaperDialog.vue

@@ -0,0 +1,173 @@
+<template>
+  <el-dialog
+    ref="dialog"
+    title="导入试卷"
+    width="800px"
+    :visible.sync="visible"
+    @close="closeDialog"
+  >
+    <el-form
+      :model="form"
+      ref="form"
+      :rules="rules"
+      label-position="right"
+      label-width="120px"
+      inline
+    >
+      <el-row>
+        <el-form-item label="批次名称">
+          <ExamSelect v-model="course.examId" disabled />
+        </el-form-item>
+        <el-form-item label="科目名称">
+          <CourseSelect
+            :examId="course.examId"
+            v-model="course.courseCode"
+            disabled
+          />
+        </el-form-item>
+      </el-row>
+      <el-row>
+        <el-table :data="papers" stripe style="width: 100%;">
+          <el-table-column width="42" />
+          <el-table-column width="100" label="ID">
+            <span slot-scope="scope">{{ scope.row.id }}</span>
+          </el-table-column>
+          <el-table-column label="试卷名称">
+            <span slot-scope="scope">{{ scope.row.name }}</span>
+          </el-table-column>
+          <el-table-column width="100" label="分值">
+            <span slot-scope="scope">{{ scope.row.totalScore }}</span>
+          </el-table-column>
+          <el-table-column width="170" label="抽卷几率">
+            <span slot-scope="scope">
+              <el-input-number v-model.trim="scope.row.weight">
+                <template slot="append">%</template></el-input-number
+              >
+            </span>
+          </el-table-column>
+          <el-table-column width="170" label="音频播放次数">
+            <span slot-scope="scope">
+              <el-input-number
+                v-model.trim="scope.row.audioPlayCount"
+              ></el-input-number>
+            </span>
+          </el-table-column>
+        </el-table>
+      </el-row>
+      <el-row>
+        <el-form-item label="客观题小题乱序" prop="objectiveShuffle">
+          <el-radio-group
+            class="pull_right_sm"
+            v-model="refreshCourse.objectiveShuffle"
+          >
+            <el-radio :label="1">启用</el-radio>
+            <el-radio :label="0">禁用</el-radio>
+          </el-radio-group>
+        </el-form-item>
+      </el-row>
+      <el-row>
+        <el-form-item label="客观题选项乱序" prop="optionShuffle">
+          <el-radio-group
+            class="pull_right_sm"
+            v-model="refreshCourse.optionShuffle"
+          >
+            <el-radio :label="1">启用</el-radio>
+            <el-radio :label="0">禁用</el-radio>
+          </el-radio-group>
+        </el-form-item>
+      </el-row>
+      <el-row class="d-flex justify-content-center">
+        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button @click="closeDialog">取 消</el-button>
+      </el-row>
+    </el-form>
+  </el-dialog>
+</template>
+
+<script>
+import {
+  searchCourses,
+  searchPapers,
+  saveCourse,
+  savePapers,
+} from "@/api/examwork-course";
+
+export default {
+  name: "CoursePaperDialog",
+  props: {
+    course: Object,
+  },
+  data() {
+    return {
+      visible: false,
+      form: {},
+      rules: {},
+      refreshCourse: {},
+      papers: [],
+    };
+  },
+  watch: {
+    course: {
+      immediate: true,
+      handler() {
+        this.refreshCourse = {};
+        this.papers = [];
+        this.initData();
+      },
+    },
+  },
+  methods: {
+    async initData() {
+      if (!this.course?.examId) return;
+      const courseRes = await searchCourses({
+        id: this.course.id,
+        examId: this.course.examId,
+        pageNumber: 1,
+        pageSize: 1,
+      });
+      this.refreshCourse = courseRes?.data.data.records.records[0];
+
+      const res = await searchPapers({
+        examId: this.refreshCourse.examId,
+        courseCode: this.refreshCourse.courseCode,
+        pageNumber: this.currentPage,
+        pageSize: this.pageSize,
+      });
+      this.papers = res?.data.data.records;
+    },
+    openDialog() {
+      this.visible = true;
+    },
+    closeDialog() {
+      this.visible = false;
+    },
+    async submitForm() {
+      try {
+        await saveCourse({
+          examId: this.refreshCourse.examId,
+          courseCode: this.refreshCourse.courseCode,
+          objectiveShuffle: this.refreshCourse.objectiveShuffle,
+          optionShuffle: this.refreshCourse.optionShuffle,
+        });
+        const ps = [];
+        for (const paper of this.papers) {
+          ps.push({
+            id: paper.id,
+            weight: paper.weight,
+            audioPlayCount: paper.audioPlayCount,
+          });
+        }
+        await savePapers(ps);
+        this.$emit("reload");
+        this.$notify({ title: "保存成功", type: "success" });
+        this.closeDialog();
+      } catch (error) {
+        this.initData();
+        this.$notify({ title: "保存失败", type: "warning" });
+      }
+    },
+  },
+};
+</script>
+
+<style></style>