This commit is contained in:
parent
8b6e783246
commit
25b63f3250
|
|
@ -860,6 +860,14 @@ public class SaleOrderServiceImpl implements SaleOrderService {
|
|||
.setValue(CollUtil.get(value, index))
|
||||
.setReference(CollUtil.get(reference, index)))
|
||||
.collect(Collectors.toList());
|
||||
}else{
|
||||
List<TradeOrderTrendRespVO> reference = new ArrayList<>();
|
||||
// 顺序对比返回
|
||||
collect = IntStream.range(0, value.size())
|
||||
.mapToObj(index -> new DataComparisonRespVO<TradeOrderTrendRespVO>()
|
||||
.setValue(CollUtil.get(value, index))
|
||||
.setReference(CollUtil.get(reference, index)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
<template #header>
|
||||
<div class="flex flex-row items-center justify-between">
|
||||
<CardTitle title="交易量趋势" />
|
||||
<!-- 查询条件 -->
|
||||
<div class="flex flex-row items-center gap-2">
|
||||
<el-radio-group v-model="timeRangeType" @change="handleTimeRangeTypeChange">
|
||||
<el-radio-button v-for="[key, value] in timeRange.entries()" :key="key" :label="key">
|
||||
|
|
@ -13,7 +12,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 折线图 -->
|
||||
<Echart :height="300" :options="eChartOptions" />
|
||||
</el-card>
|
||||
</template>
|
||||
|
|
@ -24,7 +22,6 @@ import * as TradeStatisticsApi from '@/api/oms/statistics/trade'
|
|||
import { formatDate } from '@/utils/formatTime'
|
||||
import { CardTitle } from '@/components/Card'
|
||||
|
||||
/** 交易量趋势 */
|
||||
defineOptions({ name: 'TradeTrendCard' })
|
||||
|
||||
enum TimeRangeTypeEnum {
|
||||
|
|
@ -32,10 +29,10 @@ enum TimeRangeTypeEnum {
|
|||
WEEK = 7,
|
||||
MONTH = 30,
|
||||
YEAR = 365
|
||||
} // 日期类型
|
||||
const timeRangeType = ref(TimeRangeTypeEnum.DAY30) // 日期快捷选择按钮, 默认30天
|
||||
const loading = ref(true) // 加载中
|
||||
// 时间范围 Map
|
||||
}
|
||||
const timeRangeType = ref(TimeRangeTypeEnum.DAY30)
|
||||
const loading = ref(true)
|
||||
|
||||
const timeRange = new Map()
|
||||
.set(TimeRangeTypeEnum.DAY30, {
|
||||
name: '30天',
|
||||
|
|
@ -71,7 +68,7 @@ const timeRange = new Map()
|
|||
{ name: '今年数量', type: 'line', smooth: true, data: [], yAxisIndex: 1 }
|
||||
]
|
||||
})
|
||||
/** 图表配置 */
|
||||
|
||||
const eChartOptions = reactive<EChartsOption>({
|
||||
grid: {
|
||||
left: 20,
|
||||
|
|
@ -99,8 +96,8 @@ const eChartOptions = reactive<EChartsOption>({
|
|||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
inverse: true, // 倒序展示,数据需同步倒序
|
||||
boundaryGap: true, // 修复:柱图需要开启边界间隙,避免贴边错位
|
||||
inverse: true,
|
||||
boundaryGap: true,
|
||||
axisTick: { show: false },
|
||||
data: [],
|
||||
axisLabel: {
|
||||
|
|
@ -124,23 +121,21 @@ const eChartOptions = reactive<EChartsOption>({
|
|||
},
|
||||
yAxis: [
|
||||
{
|
||||
// 左侧Y轴:金额
|
||||
axisTick: { show: false },
|
||||
type: 'value',
|
||||
name: ' '
|
||||
},
|
||||
{
|
||||
// 右侧Y轴:数量
|
||||
axisTick: { show: false },
|
||||
type: 'value',
|
||||
name: ' ',
|
||||
position: 'right', // 显示在右侧
|
||||
offset: 0
|
||||
position: 'right',
|
||||
offset: 0,
|
||||
// 初始不设置max,后续动态计算
|
||||
}
|
||||
]
|
||||
}) as EChartsOption
|
||||
|
||||
/** 时间范围类型单选按钮选中 */
|
||||
const handleTimeRangeTypeChange = async () => {
|
||||
let beginTime: Dayjs
|
||||
let endTime: Dayjs
|
||||
|
|
@ -159,7 +154,6 @@ const handleTimeRangeTypeChange = async () => {
|
|||
break
|
||||
case TimeRangeTypeEnum.DAY30:
|
||||
default:
|
||||
// 修复:startOf('d') → startOf('day'),参数错误导致时间范围计算错误
|
||||
beginTime = dayjs().subtract(30, 'day').startOf('day')
|
||||
endTime = dayjs().endOf('day')
|
||||
break
|
||||
|
|
@ -167,7 +161,6 @@ const handleTimeRangeTypeChange = async () => {
|
|||
await getOrderCountTrendComparison(beginTime, endTime)
|
||||
}
|
||||
|
||||
/** 查询订单数量趋势对照数据 */
|
||||
const getOrderCountTrendComparison = async (
|
||||
beginTime: dayjs.ConfigType,
|
||||
endTime: dayjs.ConfigType
|
||||
|
|
@ -180,23 +173,18 @@ const getOrderCountTrendComparison = async (
|
|||
endTime
|
||||
)
|
||||
|
||||
// 修复1:初始化数据容器,清空残留
|
||||
const dates: string[] = []
|
||||
// 深拷贝series模板,避免污染原Map数据
|
||||
const seriesTemplate = timeRange.get(timeRangeType.value)?.series || []
|
||||
const series = JSON.parse(JSON.stringify(seriesTemplate))
|
||||
series.forEach(item => item.data = []) // 清空series数据
|
||||
series.forEach(item => item.data = [])
|
||||
|
||||
// 修复2:校验数据格式 + 按时间正序排序,避免乱序
|
||||
if (Array.isArray(list) && list.length) {
|
||||
// 先按日期正序排序
|
||||
const sortedList = list.sort((a, b) => {
|
||||
return dayjs(a.value.date).unix() - dayjs(b.value.date).unix()
|
||||
})
|
||||
|
||||
// 填充数据
|
||||
sortedList.forEach(item => {
|
||||
if (!item?.value?.date) return // 过滤无效数据
|
||||
if (!item?.value?.date) return
|
||||
dates.push(item.value.date)
|
||||
if (series.length === 2) {
|
||||
series[0].data.push(item.value.orderAmount || 0)
|
||||
|
|
@ -209,7 +197,6 @@ const getOrderCountTrendComparison = async (
|
|||
}
|
||||
})
|
||||
|
||||
// 修复3:X轴逆序时,同步倒序数据,确保标签和数值一一对应
|
||||
if (eChartOptions.xAxis?.inverse) {
|
||||
eChartOptions.xAxis.data = [...dates].reverse()
|
||||
series.forEach(item => {
|
||||
|
|
@ -219,27 +206,44 @@ const getOrderCountTrendComparison = async (
|
|||
eChartOptions.xAxis.data = [...dates]
|
||||
}
|
||||
|
||||
// 修复4:强制更新系列和图例,确保匹配
|
||||
eChartOptions.series = [...series]
|
||||
eChartOptions.legend.data = series.map(item => item.name)
|
||||
|
||||
// ========== 核心修改:计算右侧Y轴(数量)最大值并设置max = 最大值 + 10 ==========
|
||||
// 1. 筛选所有yAxisIndex=1的系列(数量维度)
|
||||
const countSeries = series.filter(item => item.yAxisIndex === 1)
|
||||
// 2. 收集所有数量维度的数据
|
||||
const countData = countSeries.flatMap(item => item.data)
|
||||
// 3. 计算最大值(空数据时默认0)
|
||||
// const maxCount = countData.length ? Math.max(...countData) : 0
|
||||
// // 4. 设置右侧Y轴的max为 最大值 + 10
|
||||
// eChartOptions.yAxis![1].max = maxCount + 6
|
||||
|
||||
// 优化:取整数 + 最小值保底(比如至少显示到10)
|
||||
const maxCount = countData.length ? Math.max(...countData) : 0
|
||||
const finalMax = Math.max(Math.ceil(maxCount) + 6, 10) // 向上取整 + 10,且至少10
|
||||
eChartOptions.yAxis![1].max = finalMax
|
||||
// ===========================================================================
|
||||
|
||||
} else {
|
||||
// 空数据时清空图表
|
||||
eChartOptions.xAxis!.data = []
|
||||
eChartOptions.series = []
|
||||
eChartOptions.legend.data = []
|
||||
// 空数据时重置右侧Y轴max
|
||||
eChartOptions.yAxis![1].max = undefined
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('查询订单趋势数据失败:', error)
|
||||
// 异常时清空数据
|
||||
eChartOptions.xAxis!.data = []
|
||||
eChartOptions.series = []
|
||||
eChartOptions.legend.data = []
|
||||
// 异常时重置右侧Y轴max
|
||||
eChartOptions.yAxis![1].max = undefined
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
handleTimeRangeTypeChange()
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue