feat:
1. 更新框架
This commit is contained in:
@@ -1,83 +1 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
|
||||
|
||||
|
||||
import {
|
||||
|
||||
EchartsUI,
|
||||
|
||||
type EchartsUIType,
|
||||
|
||||
useEcharts,
|
||||
|
||||
} from '@vben/plugins/echarts';
|
||||
|
||||
|
||||
|
||||
import type { SalespersonDashboardTrendItem } from '../api';
|
||||
|
||||
|
||||
|
||||
const props = defineProps<{
|
||||
|
||||
/** 本周期 trend,用于环比柱状图「本周期」系列 */
|
||||
|
||||
current: SalespersonDashboardTrendItem[];
|
||||
|
||||
/** 上一等长周期 compare_trend,用于「上周期」系列 */
|
||||
|
||||
previous: SalespersonDashboardTrendItem[];
|
||||
|
||||
}>();
|
||||
|
||||
|
||||
|
||||
const chartRef = ref<EchartsUIType>();
|
||||
|
||||
const { renderEcharts, resize } = useEcharts(chartRef);
|
||||
|
||||
|
||||
|
||||
const maxLen = computed(() => Math.max(props.current.length, props.previous.length));
|
||||
|
||||
|
||||
|
||||
function resolveInputTotal(item: SalespersonDashboardTrendItem) {
|
||||
|
||||
return item.input_total ?? item.clinic_count + item.pharmacy_count;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 按序号对齐本周期与上周期录入总数,tooltip 展示真实时间标签 */
|
||||
|
||||
async function renderChart() {
|
||||
|
||||
const labels = Array.from({ length: maxLen.value }, (_, i) => `T${i + 1}`);
|
||||
|
||||
const currentData = props.current.map((item) => resolveInputTotal(item));
|
||||
|
||||
const previousData = props.previous.map((item) => resolveInputTotal(item));
|
||||
|
||||
|
||||
|
||||
await renderEcharts({
|
||||
|
||||
tooltip: {
|
||||
|
||||
trigger: 'axis',
|
||||
|
||||
formatter(params: any) {
|
||||
|
||||
const list = Array.isArray(params) ? params : [params];
|
||||
|
||||
const idx = list[0]?.dataIndex ?? 0;
|
||||
|
||||
const cur = props.current[idx];
|
||||
|
||||
const prev = props.previous[idx];
|
||||
|
||||
const lines = [`序号 ${idx + 1}`];
|
||||
<script setup lang="ts">
|
||||
@@ -1,86 +1 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import { nextTick, ref, watch } from 'vue';
|
||||
|
||||
|
||||
|
||||
import {
|
||||
|
||||
EchartsUI,
|
||||
|
||||
type EchartsUIType,
|
||||
|
||||
useEcharts,
|
||||
|
||||
} from '@vben/plugins/echarts';
|
||||
|
||||
|
||||
|
||||
import type { SalespersonDashboardTrendItem } from '../api';
|
||||
|
||||
|
||||
|
||||
const props = defineProps<{
|
||||
|
||||
/** 来自 dashboardData.trend:按时间桶聚合的录入趋势 */
|
||||
|
||||
data: SalespersonDashboardTrendItem[];
|
||||
|
||||
}>();
|
||||
|
||||
|
||||
|
||||
const chartRef = ref<EchartsUIType>();
|
||||
|
||||
const { renderEcharts, resize } = useEcharts(chartRef);
|
||||
|
||||
|
||||
|
||||
/** 录入总数兜底:兼容旧接口未返回 input_total 的情况 */
|
||||
|
||||
function resolveInputTotal(item: SalespersonDashboardTrendItem) {
|
||||
|
||||
return item.input_total ?? item.clinic_count + item.pharmacy_count;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 将 trend 数据映射为 ECharts series
|
||||
|
||||
* - 堆叠柱:录入诊所 / 录入药店
|
||||
|
||||
* - 折线:录入总数
|
||||
|
||||
*/
|
||||
|
||||
async function renderChart() {
|
||||
|
||||
const labels = props.data.map((item) => item.label);
|
||||
|
||||
const clinicData = props.data.map((item) => item.clinic_count);
|
||||
|
||||
const pharmacyData = props.data.map((item) => item.pharmacy_count);
|
||||
|
||||
const totalData = props.data.map((item) => resolveInputTotal(item));
|
||||
|
||||
|
||||
|
||||
await renderEcharts({
|
||||
|
||||
tooltip: { trigger: 'axis' },
|
||||
|
||||
legend: { data: ['录入诊所', '录入药店', '录入总数'] },
|
||||
|
||||
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
|
||||
|
||||
xAxis: {
|
||||
|
||||
type: 'category',
|
||||
|
||||
data: labels,
|
||||
|
||||
axisLabel: { rotate: labels.length > 10 ? 45 : 0 },
|
||||
|
||||
<script setup lang="ts">
|
||||
Reference in New Issue
Block a user