completion-rate.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航 -->
  4. <view class="header">
  5. <view class="header-left" @click="goBack">
  6. <text class="back-arrow">‹</text>
  7. </view>
  8. <text class="header-title">任务完成率分析</text>
  9. <view class="header-right" @click="togglePeriod">
  10. <text class="period-btn">{{ periodLabel }}</text>
  11. </view>
  12. </view>
  13. <view class="scroll-area">
  14. <!-- 加载状态 -->
  15. <view class="loading-state" v-if="loading">
  16. <view class="loading-spinner"></view>
  17. <text class="loading-text">正在分析数据...</text>
  18. </view>
  19. <template v-if="!loading">
  20. <!-- 整体完成率 (环形图) -->
  21. <view class="rate-card">
  22. <view class="rate-ring-wrapper">
  23. <view class="rate-ring">
  24. <svg viewBox="0 0 120 120" class="ring-svg">
  25. <circle cx="60" cy="60" r="52" fill="none" :stroke="rateColors.track" stroke-width="8" />
  26. <circle cx="60" cy="60" r="52" fill="none" stroke="url(#rateGradient)" stroke-width="8"
  27. stroke-linecap="round"
  28. :stroke-dasharray="circumference"
  29. :stroke-dashoffset="rateOffset" transform="rotate(-90 60 60)" />
  30. <defs>
  31. <linearGradient id="rateGradient" x1="0%" y1="0%" x2="100%" y2="100%">
  32. <stop offset="0%" :stop-color="rateColors.done" />
  33. <stop offset="100%" :stop-color="rateColors.doneDeep" />
  34. </linearGradient>
  35. </defs>
  36. </svg>
  37. <view class="rate-ring-text">
  38. <text class="rate-value">{{ stats.completionRate }}%</text>
  39. <text class="rate-label">完成率</text>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="rate-legend">
  44. <view class="legend-item">
  45. <view class="legend-dot" :style="{ background: rateColors.done }"></view>
  46. <text class="legend-label">已完成 {{ stats.completedTasks }}</text>
  47. </view>
  48. <view class="legend-item">
  49. <view class="legend-dot" :style="{ background: rateColors.pending }"></view>
  50. <text class="legend-label">进行中 {{ stats.pendingTasks }}</text>
  51. </view>
  52. <view class="legend-item">
  53. <view class="legend-dot" :style="{ background: rateColors.overdue }"></view>
  54. <text class="legend-label">已逾期 {{ stats.overdueTasks }}</text>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 快捷统计卡片 -->
  59. <view class="quick-stats">
  60. <view class="quick-stat-card">
  61. <text class="quick-stat-value primary-color">{{ stats.totalTasks }}</text>
  62. <text class="quick-stat-label">总任务数</text>
  63. </view>
  64. <view class="quick-stat-card">
  65. <text class="quick-stat-value success-color">{{ stats.completedTasks }}</text>
  66. <text class="quick-stat-label">已完成</text>
  67. </view>
  68. <view class="quick-stat-card">
  69. <text class="quick-stat-value danger-color">{{ stats.overdueTasks }}</text>
  70. <text class="quick-stat-label">已逾期</text>
  71. </view>
  72. </view>
  73. <!-- 逾期任务警示 -->
  74. <view class="alert-card" v-if="stats.overdueTasks > 0">
  75. <text class="alert-icon">⚠️</text>
  76. <view class="alert-body">
  77. <text class="alert-title">有 {{ stats.overdueTasks }} 个任务已逾期</text>
  78. <text class="alert-desc">请督促成员尽快完成,避免影响成长积分</text>
  79. </view>
  80. </view>
  81. <!-- 按成员对比 (仅家庭维度) -->
  82. <view class="section-block" v-if="stats.byChild && stats.byChild.length > 1">
  83. <view class="section-header">
  84. <text class="section-title">成员对比</text>
  85. </view>
  86. <view class="child-compare">
  87. <view class="compare-bar-wrapper" v-for="child in stats.byChild" :key="child.memberId">
  88. <view class="compare-row">
  89. <text class="compare-name">{{ child.childName }}</text>
  90. <text class="compare-rate">{{ child.completionRate }}%</text>
  91. </view>
  92. <view class="compare-bar-bg">
  93. <view class="compare-bar-fill" :style="{ width: child.completionRate + '%' }"
  94. :class="'bar-color-' + (child.memberId % 5)"></view>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. <!-- 分类完成情况 -->
  100. <view class="section-block" v-if="stats.categoryBreakdown && stats.categoryBreakdown.length > 0">
  101. <view class="section-header">
  102. <text class="section-title">分类详情</text>
  103. </view>
  104. <view class="category-list">
  105. <view class="category-item" v-for="cat in stats.categoryBreakdown" :key="cat.category">
  106. <view class="category-header">
  107. <text class="category-name">{{ cat.category }}</text>
  108. <text class="category-count">{{ cat.completed }}/{{ cat.total }}</text>
  109. </view>
  110. <view class="category-bar-bg">
  111. <view class="category-bar-fill" :style="{ width: cat.rate + '%' }"></view>
  112. </view>
  113. <text class="category-rate">{{ cat.rate }}%</text>
  114. </view>
  115. </view>
  116. </view>
  117. <!-- 无数据占位 -->
  118. <view class="empty-section" v-if="stats.totalTasks === 0">
  119. <view class="empty-icon-area">
  120. <text class="empty-main-icon">📊</text>
  121. </view>
  122. <text class="empty-title">暂无任务数据</text>
  123. <text class="empty-hint">创建任务后将在这里展示完成率分析</text>
  124. </view>
  125. <!-- 已完成任务 -->
  126. <view class="section-block" v-if="stats.completedTaskList && stats.completedTaskList.length > 0">
  127. <view class="section-header">
  128. <text class="section-title">已完成打卡</text>
  129. </view>
  130. <view class="completed-list">
  131. <view class="completed-item" v-for="item in stats.completedTaskList" :key="item.id">
  132. <text class="completed-title">{{ item.title }}</text>
  133. <text class="completed-meta">+{{ item.points || 0 }} 积分</text>
  134. </view>
  135. </view>
  136. </view>
  137. </template>
  138. </view>
  139. </view>
  140. </template>
  141. <script>
  142. import { getChildCompletionStats, getFamilyCompletionStats, getChildren } from '../../utils/api.js'
  143. import { BrandColors } from '../../utils/brand-colors.js'
  144. // 完成率页专属色板(flat 青绿图表系 + 米白卡片系,单页专用)
  145. const RATE_COLORS = {
  146. track: '#FFF0E6', // 环形底轨
  147. done: '#4ECDC4', // 已完成(青绿)
  148. doneDeep: '#44B09E', // 青绿渐变深档
  149. pending: '#FFB088', // 进行中(浅橙)
  150. overdue: BrandColors.primary, // 已逾期(品牌橙)
  151. bar: '#FFD93D', // 柱图高亮黄
  152. barGreen: '#A8E063', // 柱图渐变绿起
  153. barGreenTo: '#56AB2F', // 柱图渐变绿终
  154. };
  155. export default {
  156. data() {
  157. return {
  158. loading: true,
  159. memberId: '',
  160. isFamilyView: false,
  161. periodIndex: 0,
  162. periods: [
  163. { label: '本周', days: 7 },
  164. { label: '本月', days: 30 },
  165. { label: '近三月', days: 90 }
  166. ],
  167. stats: {
  168. totalTasks: 0,
  169. completedTasks: 0,
  170. pendingTasks: 0,
  171. inReviewTasks: 0,
  172. overdueTasks: 0,
  173. completionRate: 0,
  174. byChild: [],
  175. categoryBreakdown: [],
  176. completedTaskList: []
  177. }
  178. }
  179. },
  180. computed: {
  181. periodLabel() {
  182. return this.periods[this.periodIndex].label
  183. },
  184. circumference() {
  185. return 2 * Math.PI * 52
  186. },
  187. rateOffset() {
  188. const pct = this.stats.completionRate || 0
  189. return this.circumference * (1 - pct / 100)
  190. }
  191. },
  192. onLoad(options) {
  193. if (options.memberId) {
  194. this.memberId = options.memberId
  195. this.isFamilyView = false
  196. } else if (options.familyView === '1') {
  197. this.isFamilyView = true
  198. }
  199. this.loadStats()
  200. },
  201. methods: {
  202. async loadStats() {
  203. this.loading = true
  204. try {
  205. const period = this.periods[this.periodIndex]
  206. const endDate = this.formatDate(new Date())
  207. const startDate = this.formatDate(new Date(Date.now() - period.days * 24 * 60 * 60 * 1000))
  208. const params = { startDate, endDate }
  209. if (this.memberId) {
  210. params.memberId = this.memberId
  211. }
  212. let res
  213. if (this.isFamilyView || !this.memberId) {
  214. res = await getFamilyCompletionStats(params)
  215. } else {
  216. res = await getChildCompletionStats(params)
  217. }
  218. if (res && res.data) {
  219. // 兼容后端可能返回 byChild 或 categoryBreakdown
  220. const data = res.data
  221. this.stats = {
  222. totalTasks: data.totalTasks || 0,
  223. completedTasks: data.completedTasks || 0,
  224. pendingTasks: data.pendingTasks || 0,
  225. inReviewTasks: data.inReviewTasks || 0,
  226. overdueTasks: data.overdueTasks || 0,
  227. completionRate: data.completionRate || 0,
  228. byChild: data.byChild || [],
  229. categoryBreakdown: data.categoryBreakdown || [],
  230. completedTaskList: data.completedTaskList || []
  231. }
  232. }
  233. } catch (e) {
  234. console.error('加载完成率失败', e)
  235. uni.showToast({ title: '数据加载失败', icon: 'none' })
  236. } finally {
  237. this.loading = false
  238. }
  239. },
  240. togglePeriod() {
  241. this.periodIndex = (this.periodIndex + 1) % this.periods.length
  242. this.loadStats()
  243. },
  244. goBack() {
  245. uni.navigateBack()
  246. },
  247. formatDate(date) {
  248. const y = date.getFullYear()
  249. const m = String(date.getMonth() + 1).padStart(2, '0')
  250. const d = String(date.getDate()).padStart(2, '0')
  251. return y + '-' + m + '-' + d
  252. }
  253. }
  254. }
  255. </script>
  256. <style scoped lang="scss">
  257. // ===== 完成率页专属色阶(flat 图表青绿 + 米白卡片,单页专用;约定见 uni.scss §14)=====
  258. $c-comp-bg: #FFF9F0; // 页面米白底
  259. $c-comp-card: #FFF5EB; // 暖白卡片底
  260. $c-comp-warm: #FFF0E6; // 暖米色(环形底轨 / 分隔)
  261. $c-comp-done: #4ECDC4; // 已完成青绿(图表 / 图例)
  262. $c-comp-done-deep: #44B09E; // 青绿渐变深档
  263. $c-comp-ink: #2D3436; // 主文字(深灰)
  264. $c-comp-muted: #B2BEC3; // 次要文字(灰)
  265. $c-comp-muted2: #636E72; // 辅助文字(中灰)
  266. $c-comp-danger-line: #FFE0E0; // 危险浅描边
  267. $c-comp-orange-text: #E17055; // 警示橙文字
  268. $c-comp-bar-yellow: #FFD93D; // 柱图高亮黄
  269. $c-comp-bar-green: #A8E063; // 柱图绿渐变起
  270. $c-comp-bar-green-to: #56AB2F; // 柱图绿渐变终
  271. .container {
  272. background: $c-comp-bg;
  273. min-height: 100vh;
  274. display: flex;
  275. flex-direction: column;
  276. }
  277. /* 顶部导航 */
  278. .header {
  279. display: flex;
  280. align-items: center;
  281. justify-content: space-between;
  282. padding: 24rpx 32rpx;
  283. padding-top: calc(88rpx + env(safe-area-inset-top));
  284. background: $c-comp-bg;
  285. position: sticky;
  286. top: 0;
  287. z-index: 10;
  288. }
  289. .header-left, .header-right {
  290. min-width: 120rpx;
  291. }
  292. .header-right {
  293. display: flex;
  294. justify-content: flex-end;
  295. }
  296. .back-arrow {
  297. font-size: 48rpx;
  298. color: $c-comp-ink;
  299. font-weight: 300;
  300. line-height: 1;
  301. }
  302. .header-title {
  303. font-size: 34rpx;
  304. font-weight: 700;
  305. color: $c-comp-ink;
  306. }
  307. .period-btn {
  308. font-size: 26rpx;
  309. color: $dim-body;
  310. background: $c-comp-card;
  311. padding: 8rpx 20rpx;
  312. border-radius: 24rpx;
  313. font-weight: 500;
  314. }
  315. /* 滚动区 */
  316. .scroll-area {
  317. flex: 1;
  318. padding: 0 32rpx 48rpx;
  319. overflow-y: auto;
  320. }
  321. /* 加载状态 */
  322. .loading-state {
  323. display: flex;
  324. flex-direction: column;
  325. align-items: center;
  326. padding: 160rpx 0;
  327. }
  328. .loading-spinner {
  329. width: 64rpx;
  330. height: 64rpx;
  331. border: 6rpx solid $c-comp-warm;
  332. border-top-color: $dim-body;
  333. border-radius: 50%;
  334. animation: spin 0.8s linear infinite;
  335. }
  336. @keyframes spin {
  337. to { transform: rotate(360deg); }
  338. }
  339. .loading-text {
  340. font-size: 26rpx;
  341. color: $c-comp-muted;
  342. margin-top: 20rpx;
  343. }
  344. /* 整体完成率卡片 */
  345. .rate-card {
  346. background: $app-surface;
  347. border-radius: 28rpx;
  348. padding: 40rpx 32rpx;
  349. margin-bottom: 24rpx;
  350. display: flex;
  351. align-items: center;
  352. box-shadow: 0 8rpx 40rpx rgba(255, 140, 66, 0.08);
  353. }
  354. .rate-ring-wrapper {
  355. flex-shrink: 0;
  356. margin-right: 32rpx;
  357. }
  358. .rate-ring {
  359. width: 200rpx;
  360. height: 200rpx;
  361. position: relative;
  362. }
  363. .ring-svg {
  364. width: 100%;
  365. height: 100%;
  366. }
  367. .rate-ring-text {
  368. position: absolute;
  369. top: 50%;
  370. left: 50%;
  371. transform: translate(-50%, -50%);
  372. display: flex;
  373. flex-direction: column;
  374. align-items: center;
  375. }
  376. .rate-value {
  377. font-size: 40rpx;
  378. font-weight: 800;
  379. color: $c-comp-ink;
  380. line-height: 1.2;
  381. }
  382. .rate-label {
  383. font-size: 22rpx;
  384. color: $c-comp-muted;
  385. margin-top: 4rpx;
  386. }
  387. .rate-legend {
  388. flex: 1;
  389. display: flex;
  390. flex-direction: column;
  391. gap: 16rpx;
  392. }
  393. .legend-item {
  394. display: flex;
  395. align-items: center;
  396. }
  397. .legend-dot {
  398. width: 16rpx;
  399. height: 16rpx;
  400. border-radius: 50%;
  401. margin-right: 12rpx;
  402. flex-shrink: 0;
  403. }
  404. .legend-label {
  405. font-size: 26rpx;
  406. color: $c-comp-muted2;
  407. }
  408. /* 快捷统计卡片 */
  409. .quick-stats {
  410. display: flex;
  411. gap: 16rpx;
  412. margin-bottom: 24rpx;
  413. }
  414. .quick-stat-card {
  415. flex: 1;
  416. background: $app-surface;
  417. border-radius: 20rpx;
  418. padding: 24rpx 16rpx;
  419. display: flex;
  420. flex-direction: column;
  421. align-items: center;
  422. box-shadow: 0 8rpx 40rpx rgba(255, 140, 66, 0.08);
  423. }
  424. .quick-stat-value {
  425. font-size: 40rpx;
  426. font-weight: 800;
  427. line-height: 1.2;
  428. }
  429. .quick-stat-label {
  430. font-size: 22rpx;
  431. color: $c-comp-muted;
  432. margin-top: 8rpx;
  433. }
  434. .primary-color { color: $dim-body; }
  435. .success-color { color: $c-comp-done; }
  436. .danger-color { color: $brand-primary; }
  437. /* 逾期警示 */
  438. .alert-card {
  439. background: $status-danger-tint;
  440. border-radius: 20rpx;
  441. padding: 24rpx;
  442. margin-bottom: 24rpx;
  443. display: flex;
  444. align-items: flex-start;
  445. border: 1rpx solid $c-comp-danger-line;
  446. }
  447. .alert-icon {
  448. font-size: 40rpx;
  449. margin-right: 16rpx;
  450. flex-shrink: 0;
  451. }
  452. .alert-body {
  453. flex: 1;
  454. }
  455. .alert-title {
  456. font-size: 28rpx;
  457. font-weight: 600;
  458. color: $status-danger-flat;
  459. display: block;
  460. }
  461. .alert-desc {
  462. font-size: 24rpx;
  463. color: $c-comp-orange-text;
  464. margin-top: 6rpx;
  465. display: block;
  466. }
  467. /* 区块 */
  468. .section-block {
  469. background: $app-surface;
  470. border-radius: 24rpx;
  471. padding: 28rpx;
  472. margin-bottom: 24rpx;
  473. box-shadow: 0 8rpx 40rpx rgba(255, 140, 66, 0.08);
  474. }
  475. .section-header {
  476. display: flex;
  477. justify-content: space-between;
  478. align-items: center;
  479. margin-bottom: 24rpx;
  480. }
  481. .section-title {
  482. font-size: 30rpx;
  483. font-weight: 700;
  484. color: $c-comp-ink;
  485. }
  486. /* 孩子对比 */
  487. .child-compare {
  488. display: flex;
  489. flex-direction: column;
  490. gap: 20rpx;
  491. }
  492. .compare-row {
  493. display: flex;
  494. justify-content: space-between;
  495. margin-bottom: 8rpx;
  496. }
  497. .compare-name {
  498. font-size: 28rpx;
  499. color: $c-comp-ink;
  500. font-weight: 500;
  501. }
  502. .compare-rate {
  503. font-size: 28rpx;
  504. color: $dim-body;
  505. font-weight: 700;
  506. }
  507. .compare-bar-bg {
  508. height: 12rpx;
  509. background: $c-comp-warm;
  510. border-radius: 999rpx;
  511. overflow: hidden;
  512. }
  513. .compare-bar-fill {
  514. height: 100%;
  515. border-radius: 999rpx;
  516. transition: width 0.5s ease;
  517. }
  518. .bar-color-0 { background: linear-gradient(90deg, $dim-body, $c-comp-bar-yellow); }
  519. .bar-color-1 { background: linear-gradient(90deg, $c-comp-done, $c-comp-done-deep); }
  520. .bar-color-2 { background: linear-gradient(90deg, $accent-indigo, $accent-indigo-deep); }
  521. .bar-color-3 { background: linear-gradient(90deg, $brand-primary, $brand-primary-light); }
  522. .bar-color-4 { background: linear-gradient(90deg, $c-comp-bar-green, $c-comp-bar-green-to); }
  523. /* 分类列表 */
  524. .category-list {
  525. display: flex;
  526. flex-direction: column;
  527. gap: 20rpx;
  528. }
  529. .category-item {
  530. display: flex;
  531. align-items: center;
  532. gap: 12rpx;
  533. }
  534. .category-header {
  535. width: 140rpx;
  536. flex-shrink: 0;
  537. }
  538. .category-name {
  539. font-size: 24rpx;
  540. color: $c-comp-muted2;
  541. display: block;
  542. }
  543. .category-count {
  544. font-size: 20rpx;
  545. color: $c-comp-muted;
  546. display: block;
  547. margin-top: 2rpx;
  548. }
  549. .category-bar-bg {
  550. flex: 1;
  551. height: 16rpx;
  552. background: $c-comp-warm;
  553. border-radius: 999rpx;
  554. overflow: hidden;
  555. }
  556. .category-bar-fill {
  557. height: 100%;
  558. background: linear-gradient(90deg, $c-comp-done, $c-comp-done-deep);
  559. border-radius: 999rpx;
  560. transition: width 0.5s ease;
  561. }
  562. .category-rate {
  563. width: 64rpx;
  564. text-align: right;
  565. font-size: 24rpx;
  566. font-weight: 600;
  567. color: $c-comp-done;
  568. flex-shrink: 0;
  569. }
  570. /* 已完成任务列表 */
  571. .completed-list {
  572. display: flex;
  573. flex-direction: column;
  574. gap: 16rpx;
  575. }
  576. .completed-item {
  577. display: flex;
  578. justify-content: space-between;
  579. align-items: center;
  580. background: $app-surface;
  581. border-radius: 16rpx;
  582. padding: 24rpx;
  583. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  584. }
  585. .completed-title {
  586. font-size: 28rpx;
  587. color: $c-comp-ink;
  588. flex: 1;
  589. padding-right: 16rpx;
  590. }
  591. .completed-meta {
  592. font-size: 24rpx;
  593. color: $status-success;
  594. flex-shrink: 0;
  595. }
  596. /* 空状态 */
  597. .empty-section {
  598. display: flex;
  599. flex-direction: column;
  600. align-items: center;
  601. padding: 120rpx 0;
  602. }
  603. .empty-icon-area {
  604. width: 160rpx;
  605. height: 160rpx;
  606. background: $c-comp-card;
  607. border-radius: 50%;
  608. display: flex;
  609. align-items: center;
  610. justify-content: center;
  611. margin-bottom: 24rpx;
  612. }
  613. .empty-main-icon {
  614. font-size: 72rpx;
  615. }
  616. .empty-title {
  617. font-size: 30rpx;
  618. font-weight: 600;
  619. color: $c-comp-ink;
  620. margin-bottom: 12rpx;
  621. }
  622. .empty-hint {
  623. font-size: 26rpx;
  624. color: $c-comp-muted;
  625. text-align: center;
  626. }
  627. </style>