MarkPaperGroup.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <div class="mark-paper-marker">
  3. <div class="marker-header">
  4. <p
  5. class="marker-desc color-danger"
  6. v-if="subjectiveQuestionCount > groupQuestionCount"
  7. >
  8. 本试卷共<span class="mlr-1">{{ questionCount }}</span
  9. >道小题,客观题<span class="mlr-1">{{ objectiveQuestionCount }}</span
  10. >道,主观题<span class="mlr-1">{{ subjectiveQuestionCount }}</span
  11. >道,已经设置<span class="mlr-1">{{ groupQuestionCount }}</span
  12. >道主观题,还有<span class="mlr-1">{{
  13. subjectiveQuestionCount - groupQuestionCount
  14. }}</span
  15. >道主观题未设置分组,请继续设置,确保全部主观题均已设置分组!
  16. </p>
  17. <p class="marker-desc color-success" v-else>
  18. 本试卷共<span class="mlr-1">{{ questionCount }}</span
  19. >道小题,客观题<span class="mlr-1">{{ objectiveQuestionCount }}</span
  20. >道,主观题<span class="mlr-1">{{ subjectiveQuestionCount }}</span
  21. >道,主观题已全部设置分组!
  22. </p>
  23. <el-button type="primary" @click="toAdd">新增</el-button>
  24. </div>
  25. <el-table :data="groupInfo" border>
  26. <el-table-column type="index" width="50"> </el-table-column>
  27. <el-table-column label="评卷方式">
  28. <template slot-scope="scope">
  29. <el-radio-group v-model="scope.row.doubleRate">
  30. <el-radio
  31. v-for="(val, key) in MARK_TYPE"
  32. :key="key"
  33. :label="key * 1"
  34. >{{ val }}</el-radio
  35. >
  36. </el-radio-group>
  37. <span v-if="scope.row.doubleRate === 1">
  38. 仲裁阀值:<el-input-number
  39. v-model="scope.row.arbitrateThreshold"
  40. class="width-80"
  41. size="small"
  42. :min="0"
  43. :max="999999"
  44. :step="0.01"
  45. step-strictly
  46. :controls="false"
  47. >
  48. </el-input-number>
  49. </span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="评阅题目">
  53. <template slot-scope="scope">
  54. {{ scope.row.questions | questionsFilter }}
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="评卷区" width="80" align="center">
  58. <template slot-scope="scope">
  59. <i
  60. v-if="scope.row.pictureConfigList.length"
  61. class="el-icon-success color-success"
  62. ></i>
  63. </template>
  64. </el-table-column>
  65. <el-table-column class-name="action-column" label="操作" width="160px">
  66. <template slot-scope="scope">
  67. <el-button class="btn-primary" type="text" @click="toEdit(scope.row)"
  68. >编辑</el-button
  69. >
  70. <el-button
  71. v-if="!onlyMarker"
  72. class="btn-primary"
  73. type="text"
  74. :disabled="!paperList.length"
  75. @click="toSetArea(scope.row)"
  76. >评卷区</el-button
  77. >
  78. <el-button
  79. v-if="!onlyMarker"
  80. class="btn-danger"
  81. type="text"
  82. @click="toDelete(scope.row)"
  83. >删除</el-button
  84. >
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <!-- ModifyMarkerQuestion -->
  89. <modify-marker-question
  90. ref="ModifyMarkerQuestion"
  91. :course-code="datas.basicPaperInfo.courseCode"
  92. :instance="curGroupInfo"
  93. :disabled-question-ids="disabledQuestionIds"
  94. :paper-structure="subjectiveQuestionList"
  95. @modified="groupModified"
  96. ></modify-marker-question>
  97. <!-- ModifyMarkArea -->
  98. <modify-mark-area
  99. v-if="!onlyMarker"
  100. ref="ModifyMarkArea"
  101. :base-info="datas.basicPaperInfo"
  102. :group="curGroupInfo"
  103. :paper-list="paperList"
  104. @modified="areaModified"
  105. ></modify-mark-area>
  106. </div>
  107. </template>
  108. <script>
  109. import ModifyMarkerQuestion from "./ModifyMarkerQuestion.vue";
  110. import ModifyMarkArea from "./ModifyMarkArea.vue";
  111. import { examStructureFindJpg } from "../../api";
  112. import { cardDetail } from "../../../card/api";
  113. export default {
  114. name: "mark-paper-marker",
  115. components: { ModifyMarkerQuestion, ModifyMarkArea },
  116. props: {
  117. datas: {
  118. type: Object,
  119. default() {
  120. return {
  121. basicPaperInfo: {},
  122. paperStructureInfo: [],
  123. groupInfo: [],
  124. };
  125. },
  126. },
  127. },
  128. data() {
  129. return {
  130. questionCount: 0,
  131. groupQuestionCount: 0,
  132. groupInfo: [],
  133. disabledQuestionIds: [],
  134. curGroupInfo: {},
  135. subjectiveQuestionList: [],
  136. subjectiveQuestionCount: 0,
  137. objectiveQuestionCount: 0,
  138. MARK_TYPE: {
  139. 0: "单评",
  140. 1: "双评",
  141. },
  142. paperList: [],
  143. cardPages: [],
  144. };
  145. },
  146. filters: {
  147. questionsFilter(val) {
  148. return val
  149. .map((item) => `${item.mainNumber}-${item.subNumber}`)
  150. .join(",");
  151. },
  152. },
  153. mounted() {
  154. this.initData();
  155. this.getPaperList();
  156. this.getCardPages();
  157. },
  158. methods: {
  159. async getPaperList() {
  160. this.paperList = [];
  161. const data = await examStructureFindJpg({
  162. examId: this.datas.basicPaperInfo.examId,
  163. courseCode: this.datas.basicPaperInfo.courseCode,
  164. paperNumber: this.datas.basicPaperInfo.paperNumber,
  165. paperType: this.datas.basicPaperInfo.paperType,
  166. });
  167. const papers = data || [];
  168. papers.sort((a, b) => a.index - b.index);
  169. this.paperList = papers.map((paper) => {
  170. return {
  171. imgUrl: paper.path,
  172. areas: [],
  173. };
  174. });
  175. },
  176. async getCardPages() {
  177. const detData = await cardDetail(this.datas.basicPaperInfo.cardId);
  178. const cardContent = JSON.parse(detData.content);
  179. this.cardPages = cardContent.pages;
  180. },
  181. initData() {
  182. this.groupInfo = this.datas.groupInfo.map((item, index) => {
  183. return { ...item, groupNumber: index + 1 };
  184. });
  185. this.questionCount = this.datas.paperStructureInfo.length;
  186. this.updateDisableQuestionIds();
  187. this.subjectiveQuestionList = this.datas.paperStructureInfo.filter(
  188. (item) => item.qType === "subjective"
  189. );
  190. this.subjectiveQuestionCount = this.subjectiveQuestionList.length;
  191. this.objectiveQuestionCount =
  192. this.questionCount - this.subjectiveQuestionCount;
  193. this.$emit("on-ready");
  194. },
  195. updateDisableQuestionIds(filterId) {
  196. let groupInfo = this.groupInfo;
  197. if (filterId)
  198. groupInfo = this.groupInfo.filter((item) => item.id !== filterId);
  199. let disabledQuestionIds = [];
  200. groupInfo.forEach((item) => {
  201. disabledQuestionIds = [
  202. ...disabledQuestionIds,
  203. ...item.questions.map((item) => item.id),
  204. ];
  205. });
  206. this.disabledQuestionIds = disabledQuestionIds;
  207. if (!filterId) this.groupQuestionCount = disabledQuestionIds.length;
  208. },
  209. updateGroupNumber() {
  210. this.groupInfo.forEach((group, index) => {
  211. group.groupNumber = index + 1;
  212. });
  213. },
  214. toAdd() {
  215. this.updateDisableQuestionIds();
  216. if (this.groupQuestionCount === this.subjectiveQuestionCount) {
  217. this.$message.error("当前已经没有主观题目可供设置!");
  218. return;
  219. }
  220. this.curGroupInfo = {
  221. id: this.$randomCode(),
  222. groupNumber: null,
  223. markerList: [],
  224. doubleRate: 0,
  225. arbitrateThreshold: 1,
  226. questions: [],
  227. pictureConfigList: [],
  228. };
  229. this.$refs.ModifyMarkerQuestion.open();
  230. },
  231. toEdit(row) {
  232. this.curGroupInfo = row;
  233. this.updateDisableQuestionIds(row.id);
  234. this.$refs.ModifyMarkerQuestion.open();
  235. },
  236. toSetArea(row) {
  237. this.curGroupInfo = row;
  238. this.$refs.ModifyMarkArea.open();
  239. },
  240. toDelete(row) {
  241. const pos = this.groupInfo.findIndex((item) => item.id === row.id);
  242. this.groupInfo.splice(pos, 1);
  243. this.updateDisableQuestionIds();
  244. this.updateGroupNumber();
  245. },
  246. groupModified(row) {
  247. const pos = this.groupInfo.findIndex((item) => item.id === row.id);
  248. if (!row.pictureConfigList.length) {
  249. row.pictureConfigList = this.autoParsePictureConfigList(row.questions);
  250. }
  251. if (pos === -1) {
  252. this.groupInfo.push(row);
  253. } else {
  254. this.groupInfo.splice(pos, 1, row);
  255. }
  256. this.updateDisableQuestionIds();
  257. this.updateGroupNumber();
  258. },
  259. autoParsePictureConfigList(questions) {
  260. if (!questions.length) return [];
  261. let pictureConfigList = [];
  262. const structs = questions.map(
  263. (item) => `${item.mainNumber}_${item.subNumber}`
  264. );
  265. this.cardPages.forEach((page, pindex) => {
  266. page.exchange.answer_area.forEach((area) => {
  267. const [x, y, w, h] = area.area;
  268. const qStruct = `${area.main_number}_${area.sub_number}`;
  269. const pConfig = {
  270. i: pindex + 1,
  271. x,
  272. y,
  273. w,
  274. h,
  275. qStruct,
  276. };
  277. if (typeof area.sub_number === "number") {
  278. if (!structs.includes(qStruct)) return;
  279. pictureConfigList.push(pConfig);
  280. return;
  281. }
  282. // 复合区域处理,比如填空题,多个小题合并为一个区域
  283. if (typeof area.sub_number === "string") {
  284. const areaStructs = area.sub_number
  285. .split(",")
  286. .map((subNumber) => `${area.main_number}_${subNumber}`);
  287. if (
  288. structs.some((struct) => areaStructs.includes(struct)) &&
  289. !pictureConfigList.find((item) => item.qStruct === qStruct)
  290. ) {
  291. pictureConfigList.push(pConfig);
  292. }
  293. }
  294. });
  295. });
  296. pictureConfigList.forEach((item) => {
  297. delete item.qStruct;
  298. });
  299. // 合并相邻区域
  300. pictureConfigList.sort((a, b) => {
  301. return a.i - b.i || a.x - b.x || a.y - b.y;
  302. });
  303. let combinePictureConfigList = [];
  304. let prevConfig = null;
  305. pictureConfigList.forEach((item, index) => {
  306. if (!index) {
  307. prevConfig = { ...item };
  308. combinePictureConfigList.push(prevConfig);
  309. return;
  310. }
  311. if (
  312. prevConfig.i === item.i &&
  313. prevConfig.y + prevConfig.h >= item.y &&
  314. prevConfig.w === item.w &&
  315. prevConfig.x === item.x
  316. ) {
  317. prevConfig.h = item.y + item.h - prevConfig.y;
  318. } else {
  319. prevConfig = { ...item };
  320. combinePictureConfigList.push(prevConfig);
  321. }
  322. });
  323. // console.log(combinePictureConfigList);
  324. // 自动扩展区域。
  325. let scaleRate = 0.002;
  326. combinePictureConfigList = combinePictureConfigList.map((item) => {
  327. return {
  328. i: item.i,
  329. x: item.x - scaleRate,
  330. y: item.y - scaleRate,
  331. w: item.w + 2 * scaleRate,
  332. h: item.h + 2 * scaleRate,
  333. };
  334. });
  335. return combinePictureConfigList;
  336. },
  337. areaModified(row) {
  338. const pos = this.groupInfo.findIndex((item) => item.id === row.id);
  339. if (pos === -1) return;
  340. this.groupInfo.splice(pos, 1, row);
  341. },
  342. checkData() {
  343. let errorMessages = [];
  344. if (this.subjectiveQuestionCount > this.groupQuestionCount) {
  345. errorMessages.push("当前还有题目未设置分组");
  346. }
  347. this.groupInfo.forEach((item, index) => {
  348. if (item.doubleRate === 1 && !item.arbitrateThreshold) {
  349. errorMessages.push(`序号${index + 1}设置中,仲裁阀值不能为空`);
  350. }
  351. });
  352. if (errorMessages.length) {
  353. this.$message.error(errorMessages.join("。"));
  354. return;
  355. }
  356. this.updateData();
  357. this.$emit("next-step");
  358. },
  359. getData() {
  360. return this.groupInfo.map((item) => {
  361. return { ...item };
  362. });
  363. },
  364. updateData() {
  365. this.$emit("data-change", { groupInfo: this.getData() });
  366. },
  367. },
  368. };
  369. </script>