This commit is contained in:
wwb 2026-03-16 20:21:41 +08:00
parent 8b6e783246
commit 25b63f3250
2 changed files with 41 additions and 29 deletions

View File

@ -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());
}

View File

@ -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[] = []
// seriesMap
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 (
}
})
// 3X
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)
// ========== Ymax = + 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. Ymax + 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) // + 1010
eChartOptions.yAxis![1].max = finalMax
// ===========================================================================
} else {
//
eChartOptions.xAxis!.data = []
eChartOptions.series = []
eChartOptions.legend.data = []
// Ymax
eChartOptions.yAxis![1].max = undefined
}
} catch (error) {
console.error('查询订单趋势数据失败:', error)
//
eChartOptions.xAxis!.data = []
eChartOptions.series = []
eChartOptions.legend.data = []
// Ymax
eChartOptions.yAxis![1].max = undefined
} finally {
loading.value = false
}
}
/** 初始化 **/
onMounted(() => {
handleTimeRangeTypeChange()
})