exam.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view>
  3. <swiper class="question_content">
  4. <swiper-item v-for="(item, index) in question_Info.question_list" :key="index">
  5. <view class="question_item">
  6. <view class="question_content_text">{{ item.question_title }}</view>
  7. <view class="question_options">
  8. <view v-for="(option, cIndex) in item.answer_list" :key="index" :class="['question_answer', { active: item.checkAnswer == option.id }]" @click="_selectAnswer(index, option.id)">
  9. <view :class="['question_index', { active: item.checkAnswer == option.id }]">{{ option.value.substring(0, 1) }}</view>
  10. {{ option.value.substring(2) }}
  11. </view>
  12. </view>
  13. </view>
  14. </swiper-item>
  15. </swiper>
  16. <view class="bottom_btn">
  17. <view class="answer_info"
  18. >已答&nbsp;<view style="color: #5045e6">{{ answeredCount }}</view
  19. >&nbsp;题,共&nbsp;{{ question_Info.question_total }}&nbsp;题</view
  20. >
  21. <view class="submit-btn" @click="_handleSubmit">交卷</view>
  22. </view>
  23. <uni-popup ref="tipRef" type="center" @change="_changeTip">
  24. <view class="tip_content">
  25. <view code>&nbsp;{{ "<" }}&nbsp; &nbsp;{{ ">" }}&nbsp;</view>
  26. <view>左右滑动切换题目</view>
  27. </view>
  28. </uni-popup>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. course_id: null,
  36. question_Info: {},
  37. };
  38. },
  39. onLoad(param) {
  40. this.course_id = param.id;
  41. if (!uni.getStorageSync("isShowExamTip")) {
  42. this.$refs.tipRef.open("center");
  43. }
  44. uni.enableAlertBeforeUnload({
  45. message: "您确定要退出答题吗?",
  46. success: function (res) {
  47. console.log("方法注册成功:", res);
  48. },
  49. fail: function (errMsg) {
  50. console.log("方法注册失败:", errMsg);
  51. },
  52. });
  53. },
  54. onShow() {
  55. this._getDetail();
  56. },
  57. computed: {
  58. answeredCount() {
  59. if (!this.question_Info.question_list) return 0;
  60. return this.question_Info.question_list.filter((item) => item.checkAnswer).length;
  61. },
  62. },
  63. methods: {
  64. _changeTip() {
  65. uni.setStorageSync("isShowExamTip", true);
  66. },
  67. _getDetail() {
  68. this.$http
  69. .request("api/video_exam_question/get_list", {
  70. course_id: this.course_id,
  71. })
  72. .then((re) => {
  73. if (re.code == "success") {
  74. this.question_Info = re.data;
  75. }
  76. });
  77. },
  78. _selectAnswer(index, id) {
  79. this.question_Info.question_list[index].checkAnswer = id;
  80. },
  81. _handleSubmit() {
  82. if (this.answeredCount !== this.question_Info.question_total) {
  83. uni.showModal({
  84. title: "温馨提示",
  85. content: "还有未完成的题目,是否交卷",
  86. confirmText: "继续交卷",
  87. cancelText: "继续答题",
  88. success: (res) => {
  89. if (res.confirm) {
  90. this._handleIn();
  91. }
  92. },
  93. });
  94. } else {
  95. this._handleIn();
  96. }
  97. },
  98. _handleIn() {
  99. const _this = this
  100. const question_list = this.question_Info.question_list.filter((item) => item.checkAnswer);
  101. const answer_list = question_list.map((item) => {
  102. return { question_id: item.question_id, answer_id: item.checkAnswer };
  103. });
  104. this.$http
  105. .request(
  106. "api/video_exam_record/hand_in",
  107. {
  108. record_id: this.question_Info.record_id,
  109. answer_list: JSON.stringify(answer_list),
  110. },
  111. "POST"
  112. )
  113. .then((re) => {
  114. if (re.code == "success") {
  115. uni.showModal({
  116. title: "完成测评",
  117. content: "恭喜您完成测评,是否查看报告",
  118. confirmText: "查看报告",
  119. cancelText: "返回列表",
  120. success(res) {
  121. if (res.confirm) {
  122. uni.redirectTo({
  123. url: `/pages/video/record?type=exam&record_id=${_this.question_Info.record_id}`,
  124. });
  125. } else {
  126. uni.redirectTo({
  127. url: `/pages/video/index`,
  128. });
  129. }
  130. },
  131. });
  132. }
  133. });
  134. },
  135. },
  136. };
  137. </script>
  138. <style lang="less" scoped>
  139. .tip_content {
  140. font-size: 64rpx;
  141. font-weight: bold;
  142. color: #fff;
  143. display: flex;
  144. flex-direction: column;
  145. justify-content: center;
  146. align-items: center;
  147. gap: 20rpx;
  148. }
  149. .question_content {
  150. height: calc(100vh - 150rpx);
  151. background-color: #f2f2f2;
  152. width: 100%;
  153. box-sizing: border-box;
  154. padding: 30rpx 20rpx;
  155. .question_item {
  156. width: 100%;
  157. padding: 30rpx 20rpx;
  158. box-sizing: border-box;
  159. border: 2rpx solid #ddd;
  160. border-radius: 8rpx;
  161. .question_content_text {
  162. font-size: 32rpx;
  163. margin-bottom: 80rpx;
  164. font-weight: bold;
  165. }
  166. .question_options {
  167. display: flex;
  168. flex-direction: column;
  169. gap: 40rpx;
  170. width: 100%;
  171. .question_index {
  172. border: 2rpx solid #ddd;
  173. border-radius: 50%;
  174. width: 50rpx;
  175. height: 50rpx;
  176. text-align: center;
  177. line-height: 50rpx;
  178. margin-right: 20rpx;
  179. &.active {
  180. border-color: #5045e6;
  181. background-color: #5045e6;
  182. color: #fff;
  183. }
  184. }
  185. .question_answer {
  186. height: 80rpx;
  187. width: 100%;
  188. border-radius: 20rpx;
  189. display: flex;
  190. align-items: center;
  191. &.active {
  192. color: #5045e6;
  193. }
  194. }
  195. }
  196. }
  197. }
  198. .bottom_btn {
  199. position: fixed;
  200. bottom: 0;
  201. left: 0;
  202. width: 100%;
  203. height: 150rpx;
  204. border-top: 4rpx solid #ddd;
  205. display: flex;
  206. align-items: center;
  207. justify-content: space-between;
  208. padding: 0 40rpx;
  209. box-sizing: border-box;
  210. .answer_info {
  211. display: flex;
  212. align-items: baseline;
  213. }
  214. .submit-btn {
  215. background-color: #5045e6;
  216. color: #fff;
  217. font-size: 28rpx;
  218. width: 200rpx;
  219. height: 80rpx;
  220. line-height: 80rpx;
  221. border-radius: 8rpx;
  222. box-shadow: 2rpx 2rpx 8rpx rgba(0, 0, 0, 0.1);
  223. text-align: center;
  224. }
  225. }
  226. </style>