language-test.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <view class="test-container" :style="{ '--font-scale': fontScale }">
  3. <!-- 步骤一:测试说明 -->
  4. <view class="step-panel" v-if="step === 'instruction'">
  5. <view class="title-icon">🗣️</view>
  6. <text class="test-title">语言表达测试</text>
  7. <text class="test-desc">观察每组词语,找出与其它三个不同类的那一个。</text>
  8. <text class="test-desc">考验你的词汇理解和分类归纳能力!</text>
  9. <text class="test-meta">共 6 题 · 每题限时 12 秒 · 超时自动进入下一题</text>
  10. <button class="btn-primary" @click="startTest">开始测试</button>
  11. </view>
  12. <!-- 步骤二:答题中 -->
  13. <view class="step-panel" v-else-if="step === 'playing'">
  14. <view class="progress-row">
  15. <text class="progress-text">第 {{ currentIndex + 1 }}/6 题</text>
  16. <text class="progress-text">答对 {{ correctCount }} 题</text>
  17. </view>
  18. <view class="timer-bar">
  19. <view class="timer-fill" :style="timerBarStyle"></view>
  20. </view>
  21. <text class="timer-text">{{ timerLeft }}秒</text>
  22. <text class="question-hint" v-if="currentQuestion">{{ currentQuestion.prompt }}</text>
  23. <view class="option-wrap">
  24. <view
  25. class="option-cell"
  26. v-for="(opt, index) in currentQuestionOptions"
  27. :key="index"
  28. :class="{
  29. 'cell-correct': lockInput && index === currentQuestion.answerIndex,
  30. 'cell-wrong': tappedIndex === index && index !== currentQuestion.answerIndex
  31. }"
  32. @click="handleTap(index)"
  33. >
  34. <text class="option-text">{{ opt }}</text>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 步骤三:结果 -->
  39. <view class="step-panel" v-else>
  40. <text class="result-title">测试完成</text>
  41. <view class="score-circle">
  42. <text class="score-num">{{ score }}</text>
  43. </view>
  44. <view class="score-row">
  45. <text class="score-label">答对 {{ correctCount }}/6 题</text>
  46. <text class="dimension-tag">语言表达</text>
  47. </view>
  48. <view class="result-tip" v-if="score >= 75">
  49. <text class="result-tip-text">词汇丰富,语言表达能力强!</text>
  50. </view>
  51. <view class="result-tip" v-else-if="score >= 50">
  52. <text class="result-tip-text">表现不错,多阅读会更好!</text>
  53. </view>
  54. <view class="result-tip" v-else>
  55. <text class="result-tip-text">别灰心,平时多积累词汇!</text>
  56. </view>
  57. <button class="btn-primary" @click="submitResult">提交成绩</button>
  58. <button class="btn-secondary" @click="retryTest">再测一次</button>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import { submitCognitiveSelfTest } from '../../utils/api.js'
  64. // 题库:4 个词语,其中一个是"不同类"的
  65. var QUESTION_BANK = [
  66. { prompt: '找出不同类的一项', options: ['苹果', '香蕉', '胡萝卜', '橘子'], answerIndex: 2 },
  67. { prompt: '找出不同类的一项', options: ['狗', '猫', '马', '鱼'], answerIndex: 3 },
  68. { prompt: '找出不同类的一项', options: ['红色', '蓝色', '绿色', '桌子'], answerIndex: 3 },
  69. { prompt: '找出不同类的一项', options: ['钢琴', '小提琴', '吉他', '足球'], answerIndex: 3 },
  70. { prompt: '找出不同类的一项', options: ['春天', '夏天', '秋天', '月亮'], answerIndex: 3 },
  71. { prompt: '找出不同类的一项', options: ['跑步', '游泳', '跳跃', '思考'], answerIndex: 3 },
  72. { prompt: '找出不同类的一项', options: ['父亲', '母亲', '姐姐', '老师'], answerIndex: 3 },
  73. { prompt: '找出不同类的一项', options: ['火车', '飞机', '轮船', '自行车'], answerIndex: 2 },
  74. { prompt: '找出不同类的一项', options: ['黄金', '白银', '铜', '铁'], answerIndex: 0 },
  75. { prompt: '找出不同类的一项', options: ['广州', '深圳', '香港', '北京'], answerIndex: 2 },
  76. { prompt: '找出不同类的一项', options: ['三角形', '圆形', '方形', '菱形'], answerIndex: 1 },
  77. { prompt: '找出不同类的一项', options: ['莎士比亚', '李白', '杜甫', '爱因斯坦'], answerIndex: 3 },
  78. { prompt: '找出不同类的一项', options: ['幸福', '快乐', '悲伤', '满足'], answerIndex: 2 },
  79. { prompt: '找出不同类的一项', options: ['书本', '报纸', '杂志', '电脑'], answerIndex: 3 },
  80. { prompt: '找出不同类的一项', options: ['太阳', '月亮', '星星', '云朵'], answerIndex: 3 },
  81. { prompt: '找出不同类的一项', options: ['钢笔', '铅笔', '毛笔', '画笔'], answerIndex: 0 },
  82. { prompt: '找出不同类的一项', options: ['苹果', '芒果', '榴莲', '土豆'], answerIndex: 3 },
  83. { prompt: '找出不同类的一项', options: ['大海', '河流', '湖泊', '雨水'], answerIndex: 3 },
  84. { prompt: '找出不同类的一项', options: ['红色', '橙色', '黄色', '白色'], answerIndex: 3 },
  85. { prompt: '找出不同类的一项', options: ['钢琴', '鼓', '喇叭', '篮球'], answerIndex: 3 }
  86. ]
  87. var ROUND_COUNT = 6
  88. var TIMER_SECONDS = 12
  89. import fontScaleMixin from '@/mixins/font-scale.js'
  90. export default {
  91. mixins: [fontScaleMixin],
  92. data() {
  93. return {
  94. step: 'instruction',
  95. memberId: '',
  96. roundQuestions: [],
  97. currentIndex: 0,
  98. currentQuestion: null,
  99. correctCount: 0,
  100. timerLeft: TIMER_SECONDS,
  101. timer: null,
  102. nextTimer: null,
  103. lockInput: false,
  104. tappedIndex: -1,
  105. score: 0
  106. }
  107. },
  108. computed: {
  109. timerPercent: function() {
  110. return Math.round(this.timerLeft / TIMER_SECONDS * 100)
  111. },
  112. timerBarStyle: function() {
  113. return 'width:' + this.timerPercent + '%'
  114. },
  115. currentQuestionOptions: function() {
  116. if (!this.currentQuestion) return []
  117. return this.currentQuestion.options
  118. }
  119. },
  120. onLoad: function(options) {
  121. if (options && options.memberId) {
  122. this.memberId = options.memberId
  123. }
  124. },
  125. onUnload: function() {
  126. this.stopTimer()
  127. if (this.nextTimer) {
  128. clearTimeout(this.nextTimer)
  129. this.nextTimer = null
  130. }
  131. },
  132. methods: {
  133. startTest: function() {
  134. this.correctCount = 0
  135. this.currentIndex = 0
  136. this.score = 0
  137. this.lockInput = false
  138. this.tappedIndex = -1
  139. // 洗牌后取前 6 题
  140. var bank = QUESTION_BANK.slice()
  141. for (var i = bank.length - 1; i > 0; i--) {
  142. var j = Math.floor(Math.random() * (i + 1))
  143. var tmp = bank[i]
  144. bank[i] = bank[j]
  145. bank[j] = tmp
  146. }
  147. this.roundQuestions = bank.slice(0, ROUND_COUNT)
  148. this.step = 'playing'
  149. this.loadQuestion(0)
  150. },
  151. loadQuestion: function(index) {
  152. this.currentIndex = index
  153. this.currentQuestion = this.roundQuestions[index]
  154. this.tappedIndex = -1
  155. this.lockInput = false
  156. this.timerLeft = TIMER_SECONDS
  157. this.startTimer()
  158. },
  159. startTimer: function() {
  160. this.stopTimer()
  161. this.timer = setInterval(() => {
  162. this.timerLeft--
  163. if (this.timerLeft <= 0) {
  164. this.timerLeft = 0
  165. this.onTimeout()
  166. }
  167. }, 1000)
  168. },
  169. stopTimer: function() {
  170. if (this.timer) {
  171. clearInterval(this.timer)
  172. this.timer = null
  173. }
  174. },
  175. handleTap: function(index) {
  176. if (this.lockInput || !this.currentQuestion) return
  177. this.lockInput = true
  178. this.stopTimer()
  179. this.tappedIndex = index
  180. if (index === this.currentQuestion.answerIndex) {
  181. this.correctCount++
  182. }
  183. this.scheduleNext()
  184. },
  185. onTimeout: function() {
  186. if (this.lockInput) return
  187. this.lockInput = true
  188. this.stopTimer()
  189. this.tappedIndex = -1
  190. this.scheduleNext()
  191. },
  192. scheduleNext: function() {
  193. if (this.nextTimer) clearTimeout(this.nextTimer)
  194. this.nextTimer = setTimeout(() => {
  195. this.nextTimer = null
  196. this.advance()
  197. }, 700)
  198. },
  199. advance: function() {
  200. if (this.currentIndex + 1 >= this.roundQuestions.length) {
  201. this.finishTest()
  202. } else {
  203. this.loadQuestion(this.currentIndex + 1)
  204. }
  205. },
  206. finishTest: function() {
  207. this.stopTimer()
  208. this.score = Math.round(this.correctCount / this.roundQuestions.length * 100)
  209. this.step = 'result'
  210. },
  211. submitResult: function() {
  212. var memberId = this.memberId || uni.getStorageSync('currentChildId') || ''
  213. if (!memberId) {
  214. uni.showToast({ title: '请先选择家庭成员', icon: 'none' })
  215. return
  216. }
  217. submitCognitiveSelfTest(memberId, 'languageScore', this.score)
  218. .then((res) => {
  219. uni.showToast({ title: '提交成功', icon: 'success' })
  220. setTimeout(() => {
  221. uni.navigateBack()
  222. }, 1500)
  223. })
  224. .catch((err) => {
  225. console.error('提交语言表达测试成绩失败', err)
  226. uni.showToast({ title: '提交失败,请重试', icon: 'none' })
  227. })
  228. },
  229. retryTest: function() {
  230. this.startTest()
  231. }
  232. }
  233. }
  234. </script>
  235. <style scoped lang="scss">
  236. .test-container {
  237. min-height: 100vh;
  238. background: linear-gradient(135deg, $app-ink-night 0%, $app-ink-night-2 100%);
  239. padding: 60rpx 40rpx;
  240. box-sizing: border-box;
  241. }
  242. .step-panel {
  243. display: flex;
  244. flex-direction: column;
  245. align-items: center;
  246. }
  247. /* ===== 说明页 ===== */
  248. .title-icon {
  249. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  250. margin-bottom: 24rpx;
  251. }
  252. .test-title {
  253. font-size: calc(48rpx * var(--font-scale, 1));
  254. font-weight: bold;
  255. color: $app-surface;
  256. margin-bottom: 32rpx;
  257. }
  258. .test-desc {
  259. font-size: calc(30rpx * var(--font-scale, 1));
  260. color: rgba(255,255,255,0.7);
  261. line-height: 1.7;
  262. text-align: center;
  263. }
  264. .test-meta {
  265. font-size: calc(24rpx * var(--font-scale, 1));
  266. color: rgba(255,255,255,0.45);
  267. margin-top: 24rpx;
  268. margin-bottom: 80rpx;
  269. text-align: center;
  270. }
  271. .btn-primary {
  272. background: linear-gradient(135deg, $dim-wealth, $status-warning);
  273. color: $app-ink-night;
  274. font-size: calc(34rpx * var(--font-scale, 1));
  275. font-weight: bold;
  276. width: 480rpx;
  277. height: 92rpx;
  278. line-height: 92rpx;
  279. border-radius: 24rpx;
  280. border: none;
  281. margin-top: 60rpx;
  282. padding: 0;
  283. }
  284. .btn-primary::after {
  285. border: none;
  286. }
  287. .btn-secondary {
  288. background: rgba(255,255,255,0.1);
  289. color: rgba(255,255,255,0.85);
  290. font-size: calc(32rpx * var(--font-scale, 1));
  291. width: 480rpx;
  292. height: 92rpx;
  293. line-height: 92rpx;
  294. border-radius: 24rpx;
  295. border: 2rpx solid rgba(255,255,255,0.25);
  296. margin-top: 32rpx;
  297. padding: 0;
  298. }
  299. .btn-secondary::after {
  300. border: none;
  301. }
  302. /* ===== 答题页 ===== */
  303. .progress-row {
  304. display: flex;
  305. justify-content: space-between;
  306. width: 100%;
  307. margin-bottom: 24rpx;
  308. }
  309. .progress-text {
  310. font-size: calc(28rpx * var(--font-scale, 1));
  311. color: rgba(255,255,255,0.7);
  312. }
  313. .timer-bar {
  314. width: 100%;
  315. height: 16rpx;
  316. background: rgba(255,255,255,0.12);
  317. border-radius: 8rpx;
  318. overflow: hidden;
  319. }
  320. .timer-fill {
  321. height: 100%;
  322. background: linear-gradient(90deg, $dim-wealth, $status-warning);
  323. border-radius: 8rpx;
  324. transition: width 0.9s linear;
  325. }
  326. .timer-text {
  327. display: block;
  328. font-size: calc(26rpx * var(--font-scale, 1));
  329. color: $dim-wealth;
  330. margin-top: 12rpx;
  331. text-align: center;
  332. }
  333. .question-hint {
  334. display: block;
  335. font-size: calc(32rpx * var(--font-scale, 1));
  336. font-weight: bold;
  337. color: $app-surface;
  338. margin: 40rpx 0 32rpx;
  339. text-align: center;
  340. }
  341. .option-wrap {
  342. display: flex;
  343. flex-wrap: wrap;
  344. justify-content: space-between;
  345. width: 100%;
  346. }
  347. .option-cell {
  348. display: flex;
  349. align-items: center;
  350. justify-content: center;
  351. width: 47%;
  352. min-height: 120rpx;
  353. background: $game-ink;
  354. border-radius: 24rpx;
  355. border: 4rpx solid transparent;
  356. margin-bottom: 24rpx;
  357. padding: 24rpx;
  358. box-sizing: border-box;
  359. }
  360. .option-cell:active {
  361. background: #35406b;
  362. }
  363. .option-text {
  364. font-size: calc(34rpx * var(--font-scale, 1));
  365. color: $app-surface;
  366. font-weight: 500;
  367. }
  368. .cell-correct {
  369. background: #3d4a2f;
  370. border-color: $flat-teal;
  371. }
  372. .cell-wrong {
  373. background: #4a2f35;
  374. border-color: $accent-coral;
  375. }
  376. /* ===== 结果页 ===== */
  377. .result-title {
  378. font-size: calc(40rpx * var(--font-scale, 1));
  379. font-weight: bold;
  380. color: $app-surface;
  381. margin-bottom: 48rpx;
  382. }
  383. .score-circle {
  384. display: flex;
  385. align-items: center;
  386. justify-content: center;
  387. width: 260rpx;
  388. height: 260rpx;
  389. border-radius: 50%;
  390. border: 10rpx solid $dim-wealth;
  391. background: rgba(245,158,11,0.1);
  392. margin-bottom: 36rpx;
  393. }
  394. .score-num {
  395. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  396. font-weight: bold;
  397. color: $dim-wealth;
  398. }
  399. .score-row {
  400. display: flex;
  401. align-items: center;
  402. margin-bottom: 24rpx;
  403. }
  404. .score-label {
  405. font-size: calc(30rpx * var(--font-scale, 1));
  406. color: rgba(255,255,255,0.7);
  407. margin-right: 20rpx;
  408. }
  409. .dimension-tag {
  410. font-size: calc(24rpx * var(--font-scale, 1));
  411. color: $dim-wealth;
  412. border: 2rpx solid $dim-wealth;
  413. border-radius: 24rpx;
  414. padding: 6rpx 24rpx;
  415. }
  416. .result-tip {
  417. margin-bottom: 20rpx;
  418. }
  419. .result-tip-text {
  420. font-size: calc(28rpx * var(--font-scale, 1));
  421. color: rgba(255,255,255,0.6);
  422. }
  423. </style>