SelectQuestion.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <section class="content">
  3. <LinkTitlesCustom :currentPaths="['添加试题']" />
  4. <!-- 正文信息 -->
  5. <div class="box-body">
  6. <el-form
  7. :inline="true"
  8. :model="formSearch"
  9. label-position="right"
  10. label-width="90px"
  11. >
  12. <el-row>
  13. <el-col :span="6">
  14. <el-form-item label="课程">
  15. <el-select
  16. class="search_width"
  17. :disabled="true"
  18. v-model="course"
  19. placeholder="请选择"
  20. size="small"
  21. >
  22. <el-option
  23. v-for="item in courseList"
  24. :label="item.name"
  25. :value="item.value"
  26. :key="item.value"
  27. >
  28. </el-option>
  29. </el-select>
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="6">
  33. <el-form-item label="题型">
  34. <el-select
  35. class="search_width"
  36. v-model="formSearch.questionType"
  37. @change="searchQuestionPaper"
  38. placeholder="请选择题型"
  39. size="small"
  40. >
  41. <el-option
  42. v-for="item in questionTypes"
  43. :label="item.label"
  44. :value="item.value"
  45. :key="item.value"
  46. >
  47. </el-option>
  48. </el-select>
  49. </el-form-item>
  50. </el-col>
  51. <el-col :span="6">
  52. <el-form-item label="题干">
  53. <el-input
  54. class="search_width"
  55. v-model="formSearch.quesBody"
  56. placeholder="请输入题干"
  57. @blur="searchQuestionPaper"
  58. size="small"
  59. >
  60. </el-input>
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="6">
  64. <div class="search_down">
  65. <el-button
  66. size="small"
  67. type="primary"
  68. icon="el-icon-circle-check"
  69. @click="submitQues()"
  70. >确定</el-button
  71. >
  72. <el-button
  73. size="small"
  74. type="primary"
  75. icon="el-icon-arrow-left"
  76. @click="back()"
  77. >返回</el-button
  78. >
  79. </div>
  80. </el-col>
  81. </el-row>
  82. </el-form>
  83. <!-- 页面列表 -->
  84. <el-table
  85. :data="tableData"
  86. border
  87. style="width: 100%;"
  88. @selection-change="handleSelectionChange"
  89. >
  90. <el-table-column type="selection" width="45"> </el-table-column>
  91. <el-table-column label="课程">
  92. <template slot-scope="scope">
  93. <span v-if="scope.row.course != null">{{
  94. scope.row.course.name
  95. }}</span>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="题型">
  99. <template slot-scope="scope">
  100. <span>{{ scope.row.questionType | questionType }}</span>
  101. </template>
  102. </el-table-column>
  103. <el-table-column label="题干">
  104. <template slot-scope="scope">
  105. <span class="small">
  106. <a
  107. href="javascript:;"
  108. @click="prevViewQues(scope.row)"
  109. v-html="scope.row.quesBody"
  110. >
  111. </a>
  112. </span>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. <!--分页栏-->
  117. <div class="page pull-right">
  118. <el-pagination
  119. @current-change="handleCurrentChange"
  120. :current-page="currentPage"
  121. :page-size="pageSize"
  122. layout="total, prev, pager, next, jumper"
  123. :total="total"
  124. >
  125. </el-pagination>
  126. </div>
  127. </div>
  128. <div class="text-left">
  129. <el-dialog
  130. @close="closeQuesDialog"
  131. v-loading.body="dialogLoading"
  132. title="试题预览"
  133. :visible.sync="quesDialog"
  134. >
  135. <el-form :model="quesModel" label-position="right" label-width="80px">
  136. <el-row :gutter="10">
  137. <el-col :xs="10" :sm="10" :md="10" :lg="10">
  138. <el-form-item label="题型">
  139. <el-select
  140. :disabled="true"
  141. v-model="quesModel.questionType"
  142. placeholder="题型"
  143. >
  144. <el-option
  145. v-for="item in questionTypes"
  146. :label="item.label"
  147. :value="item.value"
  148. :key="item.value"
  149. >
  150. </el-option>
  151. </el-select>
  152. </el-form-item>
  153. </el-col>
  154. </el-row>
  155. <el-row :gutter="10">
  156. <el-col :xs="30" :sm="30" :md="30" :lg="30">
  157. <el-form-item label="题干">
  158. <span v-html="quesModel.quesBody"></span>
  159. </el-form-item>
  160. </el-col>
  161. </el-row>
  162. <!--非套题-->
  163. <div v-if="quesModel.questionType !== 'NESTED_ANSWER_QUESTION'">
  164. <el-row
  165. :gutter="10"
  166. v-for="(quesOption, index) in quesModel.quesOptions"
  167. :key="quesOption.number"
  168. >
  169. <el-col :xs="30" :sm="30" :md="30" :lg="30">
  170. <el-form-item :label="index | optionOrderWordFilter">
  171. <span v-html="quesOption.optionBody"></span>
  172. </el-form-item>
  173. </el-col>
  174. </el-row>
  175. </div>
  176. <!--套题-->
  177. <div v-if="quesModel.questionType === 'NESTED_ANSWER_QUESTION'">
  178. <el-row
  179. :gutter="10"
  180. v-for="(subQuestionModel, index) in quesModel.subQuestions"
  181. :key="index"
  182. >
  183. <el-col :xs="30" :sm="30" :md="30" :lg="30">
  184. <el-row>
  185. <el-form-item label="题目">
  186. <span v-html="subQuestionModel.quesBody"></span>
  187. </el-form-item>
  188. </el-row>
  189. <el-row
  190. :gutter="10"
  191. v-for="(subQuesOption, index) in subQuestionModel.quesOptions"
  192. :key="index"
  193. >
  194. <el-col :xs="30" :sm="30" :md="30" :lg="30">
  195. <el-form-item :label="index | optionOrderWordFilter">
  196. <span v-html="subQuesOption.optionBody"></span>
  197. </el-form-item>
  198. </el-col>
  199. </el-row>
  200. <el-row>
  201. <el-form-item label="答案">
  202. <span v-html="subQuestionModel.quesAnswer"></span>
  203. </el-form-item>
  204. </el-row>
  205. </el-col>
  206. </el-row>
  207. </div>
  208. <!--非套题答案-->
  209. <div v-if="quesModel.questionType !== 'NESTED_ANSWER_QUESTION'">
  210. <el-form-item label="答案">
  211. <span v-html="answer"></span>
  212. </el-form-item>
  213. </div>
  214. </el-form>
  215. </el-dialog>
  216. </div>
  217. </section>
  218. </template>
  219. <script>
  220. import { QUESTION_API } from "@/constants/constants";
  221. import { QUESTION_TYPES } from "../constants/constants";
  222. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  223. export default {
  224. components: { LinkTitlesCustom },
  225. data() {
  226. return {
  227. formSearch: {
  228. questionType: "",
  229. quesBody: ""
  230. },
  231. course: "",
  232. paperId: "",
  233. paperDetailId: "",
  234. parentView: "",
  235. courseList: [],
  236. tableData: [],
  237. multipleSelection: [],
  238. currentPage: 1,
  239. pageSize: 10,
  240. total: 10,
  241. courseName: "",
  242. quesModel: {},
  243. questionTypes: QUESTION_TYPES,
  244. quesDialog: false,
  245. loading: false,
  246. dialogLoading: false,
  247. singleRightAnswer: "", //接收单选答案
  248. multipleRightAnswer: [] //接收多选答案
  249. };
  250. },
  251. methods: {
  252. //查询列表
  253. searchQuestionPaper() {
  254. this.loading = true;
  255. this.$http
  256. .get(
  257. QUESTION_API +
  258. "/paper/listQuestion/" +
  259. this.paperId +
  260. "/" +
  261. this.currentPage +
  262. "/" +
  263. this.pageSize +
  264. "?quesType=" +
  265. this.formSearch.questionType +
  266. "&quesBody=" +
  267. this.formSearch.quesBody
  268. )
  269. .then(response => {
  270. this.tableData = response.data.content;
  271. this.total = response.data.totalElements;
  272. this.loading = false;
  273. });
  274. },
  275. //分页
  276. handleCurrentChange(val) {
  277. this.currentPage = val;
  278. this.searchQuestionPaper();
  279. },
  280. openQuesDialog() {
  281. this.quesDialog = true;
  282. },
  283. closeQuesDialog() {
  284. this.quesDialog = false;
  285. this.quesModel = {};
  286. },
  287. //预览
  288. prevViewQues(row) {
  289. this.quesModel = row;
  290. this.disposeSelectAnswer();
  291. this.openQuesDialog();
  292. },
  293. //添加试题
  294. submitQues() {
  295. if (this.multipleSelection.length === 0) {
  296. this.$notify({
  297. type: "error",
  298. message: "请选择要添加的试题"
  299. });
  300. } else {
  301. this.$confirm("是否添加这些试题?", "提示", {
  302. confirmButtonText: "确定",
  303. cancelButtonText: "取消",
  304. type: "warning"
  305. }).then(() => {
  306. console.log(this.multipleSelection[0]);
  307. this.$http
  308. .post(
  309. QUESTION_API +
  310. "/paper/selectQuestions/" +
  311. this.paperId +
  312. "/" +
  313. this.paperDetailId,
  314. this.multipleSelection
  315. )
  316. .then(() => {
  317. this.$notify({
  318. type: "success",
  319. message: "添加成功!"
  320. });
  321. this.$router.push({
  322. path: "/edit_paper/" + this.paperId + "/" + this.parentView
  323. });
  324. })
  325. .catch(() => {
  326. this.$notify({
  327. type: "error",
  328. message: "添加失败!"
  329. });
  330. });
  331. });
  332. }
  333. },
  334. //返回
  335. back() {
  336. this.$router.push({
  337. path: "/edit_paper/" + this.paperId + "/" + this.parentView
  338. });
  339. },
  340. //全选
  341. handleSelectionChange(val) {
  342. this.multipleSelection = val;
  343. },
  344. /**
  345. * 处理选择题答案显示
  346. * 处理套题下选择题答案显示
  347. */
  348. disposeSelectAnswer() {
  349. this.singleRightAnswer = "";
  350. this.multipleRightAnswer = [];
  351. //处理选择题答案显示
  352. if (
  353. this.quesModel.questionType == "SINGLE_ANSWER_QUESTION" ||
  354. this.quesModel.questionType == "MULTIPLE_ANSWER_QUESTION"
  355. ) {
  356. for (var i = 0; i < this.quesModel.quesOptions.length; i++) {
  357. var option_i = this.quesModel.quesOptions[i];
  358. var orderNum_i = String.fromCharCode(65 + i);
  359. if (
  360. this.quesModel.questionType == "SINGLE_ANSWER_QUESTION" &&
  361. option_i.isCorrect == 1
  362. ) {
  363. this.singleRightAnswer = orderNum_i;
  364. }
  365. if (
  366. this.quesModel.questionType == "MULTIPLE_ANSWER_QUESTION" &&
  367. option_i.isCorrect == 1
  368. ) {
  369. this.multipleRightAnswer.push(orderNum_i);
  370. }
  371. }
  372. }
  373. //处理套题下选择题答案显示
  374. if (this.quesModel.questionType == "NESTED_ANSWER_QUESTION") {
  375. var subQuestions = this.quesModel.subQuestions;
  376. for (var k = 0; k < subQuestions.length; k++) {
  377. var subQuestion = subQuestions[k];
  378. if (subQuestion.questionType == "SINGLE_ANSWER_QUESTION") {
  379. for (var j = 0; j < subQuestion.quesOptions.length; j++) {
  380. var option_j = subQuestion.quesOptions[j];
  381. var orderNum_j = String.fromCharCode(65 + j);
  382. if (option_j.isCorrect == 1) {
  383. subQuestion["quesAnswer"] = orderNum_j;
  384. }
  385. }
  386. }
  387. if (subQuestion.questionType == "MULTIPLE_ANSWER_QUESTION") {
  388. var subQuestionMultipleRightAnswer = [];
  389. for (var z = 0; z < subQuestion.quesOptions.length; z++) {
  390. var option_k = subQuestion.quesOptions[z];
  391. var orderNum_k = String.fromCharCode(65 + z);
  392. if (option_k.isCorrect == 1) {
  393. subQuestionMultipleRightAnswer.push(orderNum_k);
  394. }
  395. }
  396. subQuestion[
  397. "quesAnswer"
  398. ] = subQuestionMultipleRightAnswer.sort().toString();
  399. }
  400. }
  401. }
  402. }
  403. },
  404. computed: {
  405. answer: function() {
  406. if (this.quesModel.questionType == "SINGLE_ANSWER_QUESTION") {
  407. return this.singleRightAnswer;
  408. } else if (this.quesModel.questionType == "MULTIPLE_ANSWER_QUESTION") {
  409. var obj = Object.assign({}, this.multipleRightAnswer); //浅拷贝;
  410. return obj.sort().toString();
  411. } else {
  412. return this.quesModel.quesAnswer;
  413. }
  414. }
  415. },
  416. //钩子函数
  417. created() {
  418. this.paperId = this.$route.params.id;
  419. this.courseName = this.$route.params.courseName;
  420. var courseNo = this.$route.params.courseNo;
  421. this.paperDetailId = this.$route.params.paperDetailId;
  422. this.parentView = this.$route.params.parentView;
  423. this.courseList.push({ name: this.courseName, value: courseNo });
  424. this.course = this.courseList[0].value;
  425. this.searchQuestionPaper();
  426. }
  427. };
  428. </script>
  429. <style></style>