index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div id="testpaper">
  3. <div class="card">
  4. <el-card shadow="hover">
  5. <Radio
  6. v-if="Data.type=='radio'"
  7. :Data="Data"
  8. :State="State"
  9. @Func="Answer"
  10. />
  11. <Checkbox
  12. v-if="Data.type=='checkbox'"
  13. :Data="Data"
  14. :State="State"
  15. @Func="Answer"
  16. />
  17. <Input
  18. v-if="Data.type=='input'"
  19. :Data="Data"
  20. :State="State"
  21. @Func="Answer"
  22. />
  23. <Bool
  24. v-if="Data.type=='bool'"
  25. :Data="Data"
  26. :State="State"
  27. @Func="Answer"
  28. />
  29. <p v-if="!State">
  30. <el-button
  31. :disabled="A"
  32. @click="Success({tag:'btn',type:'-',id:Data.id})"
  33. type="success"
  34. >上一题</el-button>
  35. <el-button
  36. :disabled="B"
  37. @click="Success({tag:'btn',type:'+',id:Data.id})"
  38. type="success"
  39. >下一题</el-button>
  40. </p>
  41. </el-card>
  42. </div>
  43. <div
  44. v-if="!State"
  45. class="list"
  46. >
  47. <el-card
  48. style="background-color:#f03;color:#fff;text-align:center"
  49. shadow="never"
  50. >{{timer_msg}}</el-card>
  51. <br />
  52. <el-card shadow="hover">
  53. <div class="exam-card">
  54. <h3>答题卡</h3>
  55. <SelectCircle
  56. v-for="(item,index) in StateData"
  57. :key="index"
  58. :Data="item"
  59. :props="index"
  60. @Success="Success"
  61. />
  62. <el-button
  63. @click="JJ({tag:'btn',type:'+',id:Data.id})"
  64. type="success"
  65. >交卷</el-button>
  66. </div>
  67. </el-card>
  68. </div>
  69. <!-- 对话框 -->
  70. <el-dialog
  71. title="提示"
  72. :visible.sync="dialogVisible"
  73. width="30%"
  74. >
  75. <span>{{dialog_msg}}</span>
  76. <span
  77. slot="footer"
  78. class="dialog-footer"
  79. >
  80. <el-button @click="dialogVisible = false">取 消</el-button>
  81. <el-button
  82. type="primary"
  83. @click="dialog"
  84. >确 定</el-button>
  85. </span>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script>
  90. const Radio = () => import("@/components/TestPaper/components/radio");
  91. const Checkbox = () => import("@/components/TestPaper/components/checkbox");
  92. const Input = () => import("@/components/TestPaper/components/input");
  93. const Bool = () => import("@/components/TestPaper/components/bool");
  94. const SelectCircle = () => import("@/components/SelectCircle/index");
  95. export default {
  96. components: {
  97. Radio, Checkbox, Input, Bool, SelectCircle
  98. },
  99. props: {
  100. //状态 答题 查看答案
  101. State: {
  102. type: Boolean,
  103. default: false
  104. },
  105. // 题
  106. Data: {
  107. type: Object,
  108. default: {}
  109. },
  110. // 总题数
  111. Total: {
  112. type: Number / String,
  113. default: 1
  114. },
  115. // 计时器
  116. Timer: {
  117. type: Number / String,
  118. default: 0,
  119. },
  120. // 未做题目
  121. Unselected: {
  122. type: Number / String,
  123. default: 0
  124. },
  125. // 答题卡
  126. StateData: {
  127. type: Array,
  128. default: function () {
  129. return [];
  130. }
  131. },
  132. // 类型
  133. Type: {
  134. type: String,
  135. default: ""
  136. }
  137. },
  138. data () {
  139. return {
  140. value: null,//答题的值
  141. timer_msg: '',//计时器
  142. A: false, B: false,
  143. dialogVisible: false,//对话框,
  144. dialog_msg: "",
  145. }
  146. },
  147. created () {
  148. },
  149. mounted () {
  150. this.Type == 'formal' ?
  151. this.TimeFunc(false) : this.TimeFunc();
  152. },
  153. methods: {
  154. // 倒计时结束交卷 会话框确定
  155. dialog () {
  156. this.dialogVisible = false;
  157. this.Success({ tag: 'btns', type: '+', id: this.Data.id })
  158. },
  159. // 定时器
  160. TimeFunc (data = true) {
  161. let that = this;
  162. // 计时器
  163. let time = this.Timer;
  164. this.timer = setInterval(() => {
  165. if (data) {
  166. ++time;
  167. let hours = Math.floor(time / 60 / 60),
  168. minutes = Math.floor((time - hours * 60 * 60) / 60),
  169. seconds = Math.floor(time % 60);
  170. that.timer_msg = `练习时间:${hours}时${minutes}分${seconds}秒`
  171. } else {
  172. --time;
  173. let hours = Math.floor(time / 60 / 60),
  174. minutes = Math.floor((time - hours * 60 * 60) / 60),
  175. seconds = Math.floor(time % 60);
  176. that.timer_msg = `结束时间:${hours}时${minutes}分${seconds}秒`;
  177. if (time <= 0) {
  178. this.dialog();
  179. clearInterval(this.timer)
  180. }
  181. }
  182. }, 1000)
  183. },
  184. // 答题
  185. Answer (data) {
  186. this.value = data;
  187. },
  188. // 交卷
  189. JJ () {
  190. if (this.Unselected <= 1) {
  191. this.dialog_msg = "确认交卷吗?"
  192. } else {
  193. this.dialog_msg = `你还有${this.Unselected}道题尚未完成,确认交卷吗?`;
  194. }
  195. this.dialogVisible = true;
  196. },
  197. // 答题卡 上一题 下一题
  198. Success (data) {
  199. this.$emit('Func', JSON.parse(JSON.stringify({ data, value: this.value })));
  200. },
  201. able (type, id) {
  202. if (type == '-' && id == 1) return true;
  203. if (type == '+' && id >= this.Total) return true;
  204. }
  205. },
  206. watch: {
  207. Data (val, oldval) {
  208. val.id == 1 ? this.A = true : this.A = false;
  209. val.id == this.Total ? this.B = true : this.B = false;
  210. this.value = [];
  211. }
  212. },
  213. beforeDestroy () {
  214. clearInterval(this.timer)
  215. },
  216. }
  217. </script>
  218. <style lang="less" scoped>
  219. #testpaper {
  220. display: flex;
  221. .card {
  222. width: 100%;
  223. box-sizing: border-box;
  224. }
  225. .list {
  226. width: 300px;
  227. margin-left: 20px;
  228. }
  229. .exam-card {
  230. h3 {
  231. margin-top: 0;
  232. }
  233. .el-button {
  234. margin-top: 10px;
  235. width: 100%;
  236. }
  237. }
  238. }
  239. </style>