| | |
| | | const charts = ref<BiDashboardApi.ChartItem[]>([]); |
| | | const loading = ref(true); |
| | | const lastUpdateTime = ref(''); |
| | | let dataRefreshTimer: ReturnType<typeof setInterval> | undefined; |
| | | |
| | | async function loadData() { |
| | | async function loadData(background = false) { |
| | | if (!meta.value) return; |
| | | if (!background && dataRefreshTimer) clearInterval(dataRefreshTimer); |
| | | try { |
| | | loading.value = true; |
| | | if (!background) loading.value = true; |
| | | const data = await getDashboardData(meta.value.code); |
| | | charts.value = data.length > 0 ? data : getDefaultCharts(); |
| | | lastUpdateTime.value = new Date().toLocaleTimeString('zh-CN', { hour12: false }); |
| | | } catch { |
| | | charts.value = getDefaultCharts(); |
| | | if (!background) charts.value = getDefaultCharts(); |
| | | } finally { |
| | | loading.value = false; |
| | | await nextTick(); |
| | | resizeAllCharts(); |
| | | if (!background && dashboardCode.value === 'purchase-sales') { |
| | | const intervals = charts.value.map((chart) => chart.refreshInterval).filter((interval) => interval > 0); |
| | | if (intervals.length) dataRefreshTimer = setInterval(() => { |
| | | if (!loading.value && document.visibilityState === 'visible') loadData(true); |
| | | }, Math.max(15, Math.min(...intervals)) * 1000); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // ======== 分类 ======== |
| | | const numberCards = computed(() => charts.value.filter((c) => c.chartType === 'number')); |
| | | const tableCharts = computed(() => charts.value.filter((c) => c.chartType === 'table')); |
| | | const echartsCharts = computed(() => charts.value.filter((c) => !['number', 'table'].includes(c.chartType))); |
| | | const displayCharts = computed(() => { |
| | | if (dashboardCode.value !== 'purchase-sales') return charts.value; |
| | | return [...charts.value].sort((a, b) => |
| | | Number(b.chartOptions?.dashboardSection === 'crm') - Number(a.chartOptions?.dashboardSection === 'crm'), |
| | | ); |
| | | }); |
| | | const numberCards = computed(() => displayCharts.value.filter((c) => c.chartType === 'number')); |
| | | const tableCharts = computed(() => displayCharts.value.filter((c) => c.chartType === 'table')); |
| | | const echartsCharts = computed(() => displayCharts.value.filter((c) => !['number', 'table'].includes(c.chartType))); |
| | | |
| | | // ======== 图表 Grid 列跨度 ======== |
| | | function isFullWidth(chart: BiDashboardApi.ChartItem): boolean { |
| | |
| | | const progress = Math.min((currentTime - startTime) / duration, 1); |
| | | const eased = 1 - (1 - progress) ** 3; |
| | | el.textContent = (end * eased).toFixed(decimals); |
| | | if (progress === 1) el.textContent = formatNumber(end); |
| | | if (progress < 1) requestAnimationFrame(update); |
| | | } |
| | | requestAnimationFrame(update); |
| | |
| | | function maybeAnimate(el: HTMLElement, cardId: number, value: number) { |
| | | if (animatedIds.has(cardId)) return; |
| | | animatedIds.add(cardId); |
| | | animateValue(el, value, 0); |
| | | animateValue(el, value, Number.isInteger(value) ? 0 : 2); |
| | | } |
| | | |
| | | watch(() => charts.value, () => { |
| | |
| | | |
| | | // ======== KPI 图标/颜色 ======== |
| | | function getKpiIcon(name: string): string { |
| | | if (name.includes('客户')) return 'lucide:users'; |
| | | if (name.includes('商机')) return 'lucide:target'; |
| | | if (name.includes('回款')) return 'lucide:wallet'; |
| | | if (name.includes('报价')) return 'lucide:receipt-text'; |
| | | if (name.includes('采购')) return 'lucide:shopping-cart'; |
| | | if (name.includes('销售')) return 'lucide:trending-up'; |
| | | if (name.includes('售后')) return 'lucide:headphones'; |
| | |
| | | loadData(); |
| | | }); |
| | | onBeforeUnmount(() => { |
| | | if (dataRefreshTimer) clearInterval(dataRefreshTimer); |
| | | document.removeEventListener('fullscreenchange', onFullscreenChange); |
| | | resizeObserver?.disconnect(); |
| | | }); |
| | |
| | | <IconifyIcon :icon="getKpiIcon(card.name)" /> |
| | | </div> |
| | | <div class="kpi-body"> |
| | | <span class="kpi-label">{{ card.name }}</span> |
| | | <span class="kpi-label" :title="card.name">{{ card.name }}</span> |
| | | <span |
| | | class="kpi-value" |
| | | :ref="(el: unknown) => { |
| | |
| | | |
| | | .kpi-label { |
| | | font-size: 11px; color: var(--text-secondary); letter-spacing: 0.3px; |
| | | white-space: nowrap; overflow: hidden; text-overflow: ellipsis; |
| | | white-space: normal; overflow-wrap: anywhere; line-height: 1.4; |
| | | } |
| | | |
| | | .kpi-value { |