fix: 订单数据流抽屉全量任务表占满剩余高度

This commit is contained in:
2026-09-05 18:14:43 +08:00
parent 2194fbe3c3
commit d99d8352b6
@@ -1,7 +1,7 @@
<script lang="ts" setup>
/**
* 店铺订单管线抽屉:同步 / 转换 / 计算 三阶段合一。
* 顶区状态+动作;历史全量任务用紧凑表;创建全量内联,不再套第二层弹窗。
* 顶区状态+动作;历史全量任务用紧凑表;创建全量走模态框。
* shopId 为经营店铺 id(API 约定);可由渠道店页传入仅含 id/name 的引用。
*/
import type { PddOrderSyncVO } from '#/api/channel/pdd/order-sync';
@@ -9,7 +9,9 @@ import type { PddOrderConvertVO } from '#/api/channel/pdd/order-convert';
import type { BiOrderStatCalcVO } from '#/api/bi/order-stat-calc';
import type { Dayjs } from 'dayjs';
import { computed, onBeforeUnmount, ref, watch } from 'vue';
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import {
Alert,
@@ -18,7 +20,6 @@ import {
Drawer,
Form,
Progress,
Radio,
Segmented,
Space,
Switch,
@@ -112,16 +113,28 @@ const syncTasks = ref<PddOrderSyncVO.FullTask[]>([]);
const syncListLoading = ref(false);
const syncActionLoading = ref(false);
const incSubmitting = ref(false);
const createOpen = ref(false);
const createSubmitting = ref(false);
const createMode = ref<'day' | 'range'>('range');
/** 当前内联创建表单所属阶段 */
/** 当前创建表单所属阶段 */
const createForStage = ref<PipelineStageKey>('sync');
const confirmDate = ref<Dayjs>(dayjs().startOf('day'));
const range = ref<[Dayjs, Dayjs]>([
dayjs().startOf('day').subtract(FULL_SYNC_MAX_CALENDAR_DAYS - 1, 'day'),
dayjs().startOf('day'),
]);
/**
* 与 ProductDetailModal 同款 useVbenModal。
* zIndex 须高于 ant DesignTokens.zIndexPopupBase(2000),否则会被本页 Drawer 挡住。
*/
const [CreateFullModal, createFullModalApi] = useVbenModal({
title: '创建全量任务',
class: 'w-[480px] max-w-[calc(100vw-2rem)]',
draggable: true,
zIndex: 2100,
confirmText: '创建并开始',
cancelText: '取消',
destroyOnClose: true,
onConfirm: () => handleCreateTask(),
});
let pollTimer: null | ReturnType<typeof setInterval> = null;
let unsubProgress: (() => void) | null = null;
const terminalNotifiedTaskIds = new Set<number>();
@@ -151,6 +164,21 @@ const stageOptions = computed(() =>
const showStageTabs = computed(() => enabledStages.value.length > 1);
const createModalTitle = computed(() => {
const name = shop.value?.name ? ` · ${shop.value.name}` : '';
return `创建全量${STAGE_LABEL[createForStage.value]}${name}`;
});
const createDateRangeLabel = computed(() => {
if (createForStage.value === 'convert') {
return '成交日区间(近 90 天,按渠道镜像扫日)';
}
if (createForStage.value === 'calc') {
return '统计日区间(近 90 天,按内部订单重算)';
}
return '成交日区间(近 90 天)';
});
const hasActiveSyncTask = computed(() =>
syncTasks.value.some((t) => t.status === 'PENDING' || t.status === 'RUNNING'),
);
@@ -537,45 +565,47 @@ async function handleResumeFull(task: PddOrderSyncVO.FullTask) {
function openCreateForm(forStage: PipelineStageKey = 'sync') {
createForStage.value = forStage;
createMode.value = 'range';
confirmDate.value = fullSyncLatest();
range.value = [fullSyncEarliest(), fullSyncLatest()];
createOpen.value = true;
createFullModalApi.setState({ title: createModalTitle.value });
createFullModalApi.open();
}
/** 快捷将区间设为今天(单日全量) */
function setCreateRangeToToday() {
const today = fullSyncLatest();
range.value = [today, today];
}
async function handleCreateTask() {
if (!shop.value) return;
if (createMode.value === 'day' && !confirmDate.value) {
message.warning('请选择成交日期');
return;
if (!shop.value) {
return Promise.reject(new Error('no shop'));
}
if (createMode.value === 'range' && (!range.value?.[0] || !range.value?.[1])) {
if (!range.value?.[0] || !range.value?.[1]) {
message.warning('请选择日期区间');
return;
return Promise.reject(new Error('invalid range'));
}
const from =
createMode.value === 'day' ? confirmDate.value : range.value[0];
const to = createMode.value === 'day' ? confirmDate.value : range.value[1];
const from = range.value[0];
const to = range.value[1];
if (
disabledFullSyncDate(from) ||
disabledFullSyncDate(to) ||
to.isBefore(from, 'day')
) {
message.warning('日期须在近 90 天内,且结束不早于开始');
return;
return Promise.reject(new Error('date out of range'));
}
const stageKey = createForStage.value;
if (stageKey === 'sync' && hasActiveSyncTask.value) {
message.warning('已有进行中的全量同步任务');
return;
return Promise.reject(new Error('active sync'));
}
if (stageKey === 'convert' && hasActiveConvertTask.value) {
message.warning('已有进行中的全量转换任务');
return;
return Promise.reject(new Error('active convert'));
}
if (stageKey === 'calc' && hasActiveCalcTask.value) {
message.warning('已有进行中的全量计算任务');
return;
return Promise.reject(new Error('active calc'));
}
const payload = {
shopId: shop.value.id,
@@ -583,7 +613,7 @@ async function handleCreateTask() {
dateTo: to.format('YYYY-MM-DD'),
};
try {
createSubmitting.value = true;
createFullModalApi.setState({ confirmLoading: true });
if (stageKey === 'sync') {
const task = await createPddFullSyncTaskApi(payload);
terminalNotifiedTaskIds.delete(task.id);
@@ -599,12 +629,13 @@ async function handleCreateTask() {
calcTasks.value.unshift(task);
message.success('全量计算任务已创建');
}
createOpen.value = false;
createFullModalApi.close();
emit('success');
} catch (e) {
console.error(e);
return Promise.reject(e);
} finally {
createSubmitting.value = false;
createFullModalApi.setState({ confirmLoading: false });
}
}
@@ -641,7 +672,7 @@ async function handleResumeCalc() {
function handleClose() {
stopPoll();
unsubscribeProgress();
createOpen.value = false;
createFullModalApi.close();
openFlag.value = false;
}
@@ -663,7 +694,7 @@ async function open(
convertTasks.value = [];
calcInc.value = null;
calcTasks.value = [];
createOpen.value = false;
createFullModalApi.close();
terminalNotifiedTaskIds.clear();
stopPoll();
subscribeProgress();
@@ -673,23 +704,84 @@ async function open(
await loadStage(stage.value);
} finally {
pageLoading.value = false;
scheduleMeasureTableScrollY();
}
}
/** 全量任务表滚动高度:吃满抽屉剩余空间 */
const tableScrollY = ref(360);
const pipelineBodyRef = ref<HTMLElement | null>(null);
let tableHostRo: null | ResizeObserver = null;
/**
* v-show 隐藏时祖先 display:none,子节点 computed display 仍非 none,
* 必须用布局尺寸判断,否则会一直量到排在前面的同步宿主(高度 0 → scroll.y=120)。
*/
function measureTableScrollY() {
const root = pipelineBodyRef.value;
if (!root) return;
const hosts = root.querySelectorAll<HTMLElement>('.pipeline-table-host');
for (const host of hosts) {
if (host.getClientRects().length === 0 || host.clientHeight < 40) continue;
// small 表头约 39px,略留缝
tableScrollY.value = Math.max(120, Math.floor(host.clientHeight - 40));
return;
}
}
function scheduleMeasureTableScrollY() {
void nextTick(() => {
requestAnimationFrame(() => {
measureTableScrollY();
// 抽屉动画 / 分段切换后再量一次,避免首帧高度未撑开
requestAnimationFrame(measureTableScrollY);
});
});
}
function bindTableHostObserver() {
tableHostRo?.disconnect();
tableHostRo = null;
const root = pipelineBodyRef.value;
if (!root || typeof ResizeObserver === 'undefined') {
scheduleMeasureTableScrollY();
return;
}
tableHostRo = new ResizeObserver(() => measureTableScrollY());
tableHostRo.observe(root);
for (const host of root.querySelectorAll('.pipeline-table-host')) {
tableHostRo.observe(host);
}
scheduleMeasureTableScrollY();
}
watch(stage, async (s) => {
if (!openFlag.value || !shop.value) return;
createOpen.value = false;
createFullModalApi.close();
pageLoading.value = true;
try {
await loadStage(s);
} finally {
pageLoading.value = false;
scheduleMeasureTableScrollY();
}
});
watch(openFlag, (open) => {
if (open) {
scheduleMeasureTableScrollY();
void nextTick(() => bindTableHostObserver());
} else {
tableHostRo?.disconnect();
tableHostRo = null;
}
});
onBeforeUnmount(() => {
stopPoll();
unsubscribeProgress();
tableHostRo?.disconnect();
tableHostRo = null;
});
defineExpose({ open, close: handleClose });
@@ -702,18 +794,23 @@ defineExpose({ open, close: handleClose });
:width="640"
destroy-on-close
:mask-closable="!hasActiveSyncTask"
root-class-name="shop-order-pipeline-drawer"
@close="handleClose"
>
<div class="flex h-full min-h-0 flex-col gap-4">
<div
ref="pipelineBodyRef"
class="flex min-h-0 flex-1 flex-col gap-4"
>
<Segmented
v-if="showStageTabs"
v-model:value="stage"
block
class="shrink-0"
:options="stageOptions"
/>
<div
v-else
class="text-sm font-medium text-slate-700 dark:text-slate-200"
class="shrink-0 text-sm font-medium text-slate-700 dark:text-slate-200"
>
{{ STAGE_LABEL[stage] }}
</div>
@@ -721,10 +818,10 @@ defineExpose({ open, close: handleClose });
<!-- 同步 -->
<div
v-show="stage === 'sync'"
class="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto"
class="flex min-h-0 flex-1 flex-col gap-3 overflow-hidden"
>
<div
class="rounded-lg border border-slate-200/80 px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)]"
class="shrink-0 rounded-lg border border-slate-200/80 px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)]"
>
<div class="mb-2 flex flex-wrap items-center justify-between gap-2">
<Space wrap>
@@ -769,18 +866,13 @@ defineExpose({ open, close: handleClose });
/>
</div>
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="flex shrink-0 flex-wrap items-center justify-between gap-2">
<span class="text-sm font-medium">全量任务</span>
<Space size="small">
<Button
size="small"
:loading="syncListLoading"
@click="loadSyncTasks"
>
<Space>
<Button :loading="syncListLoading" @click="loadSyncTasks">
刷新
</Button>
<Button
size="small"
type="primary"
:disabled="hasActiveSyncTask"
@click="openCreateForm('sync')"
@@ -791,58 +883,20 @@ defineExpose({ open, close: handleClose });
</div>
<div
v-if="createOpen && createForStage === 'sync'"
class="rounded-lg border border-dashed border-slate-300 px-3 py-2 dark:border-[hsl(240deg_3.7%_28%)]"
v-if="syncTasks.some((x) => x.lastError)"
class="shrink-0 space-y-2"
>
<Form layout="vertical" class="!mb-0">
<Form.Item label="类型" class="!mb-2">
<Radio.Group v-model:value="createMode" size="small">
<Radio.Button value="range">区间</Radio.Button>
<Radio.Button value="day">单日</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item
v-if="createMode === 'range'"
label="成交日区间(近 90 天)"
class="!mb-2"
>
<DatePicker.RangePicker
v-model:value="range"
class="w-full"
size="small"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
<Alert
v-for="t in syncTasks.filter((x) => x.lastError)"
:key="`err-${t.id}`"
type="error"
show-icon
class="!text-xs"
:message="`#${t.id} ${t.lastError}`"
/>
</Form.Item>
<Form.Item
v-else
label="成交日"
class="!mb-2"
>
<DatePicker
v-model:value="confirmDate"
class="w-full"
size="small"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
/>
</Form.Item>
<Space>
<Button
type="primary"
size="small"
:loading="createSubmitting"
@click="handleCreateTask"
>
创建并开始
</Button>
<Button size="small" @click="createOpen = false">取消</Button>
</Space>
</Form>
</div>
<div class="pipeline-table-host min-h-0 flex-1 overflow-hidden">
<Table
size="small"
:columns="taskColumns"
@@ -850,7 +904,7 @@ defineExpose({ open, close: handleClose });
:loading="syncListLoading || pageLoading"
:pagination="false"
row-key="id"
:scroll="{ y: 360 }"
:scroll="{ y: tableScrollY }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
@@ -924,23 +978,16 @@ defineExpose({ open, close: handleClose });
</template>
</template>
</Table>
<Alert
v-for="t in syncTasks.filter((x) => x.lastError)"
:key="`err-${t.id}`"
type="error"
show-icon
class="!text-xs"
:message="`#${t.id} ${t.lastError}`"
/>
</div>
</div>
<!-- 转换 -->
<div
v-show="stage === 'convert'"
class="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto"
class="flex min-h-0 flex-1 flex-col gap-3 overflow-hidden"
>
<div
class="rounded-lg border border-slate-200/80 px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)]"
class="shrink-0 rounded-lg border border-slate-200/80 px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)]"
>
<div class="mb-2 flex flex-wrap items-center justify-between gap-2">
<Space wrap>
@@ -976,18 +1023,13 @@ defineExpose({ open, close: handleClose });
/>
</div>
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="flex shrink-0 flex-wrap items-center justify-between gap-2">
<span class="text-sm font-medium">全量任务</span>
<Space size="small">
<Button
size="small"
:loading="convertListLoading"
@click="loadConvertTasks"
>
<Space>
<Button :loading="convertListLoading" @click="loadConvertTasks">
刷新
</Button>
<Button
size="small"
type="primary"
:disabled="hasActiveConvertTask"
@click="openCreateForm('convert')"
@@ -997,55 +1039,7 @@ defineExpose({ open, close: handleClose });
</Space>
</div>
<div
v-if="createOpen && createForStage === 'convert'"
class="rounded-lg border border-dashed border-slate-300 px-3 py-2 dark:border-[hsl(240deg_3.7%_28%)]"
>
<Form layout="vertical" class="!mb-0">
<Form.Item label="类型" class="!mb-2">
<Radio.Group v-model:value="createMode" size="small">
<Radio.Button value="range">区间</Radio.Button>
<Radio.Button value="day">单日</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item
v-if="createMode === 'range'"
label="成交日区间(近 90 天,按渠道镜像扫日)"
class="!mb-2"
>
<DatePicker.RangePicker
v-model:value="range"
class="w-full"
size="small"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
/>
</Form.Item>
<Form.Item v-else label="成交日" class="!mb-2">
<DatePicker
v-model:value="confirmDate"
class="w-full"
size="small"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
/>
</Form.Item>
<Space>
<Button
type="primary"
size="small"
:loading="createSubmitting"
@click="handleCreateTask"
>
创建并开始
</Button>
<Button size="small" @click="createOpen = false">取消</Button>
</Space>
</Form>
</div>
<div class="pipeline-table-host min-h-0 flex-1 overflow-hidden">
<Table
size="small"
:columns="pipelineTaskColumns"
@@ -1053,7 +1047,7 @@ defineExpose({ open, close: handleClose });
:loading="convertListLoading || pageLoading"
:pagination="false"
row-key="id"
:scroll="{ y: 360 }"
:scroll="{ y: tableScrollY }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
@@ -1106,14 +1100,15 @@ defineExpose({ open, close: handleClose });
</template>
</Table>
</div>
</div>
<!-- 计算 -->
<div
v-show="stage === 'calc'"
class="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto"
class="flex min-h-0 flex-1 flex-col gap-3 overflow-hidden"
>
<div
class="rounded-lg border border-slate-200/80 px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)]"
class="shrink-0 rounded-lg border border-slate-200/80 px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)]"
>
<div class="mb-2 flex flex-wrap items-center justify-between gap-2">
<Space wrap>
@@ -1151,18 +1146,13 @@ defineExpose({ open, close: handleClose });
/>
</div>
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="flex shrink-0 flex-wrap items-center justify-between gap-2">
<span class="text-sm font-medium">全量任务</span>
<Space size="small">
<Button
size="small"
:loading="calcListLoading"
@click="loadCalcTasks"
>
<Space>
<Button :loading="calcListLoading" @click="loadCalcTasks">
刷新
</Button>
<Button
size="small"
type="primary"
:disabled="hasActiveCalcTask"
@click="openCreateForm('calc')"
@@ -1172,55 +1162,7 @@ defineExpose({ open, close: handleClose });
</Space>
</div>
<div
v-if="createOpen && createForStage === 'calc'"
class="rounded-lg border border-dashed border-slate-300 px-3 py-2 dark:border-[hsl(240deg_3.7%_28%)]"
>
<Form layout="vertical" class="!mb-0">
<Form.Item label="类型" class="!mb-2">
<Radio.Group v-model:value="createMode" size="small">
<Radio.Button value="range">区间</Radio.Button>
<Radio.Button value="day">单日</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item
v-if="createMode === 'range'"
label="统计日区间(近 90 天,按内部订单重算)"
class="!mb-2"
>
<DatePicker.RangePicker
v-model:value="range"
class="w-full"
size="small"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
/>
</Form.Item>
<Form.Item v-else label="统计日" class="!mb-2">
<DatePicker
v-model:value="confirmDate"
class="w-full"
size="small"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
/>
</Form.Item>
<Space>
<Button
type="primary"
size="small"
:loading="createSubmitting"
@click="handleCreateTask"
>
创建并开始
</Button>
<Button size="small" @click="createOpen = false">取消</Button>
</Space>
</Form>
</div>
<div class="pipeline-table-host min-h-0 flex-1 overflow-hidden">
<Table
size="small"
:columns="pipelineTaskColumns"
@@ -1228,7 +1170,7 @@ defineExpose({ open, close: handleClose });
:loading="calcListLoading || pageLoading"
:pagination="false"
row-key="id"
:scroll="{ y: 360 }"
:scroll="{ y: tableScrollY }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
@@ -1299,5 +1241,43 @@ defineExpose({ open, close: handleClose });
</Table>
</div>
</div>
</div>
</Drawer>
<CreateFullModal>
<Form layout="vertical" class="!mb-0 px-1 pt-1">
<Form.Item :label="createDateRangeLabel" class="!mb-0">
<div class="flex flex-wrap items-center gap-2">
<DatePicker.RangePicker
v-model:value="range"
class="min-w-0 flex-1"
:allow-clear="false"
:disabled-date="disabledFullSyncDate"
format="YYYY-MM-DD"
/>
<Button @click="setCreateRangeToToday">今天</Button>
</div>
</Form.Item>
</Form>
</CreateFullModal>
</template>
<style scoped>
/* 抽屉内容撑满视口高度,body 吃掉标题以下剩余空间,供表格 flex 伸展 */
:global(.shop-order-pipeline-drawer .ant-drawer-content-wrapper),
:global(.shop-order-pipeline-drawer .ant-drawer-content) {
display: flex;
flex-direction: column;
height: 100%;
}
:global(.shop-order-pipeline-drawer .ant-drawer-body) {
display: flex;
flex: 1;
flex-direction: column;
min-height: 0;
overflow: hidden;
padding-top: 16px;
padding-bottom: 16px;
}
</style>