Exam-Marking-View.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <el-dialog v-model="state.dialogVisible" draggable destroy-on-close :show-close="false" width="80%" :before-close="closeDialog">
  3. <template #header="{ close, titleId, titleClass }">
  4. <div class="topContent">
  5. <div class="titleBox">
  6. <span class="title">自我练习</span>
  7. </div>
  8. <div class="submitBox">
  9. <el-button type="info" @click="closeDialog">关 闭</el-button>
  10. </div>
  11. </div>
  12. </template>
  13. <el-row :gutter="10" v-loading="state.loading">
  14. <el-col :xs="6" :sm="6" :md="6" :lg="6" :xl="6">
  15. <div class="examListContent" v-for="item in state.questionTypeData">
  16. <p class="examType">{{ item.questionTypeDesc }}</p>
  17. <ul class="examList">
  18. <li
  19. class="examListItem"
  20. :class="{ select: questionsItem.id == state.selQuestionID, right: questionsItem.isRight, error: !questionsItem.isRight }"
  21. v-for="questionsItem in item.questions"
  22. @click="onSelQuestion(questionsItem.id)"
  23. >
  24. {{ questionsItem.sortIndex }}
  25. </li>
  26. </ul>
  27. </div>
  28. </el-col>
  29. <el-col :xs="18" :sm="18" :md="18" :lg="18" :xl="18">
  30. <div class="questionBox" v-if="state.questionDetail">
  31. <p class="questionTitle">题干:{{ state.questionDetail.title }}</p>
  32. <div class="questionAnswer">
  33. <div v-if="[0, 2].includes(state.questionDetail.questionType)">
  34. <el-radio-group style="display: block" v-model="state.selRadioValue">
  35. <el-form-item :label="item.label + '. '" v-for="item in state.questionDetail.practiceQuestionOptionsDtos" style="margin-bottom: 10px">
  36. <el-radio :label="item.content" :value="item.questionOptionId" disabled />
  37. </el-form-item>
  38. </el-radio-group>
  39. </div>
  40. <div v-else-if="state.questionDetail.questionType == 1">
  41. <el-checkbox-group v-model="state.selCheckboxValue">
  42. <el-form-item :label="item.label + '. '" v-for="item in state.questionDetail.practiceQuestionOptionsDtos" style="margin-bottom: 10px">
  43. <el-checkbox :label="item.content" :value="item.questionOptionId" disabled />
  44. </el-form-item>
  45. </el-checkbox-group>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="referenceAnswer" v-if="state.questionDetail">
  50. <span>参考答案:</span>
  51. <p>{{ state.questionDetail.answerDesc || '略' }}</p>
  52. </div>
  53. <div class="referenceAnswer" v-if="state.questionDetail && state.questionDetail.practiceQuestionKnowladgeDtos.length > 0">
  54. <span>关联知识:</span>
  55. <p v-for="item in state.questionDetail.practiceQuestionKnowladgeDtos" @click="onKnowladgeTo(item)">{{ item.title }}</p>
  56. </div>
  57. <div class="referenceAnswer" v-if="state.questionDetail && state.questionDetail.practiceQuestionSourcewareDtos.length > 0">
  58. <span>关联课件:</span>
  59. <p v-for="item in state.questionDetail.practiceQuestionSourcewareDtos" @click="onSourcewareTo(item)">{{ item.name }}</p>
  60. </div>
  61. </el-col>
  62. </el-row>
  63. <template #footer>
  64. <span class="dialog-footer" v-if="state.selQuestionID">
  65. <el-button type="primary" @click="onLastQuestion" :loading="state.loading">上一题</el-button>
  66. <el-button type="primary" @click="onNextQuestion" :loading="state.loading">下一题</el-button>
  67. </span>
  68. </template>
  69. </el-dialog>
  70. </template>
  71. <script setup lang="ts">
  72. import { reactive, ref } from 'vue';
  73. import { useRouter } from 'vue-router';
  74. import { ElMessage, ElMessageBox } from 'element-plus';
  75. import { excludeSelfById } from '@/utils/tools';
  76. import other from '@/utils/other';
  77. import { fileDownloadByUrl } from '@/api/public/file';
  78. import { getViewPracticeQuestions, getPracticeView } from '@/api/examTrain/practice';
  79. const router = useRouter(); // 路由
  80. // 定义子组件向父组件传值/事件
  81. const emit = defineEmits(['updateList']);
  82. // 定义变量内容
  83. const state = reactive<any>({
  84. dialogVisible: false, // 弹窗
  85. loading: false, // 加载
  86. practiceId: '', // 用户练习id
  87. questionTypeData: [] as any[], // 试卷题型数据
  88. questionsData: [] as any[], // 试题集合
  89. selQuestionID: '', // 选择的问题id
  90. questionDetail: null, // 选择的问题明细
  91. selRadioValue: '', // 单选题选择的值
  92. selCheckboxValue: [] as any[], // 多选题选择的值
  93. });
  94. // 打开弹窗
  95. const openDialog = async (rows: any) => {
  96. state.dialogVisible = true;
  97. state.practiceId = rows.id;
  98. state.loading = true;
  99. getQuestionsData();
  100. };
  101. const getQuestionsData = async () => {
  102. try {
  103. const { result } = await getViewPracticeQuestions(state.practiceId);
  104. let sortIndexNum = 1;
  105. result.forEach((item) => {
  106. switch (item.questionType) {
  107. case 0:
  108. item.questionTypeDesc = '单选题';
  109. break;
  110. case 1:
  111. item.questionTypeDesc = '多选题';
  112. break;
  113. case 2:
  114. item.questionTypeDesc = '判断题';
  115. break;
  116. default:
  117. break;
  118. }
  119. item.questions.forEach((it) => {
  120. it.sortIndex = sortIndexNum;
  121. it.questionType = item.questionType;
  122. state.questionsData.push(it);
  123. sortIndexNum++;
  124. });
  125. });
  126. state.questionTypeData = result;
  127. state.loading = false;
  128. } catch (error) {
  129. // 打印错误信息
  130. console.error(error);
  131. }
  132. };
  133. // 关闭弹窗
  134. const closeDialog = () => {
  135. state.dialogVisible = false;
  136. state.questionTypeData = [];
  137. state.questionsData = [];
  138. state.selQuestionID = '';
  139. state.questionDetail = null;
  140. state.selRadioValue = '';
  141. state.selCheckboxValue = [];
  142. };
  143. // 上一题下一题
  144. const onLastQuestion = () => {
  145. let index: number = state.questionsData.findIndex((it) => it.id == state.selQuestionID);
  146. index = index - 1 == -1 ? state.questionsData.length - 1 : index - 1;
  147. onSelQuestion(state.questionsData[index].id);
  148. };
  149. const onNextQuestion = () => {
  150. let index: number = state.questionsData.findIndex((it) => it.id == state.selQuestionID);
  151. index = index + 1 == state.questionsData.length ? 0 : index + 1;
  152. onSelQuestion(state.questionsData[index].id);
  153. };
  154. // 选择的问题id 提交当前试题答案,再请求下一道题详情 value: 请求下一题详情id
  155. const onSelQuestion = async (value: any) => {
  156. state.loading = true;
  157. onGetQuestionDetail(value);
  158. };
  159. const onGetQuestionDetail = async (value) => {
  160. // 初始化选择选择/填写的答案
  161. state.selRadioValue = '';
  162. state.selCheckboxValue = [];
  163. // 请求下一道题
  164. state.selQuestionID = value;
  165. try {
  166. const { result } = await getPracticeView(state.selQuestionID);
  167. state.questionDetail = result;
  168. let answerDesc = '';
  169. state.questionDetail.practiceQuestionOptionsDtos.forEach((it) => {
  170. it.isAnswer && (answerDesc += it.label);
  171. });
  172. state.questionDetail.answerDesc = answerDesc;
  173. if ([0, 2].includes(state.questionDetail.questionType)) {
  174. let obj = state.questionDetail.practiceQuestionOptionsDtos.find((x: any) => x.isSelected === true);
  175. state.selRadioValue = obj ? obj.questionOptionId : '';
  176. } else if (state.questionDetail.questionType == 1) {
  177. let arr = [] as any[];
  178. state.questionDetail.practiceQuestionOptionsDtos.forEach((it) => {
  179. if (it.isSelected) arr.push(it);
  180. });
  181. state.selCheckboxValue = arr ? arr.map((x: any) => x.questionOptionId) : [];
  182. }
  183. state.loading = false;
  184. } catch (error) {
  185. // 打印错误信息
  186. console.error(error);
  187. }
  188. };
  189. // 跳转知识详情页面
  190. const onKnowladgeTo = (row: any) => {
  191. router.push({
  192. name: 'knowledgePreview',
  193. params: {
  194. id: row.knowladgeId,
  195. isAddPv: 'isAddPv',
  196. tagsViewName: row.title,
  197. },
  198. });
  199. };
  200. // 课件预览下载
  201. const onSourcewareTo = (row: any) => {
  202. ElMessageBox.confirm(`您确定要下载课件,是否继续?`, '提示', {
  203. confirmButtonText: '确认',
  204. cancelButtonText: '取消',
  205. type: 'warning',
  206. draggable: true,
  207. cancelButtonClass: 'default-button',
  208. autofocus: false,
  209. })
  210. .then(() => {
  211. fileDownloadByUrl({
  212. Source: 'hotline',
  213. Id: row.attachmentId,
  214. }).then((res: any) => {
  215. let blob: Blob = new Blob([res.data], { type: res.data.type }); // 创建blob 设置blob文件类型 data 设置为后端返回的文件(例如mp3,jpeg) type:这里设置后端返回的类型 为 mp3
  216. let down: HTMLAnchorElement = document.createElement('a'); // 创建A标签
  217. let href: string = window.URL.createObjectURL(blob); // 创建下载的链接
  218. down.href = href; // 下载地址
  219. down.download = row.name; // 下载文件名
  220. document.body.appendChild(down);
  221. down.click(); // 模拟点击A标签
  222. document.body.removeChild(down); // 下载完成移除元素
  223. window.URL.revokeObjectURL(href); // 释放blob对象
  224. });
  225. })
  226. .catch(() => {});
  227. };
  228. // 暴露变量
  229. defineExpose({
  230. openDialog,
  231. closeDialog,
  232. });
  233. </script>
  234. <style lang="scss">
  235. .topContent {
  236. padding: 10px 30px;
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. }
  241. .topContent .surplusBox {
  242. text-align: center;
  243. }
  244. .topContent .surplusBox .surplus {
  245. font-size: 18px;
  246. color: #000000;
  247. }
  248. .topContent .titleBox {
  249. text-align: center;
  250. }
  251. .topContent .titleBox .title {
  252. font-size: 20px;
  253. font-weight: bold;
  254. letter-spacing: 1px;
  255. color: #000000;
  256. }
  257. .topContent .submitBox {
  258. text-align: right;
  259. vertical-align: top;
  260. }
  261. .examListContent .examType {
  262. font-weight: bold;
  263. color: #000000;
  264. }
  265. .examListContent .examList {
  266. padding: 5px 0 10px;
  267. }
  268. .examListContent .examList .examListItem {
  269. display: inline-block;
  270. margin: 5px 10px 5px 0;
  271. text-align: center;
  272. width: 50px;
  273. height: 35px;
  274. line-height: 35px;
  275. cursor: pointer;
  276. position: relative;
  277. border: #f2f2f2 1px solid;
  278. }
  279. .examListContent .examList .right::after {
  280. content: ' ';
  281. width: 5px;
  282. height: 5px;
  283. position: absolute;
  284. top: 2px;
  285. right: 3px;
  286. background-color: #009688;
  287. border-radius: 50%;
  288. }
  289. .examListContent .examList .error::after {
  290. content: ' ';
  291. width: 5px;
  292. height: 5px;
  293. position: absolute;
  294. top: 2px;
  295. right: 3px;
  296. background-color: #ff5722;
  297. border-radius: 50%;
  298. }
  299. .examListContent .examList .select {
  300. background-color: #1890ff;
  301. color: #fff;
  302. }
  303. .questionBox {
  304. padding: 20px 10px 0;
  305. }
  306. .questionBox .questionTitle {
  307. margin-bottom: 10px;
  308. font-size: 16px;
  309. }
  310. .questionBox .questionAnswer {
  311. padding: 0 20px;
  312. }
  313. .referenceAnswer {
  314. background-color: #ebf9ff;
  315. margin: 15px 40px 15px 30px;
  316. padding: 10px;
  317. }
  318. .referenceAnswer span {
  319. display: block;
  320. }
  321. .referenceAnswer p {
  322. width: calc(100% - 80px);
  323. display: block;
  324. margin-top: 10px;
  325. color: #1890ff;
  326. cursor: pointer;
  327. }
  328. </style>