AreaDataCard.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!-- 数据卡片 -->
  2. <script setup lang="ts">
  3. import {TransitionPresets, useTransition} from "@vueuse/core";
  4. const props = defineProps({
  5. students: {
  6. type: Number,
  7. default: 0,
  8. required: true,
  9. },
  10. games: {
  11. type: Number,
  12. default: 0,
  13. required: true,
  14. },
  15. schools: {
  16. type: Number,
  17. default: 0,
  18. required: true,
  19. },
  20. });
  21. // 卡片数字动效
  22. function countNumber(number: any) {
  23. return useTransition(number, {
  24. duration: 5000,
  25. transition: TransitionPresets.easeOutExpo,
  26. });
  27. }
  28. // 样本人数
  29. const studentsCount = ref(0);
  30. const studentsCountOutput = countNumber(studentsCount);
  31. // 累计训练次数
  32. const gamesCount = ref(0);
  33. const gamesCountOutput = countNumber(gamesCount);
  34. // 全部学校
  35. const schoolsCount = ref(0);
  36. const schoolsCountOutput = countNumber(schoolsCount);
  37. // 监听数据变化
  38. watchEffect(() => {
  39. studentsCount.value = <number>props.students;
  40. gamesCount.value = <number>props.games;
  41. schoolsCount.value = <number>props.schools;
  42. });
  43. </script>
  44. <template>
  45. <div class="clear">
  46. <div class="data-card c1">
  47. <span class="n">{{ Math.round(Number(studentsCountOutput)) }}</span
  48. ><span>样本人数</span>
  49. </div>
  50. <div class="data-card c2">
  51. <span class="n">{{ Math.round(Number(gamesCountOutput)) }}</span
  52. ><span>累计训练次数</span>
  53. </div>
  54. <div class="data-card c3">
  55. <span class="n">{{ Math.round(Number(schoolsCountOutput)) }}</span
  56. ><span>全部学校</span>
  57. </div>
  58. </div>
  59. </template>
  60. <style lang="scss" scoped>
  61. .data-card {
  62. box-sizing: border-box;
  63. float: left;
  64. width: 300px;
  65. height: 140px;
  66. padding: 30px 0 0 30px;
  67. margin: 0 20px 20px 0;
  68. border: 1px solid #e6e8eb;
  69. border-radius: 30px;
  70. span {
  71. display: block;
  72. font-size: 18px;
  73. color: #23283c;
  74. &.n {
  75. margin-bottom: 15px;
  76. font-size: 24px;
  77. font-weight: bold;
  78. }
  79. }
  80. &.c1 {
  81. background: #fef6e9 url("../../../../assets/areaboard/students.png") 90% 50% no-repeat;
  82. span.n {
  83. color: #e08e0a;
  84. }
  85. }
  86. &.c2 {
  87. background: #feeeee url("../../../../assets/areaboard/games.png") 90% 50% no-repeat;
  88. span.n {
  89. color: #ca7676;
  90. }
  91. }
  92. &.c3 {
  93. background: #d0f6f1 url("../../../../assets/areaboard/schools.png") 90% 50% no-repeat;
  94. span.n {
  95. color: #45a498;
  96. }
  97. }
  98. }
  99. </style>