VisitSource.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <Card title="访问来源" :loading="loading">
  3. <div ref="chartRef" :style="{ width, height }"></div>
  4. </Card>
  5. </template>
  6. <script lang="ts" setup>
  7. import { Ref, ref, watch } from 'vue';
  8. import { Card } from 'ant-design-vue';
  9. import { useECharts } from '/@/hooks/web/useECharts';
  10. const props = defineProps({
  11. loading: Boolean,
  12. width: {
  13. type: String as PropType<string>,
  14. default: '100%',
  15. },
  16. height: {
  17. type: String as PropType<string>,
  18. default: '300px',
  19. },
  20. });
  21. const chartRef = ref<HTMLDivElement | null>(null);
  22. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  23. watch(
  24. () => props.loading,
  25. () => {
  26. if (props.loading) {
  27. return;
  28. }
  29. setOptions({
  30. tooltip: {
  31. trigger: 'item',
  32. },
  33. legend: {
  34. bottom: '1%',
  35. left: 'center',
  36. },
  37. series: [
  38. {
  39. color: ['#5ab1ef', '#b6a2de', '#67e0e3', '#2ec7c9'],
  40. name: '访问来源',
  41. type: 'pie',
  42. radius: ['40%', '70%'],
  43. avoidLabelOverlap: false,
  44. itemStyle: {
  45. borderRadius: 10,
  46. borderColor: '#fff',
  47. borderWidth: 2,
  48. },
  49. label: {
  50. show: false,
  51. position: 'center',
  52. },
  53. emphasis: {
  54. label: {
  55. show: true,
  56. fontSize: '12',
  57. fontWeight: 'bold',
  58. },
  59. },
  60. labelLine: {
  61. show: false,
  62. },
  63. data: [
  64. { value: 1048, name: '搜索引擎' },
  65. { value: 735, name: '直接访问' },
  66. { value: 580, name: '邮件营销' },
  67. { value: 484, name: '联盟广告' },
  68. ],
  69. animationType: 'scale',
  70. animationEasing: 'exponentialInOut',
  71. animationDelay: function () {
  72. return Math.random() * 100;
  73. },
  74. },
  75. ],
  76. });
  77. },
  78. { immediate: true },
  79. );
  80. </script>