perf: 店铺月度汇总按序渐进加载 (#1045)

This commit is contained in:
qiuxiang 2026-11-10 15:46:32 +08:00
parent 73bd32b1e7
commit 0b3e05af8f

View File

@ -166,11 +166,19 @@
<span>{{ monthlyClosingError }}</span>
<button type="button" @click="fetchMonthlyClosing">重新加载</button>
</div>
<div v-else-if="monthlyClosingView === 'store' && monthlyClosingStoreLoading" class="monthly-closing-loading" role="status">
<div
v-else-if="monthlyClosingView === 'store' && monthlyClosingStoreLoading && !monthlyStoreMonthDetails.length"
class="monthly-closing-loading"
role="status"
>
<span v-for="index in 4" :key="index"></span>
<p>正在汇总 7-10 月店铺期末余额…</p>
</div>
<div v-else-if="monthlyClosingView === 'store' && monthlyClosingStoreError" class="monthly-closing-error" role="alert">
<div
v-else-if="monthlyClosingView === 'store' && monthlyClosingStoreError && !monthlyStoreMonthDetails.length"
class="monthly-closing-error"
role="alert"
>
<span>{{ monthlyClosingStoreError }}</span>
<button type="button" @click="fetchMonthlyClosingStores">重新加载</button>
</div>
@ -206,39 +214,53 @@
</tbody>
</table>
</div>
<div v-else class="monthly-closing-scroll is-store">
<table class="monthly-closing-table monthly-closing-store-table">
<thead>
<tr>
<th scope="col">平台账户</th>
<th scope="col">店铺名称</th>
<th v-for="month in monthlyClosing.months" :key="month.key" scope="col" class="is-number">
{{ month.label }}
</th>
<th scope="col" class="is-number monthly-closing-compare-head">环比</th>
</tr>
</thead>
<tbody>
<tr
v-for="row in monthlyStoreRows"
:key="row.key"
:class="{ 'is-total': row.isTotal, 'is-unavailable': !row.available }"
>
<th scope="row">{{ row.platform }}</th>
<td class="monthly-store-name">{{ row.store_name }}</td>
<td v-for="month in monthlyClosing.months" :key="month.key" class="is-number">
{{ monthlyBalanceWan(row, month.key) }}
</td>
<td class="is-number monthly-closing-compare">
<span :class="changeClass(row.change.amount)">{{ signedMoneyWan(row.change.amount) }}</span>
<small v-if="row.change.rate !== null" :class="changeClass(row.change.amount)">
{{ signedPercent(row.change.rate) }}
</small>
</td>
</tr>
</tbody>
</table>
</div>
<template v-else>
<div
v-if="monthlyClosingStoreLoading || monthlyClosingStoreError"
class="monthly-store-progress"
:class="{ 'is-error': monthlyClosingStoreError }"
role="status"
>
<span v-if="monthlyClosingStoreLoading">
正在补齐历史月份({{ monthlyStoreMonthDetails.length }} / {{ monthlyClosing.months.length }})…
</span>
<span v-else>{{ monthlyClosingStoreError }}</span>
<button v-if="monthlyClosingStoreError" type="button" @click="fetchMonthlyClosingStores">重新加载</button>
</div>
<div class="monthly-closing-scroll is-store">
<table class="monthly-closing-table monthly-closing-store-table">
<thead>
<tr>
<th scope="col">平台账户</th>
<th scope="col">店铺名称</th>
<th v-for="month in monthlyClosing.months" :key="month.key" scope="col" class="is-number">
{{ month.label }}
</th>
<th scope="col" class="is-number monthly-closing-compare-head">环比</th>
</tr>
</thead>
<tbody>
<tr
v-for="row in monthlyStoreRows"
:key="row.key"
:class="{ 'is-total': row.isTotal, 'is-unavailable': !row.available }"
>
<th scope="row">{{ row.platform }}</th>
<td class="monthly-store-name">{{ row.store_name }}</td>
<td v-for="month in monthlyClosing.months" :key="month.key" class="is-number">
{{ monthlyBalanceWan(row, month.key) }}
</td>
<td class="is-number monthly-closing-compare">
<span :class="changeClass(row.change.amount)">{{ signedMoneyWan(row.change.amount) }}</span>
<small v-if="row.change.rate !== null" :class="changeClass(row.change.amount)">
{{ signedPercent(row.change.rate) }}
</small>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<footer class="monthly-closing-foot">
<span>环比口径:2026年10月期末余额 − 2026年9月期末余额,金额单位为万元,百分比以上月余额为基数。</span>
<span v-if="!monthlyClosingLoading && !monthlyClosingError">
@ -856,31 +878,32 @@ export default {
const requestId = ++this.monthlyClosingStoreRequestSerial;
this.monthlyClosingStoreLoading = true;
this.monthlyClosingStoreError = '';
this.monthlyStoreMonthDetails = [];
try {
const responses = await Promise.all(months.map((month) => {
for (const month of months) {
const [year, monthNumber] = month.key.split('-').map(Number);
const lastDay = new Date(year, monthNumber, 0).getDate();
return window.axios.get(`${this.apiBase}/balance-store-detail`, {
const response = await window.axios.get(`${this.apiBase}/balance-store-detail`, {
params: {
start: `${month.key}-01`,
end: `${month.key}-${pad(lastDay)}`,
},
});
}));
if (requestId !== this.monthlyClosingStoreRequestSerial) return;
this.monthlyStoreMonthDetails = [...this.monthlyStoreMonthDetails, {
month: month.key,
details: Array.isArray(response.data && response.data.details)
? response.data.details
: [],
}];
}
if (requestId !== this.monthlyClosingStoreRequestSerial) return;
this.monthlyStoreMonthDetails = responses.map((response, index) => ({
month: months[index].key,
details: Array.isArray(response.data && response.data.details)
? response.data.details
: [],
}));
this.monthlyClosingStoreLoaded = true;
} catch (error) {
if (requestId !== this.monthlyClosingStoreRequestSerial) return;
this.monthlyStoreMonthDetails = [];
this.monthlyClosingStoreLoaded = false;
this.monthlyClosingStoreError = (error.response && error.response.data && error.response.data.message)
|| '店铺月度期末余额暂时无法读取,请稍后重试。';
@ -1516,6 +1539,30 @@ export default {
z-index: 2;
top: 0;
}
.monthly-store-progress {
display: flex;
align-items: center;
justify-content: space-between;
gap: .75rem;
padding: .5rem .8rem;
border-bottom: 1px solid #eee7da;
background: #fbf7ef;
color: var(--overview-muted);
font-size: .6875rem;
}
.monthly-store-progress.is-error {
background: #fff6f3;
color: #9b3c2d;
}
.monthly-store-progress button {
padding: .2rem .55rem;
border: 1px solid currentColor;
border-radius: .35rem;
background: transparent;
color: inherit;
font: inherit;
cursor: pointer;
}
.monthly-closing-table {
width: 100%;
min-width: 44rem;