GwStatistic.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div shadow="always" class="gw-statistic boxShadow">
  3. <div class="gw-statistic-value" :style="{'color': color}" v-html="showValue">
  4. </div>
  5. <div class="gw-statistic-name" :style="{'background-color': color}">
  6. <slot name="name">
  7. {{ name }}
  8. </slot>
  9. </div>
  10. </div>
  11. </template>
  12. <script setup>
  13. import {isString} from "@/utils/validate.js";
  14. const emit = defineEmits(['update'])
  15. const props = defineProps({
  16. name: {
  17. type: String,
  18. default: ""
  19. },
  20. value: {
  21. default: ""
  22. },
  23. color: {
  24. type: String,
  25. default: "#477ACF"
  26. },
  27. })
  28. const showValue = ref("")
  29. watch(() => props.value, v => {
  30. if (v && isString(v)) {
  31. if (v.length > 11) {
  32. const index = Math.floor(v.length / 2)
  33. showValue.value = v.substring(0, index + 1) + '<br/>' + v.substring(index + 1)
  34. return
  35. }
  36. }
  37. showValue.value = v
  38. }, {immediate: true})
  39. </script>
  40. <style scoped lang="scss">
  41. .gw-statistic {
  42. width: 100%;
  43. height: 100%;;
  44. border-radius: 8px;
  45. background-color: white;
  46. .gw-statistic-name {
  47. display: flex;
  48. align-items: center;
  49. justify-content: center;
  50. font-size: 20px;
  51. width: 100%;
  52. color: white;
  53. text-align: center;
  54. border-radius: 0 0 8px 8px;
  55. height: 30%;
  56. }
  57. .gw-statistic-value {
  58. width: 100%;
  59. display: flex;
  60. align-items: center;
  61. justify-content: center;
  62. font-size: 1.8rem;
  63. font-weight: bold;
  64. height: 70%
  65. }
  66. }
  67. .boxShadow {
  68. box-shadow: -8px 0 15px -10px rgba(0, 0, 0, 0.1), /* 左侧阴影 */
  69. 8px 0 15px -10px rgba(0, 0, 0, 0.1); /* 右侧阴影 */
  70. transition: box-shadow 0.3s ease;
  71. }
  72. </style>