| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <template>
- <div class="chart-container" :class="{ 'chart-container--loading': loading }">
- <div class="chart-header" v-if="title || $slots.header">
- <div class="chart-title" v-if="title">
- <h4>{{ title }}</h4>
- <p v-if="subtitle">{{ subtitle }}</p>
- </div>
- <div class="chart-actions" v-if="$slots.header">
- <slot name="header"></slot>
- </div>
- </div>
- <div class="chart-content" :style="{ height: height }">
- <div v-if="loading" class="chart-loading">
- <el-icon class="loading-icon">
- <Loading />
- </el-icon>
- <p>数据加载中...</p>
- </div>
- <div v-else-if="!hasData" class="chart-placeholder">
- <el-icon class="placeholder-icon">
- <component :is="placeholderIcon" />
- </el-icon>
- <p>{{ placeholderText }}</p>
- </div>
- <div v-else class="chart-wrapper">
- <slot></slot>
- </div>
- </div>
- <div class="chart-footer" v-if="$slots.footer">
- <slot name="footer"></slot>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { computed } from 'vue'
- import { Loading, TrendCharts } from '@element-plus/icons-vue'
- const props = defineProps<{
- title?: string
- subtitle?: string
- height?: string
- loading?: boolean
- hasData?: boolean
- placeholderText?: string
- placeholderIcon?: any
- }>()
- const placeholderIcon = computed(() => props.placeholderIcon || TrendCharts)
- const placeholderText = computed(() => props.placeholderText || '暂无数据')
- </script>
- <style scoped>
- .chart-container {
- background: white;
- border-radius: 12px;
- padding: 20px;
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
- border: 1px solid #e4e7ed;
- transition: all 0.3s ease;
- }
- .chart-container:hover {
- box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
- }
- .chart-header {
- display: flex;
- justify-content: space-between;
- align-items: flex-start;
- margin-bottom: 20px;
- padding-bottom: 16px;
- border-bottom: 1px solid #f0f2f5;
- }
- .chart-title h4 {
- margin: 0 0 4px 0;
- color: #2c3e50;
- font-size: 18px;
- font-weight: 600;
- }
- .chart-title p {
- margin: 0;
- color: #7f8c8d;
- font-size: 14px;
- }
- .chart-actions {
- display: flex;
- align-items: center;
- gap: 8px;
- }
- .chart-content {
- position: relative;
- min-height: 200px;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .chart-wrapper {
- width: 100%;
- height: 100%;
- }
- .chart-loading,
- .chart-placeholder {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- height: 100%;
- color: #7f8c8d;
- }
- .loading-icon,
- .placeholder-icon {
- font-size: 48px;
- margin-bottom: 12px;
- color: #4facfe;
- }
- .loading-icon {
- animation: rotate 2s linear infinite;
- }
- .chart-loading p,
- .chart-placeholder p {
- margin: 0;
- font-size: 16px;
- }
- .chart-footer {
- margin-top: 16px;
- padding-top: 16px;
- border-top: 1px solid #f0f2f5;
- }
- .chart-container--loading {
- pointer-events: none;
- }
- @keyframes rotate {
- from {
- transform: rotate(0deg);
- }
- to {
- transform: rotate(360deg);
- }
- }
- </style>
|