Commit bc456653 by linjinhong Committed by wusiyi

fix:修改字段

parent 095d7726
......@@ -546,7 +546,10 @@ import { LineChart } from 'echarts/charts'
import { UniversalTransition } from 'echarts/features'
import { CanvasRenderer } from 'echarts/renderers'
import { getStatisticData, trendApi } from '@/api/statistic'
import type { statisticData as StatisticData } from '@/types/api/statistic'
import type {
statisticData as StatisticData,
trendType as trendType,
} from '@/types/api/statistic'
import { TooltipComponent } from 'echarts/components'
echarts.use([TooltipComponent])
echarts.use([
......@@ -560,63 +563,11 @@ echarts.use([
// 获取统计数据
const statisticData = ref<StatisticData | null>(null)
const getStatisticDataApi = async () => {
const [statisticRes, orderRes, shipmentRes, overTimeRes] =
await Promise.allSettled([
getStatisticData(),
trendApi({
timeUnit: 0,
trendType: 'ORDER_TREND',
}),
trendApi({
timeUnit: 0,
trendType: 'SHIPMENT_TREND',
}),
trendApi({
timeUnit: 0,
trendType: 'OVERTIME_SHIPMENT_TREND',
}),
])
if (statisticRes.status === 'fulfilled') {
const res = statisticRes.value
if (res.code === 200) {
statisticData.value = res.data
}
}
if (orderRes.status === 'fulfilled') {
const res = orderRes.value
if (res.code === 200) {
const confirmNums = res.data.map((el) => el.confirmNum)
const producedNums = res.data.map((el) => el.producedNum)
const shipmentNums = res.data.map((el) => el.shipmentNum)
chartConfig1.value.series[0].data = confirmNums
chartConfig1.value.series[1].data = producedNums
chartConfig1.value.series[2].data = shipmentNums
}
}
if (shipmentRes.status === 'fulfilled') {
const res = shipmentRes.value
if (res.code === 200) {
const producedNums = res.data.map((el) => el.producedNum)
const shipmentNums = res.data.map((el) => el.shipmentNum)
chartConfig2.value.series[0].data = producedNums
chartConfig2.value.series[1].data = shipmentNums
}
}
if (overTimeRes.status === 'fulfilled') {
const res = overTimeRes.value
if (res.code === 200) {
const producedNums = res.data.map((el) => el.producedNum)
chartConfig2.value.series[0].data = producedNums
}
}
// const res = await getStatisticData()
}
const timeOptions = ref<{ type: string; name: string }[]>([
{ type: '0', name: '日数据' },
{ type: '1', name: '数据' },
{ type: '2', name: '数据' },
{ type: '1', name: '数据' },
{ type: '2', name: '数据' },
])
const chartTimes1 = ref<string>('0')
......@@ -635,40 +586,41 @@ const chartInstances: (echarts.ECharts | null)[] = [null, null, null]
const chartConfig1 = ref({
title: '订单趋势统计(单)',
legend: ['接单数', '生产数', '发货数'],
xAxisData: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
xAxisData: [''],
series: [
{
name: '接单数',
data: [0],
color: '#6495ED',
color: '#30d2cb',
},
{
name: '生产数',
data: [0],
color: '#9370DB',
color: '#9e95ff',
},
{
name: '发货数',
data: [0],
color: '#48D1CC',
color: '#6bb3fd',
},
],
})
const chartConfig2 = ref({
title: '订单发货效率',
legend: ['生产数', '发货数'],
xAxisData: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
legend: ['24H发货率', '48H发货率'],
xAxisData: [''],
series: [
{
name: '生产数',
name: '24H发货率',
data: [0],
color: '#4ECDC4',
color: '#3e9fff',
},
{
name: '发货数',
name: '48H发货率',
data: [0],
color: '#95E1D3',
color: '#ac84ff',
},
],
})
......@@ -676,12 +628,13 @@ const chartConfig2 = ref({
const chartConfig3 = ref({
title: '订单生产效率',
legend: ['发货超时率'],
xAxisData: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
xAxisData: [''],
series: [
{
name: '发货超时率',
data: [0],
color: '#AA96DA',
color: '#ff6845',
},
],
})
......@@ -722,6 +675,19 @@ const createChartOption = (config: typeof chartConfig1) => {
type: 'category',
boundaryGap: false,
data: data.xAxisData,
axisLabel: {
// 关键配置:添加省略号
overflow: 'truncate', // 截断显示
width: 120, // 每个标签的最大宽度(像素)
formatter: function (value: string) {
// 手动截断,超过6个字符加省略号
if (value.length > 10) {
return value.substring(0, 10) + '...'
}
return value
},
},
},
yAxis: {
type: 'value',
......@@ -763,6 +729,50 @@ const createChartOption = (config: typeof chartConfig1) => {
}
}
const getStatisticDataApi = async () => {
const [statisticRes, orderRes, shipmentRes, overTimeRes] =
await Promise.allSettled([
getStatisticData(),
trendApi({
timeUnit: 0,
trendType: 'ORDER_TREND',
}),
trendApi({
timeUnit: 0,
trendType: 'SHIPMENT_TREND',
}),
trendApi({
timeUnit: 0,
trendType: 'OVERTIME_SHIPMENT_TREND',
}),
])
if (statisticRes.status === 'fulfilled') {
const res = statisticRes.value
if (res.code === 200) {
statisticData.value = res.data
}
}
if (orderRes.status === 'fulfilled') {
const res = orderRes.value
if (res.code === 200) {
updateOrderTrendChart(res.data, 0)
}
}
if (shipmentRes.status === 'fulfilled') {
const res = shipmentRes.value
if (res.code === 200) {
updateShipmentTrendChart(res.data, 0)
}
}
if (overTimeRes.status === 'fulfilled') {
const res = overTimeRes.value
if (res.code === 200) {
updateOvertimeTrendChart(res.data, 0)
}
}
// const res = await getStatisticData()
}
onMounted(async () => {
await nextTick()
await getStatisticDataApi()
......@@ -785,12 +795,6 @@ onMounted(async () => {
window.addEventListener('resize', handleResize)
})
const handleResize = () => {
chartInstances.forEach((instance) => {
instance?.resize()
})
}
const getchartTimes = async (v: string, type: string) => {
try {
const { data } = await trendApi({
......@@ -798,11 +802,75 @@ const getchartTimes = async (v: string, type: string) => {
trendType: type,
})
console.log(data)
if (type == 'ORDER_TREND') {
updateOrderTrendChart(data, v)
chartInstances[0]?.setOption(createChartOption(chartConfig1))
} else if (type == 'SHIPMENT_TREND') {
updateShipmentTrendChart(data, v)
chartInstances[1]?.setOption(createChartOption(chartConfig2))
} else {
updateOvertimeTrendChart(data, v)
chartInstances[2]?.setOption(createChartOption(chartConfig3))
}
} catch (error) {
console.log(error)
}
}
const updateOrderTrendChart = (data: trendType[], type: number | string) => {
const confirmNums = data.map((el) => el.confirmNum)
const producedNums = data.map((el) => el.produceNum)
const shipmentNums = data.map((el) => el.shipmentNum)
const startTimes = data.map((el) => el.startTime)
const timerange = data.map((el) => `${el.startTime}——${el.endTime}`)
if (type == 0) {
chartConfig1.value.xAxisData = startTimes
} else {
chartConfig1.value.xAxisData = timerange
}
chartConfig1.value.series[0].data = confirmNums
chartConfig1.value.series[1].data = producedNums
chartConfig1.value.series[2].data = shipmentNums
}
const updateShipmentTrendChart = (data: trendType[], type: number | string) => {
const shipmentRateOf24Hours = data.map((el) => el.shipmentRateOf24Hour)
const shipmentRateOf48Hours = data.map((el) => el.shipmentRateOf48Hour)
const startTimes = data.map((el) => el.startTime)
const timerange = data.map((el) => `${el.startTime}-${el.endTime}`)
if (type == 0) {
chartConfig2.value.xAxisData = startTimes
} else {
chartConfig2.value.xAxisData = timerange
}
chartConfig2.value.series[0].data = shipmentRateOf24Hours
chartConfig2.value.series[1].data = shipmentRateOf48Hours
}
const updateOvertimeTrendChart = (data: trendType[], type: number | string) => {
const overtimeShipmentOrderNums = data.map(
(el) => el.overtimeShipmentOrderNum,
)
const startTimes = data.map((el) => el.startTime)
const timerange = data.map((el) => `${el.startTime}-${el.endTime}`)
if (type == 0) {
chartConfig3.value.xAxisData = startTimes
} else {
chartConfig3.value.xAxisData = timerange
}
chartConfig3.value.series[0].data = overtimeShipmentOrderNums
}
const handleResize = () => {
chartInstances.forEach((instance) => {
instance?.resize()
})
}
onBeforeUnmount(() => {
window.removeEventListener('resize', handleResize)
chartInstances.forEach((instance, index) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment