Browse Source

feat: 学校设置调试

zhangjie 2 months ago
parent
commit
8b61ea10a4

+ 12 - 20
src/modules/admin/components/school/SchoolSetAi.vue

@@ -60,12 +60,6 @@
         >
         </el-input>
       </el-form-item>
-
-      <el-form-item>
-        <el-button type="primary" :loading="loading" @click="confirm"
-          >保存</el-button
-        >
-      </el-form-item>
     </el-form>
   </div>
 </template>
@@ -177,20 +171,18 @@ export default {
 
       if (this.loading) return;
       this.loading = true;
-      try {
-        this.fields[0].value = JSON.stringify(this.formData);
-        await schoolSetAiUpdate({
-          param: this.fields,
-          schoolId: this.school.id,
-        });
-        this.cachedFormData = JSON.parse(JSON.stringify(this.formData));
-        this.$emit("config-changed", false);
-        this.$message.success("修改成功!");
-      } catch (error) {
-        this.$message.error(error.message || "保存失败");
-      } finally {
-        this.loading = false;
-      }
+
+      this.fields[0].value = JSON.stringify(this.formData);
+      const res = await schoolSetAiUpdate({
+        param: this.fields,
+        schoolId: this.school.id,
+      }).catch(() => {});
+      this.loading = false;
+      if (!res) return;
+
+      this.cachedFormData = JSON.parse(JSON.stringify(this.formData));
+      this.$emit("config-changed", false);
+      this.initData();
     },
   },
 };

+ 1 - 7
src/modules/admin/components/school/SchoolSetBase.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="school-set-base">
-    <div v-for="tab in tabs" :key="tab.val" class="part-box mb-4">
+    <div v-for="tab in tabs" :key="tab.val" class="part-box part-box-pad mb-4">
       <div class="part-title">{{ tab.name }}</div>
       <component
         :is="getCompName(tab.val)"
@@ -125,9 +125,3 @@ export default {
   },
 };
 </script>
-
-<style lang="scss" scoped>
-.school-set-base {
-  padding: 20px;
-}
-</style>

+ 8 - 18
src/modules/admin/components/school/SchoolSetCheck.vue

@@ -23,11 +23,6 @@
         >
         </el-input>
       </el-form-item>
-      <el-form-item>
-        <el-button type="primary" :loading="loading" @click="confirm"
-          >保存</el-button
-        >
-      </el-form-item>
     </el-form>
   </div>
 </template>
@@ -86,19 +81,14 @@ export default {
     async confirm() {
       if (this.loading) return;
       this.loading = true;
-      try {
-        await schoolSetCheckUpdate({
-          param: this.fields,
-          schoolId: this.school.id,
-        });
-        this.cachedFields = JSON.parse(JSON.stringify(this.fields));
-        this.$emit("config-changed", false);
-        this.$message.success("修改成功!");
-      } catch (error) {
-        this.$message.error(error.message || "保存失败");
-      } finally {
-        this.loading = false;
-      }
+      const datas = { param: this.fields, schoolId: this.school.id };
+      const res = await schoolSetCheckUpdate(datas).catch(() => {});
+      this.loading = false;
+      if (!res) return;
+
+      this.cachedFields = JSON.parse(JSON.stringify(this.fields));
+      this.$emit("config-changed", false);
+      this.initData();
     },
   },
 };

+ 17 - 20
src/modules/admin/components/school/SchoolSetPaper.vue

@@ -30,11 +30,6 @@
           </el-radio>
         </el-radio-group>
       </el-form-item>
-      <el-form-item>
-        <el-button type="primary" :loading="loading" @click="confirm"
-          >保存</el-button
-        >
-      </el-form-item>
     </el-form>
   </div>
 </template>
@@ -112,7 +107,11 @@ export default {
         item ? JSON.parse(item) : ""
       );
       const data = await schoolSetPaperInfo(this.school.id);
-      this.modalForm = data.result || { pdfSize: [], cardSize: "" };
+      this.paperInfo = data.result;
+      this.modalForm.pdfSize = data.result[0]?.value || [];
+      this.modalForm.cardSize = data.result[1]?.value
+        ? data.result[1].value[0]
+        : "";
       this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
     },
     checkConfigChanged() {
@@ -122,25 +121,23 @@ export default {
       );
     },
     async confirm() {
-      const valid = await this.$refs.modalFormComp.validate();
+      const valid = await this.$refs.modalFormComp.validate().catch(() => {});
       if (!valid) return;
 
       if (this.loading) return;
       this.loading = true;
 
-      try {
-        await schoolSetPaperUpdate({
-          ...this.modalForm,
-          schoolId: this.school.id,
-        });
-        this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
-        this.$emit("config-changed", false);
-        this.$message.success("修改成功!");
-      } catch (error) {
-        this.$message.error(error.message || "保存失败");
-      } finally {
-        this.loading = false;
-      }
+      this.paperInfo[0].value = this.modalForm.pdfSize;
+      this.paperInfo[1].value = [this.modalForm.cardSize];
+      let datas = { param: this.paperInfo, schoolId: this.school.id };
+      const res = await schoolSetPaperUpdate(datas).catch(() => {});
+      this.loading = false;
+
+      if (!res) return;
+
+      this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
+      this.$emit("config-changed", false);
+      this.initData();
     },
   },
 };

+ 10 - 19
src/modules/admin/components/school/SchoolSetRecognition.vue

@@ -6,11 +6,6 @@
           单选题有且仅有一个识别答案不进客观题检查
         </el-checkbox>
       </el-form-item>
-      <el-form-item>
-        <el-button type="primary" :loading="loading" @click="confirm"
-          >保存</el-button
-        >
-      </el-form-item>
     </el-form>
   </div>
 </template>
@@ -70,20 +65,16 @@ export default {
 
       if (this.loading) return;
       this.loading = true;
-      try {
-        const datas = {
-          enable: this.modalForm.avoidSingleChoice,
-          schoolId: this.school.id,
-        };
-        await schoolSetRecognitionUpdate(datas);
-        this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
-        this.$emit("config-changed", false);
-        this.$message.success("修改成功!");
-      } catch (error) {
-        this.$message.error(error.message || "保存失败");
-      } finally {
-        this.loading = false;
-      }
+      const datas = {
+        enable: this.modalForm.avoidSingleChoice,
+        schoolId: this.school.id,
+      };
+      const res = await schoolSetRecognitionUpdate(datas).catch(() => {});
+      this.loading = false;
+      if (!res) return;
+
+      this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
+      this.$emit("config-changed", false);
     },
   },
 };

+ 17 - 6
src/modules/admin/components/school/SchoolSetRobot.vue

@@ -23,11 +23,6 @@
         >
         </el-input>
       </el-form-item>
-      <el-form-item>
-        <el-button type="primary" :loading="loading" @click="confirm"
-          >保存</el-button
-        >
-      </el-form-item>
     </el-form>
   </div>
 </template>
@@ -50,9 +45,19 @@ export default {
     return {
       loading: false,
       fields: [],
+      cachedFields: null,
       OPEN_STATUS,
     };
   },
+  watch: {
+    fields: {
+      deep: true,
+      handler() {
+        const isChanged = this.checkConfigChanged();
+        this.$emit("config-changed", isChanged);
+      },
+    },
+  },
   mounted() {
     this.initData();
   },
@@ -67,6 +72,11 @@ export default {
         if (field.isBoolean && ["true", "false"].includes(field.value))
           field.value = field.value === "true";
       });
+      this.cachedFields = JSON.parse(JSON.stringify(this.fields));
+    },
+    checkConfigChanged() {
+      if (!this.cachedFields) return false;
+      return JSON.stringify(this.fields) !== JSON.stringify(this.cachedFields);
     },
     async confirm() {
       if (this.loading) return;
@@ -76,7 +86,8 @@ export default {
       this.loading = false;
       if (!res) return;
 
-      this.$message.success("修改成功!");
+      this.cachedFields = JSON.parse(JSON.stringify(this.fields));
+      this.$emit("config-changed", false);
       this.initData();
     },
   },

+ 12 - 19
src/modules/admin/components/school/SchoolSetRole.vue

@@ -17,11 +17,6 @@
           >
         </el-checkbox-group>
       </el-form-item>
-      <el-form-item>
-        <el-button type="primary" :loading="loading" @click="confirm"
-          >保存</el-button
-        >
-      </el-form-item>
     </el-form>
   </div>
 </template>
@@ -105,25 +100,23 @@ export default {
       );
     },
     async confirm() {
-      const valid = await this.$refs.modalFormComp.validate();
+      const valid = await this.$refs.modalFormComp.validate().catch(() => {});
       if (!valid) return;
 
       if (this.loading) return;
       this.loading = true;
 
-      try {
-        await schoolSetRoleUpdate({
-          roleIds: this.modalForm.roleIds,
-          schoolId: this.school.id,
-        });
-        this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
-        this.$emit("config-changed", false);
-        this.$message.success("修改成功!");
-      } catch (error) {
-        this.$message.error(error.message || "保存失败");
-      } finally {
-        this.loading = false;
-      }
+      let datas = {
+        roleIds: this.modalForm.roleIds,
+        schoolId: this.school.id,
+      };
+      const res = await schoolSetRoleUpdate(datas).catch(() => {});
+      this.loading = false;
+
+      if (!res) return;
+
+      this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
+      this.$emit("config-changed", false);
     },
   },
 };

+ 126 - 50
src/modules/admin/components/school/SchoolSetStdno.vue

@@ -82,11 +82,6 @@
           </el-form-item>
         </template>
       </template>
-      <el-form-item>
-        <el-button type="primary" :loading="loading" @click="confirm"
-          >保存</el-button
-        >
-      </el-form-item>
     </el-form>
 
     <!-- stdno view -->
@@ -98,6 +93,7 @@
 </template>
 
 <script>
+import { deepCopy } from "@/plugins/utils";
 import { schoolSetStdnoInfo, schoolSetStdnoUpdate } from "../../api";
 import HeadStdno from "../../../../../card/elements/card-head/cardHeadSpin/HeadStdno.vue";
 
@@ -150,15 +146,17 @@ export default {
           {
             required: true,
             validator: (rule, value, callback) => {
-              if (!value) {
-                return callback(new Error(`请输入使用字母`));
-              }
-              if (!/^[A-Z]+$/.test(value)) {
-                return callback(new Error(`请输入大写字母`));
+              if (!/^[A-Z]{1,10}$/.test(value)) {
+                return callback(new Error(`只能输入大写字母,长度不超过10`));
               }
-              if (value.length > 10) {
-                return callback(new Error(`最多输入10个字母`));
+
+              const chars = Array.from(new Set((value || "").split(""))).join(
+                ""
+              );
+              if (chars !== value) {
+                return callback(new Error(`大写字母不可重复`));
               }
+
               callback();
             },
             trigger: "change",
@@ -167,6 +165,16 @@ export default {
       },
     };
   },
+  computed: {
+    headStdnoData() {
+      return {
+        examNumberStyle: "FILL",
+        fillNumber: this.modalForm.digit,
+        containsLetter: this.modalForm.containsLetter,
+        relationList: this.modalForm.relationList,
+      };
+    },
+  },
   watch: {
     modalForm: {
       deep: true,
@@ -182,9 +190,37 @@ export default {
   methods: {
     async initData() {
       const data = await schoolSetStdnoInfo(this.school.id);
-      if (data && data.result) {
-        this.modalForm = data.result;
+      const config = data.result[0].value;
+      if (!config) {
+        this.modalForm = {
+          digit: 10,
+          containsLetter: false,
+          columns: [],
+          relationList: [],
+          columnChar: "",
+        };
+        this.updateCachedModalForm();
+        return;
+      }
+
+      this.modalForm = {
+        digit: config.digit || 10,
+        containsLetter: config.containsLetter,
+        columns: [],
+        relationList: config.relationList || [],
+        columnChar: "",
+      };
+      this.modalForm.columns = this.modalForm.relationList.map(
+        (item) => item.columnIndex
+      );
+      if (this.modalForm.columns.length) {
+        this.curSelectColumn = this.modalForm.columns[0];
+        this.selectColumnChange();
       }
+
+      this.updateCachedModalForm();
+    },
+    updateCachedModalForm() {
       this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
     },
     checkConfigChanged() {
@@ -193,54 +229,94 @@ export default {
         JSON.stringify(this.modalForm) !== JSON.stringify(this.cachedModalForm)
       );
     },
-    columnChange(val) {
-      this.modalForm.relationList = val.map((item) => ({
-        columnIndex: item,
-        letters: [],
-      }));
-      this.curSelectColumn = val[0] || -1;
-      this.curSelectColumnLetters = [];
-      this.modalForm.columnChar = "";
-    },
-    selectColumnChange(val) {
-      this.curSelectColumn = val;
-      const relation = this.modalForm.relationList.find(
-        (item) => item.columnIndex === val
+    columnChange() {
+      const relationList = this.modalForm.relationList || [];
+      const relationMap = {};
+      relationList.forEach((item) => {
+        relationMap[item.columnIndex] = item.letters;
+      });
+
+      this.modalForm.columns.sort((a, b) => a - b);
+
+      this.modalForm.relationList = this.modalForm.columns.map(
+        (columnIndex) => {
+          const letters = relationMap[columnIndex] || [];
+          return {
+            columnIndex,
+            letters,
+          };
+        }
       );
-      this.curSelectColumnLetters = relation ? relation.letters : [];
-      this.modalForm.columnChar = this.curSelectColumnLetters.join("");
+
+      if (
+        this.modalForm.columns.length &&
+        !this.modalForm.columns.includes(this.curSelectColumn)
+      ) {
+        this.curSelectColumn = this.modalForm.columns[0];
+        this.selectColumnChange();
+      }
     },
-    columnCharChange(val) {
-      if (!val) return;
-      const letters = val.split("");
-      const relation = this.modalForm.relationList.find(
+    selectColumnChange() {
+      const curRelation = this.modalForm.relationList.find(
         (item) => item.columnIndex === this.curSelectColumn
       );
-      if (relation) {
-        relation.letters = letters;
+      this.modalForm.columnChar = curRelation
+        ? curRelation.letters.join("")
+        : "";
+      this.curSelectColumnLetters = curRelation ? curRelation.letters : [];
+    },
+    validateField(field) {
+      return new Promise((resolve, reject) => {
+        this.$refs.modalFormComp.validateField(field, (unvalid) => {
+          if (unvalid) {
+            reject(false);
+          } else {
+            resolve(true);
+          }
+        });
+      });
+    },
+    async columnCharChange() {
+      const res = await this.validateField("columnChar").catch(() => {});
+      if (!res) {
+        this.curSelectColumnLetters = [];
+        return;
       }
-      this.curSelectColumnLetters = letters;
+
+      const curRelation = this.modalForm.relationList.find(
+        (item) => item.columnIndex === this.curSelectColumn
+      );
+      if (!curRelation) return;
+      curRelation.letters = this.modalForm.columnChar.split("");
+      this.curSelectColumnLetters = curRelation.letters;
     },
     async confirm() {
-      const valid = await this.$refs.modalFormComp.validate();
+      const valid = await this.$refs.modalFormComp.validate().catch(() => {});
       if (!valid) return;
 
       if (this.loading) return;
       this.loading = true;
 
-      try {
-        await schoolSetStdnoUpdate({
-          ...this.modalForm,
-          schoolId: this.school.id,
-        });
-        this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
-        this.$emit("config-changed", false);
-        this.$message.success("修改成功!");
-      } catch (error) {
-        this.$message.error(error.message || "保存失败");
-      } finally {
-        this.loading = false;
-      }
+      const val = {
+        digit: this.modalForm.digit,
+        containsLetter: this.modalForm.containsLetter,
+        relationList: this.modalForm.containsLetter
+          ? this.modalForm.relationList
+          : [],
+      };
+
+      const datas = deepCopy(this.stdnoInfo);
+      datas[0].value = val;
+      const res = await schoolSetStdnoUpdate({
+        param: datas,
+        schoolId: this.school.id,
+      }).catch(() => {});
+      this.loading = false;
+
+      if (!res) return;
+      this.updateCachedModalForm();
+      this.$emit("config-changed", false);
+      this.initData();
     },
   },
 };

+ 9 - 16
src/modules/admin/components/school/SchoolSetTarget.vue

@@ -25,11 +25,6 @@
           <i class="el-icon-document mr-1"></i>课程目标达成度模板.doc
         </span>
       </el-form-item>
-      <el-form-item>
-        <el-button type="primary" :loading="loading" @click="confirm"
-          >保存</el-button
-        >
-      </el-form-item>
     </el-form>
   </div>
 </template>
@@ -120,17 +115,15 @@ export default {
 
       if (this.loading) return;
       this.loading = true;
-      try {
-        await schoolSetCourseTargetSave(this.modalForm);
-        this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
-        this.$emit("config-changed", false);
-        this.$message.success("修改成功!");
-        this.initData();
-      } catch (error) {
-        this.$message.error(error.message || "保存失败");
-      } finally {
-        this.loading = false;
-      }
+      const res = await schoolSetCourseTargetSave(this.modalForm).catch(
+        () => {}
+      );
+      this.loading = false;
+      if (!res) return;
+
+      this.cachedModalForm = JSON.parse(JSON.stringify(this.modalForm));
+      this.$emit("config-changed", false);
+      this.initData();
     },
   },
 };