Skip to content

Commit 13cf1fe

Browse files
committed
refactor: 使用try finally停止loading
1 parent 8926dd1 commit 13cf1fe

File tree

5 files changed

+152
-42
lines changed

5 files changed

+152
-42
lines changed

src/views/crm/statistics/customer/components/CustomerConversionStat.vue

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ import {
6969
CrmStatisticsCustomerSummaryByDateRespVO
7070
} from '@/api/crm/statistics/customer'
7171
import { EChartsOption } from 'echarts'
72-
import { round } from 'lodash-es'
7372
import { dateFormatter } from '@/utils/formatTime'
7473
import { erpPriceTableColumnFormatter } from '@/utils'
7574
import { DICT_TYPE } from '@/utils/dict'
7675
7776
defineOptions({ name: 'CustomerConversionStat' })
77+
7878
const props = defineProps<{ queryParams: any }>() // 搜索参数
7979
8080
const loading = ref(false) // 加载中
@@ -84,7 +84,7 @@ const list = ref<CrmStatisticsCustomerSummaryByDateRespVO[]>([]) // 列表的数
8484
const echartsOption = reactive<EChartsOption>({
8585
grid: {
8686
left: 20,
87-
right: 20,
87+
right: 40, // 让X轴右侧显示完整
8888
bottom: 20,
8989
containLabel: true
9090
},
@@ -124,11 +124,9 @@ const echartsOption = reactive<EChartsOption>({
124124
}
125125
}) as EChartsOption
126126
127-
/** 获取统计数据 */
128-
const loadData = async () => {
127+
/** 获取数据并填充图表 */
128+
const fetchAndFill = async () => {
129129
// 1. 加载统计数据
130-
loading.value = true
131-
// TODO @ddhb52:这里调用 StatisticsCustomerApi.getCustomerSummaryByDate 好像不太对???
132130
const customerCount = await StatisticsCustomerApi.getCustomerSummaryByDate(props.queryParams)
133131
const contractSummary = await StatisticsCustomerApi.getContractSummary(props.queryParams)
134132
// 2.1 更新 Echarts 数据
@@ -143,16 +141,27 @@ const loadData = async () => {
143141
return {
144142
name: item.time,
145143
value: item.customerCreateCount
146-
? round((item.customerDealCount / item.customerCreateCount) * 100, 2)
144+
? ((item.customerDealCount / item.customerCreateCount) * 100).toFixed(2)
147145
: 0
148146
}
149147
}
150148
)
151149
}
152150
// 2.2 更新列表数据
153151
list.value = contractSummary
154-
loading.value = false
155152
}
153+
154+
/** 获取统计数据 */
155+
const loadData = async () => {
156+
loading.value = true
157+
try {
158+
fetchAndFill()
159+
}
160+
finally {
161+
loading.value = false
162+
}
163+
}
164+
156165
defineExpose({ loadData })
157166
158167
/** 初始化 */

src/views/crm/statistics/customer/components/CustomerDealCycle.vue

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
import { EChartsOption } from 'echarts'
3232
3333
defineOptions({ name: 'CustomerDealCycle' })
34+
3435
const props = defineProps<{ queryParams: any }>() // 搜索参数
3536
3637
const loading = ref(false) // 加载中
@@ -40,7 +41,7 @@ const list = ref<CrmStatisticsCustomerDealCycleByDateRespVO[]>([]) // 列表的
4041
const echartsOption = reactive<EChartsOption>({
4142
grid: {
4243
left: 20,
43-
right: 20,
44+
right: 40, // 让X轴右侧显示完整
4445
bottom: 20,
4546
containLabel: true
4647
},
@@ -49,12 +50,14 @@ const echartsOption = reactive<EChartsOption>({
4950
{
5051
name: '成交周期(天)',
5152
type: 'bar',
52-
data: []
53+
data: [],
54+
yAxisIndex: 0,
5355
},
5456
{
5557
name: '成交客户数',
5658
type: 'bar',
57-
data: []
59+
data: [],
60+
yAxisIndex: 1,
5861
}
5962
],
6063
toolbox: {
@@ -74,21 +77,36 @@ const echartsOption = reactive<EChartsOption>({
7477
type: 'shadow'
7578
}
7679
},
77-
yAxis: {
78-
type: 'value',
79-
name: '数量(个)'
80-
},
80+
yAxis: [
81+
{
82+
type: 'value',
83+
name: '成交周期(天)',
84+
min: 0,
85+
minInterval: 1, // 显示整数刻度
86+
},
87+
{
88+
type: 'value',
89+
name: '成交客户数',
90+
min: 0,
91+
minInterval: 1, // 显示整数刻度
92+
splitLine: {
93+
lineStyle: {
94+
type: 'dotted', // 右侧网格线虚化, 减少混乱
95+
opacity: 0.7,
96+
}
97+
}
98+
},
99+
],
81100
xAxis: {
82101
type: 'category',
83102
name: '日期',
84103
data: []
85104
}
86105
}) as EChartsOption
87106
88-
/** 获取统计数据 */
89-
const loadData = async () => {
107+
/** 获取数据并填充图表 */
108+
const fetchAndFill = async () => {
90109
// 1. 加载统计数据
91-
loading.value = true
92110
const customerDealCycleByDate = await StatisticsCustomerApi.getCustomerDealCycleByDate(
93111
props.queryParams
94112
)
@@ -116,7 +134,17 @@ const loadData = async () => {
116134
}
117135
// 2.2 更新列表数据
118136
list.value = customerDealCycleByUser
119-
loading.value = false
137+
}
138+
139+
/** 获取统计数据 */
140+
const loadData = async () => {
141+
loading.value = true
142+
try {
143+
fetchAndFill()
144+
}
145+
finally {
146+
loading.value = false
147+
}
120148
}
121149
defineExpose({ loadData })
122150

src/views/crm/statistics/customer/components/CustomerFollowUpSummary.vue

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- 客户跟进次数分析 -->
22
<template>
33
<!-- Echarts图 -->
4-
<el-card shadow="never">
4+
<el-card shadow="never" >
55
<el-skeleton :loading="loading" animated>
66
<Echart :height="500" :options="echartsOption" />
77
</el-skeleton>
@@ -28,9 +28,11 @@ import {
2828
CrmStatisticsFollowUpSummaryByDateRespVO,
2929
CrmStatisticsFollowUpSummaryByUserRespVO
3030
} from '@/api/crm/statistics/customer'
31+
import Echart from '@/components/Echart/src/Echart.vue';
3132
import { EChartsOption } from 'echarts'
3233
3334
defineOptions({ name: 'CustomerFollowupSummary' })
35+
3436
const props = defineProps<{ queryParams: any }>() // 搜索参数
3537
3638
const loading = ref(false) // 加载中
@@ -40,7 +42,7 @@ const list = ref<CrmStatisticsFollowUpSummaryByUserRespVO[]>([]) // 列表的数
4042
const echartsOption = reactive<EChartsOption>({
4143
grid: {
4244
left: 20,
43-
right: 20,
45+
right: 30, // 让X轴右侧显示完整
4446
bottom: 20,
4547
containLabel: true
4648
},
@@ -49,11 +51,13 @@ const echartsOption = reactive<EChartsOption>({
4951
{
5052
name: '跟进客户数',
5153
type: 'bar',
54+
yAxisIndex: 0,
5255
data: []
5356
},
5457
{
5558
name: '跟进次数',
5659
type: 'bar',
60+
yAxisIndex: 1,
5761
data: []
5862
}
5963
],
@@ -74,19 +78,38 @@ const echartsOption = reactive<EChartsOption>({
7478
type: 'shadow'
7579
}
7680
},
77-
yAxis: {
78-
type: 'value',
79-
name: '数量(个)'
80-
},
81+
yAxis: [
82+
{
83+
type: 'value',
84+
name: '跟进客户数',
85+
min: 0,
86+
minInterval: 1, // 显示整数刻度
87+
},
88+
{
89+
type: 'value',
90+
name: '跟进次数',
91+
min: 0,
92+
minInterval: 1, // 显示整数刻度
93+
splitLine: {
94+
lineStyle: {
95+
type: 'dotted', // 右侧网格线虚化, 减少混乱
96+
opacity: 0.7,
97+
}
98+
}
99+
}
100+
],
81101
xAxis: {
82102
type: 'category',
83103
name: '日期',
104+
axisTick: {
105+
alignWithLabel: true
106+
},
84107
data: []
85108
}
86109
}) as EChartsOption
87110
88-
/** 获取统计数据 */
89-
const loadData = async () => {
111+
/** 获取数据并填充图表 */
112+
const fetchAndFill = async () => {
90113
// 1. 加载统计数据
91114
loading.value = true
92115
const followUpSummaryByDate = await StatisticsCustomerApi.getFollowUpSummaryByDate(
@@ -113,7 +136,17 @@ const loadData = async () => {
113136
}
114137
// 2.2 更新列表数据
115138
list.value = followUpSummaryByUser
116-
loading.value = false
139+
}
140+
141+
/** 获取统计数据 */
142+
const loadData = async () => {
143+
loading.value = true
144+
try {
145+
fetchAndFill()
146+
}
147+
finally {
148+
loading.value = false
149+
}
117150
}
118151
defineExpose({ loadData })
119152

src/views/crm/statistics/customer/components/CustomerFollowUpType.vue

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { DICT_TYPE, getDictLabel } from '@/utils/dict'
3232
import { erpCalculatePercentage } from '@/utils'
3333
3434
defineOptions({ name: 'CustomerFollowupType' })
35+
3536
const props = defineProps<{ queryParams: any }>() // 搜索参数
3637
3738
const loading = ref(false) // 加载中
@@ -73,10 +74,9 @@ const echartsOption = reactive<EChartsOption>({
7374
]
7475
}) as EChartsOption
7576
76-
/** 获取统计数据 */
77-
const loadData = async () => {
77+
/** 获取数据并填充图表 */
78+
const fetchAndFill = async () => {
7879
// 1. 加载统计数据
79-
loading.value = true
8080
const followUpSummaryByType = await StatisticsCustomerApi.getFollowUpSummaryByType(
8181
props.queryParams
8282
)
@@ -99,8 +99,19 @@ const loadData = async () => {
9999
portion: erpCalculatePercentage(row.followUpRecordCount, totalCount)
100100
}
101101
})
102-
loading.value = false
103102
}
103+
104+
/** 获取统计数据 */
105+
const loadData = async () => {
106+
loading.value = true
107+
try {
108+
fetchAndFill()
109+
}
110+
finally {
111+
loading.value = false
112+
}
113+
}
114+
104115
defineExpose({ loadData })
105116
106117
/** 初始化 */

0 commit comments

Comments
 (0)