DataCard.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!-- 数据卡片 -->
  2. <script setup lang="ts">
  3. import { TransitionPresets, useTransition } from "@vueuse/core";
  4. const props = defineProps({
  5. classes: {
  6. type: Number,
  7. default: 0,
  8. required: true,
  9. },
  10. teachers: {
  11. type: Number,
  12. default: 0,
  13. required: true,
  14. },
  15. students: {
  16. type: Number,
  17. default: 0,
  18. required: true,
  19. },
  20. equipments: {
  21. type: Number,
  22. default: 0,
  23. required: true,
  24. },
  25. trainings: {
  26. type: Number,
  27. default: 0,
  28. required: true,
  29. },
  30. });
  31. // 卡片数字动效
  32. function countNumber(number) {
  33. return useTransition(number, {
  34. duration: 2000,
  35. transition: TransitionPresets.easeOutExpo,
  36. });
  37. }
  38. // 全部班级
  39. const classCount = ref(0);
  40. const classCountOutput = countNumber(classCount);
  41. // 全部教师
  42. const teacherCount = ref(0);
  43. const teacherCountOutput = countNumber(teacherCount);
  44. // 全部学生
  45. const studentCount = ref(0);
  46. const studentCountOutput = countNumber(studentCount);
  47. // 设备套数
  48. const equipmentCount = ref(0);
  49. const equipmentCountOutput = countNumber(equipmentCount);
  50. // 累计训练次数
  51. const trainingCount = ref(0);
  52. const trainingCountOutput = countNumber(trainingCount);
  53. // 监听数据变化
  54. watchEffect(() => {
  55. classCount.value = <number>props.classes;
  56. teacherCount.value = <number>props.teachers;
  57. studentCount.value = <number>props.students;
  58. equipmentCount.value = <number>props.equipments;
  59. trainingCount.value = <number>props.trainings;
  60. });
  61. </script>
  62. <template>
  63. <el-row :gutter="40" class="data-card">
  64. <el-col :xs="24" :sm="12" :md="8" :lg="5">
  65. <div class="card c1">
  66. <span class="n">{{ Math.round(classCountOutput) }}</span
  67. ><span>全部班级</span>
  68. </div>
  69. </el-col>
  70. <el-col :xs="24" :sm="12" :md="8" :lg="5">
  71. <div class="card c2">
  72. <span class="n">{{ Math.round(teacherCountOutput) }}</span
  73. ><span>全部教师</span>
  74. </div>
  75. </el-col>
  76. <el-col :xs="24" :sm="12" :md="8" :lg="5">
  77. <div class="card c3">
  78. <span class="n">{{ Math.round(studentCountOutput) }}</span
  79. ><span>全部学生</span>
  80. </div>
  81. </el-col>
  82. <el-col :xs="24" :sm="12" :md="8" :lg="5">
  83. <div class="card c4">
  84. <span class="n">{{ Math.round(equipmentCountOutput) }}</span
  85. ><span>设备套数</span>
  86. </div>
  87. </el-col>
  88. <el-col :xs="24" :sm="12" :md="8" :lg="5">
  89. <div class="card c5">
  90. <span class="n">{{ Math.round(trainingCountOutput) }}</span
  91. ><span>累计训练次数</span>
  92. </div>
  93. </el-col>
  94. </el-row>
  95. </template>
  96. <style lang="scss" scoped>
  97. @media only screen and (min-width: 1200px) {
  98. .el-col-lg-5 {
  99. display: block;
  100. max-width: 20%;
  101. min-width: 285px;
  102. flex: 0 0 20%;
  103. }
  104. }
  105. .data-card {
  106. margin: 0 auto !important;
  107. padding: 22px 42px;
  108. background: #ffffff;
  109. border-radius: 30px;
  110. border: 1px solid #e6e8eb;
  111. .card {
  112. box-sizing: border-box;
  113. width: 265px;
  114. height: 134px;
  115. max-width: 100%;
  116. padding: 32px 0 0 145px;
  117. margin: 20px 0;
  118. background-size: 100% auto;
  119. background-repeat: no-repeat;
  120. &.c1 {
  121. background-image: url("../../../assets/index/classes.png");
  122. }
  123. &.c2 {
  124. background-image: url("../../../assets/index/teachers.png");
  125. }
  126. &.c3 {
  127. background-image: url("../../../assets/index/students.png");
  128. }
  129. &.c4 {
  130. background-image: url("../../../assets/index/equipments.png");
  131. }
  132. &.c5 {
  133. background-image: url("../../../assets/index/trainings.png");
  134. }
  135. span {
  136. display: block;
  137. color: #142141;
  138. &.n {
  139. font-size: 26px;
  140. font-weight: bold;
  141. }
  142. }
  143. }
  144. }
  145. @media only screen and (max-width: 1200px) {
  146. .data-card .card {
  147. padding: 32px 0 0 74px;
  148. text-align: center;
  149. white-space: nowrap;
  150. }
  151. }
  152. </style>