TestShow.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="TestShow"
  3. :style="localOptions.style">
  4. <q-card v-if="!answerBook.loading && answerBook.id">
  5. <q-card-section class="flex justify-between">
  6. <div>{{ answerBook.test_info.title }}</div>
  7. </q-card-section>
  8. <q-separator />
  9. <q-banner>
  10. <div class="row">
  11. <div class="col-md-4 col-12">
  12. {{ toShamsi(answerBook.attending_start_time) }}
  13. </div>
  14. <div class="col-md-4 col-12">
  15. {{ answerBook.test_info.test_set_info.test_set_questions.length }}
  16. سوال
  17. </div>
  18. <div class="col-md-4 col-12">
  19. {{ answerBook.duration }}
  20. دقیقه
  21. </div>
  22. </div>
  23. </q-banner>
  24. <q-list separator>
  25. <q-item v-for="(question, questionIndex) in answerBook.test_info.test_set_info.test_set_questions"
  26. :key="questionIndex"
  27. clickable>
  28. <q-item-section v-html="question.question_info.text" />
  29. <q-item-section side>
  30. <q-badge>
  31. {{ question.mark }}
  32. نمره
  33. </q-badge>
  34. </q-item-section>
  35. </q-item>
  36. </q-list>
  37. </q-card>
  38. <div v-else>
  39. کمی صبر کنید...
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import Assist from 'src/assets/js/Assist.js'
  45. import { mixinWidget } from 'src/mixin/Mixins.js'
  46. import { APIGateway } from 'src/api/APIGateway.js'
  47. import { AnswerBook } from 'src/models/AnswerBook.js'
  48. export default {
  49. name: 'TestShow',
  50. mixins: [mixinWidget],
  51. data () {
  52. return {
  53. mounted: false,
  54. participateType: null,
  55. participateTypeDialog: false,
  56. answerBook: new AnswerBook(),
  57. remainingTime: 0,
  58. timerInterval: null
  59. }
  60. },
  61. computed: {
  62. formattedRemainingTime () {
  63. const hours = Math.floor(this.remainingTime / 3600)
  64. const minutes = Math.floor((this.remainingTime % 3600) / 60)
  65. const seconds = this.remainingTime % 60
  66. // Add zero padding for hours, minutes, and seconds
  67. const formattedHours = hours.toString().padStart(2, '0')
  68. const formattedMinutes = minutes.toString().padStart(2, '0')
  69. const formattedSeconds = seconds.toString().padStart(2, '0')
  70. return formattedHours + ':' + formattedMinutes + ':' + formattedSeconds
  71. }
  72. },
  73. mounted () {
  74. // this.getAnswerBook()
  75. this.getTestQuestions()
  76. this.mounted = true
  77. },
  78. methods: {
  79. onAllQuestionsSending () {
  80. this.answerBook.loading = true
  81. },
  82. onAllQuestionsSentSuccess () {
  83. this.answerBook.loading = false
  84. this.backToClassList()
  85. },
  86. onAllQuestionsSentFailed () {
  87. this.answerBook.loading = false
  88. },
  89. onSingleQuestionsSending () {
  90. this.answerBook.loading = true
  91. },
  92. onSingleQuestionsSentSuccess () {
  93. this.answerBook.loading = false
  94. this.backToClassList()
  95. },
  96. onSingleQuestionsSentFailed () {
  97. this.answerBook.loading = false
  98. },
  99. toShamsi (miladi) {
  100. return Assist.miladiToShamsi(miladi)
  101. },
  102. startTest () {
  103. this.$router.push({ name: this.participateType, params: { question_id: 1 } })
  104. },
  105. getRemainingTimeInSeconds (serverTimeStr, attendingStartTimeStr, durationInMinutes) {
  106. // Convert the strings to Date objects
  107. const serverTime = new Date(serverTimeStr)
  108. const attendingStartTime = new Date(attendingStartTimeStr)
  109. // Calculate the difference in milliseconds
  110. const timeDiffInMilliseconds = serverTime - attendingStartTime
  111. // Convert the difference to seconds
  112. const timeDiffInSeconds = timeDiffInMilliseconds / 1000
  113. // Calculate the remaining time in seconds considering the duration
  114. return (durationInMinutes * 60) - timeDiffInSeconds
  115. },
  116. startTimer () {
  117. this.timerInterval = setInterval(() => {
  118. if (this.remainingTime <= 0) {
  119. this.stopTimer()
  120. } else {
  121. this.remainingTime--
  122. }
  123. }, 1000)
  124. },
  125. stopTimer () {
  126. if (!this.timerInterval) {
  127. return
  128. }
  129. clearInterval(this.timerInterval)
  130. },
  131. backToClassList () {
  132. // this.$router.push({ name: 'UserPanel.Profile.AllClassrooms' })
  133. },
  134. getAnswerBook () {
  135. this.answerBook.loading = true
  136. APIGateway.answerBook.get(this.$route.params.answer_book_id)
  137. .then((answerBook) => {
  138. this.answerBook = new AnswerBook(answerBook)
  139. this.answerBook.loading = false
  140. })
  141. .catch(() => {
  142. this.answerBook.loading = false
  143. this.backToClassList()
  144. })
  145. },
  146. getTestQuestions () {
  147. this.answerBook.loading = true
  148. APIGateway.answerBook.getTestQuestions(this.$route.params.answer_book_id)
  149. .then((answerBook) => {
  150. this.answerBook = new AnswerBook(answerBook)
  151. this.answerBook.loading = false
  152. this.answerBook.server_time = '2023-12-15T23:57:46.909211'
  153. this.answerBook.attending_start_time = '2023-12-15T23:27:46.909211'
  154. this.remainingTime = this.getRemainingTimeInSeconds(this.answerBook.server_time, this.answerBook.attending_start_time, this.answerBook.duration)
  155. this.startTimer()
  156. })
  157. .catch(() => {
  158. this.answerBook.loading = false
  159. this.backToClassList()
  160. })
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .TestShow {
  167. :deep(.q-banner) {
  168. background: #FCF9F4 0 0 no-repeat padding-box;
  169. padding: 20px;
  170. .q-banner__content {
  171. font-size: 16px;
  172. font-weight: normal;
  173. }
  174. }
  175. }
  176. </style>