refactor: 使用try finally停止loading

This commit is contained in:
dhb52 2024-04-06 15:38:04 +08:00
parent 8926dd1173
commit 13cf1feefb
5 changed files with 152 additions and 42 deletions

View File

@ -69,12 +69,12 @@ import {
CrmStatisticsCustomerSummaryByDateRespVO CrmStatisticsCustomerSummaryByDateRespVO
} from '@/api/crm/statistics/customer' } from '@/api/crm/statistics/customer'
import { EChartsOption } from 'echarts' import { EChartsOption } from 'echarts'
import { round } from 'lodash-es'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import { erpPriceTableColumnFormatter } from '@/utils' import { erpPriceTableColumnFormatter } from '@/utils'
import { DICT_TYPE } from '@/utils/dict' import { DICT_TYPE } from '@/utils/dict'
defineOptions({ name: 'CustomerConversionStat' }) defineOptions({ name: 'CustomerConversionStat' })
const props = defineProps<{ queryParams: any }>() // const props = defineProps<{ queryParams: any }>() //
const loading = ref(false) // const loading = ref(false) //
@ -84,7 +84,7 @@ const list = ref<CrmStatisticsCustomerSummaryByDateRespVO[]>([]) // 列表的数
const echartsOption = reactive<EChartsOption>({ const echartsOption = reactive<EChartsOption>({
grid: { grid: {
left: 20, left: 20,
right: 20, right: 40, // X
bottom: 20, bottom: 20,
containLabel: true containLabel: true
}, },
@ -124,11 +124,9 @@ const echartsOption = reactive<EChartsOption>({
} }
}) as EChartsOption }) as EChartsOption
/** 获取统计数据 */ /** 获取数据并填充图表 */
const loadData = async () => { const fetchAndFill = async () => {
// 1. // 1.
loading.value = true
// TODO @ddhb52 StatisticsCustomerApi.getCustomerSummaryByDate
const customerCount = await StatisticsCustomerApi.getCustomerSummaryByDate(props.queryParams) const customerCount = await StatisticsCustomerApi.getCustomerSummaryByDate(props.queryParams)
const contractSummary = await StatisticsCustomerApi.getContractSummary(props.queryParams) const contractSummary = await StatisticsCustomerApi.getContractSummary(props.queryParams)
// 2.1 Echarts // 2.1 Echarts
@ -143,7 +141,7 @@ const loadData = async () => {
return { return {
name: item.time, name: item.time,
value: item.customerCreateCount value: item.customerCreateCount
? round((item.customerDealCount / item.customerCreateCount) * 100, 2) ? ((item.customerDealCount / item.customerCreateCount) * 100).toFixed(2)
: 0 : 0
} }
} }
@ -151,8 +149,19 @@ const loadData = async () => {
} }
// 2.2 // 2.2
list.value = contractSummary list.value = contractSummary
loading.value = false
} }
/** 获取统计数据 */
const loadData = async () => {
loading.value = true
try {
fetchAndFill()
}
finally {
loading.value = false
}
}
defineExpose({ loadData }) defineExpose({ loadData })
/** 初始化 */ /** 初始化 */

View File

@ -31,6 +31,7 @@ import {
import { EChartsOption } from 'echarts' import { EChartsOption } from 'echarts'
defineOptions({ name: 'CustomerDealCycle' }) defineOptions({ name: 'CustomerDealCycle' })
const props = defineProps<{ queryParams: any }>() // const props = defineProps<{ queryParams: any }>() //
const loading = ref(false) // const loading = ref(false) //
@ -40,7 +41,7 @@ const list = ref<CrmStatisticsCustomerDealCycleByDateRespVO[]>([]) // 列表的
const echartsOption = reactive<EChartsOption>({ const echartsOption = reactive<EChartsOption>({
grid: { grid: {
left: 20, left: 20,
right: 20, right: 40, // X
bottom: 20, bottom: 20,
containLabel: true containLabel: true
}, },
@ -49,12 +50,14 @@ const echartsOption = reactive<EChartsOption>({
{ {
name: '成交周期(天)', name: '成交周期(天)',
type: 'bar', type: 'bar',
data: [] data: [],
yAxisIndex: 0,
}, },
{ {
name: '成交客户数', name: '成交客户数',
type: 'bar', type: 'bar',
data: [] data: [],
yAxisIndex: 1,
} }
], ],
toolbox: { toolbox: {
@ -74,10 +77,26 @@ const echartsOption = reactive<EChartsOption>({
type: 'shadow' type: 'shadow'
} }
}, },
yAxis: { yAxis: [
{
type: 'value', type: 'value',
name: '数量(个)' name: '成交周期(天)',
min: 0,
minInterval: 1, //
}, },
{
type: 'value',
name: '成交客户数',
min: 0,
minInterval: 1, //
splitLine: {
lineStyle: {
type: 'dotted', // 线,
opacity: 0.7,
}
}
},
],
xAxis: { xAxis: {
type: 'category', type: 'category',
name: '日期', name: '日期',
@ -85,10 +104,9 @@ const echartsOption = reactive<EChartsOption>({
} }
}) as EChartsOption }) as EChartsOption
/** 获取统计数据 */ /** 获取数据并填充图表 */
const loadData = async () => { const fetchAndFill = async () => {
// 1. // 1.
loading.value = true
const customerDealCycleByDate = await StatisticsCustomerApi.getCustomerDealCycleByDate( const customerDealCycleByDate = await StatisticsCustomerApi.getCustomerDealCycleByDate(
props.queryParams props.queryParams
) )
@ -116,7 +134,17 @@ const loadData = async () => {
} }
// 2.2 // 2.2
list.value = customerDealCycleByUser list.value = customerDealCycleByUser
}
/** 获取统计数据 */
const loadData = async () => {
loading.value = true
try {
fetchAndFill()
}
finally {
loading.value = false loading.value = false
}
} }
defineExpose({ loadData }) defineExpose({ loadData })

View File

@ -1,7 +1,7 @@
<!-- 客户跟进次数分析 --> <!-- 客户跟进次数分析 -->
<template> <template>
<!-- Echarts图 --> <!-- Echarts图 -->
<el-card shadow="never"> <el-card shadow="never" >
<el-skeleton :loading="loading" animated> <el-skeleton :loading="loading" animated>
<Echart :height="500" :options="echartsOption" /> <Echart :height="500" :options="echartsOption" />
</el-skeleton> </el-skeleton>
@ -28,9 +28,11 @@ import {
CrmStatisticsFollowUpSummaryByDateRespVO, CrmStatisticsFollowUpSummaryByDateRespVO,
CrmStatisticsFollowUpSummaryByUserRespVO CrmStatisticsFollowUpSummaryByUserRespVO
} from '@/api/crm/statistics/customer' } from '@/api/crm/statistics/customer'
import Echart from '@/components/Echart/src/Echart.vue';
import { EChartsOption } from 'echarts' import { EChartsOption } from 'echarts'
defineOptions({ name: 'CustomerFollowupSummary' }) defineOptions({ name: 'CustomerFollowupSummary' })
const props = defineProps<{ queryParams: any }>() // const props = defineProps<{ queryParams: any }>() //
const loading = ref(false) // const loading = ref(false) //
@ -40,7 +42,7 @@ const list = ref<CrmStatisticsFollowUpSummaryByUserRespVO[]>([]) // 列表的数
const echartsOption = reactive<EChartsOption>({ const echartsOption = reactive<EChartsOption>({
grid: { grid: {
left: 20, left: 20,
right: 20, right: 30, // X
bottom: 20, bottom: 20,
containLabel: true containLabel: true
}, },
@ -49,11 +51,13 @@ const echartsOption = reactive<EChartsOption>({
{ {
name: '跟进客户数', name: '跟进客户数',
type: 'bar', type: 'bar',
yAxisIndex: 0,
data: [] data: []
}, },
{ {
name: '跟进次数', name: '跟进次数',
type: 'bar', type: 'bar',
yAxisIndex: 1,
data: [] data: []
} }
], ],
@ -74,19 +78,38 @@ const echartsOption = reactive<EChartsOption>({
type: 'shadow' type: 'shadow'
} }
}, },
yAxis: { yAxis: [
{
type: 'value', type: 'value',
name: '数量(个)' name: '跟进客户数',
min: 0,
minInterval: 1, //
}, },
{
type: 'value',
name: '跟进次数',
min: 0,
minInterval: 1, //
splitLine: {
lineStyle: {
type: 'dotted', // 线,
opacity: 0.7,
}
}
}
],
xAxis: { xAxis: {
type: 'category', type: 'category',
name: '日期', name: '日期',
axisTick: {
alignWithLabel: true
},
data: [] data: []
} }
}) as EChartsOption }) as EChartsOption
/** 获取统计数据 */ /** 获取数据并填充图表 */
const loadData = async () => { const fetchAndFill = async () => {
// 1. // 1.
loading.value = true loading.value = true
const followUpSummaryByDate = await StatisticsCustomerApi.getFollowUpSummaryByDate( const followUpSummaryByDate = await StatisticsCustomerApi.getFollowUpSummaryByDate(
@ -113,7 +136,17 @@ const loadData = async () => {
} }
// 2.2 // 2.2
list.value = followUpSummaryByUser list.value = followUpSummaryByUser
}
/** 获取统计数据 */
const loadData = async () => {
loading.value = true
try {
fetchAndFill()
}
finally {
loading.value = false loading.value = false
}
} }
defineExpose({ loadData }) defineExpose({ loadData })

View File

@ -32,6 +32,7 @@ import { DICT_TYPE, getDictLabel } from '@/utils/dict'
import { erpCalculatePercentage } from '@/utils' import { erpCalculatePercentage } from '@/utils'
defineOptions({ name: 'CustomerFollowupType' }) defineOptions({ name: 'CustomerFollowupType' })
const props = defineProps<{ queryParams: any }>() // const props = defineProps<{ queryParams: any }>() //
const loading = ref(false) // const loading = ref(false) //
@ -73,10 +74,9 @@ const echartsOption = reactive<EChartsOption>({
] ]
}) as EChartsOption }) as EChartsOption
/** 获取统计数据 */ /** 获取数据并填充图表 */
const loadData = async () => { const fetchAndFill = async () => {
// 1. // 1.
loading.value = true
const followUpSummaryByType = await StatisticsCustomerApi.getFollowUpSummaryByType( const followUpSummaryByType = await StatisticsCustomerApi.getFollowUpSummaryByType(
props.queryParams props.queryParams
) )
@ -99,8 +99,19 @@ const loadData = async () => {
portion: erpCalculatePercentage(row.followUpRecordCount, totalCount) portion: erpCalculatePercentage(row.followUpRecordCount, totalCount)
} }
}) })
loading.value = false
} }
/** 获取统计数据 */
const loadData = async () => {
loading.value = true
try {
fetchAndFill()
}
finally {
loading.value = false
}
}
defineExpose({ loadData }) defineExpose({ loadData })
/** 初始化 */ /** 初始化 */

View File

@ -61,6 +61,7 @@ import { EChartsOption } from 'echarts'
import { erpCalculatePercentage, erpPriceTableColumnFormatter } from '@/utils' import { erpCalculatePercentage, erpPriceTableColumnFormatter } from '@/utils'
defineOptions({ name: 'CustomerSummary' }) defineOptions({ name: 'CustomerSummary' })
const props = defineProps<{ queryParams: any }>() // const props = defineProps<{ queryParams: any }>() //
const loading = ref(false) // const loading = ref(false) //
@ -70,7 +71,7 @@ const list = ref<CrmStatisticsCustomerSummaryByUserRespVO[]>([]) // 列表的数
const echartsOption = reactive<EChartsOption>({ const echartsOption = reactive<EChartsOption>({
grid: { grid: {
left: 20, left: 20,
right: 20, right: 30, // X
bottom: 20, bottom: 20,
containLabel: true containLabel: true
}, },
@ -79,11 +80,13 @@ const echartsOption = reactive<EChartsOption>({
{ {
name: '新增客户数', name: '新增客户数',
type: 'bar', type: 'bar',
yAxisIndex: 0,
data: [] data: []
}, },
{ {
name: '成交客户数', name: '成交客户数',
type: 'bar', type: 'bar',
yAxisIndex: 1,
data: [] data: []
} }
], ],
@ -104,21 +107,36 @@ const echartsOption = reactive<EChartsOption>({
type: 'shadow' type: 'shadow'
} }
}, },
yAxis: { yAxis: [
{
type: 'value', type: 'value',
name: '数量(个)' name: '新增客户数',
min: 0,
minInterval: 1, //
}, },
{
type: 'value',
name: '成交客户数',
min: 0,
minInterval: 1, //
splitLine: {
lineStyle: {
type: 'dotted', // 线,
opacity: 0.7,
}
}
}
],
xAxis: { xAxis: {
type: 'category', type: 'category',
name: '日期', name: '日期',
data: [] data: [],
} }
}) as EChartsOption }) as EChartsOption
/** 获取统计数据 */ /** 获取数据并填充图表 */
const loadData = async () => { const fetchAndFill = async () => {
// 1. // 1.
loading.value = true
const customerSummaryByDate = await StatisticsCustomerApi.getCustomerSummaryByDate( const customerSummaryByDate = await StatisticsCustomerApi.getCustomerSummaryByDate(
props.queryParams props.queryParams
) )
@ -141,10 +159,21 @@ const loadData = async () => {
(s: CrmStatisticsCustomerSummaryByDateRespVO) => s.customerDealCount (s: CrmStatisticsCustomerSummaryByDateRespVO) => s.customerDealCount
) )
} }
// 2.2 // 2.2
list.value = customerSummaryByUser list.value = customerSummaryByUser
loading.value = false
} }
/** 获取统计数据 */
const loadData = async () => {
loading.value = true
try {
fetchAndFill()
} finally {
loading.value = false
}
}
defineExpose({ loadData }) defineExpose({ loadData })
/** 初始化 */ /** 初始化 */