com-sta-data.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!-- 第一行统计数据 -->
  2. <template>
  3. <el-row :gutter="14">
  4. <el-col :lg="4" :sm="8" :xs="24">
  5. <div class="sa-wnk">
  6. <img src="../../static/icon/icon-user.png" >
  7. <div class="sa-wnk-tv">
  8. <p class="sa-wnk-title">用户</p>
  9. <p class="sa-wnk-value">{{sta.userCount}}</p>
  10. </div>
  11. </div>
  12. </el-col>
  13. <el-col :lg="4" :sm="8" :xs="24">
  14. <div class="sa-wnk">
  15. <img src="../../static/icon/icon-goods.png" >
  16. <div class="sa-wnk-tv">
  17. <p class="sa-wnk-title">商品</p>
  18. <p class="sa-wnk-value">{{sta.goodsCount}}</p>
  19. </div>
  20. </div>
  21. </el-col>
  22. <el-col :lg="4" :sm="8" :xs="24">
  23. <div class="sa-wnk">
  24. <img src="../../static/icon/icon-order.png" >
  25. <div class="sa-wnk-tv">
  26. <p class="sa-wnk-title">订单</p>
  27. <p class="sa-wnk-value">{{sta.orderCount}}</p>
  28. </div>
  29. </div>
  30. </el-col>
  31. <el-col :lg="4" :sm="8" :xs="24">
  32. <div class="sa-wnk">
  33. <img src="../../static/icon/icon-article.png" >
  34. <div class="sa-wnk-tv">
  35. <p class="sa-wnk-title">文章</p>
  36. <p class="sa-wnk-value">{{sta.articleCount}}</p>
  37. </div>
  38. </div>
  39. </el-col>
  40. <el-col :lg="4" :sm="8" :xs="24">
  41. <div class="sa-wnk">
  42. <img src="../../static/icon/icon-comment.png" >
  43. <div class="sa-wnk-tv">
  44. <p class="sa-wnk-title">评论</p>
  45. <p class="sa-wnk-value">{{sta.commentCount}}</p>
  46. </div>
  47. </div>
  48. </el-col>
  49. <el-col :lg="4" :sm="8" :xs="24">
  50. <div class="sa-wnk">
  51. <img src="../../static/icon/icon-money.png" >
  52. <div class="sa-wnk-tv">
  53. <p class="sa-wnk-title">余额</p>
  54. <p class="sa-wnk-value">{{sta.moneyCount}}</p>
  55. </div>
  56. </div>
  57. </el-col>
  58. </el-row>
  59. </template>
  60. <script>
  61. module.exports = {
  62. data() {
  63. return {
  64. // 统计数据
  65. sta: {
  66. userCount: 0,
  67. goodsCount: 0,
  68. orderCount: 0,
  69. articleCount: 0,
  70. commentCount: 0,
  71. moneyCount: 0,
  72. },
  73. }
  74. },
  75. methods: {
  76. // 数值跳动
  77. // 对象、属性、结束值、所用时间
  78. slowMotion: function(obj, prop, endValue, time) {
  79. let timeNow = 0;
  80. let fn = function() {
  81. // 如果已经接近 or 时间已到,则立即结束
  82. var jdz = Math.abs(obj[prop] - endValue);
  83. if(jdz < 2 || timeNow >= time) {
  84. // console.log('到点了');
  85. obj[prop] = endValue;
  86. } else {
  87. if(jdz < 100) {
  88. obj[prop] += 1;
  89. } else {
  90. obj[prop] += parseInt((endValue - obj[prop]) / 10); // 平均一下
  91. }
  92. timeNow += 30;
  93. setTimeout(fn, 30);
  94. }
  95. }
  96. fn();
  97. },
  98. // 设置统计数据的数值
  99. setStaDataValue: function(staData) {
  100. for (let key in staData) {
  101. this.slowMotion(this.sta, key, staData[key], 3000);
  102. }
  103. },
  104. },
  105. created() {
  106. // 写入数据
  107. this.setStaDataValue({
  108. userCount: 12361,
  109. goodsCount: 12541,
  110. orderCount: 63222,
  111. articleCount: 10368,
  112. commentCount: 2048,
  113. moneyCount: 13654.32,
  114. });
  115. }
  116. }
  117. </script>
  118. <style scoped>
  119. /* 第一行 */
  120. .sa-wnk{background-color: #FFF; border: 1px #ddd solid; margin-bottom: 14px; min-height: 100px;
  121. cursor: pointer; transition: all 0.3s; overflow: hidden;}
  122. .sa-wnk:hover{box-shadow: 0 0 20px #999;}
  123. .sa-wnk img{float: left; line-height: 100px; margin: 25px 0px 0 20px; width: 50px; height: 50px; vertical-align: middle;}
  124. .sa-wnk .sa-wnk-tv{float: left; margin-left: 10px; max-width: calc(100% - 100px);}
  125. .sa-wnk-title{margin-top: 25px; font-size: 16px;}
  126. .sa-wnk-value{margin-top: 4px; font-size: 24px; padding-bottom: 20px;}
  127. </style>