SchoolSetBase.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="school-set-base">
  3. <div v-for="tab in tabs" :key="tab.val" class="part-box mb-4">
  4. <div class="part-title">{{ tab.name }}</div>
  5. <component
  6. :is="getCompName(tab.val)"
  7. :school="school"
  8. :ref="tab.val"
  9. @config-changed="(isChanged) => handleConfigChanged(tab.val, isChanged)"
  10. ></component>
  11. </div>
  12. <div class="text-center mt-4">
  13. <el-button type="primary" @click="submit" :loading="loading"
  14. >保存</el-button
  15. >
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import SchoolSetCheck from "./SchoolSetCheck.vue";
  21. import SchoolSetStdno from "./SchoolSetStdno.vue";
  22. import SchoolSetRole from "./SchoolSetRole.vue";
  23. import SchoolSetPaper from "./SchoolSetPaper.vue";
  24. import SchoolSetTarget from "./SchoolSetTarget.vue";
  25. import SchoolSetRecognition from "./SchoolSetRecognition.vue";
  26. import SchoolSetRobot from "./SchoolSetRobot.vue";
  27. import SchoolSetAi from "./SchoolSetAi.vue";
  28. export default {
  29. name: "school-set-base",
  30. components: {
  31. SchoolSetCheck,
  32. SchoolSetStdno,
  33. SchoolSetRole,
  34. SchoolSetPaper,
  35. SchoolSetTarget,
  36. SchoolSetRecognition,
  37. SchoolSetRobot,
  38. SchoolSetAi,
  39. },
  40. props: {
  41. school: {
  42. type: Object,
  43. default() {
  44. return {};
  45. },
  46. },
  47. },
  48. data() {
  49. return {
  50. loading: false,
  51. tabs: [
  52. {
  53. name: "用户验证配置",
  54. val: "check",
  55. },
  56. {
  57. name: "学号配置",
  58. val: "stdno",
  59. },
  60. {
  61. name: "角色管理",
  62. val: "role",
  63. },
  64. {
  65. name: "试卷规格配置",
  66. val: "paper",
  67. },
  68. {
  69. name: "课程目标",
  70. val: "target",
  71. },
  72. {
  73. name: "识别配置",
  74. val: "recognition",
  75. },
  76. {
  77. name: "机器人配置",
  78. val: "robot",
  79. },
  80. {
  81. name: "AI智能评卷",
  82. val: "ai",
  83. },
  84. ],
  85. // 记录各个组件的配置是否有变更
  86. configChangedMap: {},
  87. };
  88. },
  89. methods: {
  90. getCompName(val) {
  91. const map = {
  92. check: "SchoolSetCheck",
  93. stdno: "SchoolSetStdno",
  94. role: "SchoolSetRole",
  95. paper: "SchoolSetPaper",
  96. target: "SchoolSetTarget",
  97. recognition: "SchoolSetRecognition",
  98. robot: "SchoolSetRobot",
  99. ai: "SchoolSetAi",
  100. };
  101. return map[val];
  102. },
  103. handleConfigChanged(val, isChanged) {
  104. this.$set(this.configChangedMap, val, isChanged);
  105. },
  106. async submit() {
  107. if (this.loading) return;
  108. this.loading = true;
  109. try {
  110. const promises = Object.keys(this.configChangedMap)
  111. .filter((key) => this.configChangedMap[key])
  112. .map((key) => this.$refs[key][0].confirm());
  113. await Promise.all(promises);
  114. this.$message.success("保存成功");
  115. this.configChangedMap = {};
  116. } catch (error) {
  117. this.$message.error(error.message || "保存失败");
  118. } finally {
  119. this.loading = false;
  120. }
  121. },
  122. },
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .school-set-base {
  127. padding: 20px;
  128. }
  129. </style>