SelectQuestion.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <section class="select-question body-content">
  3. <div class="part-box">
  4. <div class="part-box-header">
  5. <h2 class="part-box-title">选择试题</h2>
  6. <div>
  7. <el-button
  8. type="primary"
  9. icon="icon icon-save-white"
  10. @click="submitQues()"
  11. >确定</el-button
  12. >
  13. <el-button type="danger" plain icon="icon icon-back" @click="back()"
  14. >返回</el-button
  15. >
  16. </div>
  17. </div>
  18. <el-form
  19. :inline="true"
  20. :model="formSearch"
  21. label-position="right"
  22. label-width="90px"
  23. class="part-filter-form"
  24. >
  25. <el-form-item label="课程">
  26. <el-select v-model="course" :disabled="true" placeholder="请选择">
  27. <el-option
  28. v-for="item in courseList"
  29. :key="item.value"
  30. :label="item.name"
  31. :value="item.value"
  32. >
  33. </el-option>
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item label="题型">
  37. <el-select
  38. v-model="formSearch.questionType"
  39. placeholder="请选择题型"
  40. @change="searchQuestionPaper"
  41. >
  42. <el-option
  43. v-for="item in questionTypes"
  44. :key="item.value"
  45. :label="item.label"
  46. :value="item.value"
  47. >
  48. </el-option>
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item label="题干">
  52. <el-input
  53. v-model="formSearch.quesBody"
  54. placeholder="请输入题干"
  55. @blur="searchQuestionPaper"
  56. >
  57. </el-input>
  58. </el-form-item>
  59. <el-form-item> </el-form-item>
  60. </el-form>
  61. </div>
  62. <!-- 正文信息 -->
  63. <div class="part-box">
  64. <!-- 页面列表 -->
  65. <el-table :data="tableData" @selection-change="handleSelectionChange">
  66. <el-table-column type="selection" width="45"> </el-table-column>
  67. <el-table-column label="课程">
  68. <template slot-scope="scope">
  69. <span v-if="scope.row.course != null">{{
  70. scope.row.course.name
  71. }}</span>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="题型" width="100">
  75. <template slot-scope="scope">
  76. <span>{{ scope.row.questionType | questionType }}</span>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="题干">
  80. <template slot-scope="scope">
  81. <span class="small">
  82. <rich-text
  83. :text-json="scope.row.quesBody"
  84. @click="prevViewQues(scope.row)"
  85. >
  86. </rich-text>
  87. </span>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <!--分页栏-->
  92. <div class="part-page">
  93. <el-pagination
  94. :current-page="currentPage"
  95. :page-size="pageSize"
  96. layout="total, prev, pager, next, jumper"
  97. :total="total"
  98. @current-change="handleCurrentChange"
  99. >
  100. </el-pagination>
  101. </div>
  102. </div>
  103. <!-- 试题预览 -->
  104. <question-preview
  105. ref="QuestionPreview"
  106. :ques-model="quesModel"
  107. ></question-preview>
  108. </section>
  109. </template>
  110. <script>
  111. import { QUESTION_API } from "@/constants/constants";
  112. import { QUESTION_TYPES } from "../constants/constants";
  113. import { mapState } from "vuex";
  114. import QuestionPreview from "./QuestionPreview";
  115. export default {
  116. name: "SelectQuestion",
  117. components: { QuestionPreview },
  118. data() {
  119. return {
  120. formSearch: {
  121. questionType: "",
  122. quesBody: "",
  123. },
  124. course: "",
  125. paperId: "",
  126. paperDetailId: "",
  127. parentView: "",
  128. courseList: [],
  129. tableData: [],
  130. multipleSelection: [],
  131. currentPage: 1,
  132. pageSize: 10,
  133. total: 10,
  134. courseName: "",
  135. quesModel: {},
  136. questionTypes: [],
  137. quesDialog: false,
  138. loading: false,
  139. dialogLoading: false,
  140. singleRightAnswer: "", //接收单选答案
  141. multipleRightAnswer: [], //接收多选答案
  142. };
  143. },
  144. computed: {
  145. ...mapState({ user: (state) => state.user }),
  146. },
  147. //钩子函数
  148. created() {
  149. var url =
  150. QUESTION_API +
  151. "/org/property/" +
  152. this.user.rootOrgId +
  153. "/ROOT_ORG_QUESTION_TYPES";
  154. this.$http.get(url).then((response) => {
  155. if (response.data && response.data.length > 0) {
  156. this.questionTypes = QUESTION_TYPES.filter((m) =>
  157. response.data.includes(m.value)
  158. );
  159. }
  160. });
  161. this.paperId = this.$route.params.id;
  162. this.courseName = this.$route.params.courseName;
  163. var courseNo = this.$route.params.courseNo;
  164. this.paperDetailId = this.$route.params.paperDetailId;
  165. this.parentView = this.$route.params.parentView;
  166. this.courseList.push({ name: this.courseName, value: courseNo });
  167. this.course = this.courseList[0].value;
  168. this.searchQuestionPaper();
  169. },
  170. mounted() {
  171. setTimeout(() => {
  172. this.$store.commit("UPDATE_CURRENT_PATHS", ["添加试题"]);
  173. }, 200);
  174. },
  175. methods: {
  176. //查询列表
  177. searchQuestionPaper() {
  178. this.loading = true;
  179. this.$http
  180. .get(
  181. QUESTION_API +
  182. "/paper/listQuestion/" +
  183. this.paperId +
  184. "/" +
  185. this.currentPage +
  186. "/" +
  187. this.pageSize +
  188. "?quesType=" +
  189. this.formSearch.questionType +
  190. "&quesBody=" +
  191. this.formSearch.quesBody
  192. )
  193. .then((response) => {
  194. this.tableData = response.data.content;
  195. this.total = response.data.totalElements;
  196. this.loading = false;
  197. });
  198. },
  199. //分页
  200. handleCurrentChange(val) {
  201. this.currentPage = val;
  202. this.searchQuestionPaper();
  203. },
  204. openQuesDialog() {
  205. this.quesDialog = true;
  206. },
  207. closeQuesDialog() {
  208. this.quesDialog = false;
  209. this.quesModel = {};
  210. },
  211. //预览
  212. prevViewQues(row) {
  213. this.quesModel = row;
  214. this.disposeSelectAnswer();
  215. this.$refs.QuestionPreview.open();
  216. },
  217. //添加试题
  218. submitQues() {
  219. if (this.multipleSelection.length === 0) {
  220. this.$notify({
  221. type: "error",
  222. message: "请选择要添加的试题",
  223. });
  224. } else {
  225. this.$confirm("是否添加这些试题?", "提示", {
  226. confirmButtonText: "确定",
  227. cancelButtonText: "取消",
  228. type: "warning",
  229. }).then(() => {
  230. this.$http
  231. .post(
  232. QUESTION_API +
  233. "/paper/selectQuestions/" +
  234. this.paperId +
  235. "/" +
  236. this.paperDetailId,
  237. this.multipleSelection
  238. )
  239. .then(() => {
  240. this.$notify({
  241. type: "success",
  242. message: "添加成功!",
  243. });
  244. this.$router.push({
  245. path: "/edit_paper/" + this.paperId + "/" + this.parentView,
  246. });
  247. })
  248. .catch(() => {
  249. this.$notify({
  250. type: "error",
  251. message: "添加失败!",
  252. });
  253. });
  254. });
  255. }
  256. },
  257. //返回
  258. back() {
  259. this.$router.push({
  260. path: "/edit_paper/" + this.paperId + "/" + this.parentView,
  261. });
  262. },
  263. //全选
  264. handleSelectionChange(val) {
  265. this.multipleSelection = val;
  266. },
  267. /**
  268. * 处理选择题答案显示
  269. * 处理套题下选择题答案显示
  270. */
  271. disposeSelectAnswer() {
  272. //处理选择题答案显示
  273. if (
  274. this.quesModel.questionType == "SINGLE_ANSWER_QUESTION" ||
  275. this.quesModel.questionType == "MULTIPLE_ANSWER_QUESTION"
  276. ) {
  277. let answers = [];
  278. this.quesModel.quesOptions.forEach((option, index) => {
  279. if (option.isCorrect) {
  280. answers.push(String.fromCharCode(65 + index));
  281. }
  282. });
  283. this.quesModel.quesAnswer = answers.sort().toString();
  284. }
  285. //处理套题下选择题答案显示
  286. if (this.quesModel.questionType == "NESTED_ANSWER_QUESTION") {
  287. var subQuestions = this.quesModel.subQuestions;
  288. for (var k = 0; k < subQuestions.length; k++) {
  289. var subQuestion = subQuestions[k];
  290. if (subQuestion.questionType == "SINGLE_ANSWER_QUESTION") {
  291. for (var j = 0; j < subQuestion.quesOptions.length; j++) {
  292. var option_j = subQuestion.quesOptions[j];
  293. var orderNum_j = String.fromCharCode(65 + j);
  294. if (option_j.isCorrect == 1) {
  295. subQuestion["quesAnswer"] = orderNum_j;
  296. }
  297. }
  298. }
  299. if (subQuestion.questionType == "MULTIPLE_ANSWER_QUESTION") {
  300. var subQuestionMultipleRightAnswer = [];
  301. for (var z = 0; z < subQuestion.quesOptions.length; z++) {
  302. var option_k = subQuestion.quesOptions[z];
  303. var orderNum_k = String.fromCharCode(65 + z);
  304. if (option_k.isCorrect == 1) {
  305. subQuestionMultipleRightAnswer.push(orderNum_k);
  306. }
  307. }
  308. subQuestion["quesAnswer"] = subQuestionMultipleRightAnswer
  309. .sort()
  310. .toString();
  311. }
  312. }
  313. }
  314. },
  315. },
  316. };
  317. </script>