columns.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {
  2. clone,
  3. useDark,
  4. useECharts,
  5. type EchartOptions
  6. } from "@pureadmin/utils";
  7. import { tableDataDrag } from "../data";
  8. import { message } from "@/utils/message";
  9. import { templateRef } from "@vueuse/core";
  10. import { ref, type Ref, computed } from "vue";
  11. export function useColumns() {
  12. const dataList = ref(clone(tableDataDrag, true).splice(0, 4));
  13. const columns: TableColumnList = [
  14. {
  15. label: "ID",
  16. prop: "id"
  17. },
  18. {
  19. label: "姓名",
  20. prop: "name"
  21. },
  22. {
  23. label: "日期",
  24. prop: "date"
  25. },
  26. {
  27. label: "echarts图表",
  28. slot: "echart"
  29. }
  30. ];
  31. const { isDark } = useDark();
  32. const theme: EchartOptions["theme"] = computed(() => {
  33. return isDark.value ? "dark" : "light";
  34. });
  35. dataList.value.forEach((_, i) => {
  36. const { setOptions } = useECharts(
  37. templateRef(`PieChartRef${i}`) as Ref<HTMLDivElement>,
  38. {
  39. theme
  40. }
  41. );
  42. // https://pure-admin-utils.netlify.app/hooks/useEcharts/useEcharts.html
  43. setOptions(
  44. {
  45. tooltip: {
  46. trigger: "item",
  47. // 将 tooltip 控制在图表区域里
  48. confine: true
  49. },
  50. series: [
  51. {
  52. name: "Github信息",
  53. type: "pie",
  54. // center: ["30%", "50%"],
  55. data: [
  56. { value: 1067, name: "watchers" },
  57. { value: 4037, name: "star" },
  58. { value: 859, name: "forks" }
  59. ],
  60. emphasis: {
  61. itemStyle: {
  62. shadowBlur: 10,
  63. shadowOffsetX: 0,
  64. shadowColor: "rgba(0, 0, 0, 0.5)"
  65. }
  66. }
  67. }
  68. ]
  69. },
  70. {
  71. name: "click",
  72. callback: ({ data: { name, value } }) => {
  73. message(
  74. `您点击了第 ${i + 1} 行,图表标题为${name},图表数据为:${value}`,
  75. "success"
  76. );
  77. }
  78. }
  79. );
  80. });
  81. return {
  82. columns,
  83. dataList
  84. };
  85. }