VisitSource.vue 2.4 KB

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