training.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 训练概览 -->
  4. <view class="stats-card" v-if="stats">
  5. <view class="stats-row">
  6. <view class="stats-item">
  7. <text class="stats-value">{{ stats.totalGames || 0 }}</text>
  8. <text class="stats-label">总训练次数</text>
  9. </view>
  10. <view class="stats-divider"></view>
  11. <view class="stats-item">
  12. <text class="stats-value">{{ stats.bestScore || 0 }}</text>
  13. <text class="stats-label">最高分</text>
  14. </view>
  15. <view class="stats-divider"></view>
  16. <view class="stats-item">
  17. <text class="stats-value">{{ stats.avgScore ? Math.round(stats.avgScore) : 0 }}</text>
  18. <text class="stats-label">平均分</text>
  19. </view>
  20. <view class="stats-divider"></view>
  21. <view class="stats-item">
  22. <text class="stats-value">{{ stats.totalPoints || 0 }}</text>
  23. <text class="stats-label">累计积分</text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="stats-card stats-loading" v-else-if="statsLoading">
  28. <text class="stats-loading-text">加载训练数据...</text>
  29. </view>
  30. <!-- 训练维度描述 -->
  31. <view class="dimension-card" v-if="currentDim">
  32. <view class="dimension-icon-wrap" :style="{ background: currentDim.lightColor }">
  33. <text class="dimension-icon">{{ currentDim.icon }}</text>
  34. </view>
  35. <text class="dimension-name">{{ currentDim.name }}</text>
  36. <text class="dimension-desc">{{ currentDim.desc }}</text>
  37. </view>
  38. <!-- 推荐游戏 -->
  39. <view class="section" v-if="currentDim && currentDim.games.length > 0">
  40. <view class="section-header">
  41. <text class="section-title">推荐训练</text>
  42. </view>
  43. <view class="game-list">
  44. <view class="game-card" v-for="game in currentDim.games" :key="game.code" @click="goGame(game)">
  45. <view class="game-icon-wrap" :style="{ background: currentDim.lightColor }">
  46. <text class="game-card-icon">{{ game.icon }}</text>
  47. </view>
  48. <view class="game-info">
  49. <text class="game-title">{{ game.name }}</text>
  50. <text class="game-desc">{{ game.desc }}</text>
  51. </view>
  52. <text class="game-arrow">&#x2192;</text>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 成长建议 -->
  57. <view class="section" v-if="currentDim">
  58. <view class="section-header">
  59. <text class="section-title">成长建议</text>
  60. </view>
  61. <view class="tip-card">
  62. <view class="tip-left-bar" :style="{ background: currentDim.color }"></view>
  63. <view class="tip-body">
  64. <text class="tip-content">{{ currentDim.tip }}</text>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 其他维度训练 -->
  69. <view class="section">
  70. <view class="section-header">
  71. <text class="section-title">其他维度</text>
  72. </view>
  73. <view class="other-grid">
  74. <view class="other-item" v-for="dim in otherDimensions" :key="dim.key" @click="switchDimension(dim.key)">
  75. <view class="other-icon-wrap" :style="{ background: dim.lightColor }">
  76. <text class="other-icon">{{ dim.icon }}</text>
  77. </view>
  78. <text class="other-name">{{ dim.name }}</text>
  79. </view>
  80. </view>
  81. </view>
  82. <!-- 底部占位 -->
  83. <view class="bottom-spacer"></view>
  84. </view>
  85. </template>
  86. <script>
  87. import { BrandColors } from '../../utils/brand-colors.js'
  88. import { getGameStats } from '../../utils/api.js'
  89. var DIMENSION_MAP = {
  90. perception: {
  91. key: 'perception',
  92. name: '感知训练',
  93. icon: '\u{1F441}',
  94. color: BrandColors.violet,
  95. lightColor: '#EDE9FE',
  96. desc: '通过图形匹配、颜色分辨等练习提升感知能力',
  97. tip: '感知力是认知的起点。多观察身边事物的细节,锻炼视觉辨识能力,能有效提升感知水平。',
  98. games: [
  99. { code: 'schulte', name: '舒尔特方格', icon: '\u{1F3AF}', desc: '快速定位数字,训练视觉搜索' }
  100. ]
  101. },
  102. focus: {
  103. key: 'focus',
  104. name: '专注训练',
  105. icon: '\u{1F3AF}',
  106. color: BrandColors.primary,
  107. lightColor: '#FFF7ED',
  108. desc: '通过舒尔特方格、数字追踪等练习提升专注力',
  109. tip: '专注力是一切学习的基础。每天坚持10分钟专注训练,持续21天会有显著提升。',
  110. games: [
  111. { code: 'schulte', name: '舒尔特方格', icon: '\u{1F3AF}', desc: '按序点击数字,训练持续专注' }
  112. ]
  113. },
  114. memory: {
  115. key: 'memory',
  116. name: '记忆训练',
  117. icon: '\u{1F9E0}',
  118. color: BrandColors.success,
  119. lightColor: BrandColors.emerald50,
  120. desc: '通过数字记忆、序列回忆等练习提升记忆力',
  121. tip: '记忆力可以通过科学训练显著提升。联想记忆法和间隔重复是最有效的两种方法。',
  122. games: [
  123. { code: '1a2b', name: '猜数字', icon: '\u{1F522}', desc: '记忆数字排列,训练工作记忆' }
  124. ]
  125. },
  126. logic: {
  127. key: 'logic',
  128. name: '逻辑训练',
  129. icon: '\u{1F9E9}',
  130. color: BrandColors.infoBlue,
  131. lightColor: '#EFF6FF',
  132. desc: '通过推理题、模式识别等练习提升逻辑思维',
  133. tip: '逻辑思维是解决复杂问题的关键。多做推理和归纳练习,能帮助建立清晰的思维框架。',
  134. games: [
  135. { code: 'sudoku', name: '数独', icon: '\u{1F9E9}', desc: '数字逻辑推理,训练演绎思维' },
  136. { code: '1a2b', name: '猜数字', icon: '\u{1F522}', desc: '逻辑排除推理,训练分析能力' }
  137. ]
  138. },
  139. spatial: {
  140. key: 'spatial',
  141. name: '空间训练',
  142. icon: '\u{1F9CA}',
  143. color: BrandColors.brownWarm,
  144. lightColor: '#EFEBE9',
  145. desc: '通过空间旋转、立体构建等练习提升空间思维能力',
  146. tip: '空间思维对数学和科学学习至关重要。拼图和积木是提升空间能力的最佳方式。',
  147. games: [
  148. { code: 'sudoku', name: '数独', icon: '\u{1F9E9}', desc: '九宫格空间布局,训练空间推理' }
  149. ]
  150. },
  151. processingSpeed: {
  152. key: 'processingSpeed',
  153. name: '加工速度训练',
  154. icon: '\u26A1',
  155. color: '#FFD700',
  156. lightColor: BrandColors.amber50,
  157. desc: '通过快速反应、速度测试等练习提升加工速度',
  158. tip: '加工速度影响学习和反应效率。速算、速读等限时练习是提升加工速度的有效方法。',
  159. games: [
  160. { code: 'schulte', name: '舒尔特方格', icon: '\u{1F3AF}', desc: '限时完成,训练反应速度' },
  161. { code: '1a2b', name: '猜数字', icon: '\u{1F522}', desc: '快速推理,训练信息处理速度' }
  162. ]
  163. }
  164. }
  165. var GAME_PAGES = {
  166. schulte: '/pages/games/schulte',
  167. '1a2b': '/pages/games/1a2b',
  168. sudoku: '/pages/games/sudoku'
  169. }
  170. import fontScaleMixin from '@/mixins/font-scale.js'
  171. export default {
  172. mixins: [fontScaleMixin],
  173. components: { },
  174. data: function() {
  175. return {
  176. dimension: null,
  177. memberId: null,
  178. stats: null,
  179. statsLoading: false
  180. }
  181. },
  182. computed: {
  183. currentDim: function() {
  184. var dim = DIMENSION_MAP[this.dimension]
  185. return dim || null
  186. },
  187. currentQuote: function() {
  188. var dim = this.currentDim
  189. return dim ? dim.desc : '知己知彼,百战不殆'
  190. },
  191. otherDimensions: function() {
  192. var self = this
  193. var keys = Object.keys(DIMENSION_MAP)
  194. var result = []
  195. for (var i = 0; i < keys.length; i++) {
  196. if (keys[i] !== self.dimension) {
  197. result.push(DIMENSION_MAP[keys[i]])
  198. }
  199. }
  200. return result
  201. }
  202. },
  203. onLoad: function(options) {
  204. if (options && options.dimension) {
  205. this.dimension = options.dimension
  206. }
  207. if (options && options.memberId) {
  208. this.memberId = options.memberId
  209. } else {
  210. this.memberId = uni.getStorageSync('currentChildId') || null
  211. }
  212. uni.setNavigationBarTitle({
  213. title: this.currentDim ? this.currentDim.name : '能力训练'
  214. })
  215. this.loadStats()
  216. },
  217. methods: {
  218. loadStats: function() {
  219. var self = this
  220. if (!self.memberId) return
  221. self.statsLoading = true
  222. getGameStats({ memberId: self.memberId }).then(function(res) {
  223. if (res && res.data) {
  224. self.stats = res.data
  225. }
  226. }).catch(function() {
  227. // silent — stats not critical
  228. }).finally(function() {
  229. self.statsLoading = false
  230. })
  231. },
  232. goGame: function(game) {
  233. var url = GAME_PAGES[game.code]
  234. if (!url) {
  235. uni.showToast({ title: '游戏暂未开放', icon: 'none' })
  236. return
  237. }
  238. var memberId = this.memberId || ''
  239. url = url + '?memberId=' + memberId + '&dimension=' + (this.dimension || '')
  240. uni.navigateTo({ url: url })
  241. },
  242. switchDimension: function(key) {
  243. this.dimension = key
  244. uni.setNavigationBarTitle({
  245. title: DIMENSION_MAP[key].name
  246. })
  247. }
  248. }
  249. }
  250. </script>
  251. <style scoped>
  252. .container {
  253. min-height: 100vh;
  254. background: $app-bg;
  255. padding-bottom: 120rpx;
  256. }
  257. /* ===== 训练概览卡 ===== */
  258. .stats-card {
  259. margin: $uni-space-lg;
  260. background: $app-surface;
  261. border-radius: 24rpx;
  262. padding: 36rpx 24rpx;
  263. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  264. }
  265. .stats-row {
  266. display: flex;
  267. flex-direction: row;
  268. align-items: center;
  269. justify-content: space-around;
  270. }
  271. .stats-item {
  272. display: flex;
  273. flex-direction: column;
  274. align-items: center;
  275. flex: 1;
  276. }
  277. .stats-value {
  278. font-size: calc(44rpx * var(--font-scale, 1));
  279. font-weight: bold;
  280. color: $brand-primary;
  281. margin-bottom: 8rpx;
  282. }
  283. .stats-label {
  284. font-size: calc(22rpx * var(--font-scale, 1));
  285. color: $facade-text-muted;
  286. }
  287. .stats-divider {
  288. width: 1rpx;
  289. height: 60rpx;
  290. background: $facade-fill-3;
  291. flex-shrink: 0;
  292. }
  293. .stats-loading {
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. padding: 24rpx;
  298. }
  299. .stats-loading-text {
  300. font-size: calc(26rpx * var(--font-scale, 1));
  301. color: $facade-text-ghost-light;
  302. }
  303. /* ===== 维度描述卡 ===== */
  304. .dimension-card {
  305. margin: $uni-space-lg;
  306. background: $app-surface;
  307. border-radius: 24rpx;
  308. padding: 40rpx 32rpx;
  309. display: flex;
  310. flex-direction: column;
  311. align-items: center;
  312. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  313. }
  314. .dimension-icon-wrap {
  315. width: 120rpx;
  316. height: 120rpx;
  317. border-radius: 24rpx;
  318. display: flex;
  319. align-items: center;
  320. justify-content: center;
  321. margin-bottom: 20rpx;
  322. }
  323. .dimension-icon {
  324. font-size: calc($uni-font-size-display * var(--font-scale, 1));
  325. }
  326. .dimension-name {
  327. font-size: calc(36rpx * var(--font-scale, 1));
  328. font-weight: bold;
  329. color: $facade-text-strong;
  330. margin-bottom: 16rpx;
  331. }
  332. .dimension-desc {
  333. font-size: calc(26rpx * var(--font-scale, 1));
  334. color: $facade-text-faint;
  335. text-align: center;
  336. line-height: 1.6;
  337. }
  338. /* ===== 通用区段 ===== */
  339. .section {
  340. margin: 20rpx $uni-space-lg;
  341. }
  342. .section-header {
  343. margin-bottom: 20rpx;
  344. }
  345. .section-title {
  346. font-size: calc(30rpx * var(--font-scale, 1));
  347. font-weight: bold;
  348. color: $facade-text-strong;
  349. }
  350. /* ===== 推荐游戏列表 ===== */
  351. .game-list {
  352. display: flex;
  353. flex-direction: column;
  354. }
  355. .game-card {
  356. display: flex;
  357. flex-direction: row;
  358. align-items: center;
  359. background: $app-surface;
  360. border-radius: 24rpx;
  361. padding: 24rpx;
  362. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  363. margin-bottom: 20rpx;
  364. }
  365. .game-card:active {
  366. opacity: 0.7;
  367. }
  368. .game-icon-wrap {
  369. width: 80rpx;
  370. height: 80rpx;
  371. border-radius: 24rpx;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. margin-right: 20rpx;
  376. flex-shrink: 0;
  377. }
  378. .game-card-icon {
  379. font-size: calc(40rpx * var(--font-scale, 1));
  380. }
  381. .game-info {
  382. flex: 1;
  383. display: flex;
  384. flex-direction: column;
  385. }
  386. .game-title {
  387. font-size: calc(28rpx * var(--font-scale, 1));
  388. font-weight: bold;
  389. color: $facade-text-strong;
  390. margin-bottom: 6rpx;
  391. }
  392. .game-desc {
  393. font-size: calc(22rpx * var(--font-scale, 1));
  394. color: $facade-text-muted;
  395. }
  396. .game-arrow {
  397. font-size: calc(28rpx * var(--font-scale, 1));
  398. color: $facade-text-ghost;
  399. margin-left: 16rpx;
  400. flex-shrink: 0;
  401. }
  402. /* ===== 成长建议卡 ===== */
  403. .tip-card {
  404. display: flex;
  405. flex-direction: row;
  406. background: $app-surface;
  407. border-radius: 24rpx;
  408. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  409. overflow: hidden;
  410. }
  411. .tip-left-bar {
  412. width: 6rpx;
  413. flex-shrink: 0;
  414. }
  415. .tip-body {
  416. flex: 1;
  417. padding: 28rpx 24rpx;
  418. }
  419. .tip-content {
  420. font-size: calc(26rpx * var(--font-scale, 1));
  421. color: $facade-text-body;
  422. line-height: 1.7;
  423. }
  424. /* ===== 其他维度网格 ===== */
  425. .other-grid {
  426. display: flex;
  427. flex-direction: row;
  428. flex-wrap: wrap;
  429. margin: 0 -10rpx;
  430. }
  431. .other-item {
  432. width: calc(33.33% - 20rpx);
  433. display: flex;
  434. flex-direction: column;
  435. align-items: center;
  436. background: $app-surface;
  437. border-radius: 16rpx;
  438. padding: 24rpx 8rpx;
  439. margin: 0 10rpx 20rpx;
  440. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.05);
  441. }
  442. .other-item:active {
  443. opacity: 0.7;
  444. }
  445. .other-icon-wrap {
  446. width: 64rpx;
  447. height: 64rpx;
  448. border-radius: 24rpx;
  449. display: flex;
  450. align-items: center;
  451. justify-content: center;
  452. margin-bottom: 10rpx;
  453. }
  454. .other-icon {
  455. font-size: calc(32rpx * var(--font-scale, 1));
  456. }
  457. .other-name {
  458. font-size: calc(22rpx * var(--font-scale, 1));
  459. color: $facade-text-body;
  460. font-weight: 500;
  461. }
  462. /* ===== 底部 ===== */
  463. .bottom-spacer {
  464. height: 120rpx;
  465. }
  466. </style>