ChartContainer.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="chart-container" :class="{ 'chart-container--loading': loading }">
  3. <div class="chart-header" v-if="title || $slots.header">
  4. <div class="chart-title" v-if="title">
  5. <h4>{{ title }}</h4>
  6. <p v-if="subtitle">{{ subtitle }}</p>
  7. </div>
  8. <div class="chart-actions" v-if="$slots.header">
  9. <slot name="header"></slot>
  10. </div>
  11. </div>
  12. <div class="chart-content" :style="{ height: height }">
  13. <div v-if="loading" class="chart-loading">
  14. <el-icon class="loading-icon">
  15. <Loading />
  16. </el-icon>
  17. <p>数据加载中...</p>
  18. </div>
  19. <div v-else-if="!hasData" class="chart-placeholder">
  20. <el-icon class="placeholder-icon">
  21. <component :is="placeholderIcon" />
  22. </el-icon>
  23. <p>{{ placeholderText }}</p>
  24. </div>
  25. <div v-else class="chart-wrapper">
  26. <slot></slot>
  27. </div>
  28. </div>
  29. <div class="chart-footer" v-if="$slots.footer">
  30. <slot name="footer"></slot>
  31. </div>
  32. </div>
  33. </template>
  34. <script setup lang="ts">
  35. import { computed } from 'vue'
  36. import { Loading, TrendCharts } from '@element-plus/icons-vue'
  37. const props = defineProps<{
  38. title?: string
  39. subtitle?: string
  40. height?: string
  41. loading?: boolean
  42. hasData?: boolean
  43. placeholderText?: string
  44. placeholderIcon?: any
  45. }>()
  46. const placeholderIcon = computed(() => props.placeholderIcon || TrendCharts)
  47. const placeholderText = computed(() => props.placeholderText || '暂无数据')
  48. </script>
  49. <style scoped>
  50. .chart-container {
  51. background: white;
  52. border-radius: 12px;
  53. padding: 20px;
  54. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  55. border: 1px solid #e4e7ed;
  56. transition: all 0.3s ease;
  57. }
  58. .chart-container:hover {
  59. box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  60. }
  61. .chart-header {
  62. display: flex;
  63. justify-content: space-between;
  64. align-items: flex-start;
  65. margin-bottom: 20px;
  66. padding-bottom: 16px;
  67. border-bottom: 1px solid #f0f2f5;
  68. }
  69. .chart-title h4 {
  70. margin: 0 0 4px 0;
  71. color: #2c3e50;
  72. font-size: 18px;
  73. font-weight: 600;
  74. }
  75. .chart-title p {
  76. margin: 0;
  77. color: #7f8c8d;
  78. font-size: 14px;
  79. }
  80. .chart-actions {
  81. display: flex;
  82. align-items: center;
  83. gap: 8px;
  84. }
  85. .chart-content {
  86. position: relative;
  87. min-height: 200px;
  88. display: flex;
  89. align-items: center;
  90. justify-content: center;
  91. }
  92. .chart-wrapper {
  93. width: 100%;
  94. height: 100%;
  95. }
  96. .chart-loading,
  97. .chart-placeholder {
  98. display: flex;
  99. flex-direction: column;
  100. align-items: center;
  101. justify-content: center;
  102. height: 100%;
  103. color: #7f8c8d;
  104. }
  105. .loading-icon,
  106. .placeholder-icon {
  107. font-size: 48px;
  108. margin-bottom: 12px;
  109. color: #4facfe;
  110. }
  111. .loading-icon {
  112. animation: rotate 2s linear infinite;
  113. }
  114. .chart-loading p,
  115. .chart-placeholder p {
  116. margin: 0;
  117. font-size: 16px;
  118. }
  119. .chart-footer {
  120. margin-top: 16px;
  121. padding-top: 16px;
  122. border-top: 1px solid #f0f2f5;
  123. }
  124. .chart-container--loading {
  125. pointer-events: none;
  126. }
  127. @keyframes rotate {
  128. from {
  129. transform: rotate(0deg);
  130. }
  131. to {
  132. transform: rotate(360deg);
  133. }
  134. }
  135. </style>