exam.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <!-- 列表 -->
  3. <view class="safety-exam">
  4. <!-- for此部分 -->
  5. <examinationItem ref="examinationItem" :questionObj="paperQuestionList[currentIndex]" :itemIndex="currentIndex" @selected="handleSelected">
  6. </examinationItem>
  7. <u-card v-if="currentUserAnswer" padding="32" full :showHead="false">
  8. <view slot="body">
  9. <view v-if="currentUserAnswer.isCorrect" style="display: flex;align-items: center;margin-bottom: 24rpx;">
  10. <image v-if="globalImages" :src="globalImages + 'imgs/dui.png'" style="width: 28rpx;height: 28rpx;"></image>
  11. <view style="margin-left: 16rpx;color: #333333;line-height: 40rpx;font-size: 28rpx;">回答正确!</view>
  12. </view>
  13. <view v-else style="display: flex;align-items: center;margin-bottom: 24rpx;">
  14. <image v-if="globalImages" :src="globalImages + 'imgs/cha.png'" style="width: 28rpx;height: 28rpx;"></image>
  15. <view style="margin-left: 16rpx;color: #333333;line-height: 40rpx;font-size: 28rpx;">回答错误!</view>
  16. </view>
  17. <view style="display: flex;align-items: center;margin-bottom: 24rpx;" @click="showAnalysis(currentUserAnswer.analysis)">
  18. <image v-if="globalImages" :src="globalImages + 'imgs/jiexi.png'" style="width: 28rpx;height: 28rpx;"></image>
  19. <view style="margin-left: 16rpx;color: #333333;line-height: 40rpx;font-size: 28rpx;">查看解析</view>
  20. </view>
  21. <!-- <view>
  22. <view>解析</view>
  23. <view>
  24. <text>答案: {{ currentUserAnswer.correctValue }}</text>
  25. <text style="margin-left: 40rpx;">您选择: </text>
  26. <text style="color: ;">{{ currentUserAnswer.code }}</text>
  27. </view>
  28. <view>题目解析</view>
  29. <view>{{ currentUserAnswer.analysis }}</view>
  30. </view> -->
  31. </view>
  32. </u-card>
  33. <view class="placeholder"></view>
  34. <view class="tabbar_bottom">
  35. <view style="height: 100%;display: flex;justify-content: space-between;align-items: center;padding: 0 32rpx;">
  36. <view style="color: #333333;font-size: 28rpx;">已完成 {{ answerCount }}/{{ paperQuestionList.length }}</view>
  37. <view style="display: flex;align-items: center;">
  38. <u-button v-if="currentIndex > 0" type="primary" @click="prev" size="medium">上一题</u-button>
  39. <view>
  40. <u-button
  41. v-if="currentIndex < paperQuestionList.length - 1 && currentIndex !== paperQuestionList.length - 1"
  42. type="primary"
  43. size="medium"
  44. style="margin-left: 32rpx;"
  45. @click="next"
  46. >
  47. 下一题
  48. </u-button>
  49. <u-button v-else type="primary" size="medium" style="margin-left: 32rpx;" @click="navgo('/my/safety/examcomplete')">提交</u-button>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import ExaminationItem from './modules/ExaminationItem'
  58. import { waitForGlobalImages } from '@/utils/globalImageLoader'
  59. export default {
  60. components: { ExaminationItem },
  61. data() {
  62. return {
  63. globalImages: null,
  64. // 题目列表
  65. paperQuestionList: [
  66. {
  67. id: 1,
  68. questionType: 1,
  69. questionContent: '在雨天行驶时,以下哪种做法是正确的?',
  70. analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  71. questionOptionList: [
  72. { id: 1, optionCode: 'A', optionContent: '降低车速,保持安全距离 ' },
  73. { id: 2, optionCode: 'B', optionContent: '加速通过积水路段 ' },
  74. { id: 3, optionCode: 'C', optionContent: '紧急制动避免打滑 ' },
  75. { id: 4, optionCode: 'D', optionContent: '关闭雨刷器节省电力 ' }
  76. ],
  77. },
  78. {
  79. id: 2,
  80. questionType: 1,
  81. questionContent: '某日13时10分,罗某驾驶一辆中型客车从高速公路0公里处出发,下午14时10分行至该高速公路125公里加200米处时,发生追尾碰撞,机动车驶出西南侧路外边坡,造成11人死亡、2人受伤。罗某的主要违法行为是什么?',
  82. analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  83. questionOptionList: [
  84. { id: 1, optionCode: 'A', optionContent: '超速行驶' },
  85. { id: 2, optionCode: 'B', optionContent: '不按交通标线行驶' },
  86. { id: 3, optionCode: 'C', optionContent: '客车超员' },
  87. { id: 4, optionCode: 'D', optionContent: '疲劳驾驶' }
  88. ],
  89. },
  90. {
  91. id: 3,
  92. questionType: 1,
  93. questionContent: '在山区道路超车时,应怎样超越?',
  94. analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  95. questionOptionList: [
  96. { id: 1, optionCode: 'A', optionContent: '选择较缓的下坡路' },
  97. { id: 2, optionCode: 'B', optionContent: '选择较长的下坡路' },
  98. { id: 3, optionCode: 'C', optionContent: '选择宽阔的缓上坡' },
  99. { id: 4, optionCode: 'D', optionContent: '选择较长的下坡路' }
  100. ],
  101. },
  102. // {
  103. // id: 4,
  104. // questionType: 1,
  105. // questionContent: '驾驶汽车在进出隧道时应注意什么?',
  106. // analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  107. // questionOptionList: [
  108. // { id: 1, optionCode: 'A', optionContent: '开启远光灯' },
  109. // { id: 2, optionCode: 'B', optionContent: '适当提高车速' },
  110. // { id: 3, optionCode: 'C', optionContent: '关闭近光灯' },
  111. // { id: 4, optionCode: 'D', optionContent: '提前降低车速' }
  112. // ],
  113. // },
  114. // {
  115. // id: 5,
  116. // questionType: 1,
  117. // questionContent: '夜间驾驶机动车,应在哪种情况下使用远光灯?',
  118. // analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  119. // questionOptionList: [
  120. // { id: 1, optionCode: 'A', optionContent: '没有路灯或照明差的道路上' },
  121. // { id: 2, optionCode: 'B', optionContent: '车速低于30km/h时' },
  122. // { id: 3, optionCode: 'C', optionContent: '会车时' },
  123. // { id: 4, optionCode: 'D', optionContent: '跟车行驶时' }
  124. // ],
  125. // },
  126. // {
  127. // id: 6,
  128. // questionType: 1,
  129. // questionContent: '行车中发现左侧轮胎漏气时怎样处置?',
  130. // analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  131. // questionOptionList: [
  132. // { id: 1, optionCode: 'A', optionContent: '慢慢制动减速' },
  133. // { id: 2, optionCode: 'B', optionContent: '迅速制动减速' },
  134. // { id: 3, optionCode: 'C', optionContent: '迅速向右转向' },
  135. // { id: 4, optionCode: 'D', optionContent: '采取紧急制动' }
  136. // ],
  137. // },
  138. // {
  139. // id: 7,
  140. // questionType: 1,
  141. // questionContent: '大风天气行车,当感到转向盘突然“被夺”时,下列做法正确的是什么?',
  142. // analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  143. // questionOptionList: [
  144. // { id: 1, optionCode: 'A', optionContent: '顺风向转动转向盘' },
  145. // { id: 2, optionCode: 'B', optionContent: '逆风向转动转向盘' },
  146. // { id: 3, optionCode: 'C', optionContent: '采取紧急制动' },
  147. // { id: 4, optionCode: 'D', optionContent: '双手稳握转向盘' }
  148. // ],
  149. // },
  150. // {
  151. // id: 8,
  152. // questionType: 1,
  153. // questionContent: '行车中超越右侧停放的车辆时,为预防其突然起步或开启车门,应怎样做?',
  154. // analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  155. // questionOptionList: [
  156. // { id: 1, optionCode: 'A', optionContent: '预留出横向安全距离,减速行驶' },
  157. // { id: 2, optionCode: 'B', optionContent: '保持正常速度行驶' },
  158. // { id: 3, optionCode: 'C', optionContent: '长鸣喇叭' },
  159. // { id: 4, optionCode: 'D', optionContent: '加速通过' }
  160. // ],
  161. // },
  162. // {
  163. // id: 9,
  164. // questionType: 1,
  165. // questionContent: '驾驶人行车中看到注意儿童标志的时候,应怎样做?',
  166. // analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  167. // questionOptionList: [
  168. // { id: 1, optionCode: 'A', optionContent: '加速行驶' },
  169. // { id: 2, optionCode: 'B', optionContent: '绕道行驶' },
  170. // { id: 3, optionCode: 'C', optionContent: '谨慎选择行车速度' },
  171. // { id: 4, optionCode: 'D', optionContent: '保持正常车速行驶' }
  172. // ],
  173. // },
  174. // {
  175. // id: 10,
  176. // questionType: 1,
  177. // questionContent: '抢救昏迷失去知觉的伤员需注意什么?',
  178. // analysis: 'analysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysisanalysis',
  179. // questionOptionList: [
  180. // { id: 1, optionCode: 'A', optionContent: '马上实施心肺复苏' },
  181. // { id: 2, optionCode: 'B', optionContent: '使劲掐伤员的人中' },
  182. // { id: 3, optionCode: 'C', optionContent: '连续拍打伤员面部' },
  183. // { id: 4, optionCode: 'D', optionContent: '抢救前先检查呼吸' }
  184. // ],
  185. // }
  186. ],
  187. //请求接口获取答案
  188. answers: {
  189. 1: {
  190. code: 'A'
  191. },
  192. 2: {
  193. code: 'A'
  194. },
  195. 3: {
  196. code: 'A'
  197. },
  198. 4: {
  199. code: 'A'
  200. },
  201. 5: {
  202. code: 'A'
  203. },
  204. 6: {
  205. code: 'A'
  206. },
  207. 7: {
  208. code: 'A'
  209. },
  210. 8: {
  211. code: 'A'
  212. },
  213. 9: {
  214. code: 'A'
  215. },
  216. 10: {
  217. code: 'A'
  218. },
  219. },
  220. // 题目索引
  221. currentIndex: 0,
  222. // key = 题目Id, value = 回答结果数据
  223. userAnswers: {},
  224. // 回答题目数量
  225. answerCount: 0,
  226. // 当前题目, 用户的答案
  227. currentUserAnswer: null,
  228. arr: [],
  229. token: '',
  230. };
  231. },
  232. onLoad(e) {
  233. waitForGlobalImages().then((path) => {
  234. this.globalImages = path
  235. })
  236. },
  237. onShow() {
  238. this.token = this.$queue.getData('token')
  239. },
  240. methods: {
  241. next() {
  242. if(this.currentIndex < this.paperQuestionList.length - 1) {
  243. this.currentIndex = this.currentIndex + 1
  244. const questionId = this.paperQuestionList[this.currentIndex].id
  245. const answerResult = this.userAnswers[questionId]
  246. // console.log(questionId, answerResult, this.userAnswers)
  247. if(answerResult) {
  248. this.$refs.examinationItem.selectCode = answerResult.code
  249. this.currentUserAnswer = answerResult
  250. } else {
  251. this.$refs.examinationItem.selectCode = null
  252. this.currentUserAnswer = null
  253. }
  254. // console.log('下一题', this.currentUserAnswer)
  255. }
  256. },
  257. prev() {
  258. if(this.currentIndex > 0) {
  259. this.currentIndex = this.currentIndex - 1
  260. const questionId = this.paperQuestionList[this.currentIndex].id
  261. const answerResult = this.userAnswers[questionId]
  262. // console.log(questionId, answerResult, this.userAnswers)
  263. if(answerResult) {
  264. this.$refs.examinationItem.selectCode = answerResult.code
  265. this.currentUserAnswer = answerResult
  266. } else {
  267. this.$refs.examinationItem.selectCode = null
  268. this.currentUserAnswer = null
  269. }
  270. // console.log('上一题', this.currentUserAnswer)
  271. }
  272. },
  273. /**
  274. * 处理选择选项事件
  275. * @param {Object} originalCode 原来选择的答案
  276. * @param {Object} code 现在选择的答案
  277. * @param {Object} questionId 题目Id
  278. * @param {Object} questionIndex 索引
  279. */
  280. handleSelected(originalCode, code, questionId, questionIndex) {
  281. const answerResult = this.userAnswers[questionId]
  282. if(answerResult) {
  283. this.$refs.examinationItem.selectCode = originalCode
  284. return
  285. } else {
  286. // 查询答案判断是否正确
  287. const correctValue = this.answers[questionId].code
  288. const answer = {
  289. code,
  290. correctValue,
  291. isCorrect: correctValue === code,
  292. analysis: this.paperQuestionList[questionIndex].analysis
  293. }
  294. this.userAnswers[questionId] = answer
  295. this.currentUserAnswer = answer
  296. }
  297. const ids = Object.keys(this.userAnswers)
  298. this.answerCount = ids && ids.length || 0
  299. // console.log('eeeeee', code, questionId, questionIndex, this.$refs.examinationItem.testValue)
  300. },
  301. showAnalysis(analysis) {
  302. uni.showModal({
  303. title: '题目解析',
  304. content: analysis,
  305. confirmText: '确定',
  306. cancelText: '取消',
  307. })
  308. },
  309. navgo(e) {
  310. // #ifdef MP-WEIXIN
  311. if (uni.getStorageSync('sendMsg')) {
  312. uni.requestSubscribeMessage({
  313. tmplIds: this.arr,
  314. success(re) {
  315. // console.log(re,'**********')
  316. var datas = JSON.stringify(re);
  317. if (datas.indexOf("accept") != -1) {
  318. console.log(re)
  319. }
  320. },
  321. fail: (res) => {
  322. console.log(res)
  323. }
  324. })
  325. }
  326. // #endif
  327. let that = this
  328. if (that.token) {
  329. // 请求接口获取成绩, 超过了多少考生, 是否合格
  330. const params = {
  331. score: 80,
  332. exceeding: 70,
  333. qualified: true,
  334. }
  335. uni.navigateTo({
  336. url: e + '?score=' + params.score + '&exceeding=' + params.exceeding + '&qualified=' + params.qualified
  337. })
  338. } else {
  339. uni.navigateTo({
  340. url: '/pages/login/login'
  341. })
  342. }
  343. },
  344. },
  345. }
  346. </script>
  347. <style lang="scss">
  348. .safety-exam {
  349. width: 100%;
  350. position: relative;
  351. padding: 16rpx 32rpx;
  352. box-sizing: border-box;
  353. }
  354. .placeholder {
  355. height: 108rpx;
  356. padding-bottom: 16rpx;
  357. padding-bottom: constant(safe-area-inset-bottom);
  358. padding-bottom: env(safe-area-inset-bottom);
  359. box-sizing: content-box;
  360. }
  361. .tabbar_bottom {
  362. position: fixed;
  363. left: 0;
  364. bottom: 0;
  365. width: 100%;
  366. height: 108rpx;
  367. background: #FFFFFF;
  368. // padding-left: 30rpx;
  369. // padding-right: 30rpx;
  370. padding-bottom: 16rpx;
  371. padding-bottom: constant(safe-area-inset-bottom);
  372. padding-bottom: env(safe-area-inset-bottom);
  373. box-sizing: content-box;
  374. border-top: 1rpx solid #E4E7ED;
  375. z-index: 101;
  376. }
  377. </style>