train.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="app-container">
  3. <el-card style="margin-top: 20px">
  4. <div class="qu-content">
  5. <p>【{{ getQuType(quData.quType) }}】{{ quData.content }}</p>
  6. <p v-if="quData.image!=null && quData.image!=''">
  7. <el-image :src="getUrl(quData.image)" style="max-width:100%;" />
  8. </p>
  9. <div v-if="quData.quType === 1 || quData.quType===3 ">
  10. <el-radio-group v-model="answerValues[0]" readonly>
  11. <el-radio v-for="an in quData.answerList" :key="an.answerId" :label="an.answerId" readonly>
  12. {{ an.abc }}.{{ an.content }}
  13. <div v-if="an.image!=null && an.image!=''" style="clear: both">
  14. <el-image :src="an.image" style="max-width:100%;" />
  15. </div>
  16. </el-radio>
  17. </el-radio-group>
  18. </div>
  19. <!-- 多选题 -->
  20. <div v-if="quData.quType === 2">
  21. <el-checkbox-group v-model="answerValues" readonly>
  22. <el-checkbox v-for="an in quData.answerList" :key="an.answerId" :label="an.answerId">
  23. {{ an.abc }}.{{ an.content }}
  24. <div v-if="an.image!=null && an.image!=''" style="clear: both">
  25. <el-image :src="an.image" style="max-width:100%;" />
  26. </div>
  27. </el-checkbox>
  28. </el-checkbox-group>
  29. </div>
  30. <div v-if="analysisShow" style="margin-top: 20px; color: #1890ff; font-weight: bold">
  31. 正确答案:{{ rightTags.join(' ') }}
  32. </div>
  33. </div>
  34. </el-card>
  35. <el-card v-if="analysisShow" class="qu-analysis" style="margin-top: 20px">
  36. 整题解析:
  37. <p>{{ quData.analysis }}</p>
  38. <p v-if="!quData.analysis">暂无解析内容!</p>
  39. </el-card>
  40. <el-card v-if="analysisShow" class="qu-analysis" style="margin-top: 20px;">
  41. 选项解析:
  42. <div v-for="an in quData.answerList" v-if="an.analysis" class="qu-analysis-line">
  43. <p style="color: #555;">{{ an.content }}:</p>
  44. <p style="color: #1890ff;">{{ an.analysis }}</p>
  45. </div>
  46. <!-- <p v-if="analysisCount === 0">暂无选项解析</p>-->
  47. </el-card>
  48. <div style="padding-top: 30px">
  49. <el-button type="primary" @click="handNext">继续下一题</el-button>
  50. <!-- <el-button type="info" @click="onCancel">返回</el-button>-->
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import { getQu } from '@/api/training/elearn/qu'
  56. import { nextQu, addUserQu } from '@/api/training/elearn/userQu'
  57. import { addUserBook } from "@/api/training/elearn/userBook";
  58. export default {
  59. name: 'BookTrain',
  60. data() {
  61. return {
  62. repoId: null,
  63. examId: null,
  64. quId: null,
  65. tags: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'],
  66. analysisShow: false,
  67. quData: {
  68. },
  69. answerValues: [],
  70. rightValues: [],
  71. rightTags: []
  72. }
  73. },
  74. created() {
  75. this.repoId = this.$route.params.repoId
  76. this.fetchNextQu()
  77. },
  78. methods: {
  79. getQuType(data){
  80. if (data == 1) {
  81. return "单选题"
  82. }else if (data == 2){
  83. return "多选题"
  84. }else if (data == 3){
  85. return "判断题"
  86. }
  87. },
  88. // 清理值
  89. clearValues() {
  90. this.answerValues = []
  91. this.rightValues = []
  92. this.analysisShow = false
  93. this.rightTags = []
  94. },
  95. // 查找试卷详情
  96. fetchQuDetail(id) {
  97. // 当前赋值
  98. this.quId = id
  99. this.clearValues()
  100. getQu(id).then(response => {
  101. // 题目信息
  102. this.quData = response.data
  103. // 保存正确答案
  104. this.quData.answerList.forEach((an, index) => {
  105. an.abc = this.tags[index]
  106. // 用户选定的
  107. if (an.isRight) {
  108. this.rightValues.push(an.answerId)
  109. this.rightTags.push(an.abc)
  110. }
  111. })
  112. })
  113. },
  114. fetchNextQu() {
  115. // 查找下一个
  116. nextQu({repoId: this.repoId,quId: this.quId}).then(response => {
  117. this.fetchQuDetail(response.data)
  118. })
  119. },
  120. onCancel() {
  121. // this.$router.push({ name: 'ListTran' })
  122. this.$router.push({ name: 'BookList' })
  123. },
  124. getUrl(image){
  125. return process.env.VUE_APP_BASE_API + image;
  126. },
  127. addUserQu(isRight){
  128. //
  129. addUserQu({quId: this.quId,repoId: this.repoId, isRight:isRight}).then(response => {
  130. })
  131. },
  132. handNext() {
  133. // 直接显示下一个
  134. if (this.analysisShow) {
  135. // 正确显示下一个
  136. this.fetchNextQu()
  137. } else {
  138. // 直接判断正确性
  139. console.log('=======================')
  140. console.log(this.rightValues.join(','))
  141. console.log(this.answerValues.join(','))
  142. if (this.rightValues.join(',') === this.answerValues.sort((a, b) => a - b).join(',') ) {
  143. this.$message({
  144. message: '回答正确,你好棒哦!',
  145. type: 'success'
  146. })
  147. // 添加正确历史记录
  148. this.addUserQu(1)
  149. // 正确显示下一个
  150. this.fetchNextQu()
  151. } else {
  152. // 错误显示解析
  153. this.analysisShow = true
  154. // 添加错误历史记录
  155. this.addUserQu(0)
  156. this.$message({
  157. message: '很遗憾,做错了呢,请参考答案解析!',
  158. type: 'error'
  159. })
  160. }
  161. }
  162. }
  163. }
  164. }
  165. </script>
  166. <style scoped>
  167. .qu-content div{
  168. line-height: 30px;
  169. }
  170. .qu-analysis p{
  171. color: #555; font-size: 14px
  172. }
  173. .qu-analysis-line{
  174. margin-top: 20px; border-bottom: #eee 1px solid
  175. }
  176. .el-checkbox-group label,.el-radio-group label{
  177. width: 100%;
  178. }
  179. </style>