Sfoglia il codice sorgente

修改答案选择的方式为下拉框,处理相应逻辑

huangtao 4 anni fa
parent
commit
6d238e5fcf

+ 1 - 0
src/styles/common/index.less

@@ -32,6 +32,7 @@
 .exam-question-create-body {
   width: 100%;
   height: 100%;
+  padding-top: 40px !important;
   overflow-y: auto;
   display: flex;
   justify-content: center;

+ 20 - 5
src/views/examQuestionManagement/examQusetionCreateGapFilling.vue

@@ -26,9 +26,9 @@
             />
           </a-form-item>
           <div class="question-option">
-            <span class="question-option-title">题目选项:</span>
+            <span class="question-option-title">正确答案:</span>
             <span class="question-option-add" @click="questionOptionAddFun"
-              >新增选项</span
+              >新增填空</span
             >
           </div>
           <div
@@ -51,7 +51,7 @@
                 placeholder="填空需与题目一一对应"
                 :maxLength="200"
                 v-decorator="[
-                  `answers${index}`,
+                  `answers-${index}`,
                   {
                     rules: [
                       { required: true, message: 'Please input content!' },
@@ -173,14 +173,29 @@ export default {
       e.preventDefault();
       this.loginForm.validateFields((err, values) => {
         if (!err) {
+          console.log(values);
           let params = {
-            ...values,
+            type: this.questionType,
+            content: values.content,
+            engineeringWorkChooseValue: values.engineeringWorkChooseValue,
+            studyDate: this.studyDate,
+            finalAnswer: this.formatQuestionAnswersArr(values),
+            answers: [],
           };
-          params.studyDate = this.studyDate;
           this.httpQuestFun(params);
         }
       });
     },
+    // 把答案放入一个数组中
+    formatQuestionAnswersArr(values) {
+      let arr = [];
+      for (let key in values) {
+        if (key.includes('answers-')) {
+          arr.push(values[key]);
+        }
+      }
+      return arr;
+    },
     // 表单提交请求
     httpQuestFun(params) {
       this.loading = true;

+ 51 - 5
src/views/examQuestionManagement/examQusetionCreateMultiple.vue

@@ -51,7 +51,7 @@
                 placeholder="选项内容"
                 :maxLength="200"
                 v-decorator="[
-                  `answers${index}`,
+                  `answers-${index}`,
                   {
                     rules: [
                       { required: true, message: 'Please input content!' },
@@ -66,7 +66,7 @@
             :label-col="labelCol"
             :wrapper-col="wrapperCol"
           >
-            <a-input
+            <!-- <a-input
               placeholder="答案格式为大写字母"
               :maxLength="200"
               v-decorator="[
@@ -75,7 +75,24 @@
                   rules: [{ required: true, message: 'Please input content!' }],
                 },
               ]"
-            />
+            /> -->
+            <a-select
+              mode="multiple"
+              v-decorator="[
+                'finalAnswerIndexs',
+                {
+                  rules: [{ required: true, message: 'Please input content!' }],
+                },
+              ]"
+            >
+              <a-select-option
+                v-for="(item, index) in optionsList"
+                :key="index"
+                :value="index"
+              >
+                {{ index | formatQuestionIndex }}
+              </a-select-option>
+            </a-select>
           </a-form-item>
           <a-form-item
             label="必学日期"
@@ -132,6 +149,7 @@
 
 <script>
 import { ENGINEERING_WORK_LIST } from '@/common/Constant';
+import { formatQuestionIndex } from '@/filters';
 export default {
   name: 'examQusetionCreateMultiple',
   props: {},
@@ -176,6 +194,10 @@ export default {
     questionOptionDeleteFun(index) {
       this.optionsList.splice(index, 1);
     },
+    // 操作:选择答案
+    handleChange(values) {
+      console.log(values);
+    },
     // 操作:选择日期
     onDateChange(date, dateString) {
       if (date) {
@@ -190,13 +212,37 @@ export default {
       this.loginForm.validateFields((err, values) => {
         if (!err) {
           let params = {
-            ...values,
+            type: this.questionType,
+            content: values.content,
+            engineeringWorkChooseValue: values.engineeringWorkChooseValue,
+            studyDate: this.studyDate,
+            finalAnswer: this.formatQuestionFinalAnswerArr(
+              values.finalAnswerIndexs
+            ),
+            answers: this.formatQuestionAnswersArr(values),
           };
-          params.studyDate = this.studyDate;
           this.httpQuestFun(params);
         }
       });
     },
+    // 把答案下标转换为大写英文字母放入一个数组中
+    formatQuestionFinalAnswerArr(indexs) {
+      let arr = '';
+      indexs.forEach((item) => {
+        arr += formatQuestionIndex(item);
+      });
+      return [arr];
+    },
+    // 把选项放入一个数组中
+    formatQuestionAnswersArr(values) {
+      let arr = [];
+      for (let key in values) {
+        if (key.includes('answers-')) {
+          arr.push(values[key]);
+        }
+      }
+      return arr;
+    },
     // 表单提交请求
     httpQuestFun(params) {
       this.loading = true;

+ 41 - 9
src/views/examQuestionManagement/examQusetionCreateSingle.vue

@@ -51,7 +51,7 @@
                 placeholder="选项内容"
                 :maxLength="200"
                 v-decorator="[
-                  `answers${index}`,
+                  `answers-${index}`,
                   {
                     rules: [
                       { required: true, message: 'Please input content!' },
@@ -66,16 +66,26 @@
             :label-col="labelCol"
             :wrapper-col="wrapperCol"
           >
-            <a-input
-              placeholder="答案格式为大写字母"
-              :maxLength="200"
+            <a-select
+              placeholder="请选择值"
               v-decorator="[
-                'finalAnswer',
+                'finalAnswerIndexs',
                 {
-                  rules: [{ required: true, message: 'Please input content!' }],
+                  rules: [
+                    { required: true, message: 'Please selete finalAnswer!' },
+                  ],
+                  initialValue: engineeringWorkChooseValue,
                 },
               ]"
-            />
+            >
+              <a-select-option
+                :value="index"
+                v-for="(item, index) in optionsList"
+                :key="index"
+              >
+                {{ index | formatQuestionIndex }}
+              </a-select-option>
+            </a-select>
           </a-form-item>
           <a-form-item
             label="必学日期:"
@@ -132,6 +142,7 @@
 
 <script>
 import { ENGINEERING_WORK_LIST } from '@/common/Constant';
+import { formatQuestionIndex } from '@/filters';
 export default {
   name: 'examQusetionCreateSingle',
   props: {},
@@ -190,13 +201,34 @@ export default {
       this.loginForm.validateFields((err, values) => {
         if (!err) {
           let params = {
-            ...values,
+            type: this.questionType,
+            content: values.content,
+            engineeringWorkChooseValue: values.engineeringWorkChooseValue,
+            studyDate: this.studyDate,
+            finalAnswer: this.formatQuestionFinalAnswerArr(
+              values.finalAnswerIndexs
+            ),
+            answers: this.formatQuestionAnswersArr(values),
           };
-          params.studyDate = this.studyDate;
           this.httpQuestFun(params);
         }
       });
     },
+    // 把答案下标转换为大写英文字母放入一个数组中
+    formatQuestionFinalAnswerArr(index) {
+      let arr = [formatQuestionIndex(index)];
+      return arr;
+    },
+    // 把选项放入一个数组中
+    formatQuestionAnswersArr(values) {
+      let arr = [];
+      for (let key in values) {
+        if (key.includes('answers-')) {
+          arr.push(values[key]);
+        }
+      }
+      return arr;
+    },
     // 表单提交请求
     httpQuestFun(params) {
       this.loading = true;

+ 49 - 9
src/views/examQuestionManagement/examQusetionCreateTrueOrFalse.vue

@@ -45,10 +45,18 @@
               :wrapper-col="wrapperCol"
             >
               <a-input
-                v-model="item.value"
                 placeholder="选项内容"
                 disabled
                 :maxLength="200"
+                v-decorator="[
+                  `answers-${index}`,
+                  {
+                    rules: [
+                      { required: true, message: 'Please input content!' },
+                    ],
+                    initialValue: item.value,
+                  },
+                ]"
               />
             </a-form-item>
           </div>
@@ -57,16 +65,26 @@
             :label-col="labelCol"
             :wrapper-col="wrapperCol"
           >
-            <a-input
-              placeholder="答案格式为大写字母"
-              :maxLength="200"
+            <a-select
+              placeholder="请选择值"
               v-decorator="[
-                'finalAnswer',
+                'finalAnswerIndexs',
                 {
-                  rules: [{ required: true, message: 'Please input content!' }],
+                  rules: [
+                    { required: true, message: 'Please selete finalAnswer!' },
+                  ],
+                  initialValue: engineeringWorkChooseValue,
                 },
               ]"
-            />
+            >
+              <a-select-option
+                :value="index"
+                v-for="(item, index) in optionsList"
+                :key="index"
+              >
+                {{ index | formatQuestionIndex }}
+              </a-select-option>
+            </a-select>
           </a-form-item>
           <a-form-item
             label="必学日期"
@@ -123,6 +141,7 @@
 
 <script>
 import { ENGINEERING_WORK_LIST } from '@/common/Constant';
+import { formatQuestionIndex } from '@/filters';
 export default {
   name: 'examQusetionCreateTrueOrFalse',
   props: {},
@@ -177,13 +196,34 @@ export default {
       this.loginForm.validateFields((err, values) => {
         if (!err) {
           let params = {
-            ...values,
+            type: this.questionType,
+            content: values.content,
+            engineeringWorkChooseValue: values.engineeringWorkChooseValue,
+            studyDate: this.studyDate,
+            finalAnswer: this.formatQuestionFinalAnswerArr(
+              values.finalAnswerIndexs
+            ),
+            answers: this.formatQuestionAnswersArr(values),
           };
-          params.studyDate = this.studyDate;
           this.httpQuestFun(params);
         }
       });
     },
+    // 把答案下标转换为大写英文字母放入一个数组中
+    formatQuestionFinalAnswerArr(index) {
+      let arr = [formatQuestionIndex(index)];
+      return arr;
+    },
+    // 把选项放入一个数组中
+    formatQuestionAnswersArr(values) {
+      let arr = [];
+      for (let key in values) {
+        if (key.includes('answers-')) {
+          arr.push(values[key]);
+        }
+      }
+      return arr;
+    },
     // 表单提交请求
     httpQuestFun(params) {
       this.loading = true;