logic-test.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 引导页 -->
  4. <view class="step-intro" v-if="step === 'intro'">
  5. <view class="intro-icon">
  6. <text class="intro-icon-text">🧠</text>
  7. </view>
  8. <text class="intro-title">逻辑推理测试</text>
  9. <text class="intro-desc">观察数列规律,从选项中选出缺失的数字</text>
  10. <view class="intro-info">
  11. <view class="info-row">
  12. <text class="info-label">题目数量</text>
  13. <text class="info-value">8 题</text>
  14. </view>
  15. <view class="info-row">
  16. <text class="info-label">每题限时</text>
  17. <text class="info-value">15 秒</text>
  18. </view>
  19. <view class="info-row">
  20. <text class="info-label">测评维度</text>
  21. <text class="info-value">逻辑思维</text>
  22. </view>
  23. </view>
  24. <view class="btn btn--primary" @tap="startTest">开始测试</view>
  25. </view>
  26. <!-- 答题页 -->
  27. <view class="step-playing" v-if="step === 'playing'">
  28. <view class="quiz-header">
  29. <text class="quiz-progress">第 {{ currentQ + 1 }}/{{ questions.length }} 题</text>
  30. <text class="quiz-timer">{{ timerSeconds }}s</text>
  31. </view>
  32. <view class="timer-track">
  33. <view class="timer-fill" :style="'width:' + timerPct + '%'"></view>
  34. </view>
  35. <view class="question-card" v-if="currentQuestion">
  36. <text class="q-text">{{ currentQuestion.seq }}</text>
  37. <view class="q-options">
  38. <view
  39. class="q-option"
  40. v-for="(opt, oi) in currentQuestion.options"
  41. :key="oi"
  42. :class="{ 'q-option--selected': selectedIndex === oi }"
  43. @tap="selectOption(oi)"
  44. >
  45. <text class="q-option-text">{{ opt }}</text>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 结果页 -->
  51. <view class="step-result" v-if="step === 'result'">
  52. <view class="score-circle">
  53. <text class="score-value">{{ score }}</text>
  54. </view>
  55. <text class="score-label">{{ scoreText }}</text>
  56. <view class="result-info">
  57. <view class="result-row">
  58. <text class="result-label">答对题数</text>
  59. <text class="result-value">{{ correctCount }}/{{ questions.length }}</text>
  60. </view>
  61. <view class="result-row">
  62. <text class="result-label">测评维度</text>
  63. <view class="dim-tag">
  64. <text class="dim-tag-text">逻辑思维</text>
  65. </view>
  66. </view>
  67. <view class="result-row">
  68. <text class="result-label">得分</text>
  69. <text class="result-value">{{ score }} 分</text>
  70. </view>
  71. </view>
  72. <view class="btn btn--primary" @tap="submitScore">提交成绩</view>
  73. <view class="btn btn--outline" @tap="restartTest">再测一次</view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import { submitCognitiveSelfTest } from '../../utils/api.js'
  79. var TIMER_SECONDS = 15
  80. var ROUND_COUNT = 8
  81. var QUESTION_BANK = [
  82. { seq: '2, 4, 6, 8, ?', options: ['9', '10', '11', '12'], answer: '10' },
  83. { seq: '21, 18, 15, 12, ?', options: ['10', '9', '8', '7'], answer: '9' },
  84. { seq: '1, 2, 4, 8, ?', options: ['12', '14', '16', '20'], answer: '16' },
  85. { seq: '1, 3, 9, 27, ?', options: ['54', '72', '81', '90'], answer: '81' },
  86. { seq: '1, 1, 2, 3, 5, 8, ?', options: ['10', '12', '13', '15'], answer: '13' },
  87. { seq: '2, 3, 5, 8, 13, ?', options: ['18', '20', '21', '24'], answer: '21' },
  88. { seq: '1, 4, 9, 16, 25, ?', options: ['30', '32', '36', '49'], answer: '36' },
  89. { seq: '1, 8, 27, 64, ?', options: ['100', '121', '125', '144'], answer: '125' },
  90. { seq: '5, 7, 6, 8, 7, ?', options: ['8', '9', '10', '11'], answer: '9' },
  91. { seq: '2, 5, 6, 9, 10, ?', options: ['11', '12', '13', '14'], answer: '13' },
  92. { seq: '1, 3, 5, 7, 9, ?', options: ['10', '11', '12', '13'], answer: '11' },
  93. { seq: '2, 5, 11, 23, ?', options: ['35', '41', '46', '47'], answer: '47' },
  94. { seq: '1, 3, 7, 13, 21, ?', options: ['27', '29', '31', '33'], answer: '31' },
  95. { seq: '3, 8, 6, 11, 9, ?', options: ['12', '13', '14', '15'], answer: '14' },
  96. { seq: '2, 3, 5, 7, 11, ?', options: ['12', '13', '15', '17'], answer: '13' },
  97. { seq: '64, 32, 16, 8, ?', options: ['2', '4', '6', '8'], answer: '4' },
  98. { seq: '4, 7, 10, 13, 16, ?', options: ['17', '18', '19', '21'], answer: '19' },
  99. { seq: '50, 45, 40, 35, ?', options: ['25', '28', '30', '32'], answer: '30' },
  100. { seq: '1, 5, 9, 13, 17, ?', options: ['19', '20', '21', '23'], answer: '21' },
  101. { seq: '3, 5, 9, 17, 33, ?', options: ['49', '57', '63', '65'], answer: '65' },
  102. { seq: '4, 8, 7, 14, 13, ?', options: ['20', '24', '25', '26'], answer: '26' },
  103. { seq: '1, 3, 6, 10, 15, ?', options: ['18', '20', '21', '24'], answer: '21' },
  104. { seq: '30, 28, 24, 18, 10, ?', options: ['0', '2', '4', '6'], answer: '0' },
  105. { seq: '7, 14, 28, 56, ?', options: ['84', '96', '108', '112'], answer: '112' }
  106. ]
  107. import fontScaleMixin from '@/mixins/font-scale.js'
  108. export default {
  109. mixins: [fontScaleMixin],
  110. data() {
  111. return {
  112. step: 'intro',
  113. questions: [],
  114. currentQ: 0,
  115. selectedIndex: -1,
  116. correctCount: 0,
  117. timeLeft: TIMER_SECONDS,
  118. timer: null,
  119. answered: false,
  120. score: 0,
  121. memberId: ''
  122. }
  123. },
  124. computed: {
  125. currentQuestion: function() {
  126. if (this.questions.length === 0) {
  127. return null
  128. }
  129. return this.questions[this.currentQ]
  130. },
  131. timerSeconds: function() {
  132. return Math.ceil(this.timeLeft)
  133. },
  134. timerPct: function() {
  135. var pct = (this.timeLeft / TIMER_SECONDS) * 100
  136. if (pct < 0) {
  137. pct = 0
  138. }
  139. return pct
  140. },
  141. scoreText: function() {
  142. var s = this.score
  143. if (s >= 90) return '太棒了,逻辑满分!'
  144. if (s >= 70) return '逻辑思维很出色!'
  145. if (s >= 50) return '表现不错,继续加油!'
  146. return '多练习数列规律会更好!'
  147. }
  148. },
  149. onLoad(options) {
  150. if (options && options.memberId) {
  151. this.memberId = options.memberId
  152. }
  153. this.memberId = this.memberId || uni.getStorageSync('currentChildId') || ''
  154. },
  155. onUnload() {
  156. this.stopTimer()
  157. },
  158. methods: {
  159. shuffle: function(arr) {
  160. var a = arr.slice()
  161. for (var i = a.length - 1; i > 0; i--) {
  162. var j = Math.floor(Math.random() * (i + 1))
  163. var tmp = a[i]
  164. a[i] = a[j]
  165. a[j] = tmp
  166. }
  167. return a
  168. },
  169. startTest: function() {
  170. var shuffled = this.shuffle(QUESTION_BANK)
  171. this.questions = shuffled.slice(0, ROUND_COUNT)
  172. this.currentQ = 0
  173. this.correctCount = 0
  174. this.score = 0
  175. this.answered = false
  176. this.selectedIndex = -1
  177. this.step = 'playing'
  178. this.startTimer()
  179. },
  180. startTimer: function() {
  181. this.stopTimer()
  182. this.timeLeft = TIMER_SECONDS
  183. var self = this
  184. this.timer = setInterval(function() {
  185. self.timeLeft -= 0.1
  186. if (self.timeLeft <= 0.01) {
  187. self.timeLeft = 0
  188. self.onTimeout()
  189. }
  190. }, 100)
  191. },
  192. stopTimer: function() {
  193. if (this.timer) {
  194. clearInterval(this.timer)
  195. this.timer = null
  196. }
  197. },
  198. selectOption: function(idx) {
  199. if (this.answered) return
  200. this.answered = true
  201. this.selectedIndex = idx
  202. this.stopTimer()
  203. var q = this.currentQuestion
  204. if (q && q.options[idx] === q.answer) {
  205. this.correctCount++
  206. }
  207. var self = this
  208. setTimeout(function() {
  209. self.advance()
  210. }, 400)
  211. },
  212. onTimeout: function() {
  213. if (this.answered) return
  214. this.answered = true
  215. this.stopTimer()
  216. this.selectedIndex = -1
  217. var self = this
  218. setTimeout(function() {
  219. self.advance()
  220. }, 400)
  221. },
  222. advance: function() {
  223. if (this.currentQ < this.questions.length - 1) {
  224. this.currentQ++
  225. this.answered = false
  226. this.selectedIndex = -1
  227. this.startTimer()
  228. } else {
  229. this.finishTest()
  230. }
  231. },
  232. finishTest: function() {
  233. this.stopTimer()
  234. this.score = Math.round((this.correctCount / ROUND_COUNT) * 100)
  235. this.step = 'result'
  236. },
  237. restartTest: function() {
  238. this.stopTimer()
  239. this.startTest()
  240. },
  241. submitScore: function() {
  242. if (!this.memberId) {
  243. uni.showToast({ title: '未获取到成员信息', icon: 'none' })
  244. return
  245. }
  246. submitCognitiveSelfTest(this.memberId, 'logicScore', this.score)
  247. .then((res) => {
  248. if (res && res.code === 200) {
  249. uni.showToast({ title: '提交成功', icon: 'success' })
  250. var self = this
  251. setTimeout(function() {
  252. uni.navigateBack()
  253. }, 800)
  254. } else {
  255. uni.showToast({ title: '提交失败', icon: 'none' })
  256. }
  257. })
  258. .catch(function() {
  259. uni.showToast({ title: '提交失败', icon: 'none' })
  260. })
  261. }
  262. }
  263. }
  264. </script>
  265. <style scoped lang="scss">
  266. .container {
  267. min-height: 100vh;
  268. background: linear-gradient(135deg, $app-ink-night 0%, $app-ink-night-2 100%);
  269. padding: 60rpx 40rpx;
  270. box-sizing: border-box;
  271. }
  272. /* ===== 引导页 ===== */
  273. .step-intro {
  274. padding-top: 80rpx;
  275. display: flex;
  276. flex-direction: column;
  277. align-items: center;
  278. }
  279. .intro-icon {
  280. width: 160rpx;
  281. height: 160rpx;
  282. border-radius: 50%;
  283. background: rgba(255, 215, 0, 0.15);
  284. border: 3rpx solid $accent-gold;
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. margin-bottom: 40rpx;
  289. }
  290. .intro-icon-text {
  291. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  292. }
  293. .intro-title {
  294. font-size: calc(44rpx * var(--font-scale, 1));
  295. font-weight: bold;
  296. color: $accent-gold;
  297. margin-bottom: 16rpx;
  298. display: block;
  299. }
  300. .intro-desc {
  301. font-size: calc(26rpx * var(--font-scale, 1));
  302. color: rgba(255, 255, 255, 0.7);
  303. margin-bottom: 50rpx;
  304. display: block;
  305. }
  306. .intro-info {
  307. width: 100%;
  308. background: rgba(255, 255, 255, 0.06);
  309. border-radius: 24rpx;
  310. padding: 20rpx $uni-space-page;
  311. margin-bottom: 60rpx;
  312. box-sizing: border-box;
  313. }
  314. .info-row {
  315. display: flex;
  316. justify-content: space-between;
  317. align-items: center;
  318. padding: 16rpx 0;
  319. }
  320. .info-row + .info-row {
  321. border-top: 1rpx solid rgba(255, 255, 255, 0.08);
  322. }
  323. .info-label {
  324. font-size: calc(26rpx * var(--font-scale, 1));
  325. color: rgba(255, 255, 255, 0.7);
  326. }
  327. .info-value {
  328. font-size: calc(26rpx * var(--font-scale, 1));
  329. color: $accent-gold;
  330. font-weight: bold;
  331. }
  332. /* ===== 答题页 ===== */
  333. .quiz-header {
  334. display: flex;
  335. justify-content: space-between;
  336. align-items: center;
  337. margin-bottom: 20rpx;
  338. }
  339. .quiz-progress {
  340. font-size: calc(30rpx * var(--font-scale, 1));
  341. color: $app-surface;
  342. font-weight: bold;
  343. }
  344. .quiz-timer {
  345. font-size: calc(30rpx * var(--font-scale, 1));
  346. color: $accent-gold;
  347. font-weight: bold;
  348. }
  349. .timer-track {
  350. height: 12rpx;
  351. background: rgba(255, 255, 255, 0.12);
  352. border-radius: 8rpx;
  353. overflow: hidden;
  354. margin-bottom: 50rpx;
  355. }
  356. .timer-fill {
  357. height: 100%;
  358. background: linear-gradient(90deg, $accent-gold, $accent-gold-deep);
  359. border-radius: 8rpx;
  360. transition: width 0.1s linear;
  361. }
  362. .question-card {
  363. background: rgba(255, 255, 255, 0.06);
  364. border-radius: 24rpx;
  365. padding: 40rpx $uni-space-page;
  366. box-sizing: border-box;
  367. }
  368. .q-text {
  369. font-size: calc(44rpx * var(--font-scale, 1));
  370. color: $app-surface;
  371. font-weight: bold;
  372. text-align: center;
  373. display: block;
  374. margin-bottom: 50rpx;
  375. letter-spacing: 4rpx;
  376. }
  377. .q-options {
  378. display: flex;
  379. flex-direction: column;
  380. }
  381. .q-option {
  382. padding: 26rpx 0;
  383. border-radius: 16rpx;
  384. border: 3rpx solid rgba(255, 255, 255, 0.2);
  385. background: #24243e;
  386. text-align: center;
  387. margin-bottom: 20rpx;
  388. transition: transform 0.2s;
  389. }
  390. .q-option:last-child {
  391. margin-bottom: 0;
  392. }
  393. .q-option--selected {
  394. border-color: $accent-gold;
  395. background: rgba(255, 215, 0, 0.12);
  396. }
  397. .q-option:active {
  398. transform: scale(0.98);
  399. }
  400. .q-option-text {
  401. font-size: calc(34rpx * var(--font-scale, 1));
  402. color: $app-surface;
  403. font-weight: bold;
  404. }
  405. .q-option--selected .q-option-text {
  406. color: $accent-gold;
  407. }
  408. /* ===== 结果页 ===== */
  409. .step-result {
  410. padding-top: 100rpx;
  411. display: flex;
  412. flex-direction: column;
  413. align-items: center;
  414. }
  415. .score-circle {
  416. width: 240rpx;
  417. height: 240rpx;
  418. border-radius: 50%;
  419. background: linear-gradient(135deg, $accent-gold, $accent-gold-deep);
  420. display: flex;
  421. align-items: center;
  422. justify-content: center;
  423. box-shadow: 0 8rpx 40rpx rgba(255, 215, 0, 0.35);
  424. margin-bottom: $uni-space-lg;
  425. }
  426. .score-value {
  427. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  428. font-weight: bold;
  429. color: $app-ink-night;
  430. }
  431. .score-label {
  432. font-size: calc(30rpx * var(--font-scale, 1));
  433. color: $accent-gold;
  434. margin-bottom: 50rpx;
  435. display: block;
  436. }
  437. .result-info {
  438. width: 100%;
  439. background: rgba(255, 255, 255, 0.06);
  440. border-radius: 24rpx;
  441. padding: 20rpx $uni-space-page;
  442. margin-bottom: 60rpx;
  443. box-sizing: border-box;
  444. }
  445. .result-row {
  446. display: flex;
  447. justify-content: space-between;
  448. align-items: center;
  449. padding: 16rpx 0;
  450. }
  451. .result-row + .result-row {
  452. border-top: 1rpx solid rgba(255, 255, 255, 0.08);
  453. }
  454. .result-label {
  455. font-size: calc(26rpx * var(--font-scale, 1));
  456. color: rgba(255, 255, 255, 0.7);
  457. }
  458. .result-value {
  459. font-size: calc(28rpx * var(--font-scale, 1));
  460. color: $app-surface;
  461. font-weight: bold;
  462. }
  463. .dim-tag {
  464. padding: 6rpx 24rpx;
  465. border-radius: 24rpx;
  466. border: 3rpx solid $accent-gold;
  467. background: rgba(255, 215, 0, 0.12);
  468. }
  469. .dim-tag-text {
  470. font-size: calc(24rpx * var(--font-scale, 1));
  471. color: $accent-gold;
  472. font-weight: bold;
  473. }
  474. /* ===== 按钮 ===== */
  475. .btn {
  476. width: 100%;
  477. padding: 26rpx 0;
  478. border-radius: 24rpx;
  479. text-align: center;
  480. font-size: calc(30rpx * var(--font-scale, 1));
  481. font-weight: bold;
  482. box-sizing: border-box;
  483. margin-bottom: 24rpx;
  484. }
  485. .btn:last-child {
  486. margin-bottom: 0;
  487. }
  488. .btn--primary {
  489. background: linear-gradient(135deg, $accent-gold, $accent-gold-deep);
  490. color: $app-ink-night;
  491. }
  492. .btn--primary:active {
  493. opacity: 0.9;
  494. transform: scale(0.98);
  495. }
  496. .btn--outline {
  497. border: 3rpx solid $accent-gold;
  498. color: $accent-gold;
  499. background: transparent;
  500. }
  501. .btn--outline:active {
  502. background: rgba(255, 215, 0, 0.12);
  503. }
  504. </style>