index.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div class="exam-content">
  3. <el-card class="box-card" v-for="(currentQuestion, index1) in datalist" :key="index1">
  4. <div slot="header" class="clearfix">
  5. 第{{index1+1}}题 : <span v-html="currentQuestion.title"></span>
  6. </div>
  7. <div class="q-single">
  8. <!-- 判断题 -->
  9. <div class="answer" v-if="currentQuestion.type==1">
  10. <div class="answer-item" v-for="(item, index) in currentQuestion.choice" :key="index">
  11. <el-radio :label="index+1">{{transformChar[index+1]+'、 '+item}}</el-radio>
  12. </div>
  13. <span style="margin-top: 10px;"> 正确答案:{{currentQuestion.result==1?'正确':'错误'}}</span>
  14. </div>
  15. <!-- 当选题 -->
  16. <div class="answer" v-if="currentQuestion.type==2">
  17. <div class="answer-item" v-for="(item,index) in currentQuestion.choice" :key="index">
  18. <el-radio :label="index+1">{{transformChar[index+1]+'、 '+item}}</el-radio>
  19. </div>
  20. <span style="margin-top: 10px;"> 正确答案:{{transformChar[currentQuestion.result]}} </span>
  21. </div>
  22. <!-- 多选题 -->
  23. <div class="answer" v-if="currentQuestion.type==3">
  24. <div class="answer-item" v-for="(item,index) in currentQuestion.choice" :key="index">
  25. <el-checkbox :label="index+1">{{transformChar[index+1]}} '、 '{{item}}</el-checkbox>
  26. </div>
  27. <span style="margin-top: 10px;"> 正确答案:{{getMulResult(currentQuestion.result)}} </span>
  28. </div>
  29. </div>
  30. </el-card>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. filters:{
  36. getType( val ){
  37. const d = {1:'判断题', 2:'单选题', 3:'多选题'}
  38. return d[val]
  39. }
  40. },
  41. data() {
  42. return {
  43. datalist:[],
  44. transformChar: ["","A", "B", "C", "D","E"],
  45. }
  46. },
  47. created(){
  48. let id = this.$route.query.id
  49. var jsondata = require(`./${id}.json`);
  50. let list = jsondata.RECORDS.map( item =>{
  51. item.choice= [];
  52. for( let i=0;i<5;i++){
  53. let mkey = "answer"+i
  54. if(item[mkey] ) item.choice.push( item[mkey] );
  55. }
  56. return item;
  57. })
  58. this.datalist = list
  59. },
  60. methods:{
  61. getMulResult( select ){
  62. let selectList = (''+select).split("");
  63. let transformChar = this.transformChar;
  64. selectList = selectList.map( item=> {return transformChar[+item]})
  65. return selectList.join(",")
  66. }
  67. }
  68. }
  69. </script>
  70. <style>
  71. .exam-content{
  72. width: 1024px;
  73. background: #FFFFFF;
  74. margin: 0 auto;
  75. }
  76. </style>