quiz.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <template>
  2. <view class="page">
  3. <!-- 介绍页 -->
  4. <view class="intro" v-if="!started">
  5. <view class="intro-icon">
  6. <text class="intro-icon-text">{{ scaleIcon }}</text>
  7. </view>
  8. <text class="intro-title">{{ scaleTitle }}</text>
  9. <text class="intro-desc">{{ scaleDesc }}</text>
  10. <view class="intro-info">
  11. <view class="info-row">
  12. <text class="info-label">题目数量</text>
  13. <text class="info-value">{{ totalQuestions }} 题</text>
  14. </view>
  15. <view class="info-row">
  16. <text class="info-label">每题时限</text>
  17. <text class="info-value">无限制</text>
  18. </view>
  19. </view>
  20. <button class="btn-primary" @click="startQuiz">开始测评</button>
  21. </view>
  22. <!-- 答题页 -->
  23. <view class="quiz" v-else-if="!showResult">
  24. <view class="quiz-header">
  25. <text class="quiz-progress">第 {{ currentQ + 1 }} / {{ totalQuestions }} 题</text>
  26. </view>
  27. <view class="progress-track">
  28. <view class="progress-fill" :style="{ width: progressPct + '%' }"></view>
  29. </view>
  30. <view class="question-card">
  31. <text class="question-text">{{ currentQuestion && currentQuestion.text }}</text>
  32. <view class="options">
  33. <view
  34. class="option"
  35. v-for="(opt, oi) in currentQuestion && currentQuestion.options"
  36. :key="oi"
  37. :class="{ 'option-selected': selectedIndex === oi }"
  38. @click="selectOption(oi)"
  39. >
  40. <text class="option-text">{{ opt }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 结果页 -->
  46. <view class="result" v-else>
  47. <view class="score-circle">
  48. <text class="score-num">{{ score }}</text>
  49. <text class="score-unit">分</text>
  50. </view>
  51. <text class="score-comment">{{ scoreComment }}</text>
  52. <view class="result-info">
  53. <view class="info-row">
  54. <text class="info-label">答对题数</text>
  55. <text class="info-value">{{ correctCount }} / {{ totalQuestions }}</text>
  56. </view>
  57. <view class="info-row">
  58. <text class="info-label">测评维度</text>
  59. <view class="dim-tag">
  60. <text class="dim-tag-text">{{ scaleLabel }}</text>
  61. </view>
  62. </view>
  63. </view>
  64. <button class="btn-primary" :disabled="submitting" @click="submitScore">
  65. {{ submitting ? '提交中...' : '提交成绩' }}
  66. </button>
  67. <button class="btn-secondary" @click="restartQuiz">重新测评</button>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import { submitCognitiveSelfTest } from '../../utils/api.js'
  73. // PHQ-9 题目(得分:完全不会=0, 好几天=1, 一半天数=2, 几乎每天=3)
  74. var PHQ9_QUESTIONS = [
  75. { text: '做事时提不起劲或没有兴趣', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] },
  76. { text: '感到心情低落、沮丧或绝望', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] },
  77. { text: '入睡困难、睡不安稳或睡眠过多', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] },
  78. { text: '感觉疲倦或没有活力', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] },
  79. { text: '食欲不振或吃太多', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] },
  80. { text: '觉得自己很糟糕,或觉得自己很失败,让自己或家人失望', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] },
  81. { text: '对事物专注有困难,例如看报纸或看电视时', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] },
  82. { text: '动作或说话速度缓慢到别人已经察觉,或正好相反,坐立不安或比平时更激动', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] },
  83. { text: '有不如死掉或用某种方式伤害自己的念头', options: ['完全不会', '好几天', '一半以上的天数', '几乎每天'] }
  84. ]
  85. // RSES-7 题目(反向计分,得分:非常不符合=1, 比较不符合=2, 比较符合=3, 完全符合=4)
  86. var RSES_QUESTIONS = [
  87. { text: '我觉得自己是一个有价值的人,至少与其他人一样', options: ['非常不符合', '比较不符合', '比较符合', '完全符合'] },
  88. { text: '我感到自己有许多优点', options: ['非常不符合', '比较不符合', '比较符合', '完全符合'] },
  89. { text: '我对自己持肯定的态度', options: ['非常不符合', '比较不符合', '比较符合', '完全符合'] },
  90. { text: '我能够像大多数人一样把事情做好', options: ['非常不符合', '比较不符合', '比较符合', '完全符合'] },
  91. { text: '我对自己的人生态度感到满意', options: ['非常不符合', '比较不符合', '比较符合', '完全符合'] },
  92. { text: '我觉得我并没有什么值得自豪的地方', options: ['完全符合', '比较符合', '比较不符合', '非常不符合'] },
  93. { text: '总的来说,我倾向于认为自己是一个失败者', options: ['完全符合', '比较符合', '比较不符合', '非常不符合'] }
  94. ]
  95. export default {
  96. data() {
  97. return {
  98. scale: '',
  99. memberId: '',
  100. started: false,
  101. showResult: false,
  102. questions: [],
  103. currentQ: 0,
  104. selectedIndex: -1,
  105. correctCount: 0,
  106. score: 0,
  107. submitting: false
  108. }
  109. },
  110. computed: {
  111. currentQuestion: function() {
  112. if (this.questions.length === 0) return null
  113. return this.questions[this.currentQ]
  114. },
  115. totalQuestions: function() {
  116. return this.questions.length
  117. },
  118. progressPct: function() {
  119. return ((this.currentQ + 1) / this.totalQuestions) * 100
  120. },
  121. scaleIcon: function() {
  122. return this.scale === 'phq9' ? '💙' : '⭐'
  123. },
  124. scaleTitle: function() {
  125. return this.scale === 'phq9' ? '情绪健康筛查' : '自尊水平评估'
  126. },
  127. scaleDesc: function() {
  128. return this.scale === 'phq9'
  129. ? 'PHQ-9 是国际通用的抑郁症状筛查量表,过去两周内有以下症状的频率?'
  130. : 'RSES-7 是国际通用的自尊水平评估量表,请根据实际情况选择最符合的选项'
  131. },
  132. scaleLabel: function() {
  133. return this.scale === 'phq9' ? '情绪健康' : '自尊水平'
  134. },
  135. scoreComment: function() {
  136. if (this.scale === 'phq9') {
  137. if (this.score <= 4) return '情绪状态良好,建议定期监测'
  138. if (this.score <= 9) return '轻度情绪困扰,建议关注并适当调节'
  139. if (this.score <= 14) return '中度情绪困扰,建议寻求专业咨询'
  140. return '建议尽快寻求专业帮助'
  141. } else {
  142. if (this.score >= 28) return '自尊水平较高,自信心强'
  143. if (this.score >= 21) return '自尊水平中等,建议持续提升自我价值感'
  144. return '自尊水平较低,建议寻求专业支持'
  145. }
  146. }
  147. },
  148. onLoad: function(options) {
  149. if (options && options.scale) {
  150. this.scale = options.scale
  151. this.memberId = options.memberId || uni.getStorageSync('currentChildId') || ''
  152. this.initQuestions()
  153. }
  154. },
  155. methods: {
  156. initQuestions: function() {
  157. if (this.scale === 'phq9') {
  158. this.questions = PHQ9_QUESTIONS.slice()
  159. } else if (this.scale === 'reses') {
  160. this.questions = RSES_QUESTIONS.slice()
  161. }
  162. },
  163. startQuiz: function() {
  164. this.started = true
  165. this.currentQ = 0
  166. this.selectedIndex = -1
  167. this.correctCount = 0
  168. this.score = 0
  169. },
  170. selectOption: function(idx) {
  171. this.selectedIndex = idx
  172. var points = this.scale === 'phq9' ? idx : idx + 1
  173. this.correctCount += points
  174. var self = this
  175. setTimeout(function() {
  176. if (self.currentQ < self.totalQuestions - 1) {
  177. self.currentQ++
  178. self.selectedIndex = -1
  179. } else {
  180. self.finishQuiz()
  181. }
  182. }, 400)
  183. },
  184. finishQuiz: function() {
  185. this.score = this.scale === 'phq9' ? this.correctCount : this.correctCount
  186. this.showResult = true
  187. },
  188. submitScore: function() {
  189. if (this.submitting) return
  190. if (!this.memberId) {
  191. uni.showToast({ title: '未获取到成员信息', icon: 'none' })
  192. return
  193. }
  194. this.submitting = true
  195. var dimension = this.scale === 'phq9' ? 'phq9_score' : 'reses_score'
  196. submitCognitiveSelfTest(this.memberId, dimension, this.score)
  197. .then(function(res) {
  198. if (res && res.code === 200) {
  199. uni.showToast({ title: '提交成功', icon: 'success' })
  200. setTimeout(function() {
  201. uni.navigateBack()
  202. }, 800)
  203. }
  204. })
  205. .catch(function() {
  206. uni.showToast({ title: '提交失败', icon: 'none' })
  207. })
  208. .finally(function() {
  209. this.submitting = false
  210. }.bind(this))
  211. },
  212. restartQuiz: function() {
  213. this.showResult = false
  214. this.currentQ = 0
  215. this.selectedIndex = -1
  216. this.correctCount = 0
  217. this.score = 0
  218. }
  219. }
  220. }
  221. </script>
  222. <style scoped>
  223. .page {
  224. min-height: 100vh;
  225. background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  226. display: flex;
  227. flex-direction: column;
  228. align-items: center;
  229. padding: 60rpx 40rpx 80rpx;
  230. box-sizing: border-box;
  231. }
  232. /* 介绍页 */
  233. .intro {
  234. display: flex;
  235. flex-direction: column;
  236. align-items: center;
  237. width: 100%;
  238. }
  239. .intro-icon {
  240. width: 160rpx;
  241. height: 160rpx;
  242. border-radius: 50%;
  243. background: rgba(99,102,241,0.15);
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. margin-bottom: 40rpx;
  248. }
  249. .intro-icon-text {
  250. font-size: 80rpx;
  251. }
  252. .intro-title {
  253. font-size: 44rpx;
  254. font-weight: bold;
  255. color: #fff;
  256. margin-bottom: 16rpx;
  257. }
  258. .intro-desc {
  259. font-size: 28rpx;
  260. color: rgba(255,255,255,0.7);
  261. line-height: 1.6;
  262. text-align: center;
  263. margin-bottom: 40rpx;
  264. padding: 0 20rpx;
  265. }
  266. .intro-info {
  267. width: 100%;
  268. background: rgba(255,255,255,0.06);
  269. border-radius: 20rpx;
  270. padding: 20rpx 30rpx;
  271. margin-bottom: 60rpx;
  272. }
  273. .info-row {
  274. display: flex;
  275. justify-content: space-between;
  276. align-items: center;
  277. padding: 16rpx 0;
  278. }
  279. .info-row + .info-row {
  280. border-top: 1rpx solid rgba(255,255,255,0.08);
  281. }
  282. .info-label {
  283. font-size: 26rpx;
  284. color: rgba(255,255,255,0.7);
  285. }
  286. .info-value {
  287. font-size: 26rpx;
  288. color: #6366f1;
  289. font-weight: bold;
  290. }
  291. /* 答题页 */
  292. .quiz {
  293. width: 100%;
  294. display: flex;
  295. flex-direction: column;
  296. align-items: center;
  297. }
  298. .quiz-header {
  299. font-size: 30rpx;
  300. color: #fff;
  301. font-weight: bold;
  302. margin-bottom: 16rpx;
  303. }
  304. .progress-track {
  305. width: 100%;
  306. max-width: 620rpx;
  307. height: 12rpx;
  308. background: rgba(255,255,255,0.1);
  309. border-radius: 6rpx;
  310. overflow: hidden;
  311. margin-bottom: 50rpx;
  312. }
  313. .progress-fill {
  314. height: 100%;
  315. background: linear-gradient(90deg, #6366f1, #8b5cf6);
  316. border-radius: 6rpx;
  317. transition: width 0.3s ease;
  318. }
  319. .question-card {
  320. background: rgba(255,255,255,0.06);
  321. border-radius: 24rpx;
  322. padding: 40rpx 30rpx;
  323. width: 100%;
  324. max-width: 620rpx;
  325. box-sizing: border-box;
  326. }
  327. .question-text {
  328. font-size: 32rpx;
  329. color: #fff;
  330. font-weight: bold;
  331. text-align: center;
  332. display: block;
  333. margin-bottom: 40rpx;
  334. line-height: 1.5;
  335. }
  336. .options {
  337. display: flex;
  338. flex-direction: column;
  339. }
  340. .option {
  341. padding: 26rpx 0;
  342. border-radius: 16rpx;
  343. border: 3rpx solid rgba(255,255,255,0.2);
  344. background: #24243e;
  345. text-align: center;
  346. margin-bottom: 20rpx;
  347. transition: all 0.2s;
  348. }
  349. .option:last-child {
  350. margin-bottom: 0;
  351. }
  352. .option-selected {
  353. border-color: #6366f1;
  354. background: rgba(99,102,241,0.12);
  355. }
  356. .option:active {
  357. transform: scale(0.98);
  358. }
  359. .option-text {
  360. font-size: 28rpx;
  361. color: #fff;
  362. font-weight: 500;
  363. }
  364. .option-selected .option-text {
  365. color: #a5b4fc;
  366. }
  367. /* 结果页 */
  368. .result {
  369. display: flex;
  370. flex-direction: column;
  371. align-items: center;
  372. width: 100%;
  373. padding-top: 100rpx;
  374. }
  375. .score-circle {
  376. width: 240rpx;
  377. height: 240rpx;
  378. border-radius: 50%;
  379. background: linear-gradient(135deg, #6366f1, #8b5cf6);
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. justify-content: center;
  384. box-shadow: 0 8rpx 40rpx rgba(99,102,241,0.35);
  385. }
  386. .score-num {
  387. font-size: 80rpx;
  388. font-weight: bold;
  389. color: #fff;
  390. line-height: 1;
  391. }
  392. .score-unit {
  393. font-size: 28rpx;
  394. color: rgba(255,255,255,0.8);
  395. margin-top: 8rpx;
  396. }
  397. .score-comment {
  398. font-size: 30rpx;
  399. color: #a5b4fc;
  400. margin-top: 30rpx;
  401. margin-bottom: 50rpx;
  402. }
  403. .result-info {
  404. width: 100%;
  405. max-width: 620rpx;
  406. background: rgba(255,255,255,0.06);
  407. border-radius: 20rpx;
  408. padding: 20rpx 30rpx;
  409. margin-bottom: 60rpx;
  410. }
  411. .result-info .info-row {
  412. display: flex;
  413. justify-content: space-between;
  414. align-items: center;
  415. padding: 16rpx 0;
  416. }
  417. .result-info .info-row + .info-row {
  418. border-top: 1rpx solid rgba(255,255,255,0.08);
  419. }
  420. .dim-tag {
  421. padding: 6rpx 24rpx;
  422. border-radius: 24rpx;
  423. border: 3rpx solid #6366f1;
  424. background: rgba(99,102,241,0.12);
  425. }
  426. .dim-tag-text {
  427. font-size: 24rpx;
  428. color: #a5b4fc;
  429. font-weight: bold;
  430. }
  431. /* 按钮 */
  432. .btn-primary {
  433. margin-top: 60rpx;
  434. width: 480rpx;
  435. height: 96rpx;
  436. line-height: 96rpx;
  437. border-radius: 48rpx;
  438. background: linear-gradient(135deg, #6366f1, #8b5cf6);
  439. color: #fff;
  440. font-size: 34rpx;
  441. font-weight: 600;
  442. border: none;
  443. box-shadow: 0 8rpx 24rpx rgba(99,102,241,0.35);
  444. }
  445. .btn-primary::after {
  446. border: none;
  447. }
  448. .btn-primary[disabled] {
  449. opacity: 0.6;
  450. }
  451. .btn-secondary {
  452. margin-top: 30rpx;
  453. width: 480rpx;
  454. height: 96rpx;
  455. line-height: 96rpx;
  456. border-radius: 48rpx;
  457. background: transparent;
  458. color: #a5b4fc;
  459. font-size: 32rpx;
  460. border: 2rpx solid rgba(99,102,241,0.5);
  461. }
  462. .btn-secondary::after {
  463. border: none;
  464. }
  465. </style>