preview.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <!-- -->
  2. <template>
  3. <div class="question">
  4. <template v-if="context">
  5. <div v-html="context.title" v-if="context.title"></div>
  6. <div v-html="context.article" v-if="context.article"></div>
  7. <template v-if="queType == 'JUDEGE'">
  8. <Single
  9. :answer="answer"
  10. :cur="cur"
  11. :getAnswer="getAnswer"
  12. :moduleType="moduleType"
  13. :queIndex="queIndex"
  14. :uiType="context.ui_type"
  15. ref="single"
  16. />
  17. </template>
  18. <a @click="handlePrev" class="btn-prev-big"></a>
  19. <a @click="handleNext" class="btn-next-big"></a>
  20. </template>
  21. </div>
  22. </template>
  23. <script>
  24. import Single from "@/components/Single/index";
  25. export default {
  26. name: "Question",
  27. props: {
  28. // context: {
  29. // type: Array,
  30. // default: null
  31. // },
  32. },
  33. components: {
  34. Single,
  35. },
  36. data () {
  37. return {
  38. answer: [],
  39. queType: "", //题型的类型
  40. moduleType: "", //模版的类型
  41. queList: [], //题目数组
  42. queTotal: 2, //题目总数
  43. queIndex: 0, //题目的索引
  44. cur: [], //当前的题目
  45. context: null
  46. };
  47. },
  48. computed: {},
  49. watch: {},
  50. //方法集合
  51. methods: {
  52. getAnswer (data, index) {
  53. if (this.answer.length + 1 < index) {
  54. // 新答案
  55. this.answer.push(data)
  56. } else {
  57. // 修改答案
  58. this.answer[index] = data
  59. }
  60. console.log(this.answer)
  61. },
  62. handleNext () {
  63. this.$refs.single.$emit("singleActiveindex")
  64. let _this = this;
  65. if (_this.queIndex == _this.queTotal - 1) {
  66. this.$message({
  67. message: "已经是最后一题",
  68. type: "success",
  69. });
  70. } else {
  71. _this.queIndex = _this.queIndex + 1;
  72. _this.cur = _this.queList[_this.queIndex];
  73. }
  74. },
  75. handlePrev () {
  76. this.$refs.single.$emit("singleActiveindex")
  77. let _this = this;
  78. if (_this.queIndex == 0) {
  79. this.$message({
  80. message: "已经是第一题",
  81. type: "success",
  82. });
  83. } else {
  84. _this.queIndex = _this.queIndex - 1;
  85. _this.cur = _this.queList[_this.queIndex];
  86. }
  87. },
  88. },
  89. //生命周期 - 创建完成(可以访问当前this实例)
  90. created () { },
  91. //生命周期 - 挂载完成(可以访问DOM元素)
  92. mounted () {
  93. let _this = this;
  94. _this.context = {
  95. "content": "大撒大撒",
  96. "type": 9,
  97. "ui_type": "JUDEGE_01",
  98. "ui_typeList": [{ "name": "选择" }, { "name": "判断" }, { "name": "输入" }],
  99. "dataList": [
  100. {
  101. "correct": [{ "con": "á", "isAnswer": 1 }],
  102. "mp3": "",
  103. "option": [{ "con": "ā", "isAnswer": false }, { "con": "á", "isAnswer": 1 }],
  104. }
  105. ]
  106. }
  107. if (_this.context) {
  108. let queType = _this.context.ui_type.split("_");
  109. _this.queType = queType[0];
  110. _this.moduleType = queType[1];
  111. let list = _this.context.dataList;
  112. if (list && list.length > 0) {
  113. _this.queList = list;
  114. _this.cur = list[_this.queIndex];
  115. _this.queTotal = list.length;
  116. }
  117. }
  118. },
  119. beforeCreate () { }, //生命周期 - 创建之前
  120. beforeMount () { }, //生命周期 - 挂载之前
  121. beforeUpdate () { }, //生命周期 - 更新之前
  122. updated () { }, //生命周期 - 更新之后
  123. beforeDestroy () { }, //生命周期 - 销毁之前
  124. destroyed () { }, //生命周期 - 销毁完成
  125. activated () { }, //如果页面有keep-alive缓存功能,这个函数会触发
  126. };
  127. </script>
  128. <style lang='scss' scoped>
  129. .question {
  130. position: relative;
  131. width: 100%;
  132. height: 100%;
  133. background: #ffd66b url('../assets/single/bg.png') center no-repeat;
  134. background-size: cover;
  135. .btn-prev-big,
  136. .btn-next-big {
  137. width: 172px;
  138. height: 116px;
  139. position: absolute;
  140. left: 0;
  141. top: 50%;
  142. margin-top: -58px;
  143. background: url('../assets/single/btn-prev.png') center no-repeat;
  144. background-size: 100% 100%;
  145. }
  146. .btn-next-big {
  147. right: 0;
  148. left: auto;
  149. background: url('../assets/single/btn-next.png') center no-repeat;
  150. background-size: 100% 100%;
  151. }
  152. }
  153. </style>