barDim.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <script setup lang="ts">
  2. import { ref, computed, onMounted, nextTick, watch } from "vue";
  3. import { useDark, useECharts } from "@pureadmin/utils";
  4. import { getPersonDimensionChartsRanking } from "@/api/draw";
  5. import { reactive } from "vue";
  6. const props = defineProps({
  7. title: {
  8. type: String
  9. }
  10. });
  11. const dataProp = reactive({
  12. title: "",
  13. data: {}
  14. });
  15. onMounted(() => {});
  16. // 兼容dark主题
  17. const { isDark } = useDark();
  18. let theme = computed(() => {
  19. return isDark.value ? "dark" : "default";
  20. });
  21. // 初始化ECharts
  22. const chartRef = ref();
  23. const { setOptions } = useECharts(chartRef, { theme });
  24. const dataList = reactive({
  25. title: [],
  26. data: []
  27. });
  28. const init = async (item?: any, type?: number) => {
  29. dataList.title = [];
  30. dataList.data = [];
  31. const { data, code } = await getPersonDimensionChartsRanking({
  32. ...item,
  33. type
  34. });
  35. let dataListInit;
  36. if (code === 200) {
  37. dataListInit = data.sort((a, b) => a.ranking - b.ranking);
  38. dataListInit.map((it, id) => {
  39. if (id < 10) {
  40. dataList.title.push(it.assessmentObjectName);
  41. dataList.data.push(it.totalScore);
  42. }
  43. });
  44. }
  45. setOptions({
  46. title: {
  47. text: `${props.title}Top10`
  48. },
  49. tooltip: {
  50. trigger: "axis",
  51. axisPointer: {
  52. type: "shadow"
  53. }
  54. },
  55. grid: {
  56. left: "3%",
  57. right: "4%",
  58. bottom: "3%",
  59. containLabel: true
  60. },
  61. xAxis: [
  62. {
  63. type: "category",
  64. data: dataList.title,
  65. axisTick: {
  66. alignWithLabel: true
  67. }
  68. }
  69. ],
  70. yAxis: [
  71. {
  72. type: "value"
  73. }
  74. ],
  75. series: [
  76. {
  77. name: "Direct",
  78. type: "bar",
  79. barWidth: props.title == "总得分" ? "30%" : "40%",
  80. data: dataList.data
  81. }
  82. ]
  83. });
  84. };
  85. nextTick(() => {
  86. init();
  87. });
  88. defineExpose({
  89. init
  90. });
  91. </script>
  92. <template>
  93. <div ref="chartRef" class="w-full h-full" />
  94. </template>