BuildPaper.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="build-paper">
  3. <div class="part-box">
  4. <div class="part-box-header">
  5. <div class="part-box-header-left">
  6. <h1 class="part-box-title">组卷</h1>
  7. <span>课程代码:{{ modalForm.courseCode }}</span>
  8. <span>课程名称:{{ modalForm.courseName }}</span>
  9. </div>
  10. <div>
  11. <el-button
  12. type="primary"
  13. size="small"
  14. icon="icon icon-save-white"
  15. @click="confirm"
  16. >确定</el-button
  17. >
  18. <el-button
  19. type="danger"
  20. size="small"
  21. plain
  22. icon="icon icon-back"
  23. @click="toback"
  24. >返回</el-button
  25. >
  26. </div>
  27. </div>
  28. <el-form
  29. ref="modalFormComp"
  30. class="part-filter-form"
  31. :model="modalForm"
  32. :rules="rules"
  33. inline
  34. >
  35. <el-form-item prop="paperName" label="试卷名称">
  36. <el-input
  37. v-model="modalForm.paperName"
  38. placeholder="试卷名称"
  39. ></el-input>
  40. </el-form-item>
  41. <el-form-item v-if="!IS_MANUAL_MODE" prop="paperCount" label="组卷套数">
  42. <el-input-number
  43. v-model="modalForm.paperCount"
  44. :min="1"
  45. :max="20"
  46. :step="1"
  47. step-strictly
  48. ></el-input-number>
  49. </el-form-item>
  50. <el-form-item v-if="!IS_MANUAL_MODE" style="border: none">
  51. <el-checkbox v-model="modalForm.checkRepeat"
  52. >校验试卷重复率</el-checkbox
  53. >
  54. </el-form-item>
  55. <el-form-item v-else></el-form-item>
  56. </el-form>
  57. <el-form>
  58. <template v-if="modalForm.checkRepeat && !IS_MANUAL_MODE">
  59. <el-form-item
  60. label="校验重复率的试卷范围:"
  61. label-width="180px"
  62. style="margin-bottom: 10px"
  63. >
  64. <el-radio-group v-model="modalForm.storage" size="small">
  65. <el-radio-button :label="false">卷库列表试卷</el-radio-button>
  66. <el-radio-button :label="true">试卷仓库试卷</el-radio-button>
  67. </el-radio-group>
  68. </el-form-item>
  69. <el-form-item
  70. label="试卷间重复率不高于:"
  71. label-width="180px"
  72. style="margin-bottom: 10px"
  73. >
  74. <el-input-number
  75. v-model="modalForm.maxLimit"
  76. style="width: 125px"
  77. :min="0"
  78. :max="100"
  79. :step="1"
  80. step-strictly
  81. :controls="false"
  82. ></el-input-number>
  83. %
  84. <el-checkbox v-model="modalForm.topicOnly"
  85. >本次组的试卷间不允许重复</el-checkbox
  86. >
  87. <p class="tips-info">注:试卷间的重复率会小于等于设定值</p>
  88. </el-form-item>
  89. <el-form-item
  90. label="试卷重复率校验时间周期:"
  91. label-width="180px"
  92. style="margin-bottom: 10px"
  93. >
  94. <el-input-number
  95. v-model="modalForm.timeLimit"
  96. style="width: 125px"
  97. :min="1"
  98. :max="100"
  99. :step="1"
  100. step-strictly
  101. :controls="false"
  102. ></el-input-number>
  103. 个月
  104. <p class="tips-info">注:月份按照自然月计数,当前月份记为第1个月</p>
  105. </el-form-item>
  106. </template>
  107. <el-form-item label="组卷模式" style="margin: 0">
  108. <el-radio-group v-model="genModelType" style="padding-left: 15px">
  109. <el-radio
  110. v-for="item in modelTypes"
  111. :key="item.code"
  112. :label="item.code"
  113. >{{ item.name }}</el-radio
  114. >
  115. </el-radio-group>
  116. </el-form-item>
  117. </el-form>
  118. <div v-if="IS_AUTO_MODE" style="text-align: right">
  119. <el-checkbox v-model="isSaveStructInfo" style="margin-right: 10px"
  120. >同时保存为试卷结构模板</el-checkbox
  121. >
  122. <el-button type="success" size="small" @click="toSelectStruct"
  123. >选择试卷结构</el-button
  124. >
  125. </div>
  126. </div>
  127. <div class="part-box">
  128. <component
  129. :is="buildCompName"
  130. ref="BuildPaperDetail"
  131. :course-id="modalForm.courseId"
  132. ></component>
  133. </div>
  134. <!-- AutoBuildPaperStructManage -->
  135. <auto-build-paper-struct-manage
  136. v-if="IS_AUTO_MODE"
  137. ref="AutoBuildPaperStructManage"
  138. :course-id="modalForm.courseId"
  139. @selected="structSelected"
  140. ></auto-build-paper-struct-manage>
  141. </div>
  142. </template>
  143. <script>
  144. import BuildPaperAuto from "../components/BuildPaperAuto.vue";
  145. import BuildPaperManual from "../components/BuildPaperManual.vue";
  146. import BuildPaperSimple from "../components/BuildPaperSimple.vue";
  147. import AutoBuildPaperStructManage from "../components/AutoBuildPaperStructManage.vue";
  148. import { buildPaperApi, autoBuildPaperStructSaveApi } from "../api";
  149. import { deepCopy, randomCode } from "@/plugins/utils";
  150. const initModalForm = {
  151. courseId: "",
  152. courseCode: "",
  153. courseName: "",
  154. paperName: "",
  155. paperCount: 1,
  156. checkRepeat: false,
  157. storage: false,
  158. maxLimit: 0,
  159. topicOnly: false,
  160. timeLimit: 1,
  161. };
  162. export default {
  163. name: "BuildPaper",
  164. components: {
  165. BuildPaperAuto,
  166. BuildPaperManual,
  167. BuildPaperSimple,
  168. AutoBuildPaperStructManage,
  169. },
  170. data() {
  171. return {
  172. loading: false,
  173. modalForm: {
  174. ...initModalForm,
  175. },
  176. rules: {
  177. paperName: [
  178. {
  179. required: true,
  180. message: "请输入试卷名称",
  181. trigger: "change",
  182. },
  183. {
  184. max: 100,
  185. message: "试卷名称不能超过100个字",
  186. trigger: "change",
  187. },
  188. ],
  189. paperCount: [
  190. {
  191. required: true,
  192. message: "请输入组卷套数",
  193. trigger: "change",
  194. },
  195. ],
  196. },
  197. genModelType: "simple",
  198. modelTypes: [
  199. {
  200. code: "simple",
  201. name: "简易成卷",
  202. },
  203. {
  204. code: "auto",
  205. name: "自动成卷",
  206. },
  207. {
  208. code: "manual",
  209. name: "手动组卷",
  210. },
  211. ],
  212. isSaveStructInfo: false,
  213. };
  214. },
  215. computed: {
  216. buildCompName() {
  217. return `build-paper-${this.genModelType}`;
  218. },
  219. IS_MANUAL_MODE() {
  220. return this.genModelType === "manual";
  221. },
  222. IS_AUTO_MODE() {
  223. return this.genModelType === "auto";
  224. },
  225. },
  226. created() {
  227. let genPaperInfo = sessionStorage.getItem("gen_paper");
  228. genPaperInfo = genPaperInfo ? JSON.parse(genPaperInfo) : {};
  229. this.modalForm.courseCode = genPaperInfo.courseCode;
  230. this.modalForm.courseName = genPaperInfo.courseName;
  231. this.modalForm.courseId = genPaperInfo.courseId;
  232. },
  233. methods: {
  234. toSelectStruct() {
  235. this.$refs.AutoBuildPaperStructManage.open();
  236. },
  237. structSelected(row) {
  238. let details = deepCopy(row.structInfo);
  239. details.forEach((detail) => {
  240. detail.id = randomCode();
  241. });
  242. this.$refs.BuildPaperDetail.setDetails(details);
  243. },
  244. async confirm() {
  245. let valid = await this.$refs.modalFormComp.validate().catch(() => {});
  246. if (!valid) return;
  247. valid = await this.$refs.BuildPaperDetail.validate().catch(() => {});
  248. if (!valid) return;
  249. if (this.loading) return;
  250. this.loading = true;
  251. let questionInfo = this.$refs.BuildPaperDetail.getData();
  252. if (this.IS_AUTO_MODE && this.isSaveStructInfo) {
  253. // console.log(questionInfo.detailInfo);
  254. // if (questionInfo.detailInfo) return;
  255. this.saveAutoBuildPaperStruct(questionInfo.detailInfo);
  256. }
  257. const datas = {
  258. ...this.modalForm,
  259. ...questionInfo,
  260. };
  261. const res = await buildPaperApi(datas, this.genModelType).catch(() => {});
  262. this.loading = false;
  263. if (!res) return;
  264. this.$message.success("组卷成功!");
  265. this.toback();
  266. },
  267. async saveAutoBuildPaperStruct(structInfo) {
  268. await autoBuildPaperStructSaveApi({
  269. structName: `${this.modalForm.courseName}-${this.modalForm.courseCode}-${this.modalForm.paperName}`,
  270. structInfo: JSON.stringify(structInfo),
  271. courseId: this.modalForm.courseId,
  272. });
  273. },
  274. toback() {
  275. window.history.go(-1);
  276. },
  277. },
  278. };
  279. </script>