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

View File

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

View File

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

View File

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

View File

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