index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view class="report-container">
  3. <!-- 顶部标题 -->
  4. <view class="header">
  5. <text class="header-title">数据统计</text>
  6. </view>
  7. <view v-if="loading" class="loading-state">
  8. <text>加载中...</text>
  9. </view>
  10. <scroll-view v-else scroll-y class="scroll-area">
  11. <!-- 概览卡片 -->
  12. <view class="overview-grid">
  13. <view class="overview-item">
  14. <text class="ov-num">{{ overview.totalPoints || 0 }}</text>
  15. <text class="ov-label">总积分</text>
  16. </view>
  17. <view class="overview-item">
  18. <text class="ov-num">{{ (overview.taskStats && overview.taskStats.completed) || 0 }}/{{ (overview.taskStats && overview.taskStats.total) || 0 }}</text>
  19. <text class="ov-label">任务完成</text>
  20. </view>
  21. <view class="overview-item">
  22. <text class="ov-num">{{ (overview.gameStats && overview.gameStats.total) || 0 }}</text>
  23. <text class="ov-label">游戏次数</text>
  24. </view>
  25. <view class="overview-item" @click="navTo('/pages/stats/completion-rate')">
  26. <text class="ov-num">{{ (overview.taskStats && overview.taskStats.completionRate) || 0 }}%</text>
  27. <text class="ov-label">完成率 ›</text>
  28. </view>
  29. </view>
  30. <!-- 积分趋势 -->
  31. <view class="section">
  32. <view class="section-header">
  33. <text class="section-title">积分趋势(近7天)</text>
  34. </view>
  35. <view class="trend-chart">
  36. <view class="bar-item" v-for="(item, idx) in overview.pointsTrend || []" :key="idx">
  37. <view class="bar-wrapper">
  38. <view class="bar" :style="{ height: barHeight(item.points) + 'rpx' }"></view>
  39. </view>
  40. <text class="bar-label">{{ formatDay(item.date) }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 任务统计 -->
  45. <view class="section">
  46. <view class="section-header">
  47. <text class="section-title">任务统计</text>
  48. <text class="section-more" @click="navTo('/pages/stats/completion-rate')">查看详情 ›</text>
  49. </view>
  50. <view class="stat-cards">
  51. <view class="stat-row">
  52. <view class="stat-chip pending">
  53. <text class="chip-num">{{ (overview.taskStats && overview.taskStats.pending) || 0 }}</text>
  54. <text class="chip-label">待完成</text>
  55. </view>
  56. <view class="stat-chip review">
  57. <text class="chip-num">{{ (overview.taskStats && overview.taskStats.inReview) || 0 }}</text>
  58. <text class="chip-label">待审核</text>
  59. </view>
  60. <view class="stat-chip done">
  61. <text class="chip-num">{{ (overview.taskStats && overview.taskStats.completed) || 0 }}</text>
  62. <text class="chip-label">已完成</text>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 游戏统计 -->
  68. <view class="section">
  69. <view class="section-header">
  70. <text class="section-title">专注训练统计</text>
  71. <text class="section-more" @click="navTo('/pages/games/stats')">查看详情 ›</text>
  72. </view>
  73. <view class="stat-cards">
  74. <view class="stat-row">
  75. <view class="stat-chip game">
  76. <text class="chip-num">{{ (overview.gameStats && overview.gameStats.total) || 0 }}</text>
  77. <text class="chip-label">总次数</text>
  78. </view>
  79. <view class="stat-chip game">
  80. <text class="chip-num">{{ (overview.gameStats && overview.gameStats.bestScore) || 0 }}</text>
  81. <text class="chip-label">最高分</text>
  82. </view>
  83. <view class="stat-chip game">
  84. <text class="chip-num">{{ (overview.gameStats && overview.gameStats.totalPoints) || 0 }}</text>
  85. <text class="chip-label">获得积分</text>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 快捷入口 -->
  91. <view class="section">
  92. <view class="section-header">
  93. <text class="section-title">更多报表</text>
  94. </view>
  95. <view class="quick-links">
  96. <view class="quick-link" @click="navTo('/pages/games/records')">
  97. <text class="ql-icon">📋</text>
  98. <text class="ql-text">训练记录</text>
  99. </view>
  100. <view class="quick-link" @click="navTo('/pages/games/stats')">
  101. <text class="ql-icon">📊</text>
  102. <text class="ql-text">成绩统计</text>
  103. </view>
  104. <view class="quick-link" @click="navTo('/pages/rewards/badge')">
  105. <text class="ql-icon">🏅</text>
  106. <text class="ql-text">勋章墙</text>
  107. </view>
  108. <view class="quick-link" @click="navTo('/pages/stats/completion-rate')">
  109. <text class="ql-icon">✅</text>
  110. <text class="ql-text">完成率</text>
  111. </view>
  112. </view>
  113. </view>
  114. </scroll-view>
  115. </view>
  116. </template>
  117. <script>
  118. import { getChildOverview } from '../../utils/api.js'
  119. export default {
  120. data() {
  121. return {
  122. loading: true,
  123. overview: {}
  124. }
  125. },
  126. onShow() {
  127. this.loadData()
  128. },
  129. methods: {
  130. async loadData() {
  131. this.loading = true
  132. try {
  133. const memberId = uni.getStorageSync('currentChildId')
  134. if (memberId) {
  135. const res = await getChildOverview(memberId)
  136. this.overview = res.data || {}
  137. }
  138. } catch (e) {
  139. console.error('加载报表数据失败', e)
  140. } finally {
  141. this.loading = false
  142. }
  143. },
  144. barHeight(points) {
  145. const max = Math.max(...(this.overview.pointsTrend || []).map(i => i.points), 1)
  146. return Math.max(8, (points / max) * 160)
  147. },
  148. formatDay(dateStr) {
  149. if (!dateStr) return ''
  150. const parts = dateStr.split('-')
  151. return (parts[1] || '') + '/' + (parts[2] || '')
  152. },
  153. navTo(path) {
  154. uni.navigateTo({ url: path })
  155. }
  156. }
  157. }
  158. </script>
  159. <style scoped>
  160. .report-container {
  161. min-height: 100vh;
  162. background: #f5f7fa;
  163. }
  164. .header {
  165. padding: 20rpx 30rpx;
  166. background: #fff;
  167. border-bottom: 1rpx solid #f0f0f0;
  168. }
  169. .header-title {
  170. font-size: 34rpx;
  171. font-weight: bold;
  172. color: #333;
  173. }
  174. .loading-state {
  175. text-align: center;
  176. padding: 200rpx 30rpx;
  177. color: #999;
  178. font-size: 28rpx;
  179. }
  180. .scroll-area {
  181. padding: 0 20rpx 40rpx;
  182. }
  183. /* 概览 */
  184. .overview-grid {
  185. display: flex;
  186. margin: 20rpx 0;
  187. gap: 16rpx;
  188. }
  189. .overview-item {
  190. flex: 1;
  191. background: #fff;
  192. border-radius: 16rpx;
  193. padding: 24rpx 16rpx;
  194. text-align: center;
  195. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  196. }
  197. .ov-num {
  198. display: block;
  199. font-size: 36rpx;
  200. font-weight: bold;
  201. color: #F97316;
  202. }
  203. .ov-label {
  204. display: block;
  205. font-size: 22rpx;
  206. color: #999;
  207. margin-top: 6rpx;
  208. }
  209. /* 积分趋势 */
  210. .section {
  211. background: #fff;
  212. border-radius: 16rpx;
  213. padding: 24rpx;
  214. margin-bottom: 20rpx;
  215. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  216. }
  217. .section-header {
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. margin-bottom: 16rpx;
  222. }
  223. .section-title {
  224. font-size: 28rpx;
  225. font-weight: bold;
  226. color: #333;
  227. }
  228. .section-more {
  229. font-size: 24rpx;
  230. color: #F97316;
  231. }
  232. .trend-chart {
  233. display: flex;
  234. align-items: flex-end;
  235. height: 200rpx;
  236. gap: 12rpx;
  237. padding-top: 20rpx;
  238. }
  239. .bar-item {
  240. flex: 1;
  241. display: flex;
  242. flex-direction: column;
  243. align-items: center;
  244. height: 100%;
  245. }
  246. .bar-wrapper {
  247. flex: 1;
  248. width: 100%;
  249. display: flex;
  250. align-items: flex-end;
  251. justify-content: center;
  252. }
  253. .bar {
  254. width: 32rpx;
  255. background: linear-gradient(180deg, #F97316, #fb923c);
  256. border-radius: 8rpx 8rpx 0 0;
  257. min-height: 8rpx;
  258. transition: height 0.3s;
  259. }
  260. .bar-label {
  261. font-size: 20rpx;
  262. color: #999;
  263. margin-top: 8rpx;
  264. }
  265. /* 统计卡片 */
  266. .stat-cards {
  267. margin-top: 8rpx;
  268. }
  269. .stat-row {
  270. display: flex;
  271. gap: 16rpx;
  272. }
  273. .stat-chip {
  274. flex: 1;
  275. text-align: center;
  276. padding: 20rpx;
  277. border-radius: 12rpx;
  278. }
  279. .stat-chip.pending { background: #fef3c7; }
  280. .stat-chip.review { background: #dbeafe; }
  281. .stat-chip.done { background: #d1fae5; }
  282. .stat-chip.game { background: #f3e8ff; }
  283. .chip-num {
  284. display: block;
  285. font-size: 32rpx;
  286. font-weight: bold;
  287. color: #333;
  288. }
  289. .chip-label {
  290. display: block;
  291. font-size: 22rpx;
  292. color: #666;
  293. margin-top: 4rpx;
  294. }
  295. /* 快捷入口 */
  296. .quick-links {
  297. display: flex;
  298. flex-wrap: wrap;
  299. gap: 16rpx;
  300. }
  301. .quick-link {
  302. width: calc(25% - 12rpx);
  303. text-align: center;
  304. padding: 20rpx 0;
  305. }
  306. .ql-icon {
  307. display: block;
  308. font-size: 48rpx;
  309. margin-bottom: 8rpx;
  310. }
  311. .ql-text {
  312. display: block;
  313. font-size: 22rpx;
  314. color: #666;
  315. }
  316. </style>