ChartBar.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <script setup lang="ts">
  2. import { useDark, useECharts } from "@pureadmin/utils";
  3. import { type PropType, ref, computed, watch, nextTick } from "vue";
  4. const props = defineProps({
  5. attendPerson: {
  6. type: Array as PropType<Array<number>>,
  7. default: () => []
  8. },
  9. arrivePerson: {
  10. type: Array as PropType<Array<number>>,
  11. default: () => []
  12. },
  13. onlinePerson: {
  14. type: Array as PropType<Array<number>>,
  15. default: () => []
  16. }
  17. });
  18. const { isDark } = useDark();
  19. const theme = computed(() => (isDark.value ? "dark" : "light"));
  20. const chartRef = ref();
  21. const { setOptions } = useECharts(chartRef, {
  22. theme
  23. });
  24. watch(
  25. () => props,
  26. async () => {
  27. await nextTick(); // 确保DOM更新完成后再执行
  28. setOptions({
  29. container: ".bar-card",
  30. color: ["#41b6ff", "#e85f33"],
  31. tooltip: {
  32. trigger: "axis",
  33. axisPointer: {
  34. type: "none"
  35. }
  36. },
  37. grid: {
  38. top: "20px",
  39. left: "50px",
  40. right: 0
  41. },
  42. legend: {
  43. data: ["考勤人次", "到岗人次", "缺岗人次"],
  44. textStyle: {
  45. color: "#606266",
  46. fontSize: "0.875rem"
  47. },
  48. bottom: 0
  49. },
  50. xAxis: [
  51. {
  52. type: "category",
  53. data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
  54. axisLabel: {
  55. fontSize: "0.875rem"
  56. },
  57. axisPointer: {
  58. type: "shadow"
  59. }
  60. }
  61. ],
  62. yAxis: [
  63. {
  64. type: "value",
  65. axisLabel: {
  66. fontSize: "0.875rem"
  67. },
  68. splitLine: {
  69. show: false // 去网格线
  70. }
  71. // name: "单位: 个"
  72. }
  73. ],
  74. series: [
  75. {
  76. name: "考勤人次",
  77. type: "bar",
  78. barWidth: 10,
  79. itemStyle: {
  80. color: "#41b6ff",
  81. borderRadius: [10, 10, 0, 0]
  82. },
  83. data: props.attendPerson
  84. },
  85. {
  86. name: "到岗人次",
  87. type: "bar",
  88. barWidth: 10,
  89. itemStyle: {
  90. color: "#e86033ce",
  91. borderRadius: [10, 10, 0, 0]
  92. },
  93. data: props.arrivePerson
  94. },
  95. {
  96. name: "在线人次",
  97. type: "bar",
  98. barWidth: 10,
  99. itemStyle: {
  100. color: "#286011ce",
  101. borderRadius: [10, 10, 0, 0]
  102. },
  103. data: props.onlinePerson
  104. }
  105. ]
  106. });
  107. },
  108. {
  109. deep: true,
  110. immediate: true
  111. }
  112. );
  113. </script>
  114. <template>
  115. <div ref="chartRef" style="width: 100%; height: 365px" />
  116. </template>