feat: 快递报价详情按需加载并批量查分区重量带以降低延迟

This commit is contained in:
2026-10-28 11:38:01 +08:00
parent e47f76c22a
commit f382ba9bd7
7 changed files with 120 additions and 33 deletions
@@ -23,9 +23,14 @@ export async function getEnabledExpressQuotesApi() {
return requestClient.get<ExpressQuoteVO.Info[]>('/ec/express-quote/enabled');
}
export async function getExpressQuoteDetailApi(id: number) {
/** withHistory:详情抽屉拉全版本分区;编辑页默认 false 仅当前版本明细 */
export async function getExpressQuoteDetailApi(
id: number,
withHistory = false,
) {
return requestClient.get<ExpressQuoteVO.Info>(
`/ec/express-quote/detail/${id}`,
{ params: { withHistory } },
);
}
@@ -76,7 +76,7 @@ async function open(id: number) {
loading.value = true;
detail.value = null;
try {
detail.value = await getExpressQuoteDetailApi(id);
detail.value = await getExpressQuoteDetailApi(id, true);
} catch (error) {
console.error(error);
message.error('加载报价详情失败');
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import type { ExpressQuoteDTO, ExpressQuoteVO } from '#/api/ec/express-quote';
import { computed, onMounted, ref, watch } from 'vue';
import { computed, nextTick, onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ColPage } from '@vben/common-ui';
@@ -329,11 +329,21 @@ function fillRegionsFromVersion(v?: ExpressQuoteVO.Version) {
async function loadDetail() {
loading.value = true;
let tabTitle: string | undefined;
try {
if (!provinces.value.length) {
provinces.value = await getExpressProvincesApi();
// 省份与详情并行,避免串行拉长转圈
const needProvinces = !provinces.value.length;
const [provinceList, detail] = await Promise.all([
needProvinces ? getExpressProvincesApi() : Promise.resolve(null),
quoteId.value
? getExpressQuoteDetailApi(quoteId.value)
: Promise.resolve(null),
]);
if (provinceList) {
provinces.value = provinceList;
}
if (!quoteId.value) {
if (!detail) {
await formApi.resetForm();
await formApi.setValues({
carrierCode: 'ZTO',
@@ -347,13 +357,16 @@ async function loadDetail() {
weightRound: 'NONE',
});
billingMode.value = 'FLAT';
syncLeftWidthByMode();
fillRegionsFromVersion();
await syncTabTitle('新建');
tabTitle = '新建';
return;
}
const detail = await getExpressQuoteDetailApi(quoteId.value);
billingMode.value = detail.billingMode;
const v = detail.currentVersion;
billingMode.value = detail.billingMode;
syncLeftWidthByMode();
// 先回填表单并结束 loading,再挂大块分区(避免接口已返回仍长时间转圈)
await formApi.setValues({
code: detail.code,
name: detail.name,
@@ -370,15 +383,19 @@ async function loadDetail() {
useVolumetric: v?.useVolumetric === 1,
weightRound: v?.weightRound || 'NONE',
});
loading.value = false;
await nextTick();
fillRegionsFromVersion(v);
await syncTabTitle(detail.name);
tabTitle = detail.name;
} catch (error) {
console.error(error);
message.error('加载报价单失败');
} finally {
syncLeftWidthByMode();
loading.value = false;
}
if (tabTitle != null) {
void syncTabTitle(tabTitle);
}
}
function buildVersion(