train.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 { nextBookQu, removBookQu} from '@/api/training/elearn/userBook'
  57. import { addUserQu } from '@/api/training/elearn/userQu'
  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. nextBookQu({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. addUserQu({quId: this.quId,isRight:isRight}).then(response => {
  129. })
  130. },
  131. handNext() {
  132. // 直接显示下一个
  133. if (this.analysisShow) {
  134. // 正确显示下一个
  135. this.fetchNextQu()
  136. } else {
  137. // 直接判断正确性
  138. if (this.rightValues.join(',') === this.answerValues.join(',')) {
  139. this.$message({
  140. message: '回答正确,你好棒哦!',
  141. type: 'success'
  142. })
  143. // 添加正确历史记录
  144. this.addUserQu(1)
  145. removBookQu({quId: this.quId}).then(response => {
  146. })
  147. // 正确显示下一个
  148. this.fetchNextQu()
  149. } else {
  150. // 错误显示解析
  151. this.analysisShow = true
  152. // 添加错误历史记录
  153. this.addUserQu(0)
  154. this.$message({
  155. message: '很遗憾,做错了呢,请参考答案解析!',
  156. type: 'error'
  157. })
  158. }
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style scoped>
  165. .qu-content div{
  166. line-height: 30px;
  167. }
  168. .qu-analysis p{
  169. color: #555; font-size: 14px
  170. }
  171. .qu-analysis-line{
  172. margin-top: 20px; border-bottom: #eee 1px solid
  173. }
  174. .el-checkbox-group label,.el-radio-group label{
  175. width: 100%;
  176. }
  177. </style>