feat: 渠道店铺页接入订单同步与转换数据流

This commit is contained in:
2026-09-05 15:22:31 +08:00
parent 4f2cd9ecef
commit 2194fbe3c3
4 changed files with 401 additions and 18 deletions
@@ -24,6 +24,8 @@ export namespace PddShopVO {
export interface Info {
id: number;
companyId?: number;
/** 绑定的经营店铺 id;未绑定则为空 */
ecShopId?: null | number;
pddAuthId?: null | number;
auth?: AuthInfo | null;
mallId?: number;
@@ -0,0 +1,229 @@
<script lang="ts" setup>
/**
* 渠道店铺列表:订单同步→转换状态卡(点击打开管线抽屉)。
* 不展示 BI 计算(属经营店铺侧)。
*/
import type { PddOrderSyncVO } from '#/api/channel/pdd/order-sync';
import { computed } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import dayjs from 'dayjs';
defineOptions({ name: 'PddShopOrderFlowCell' });
export type OrderFlowStageKey = 'convert' | 'sync';
const props = defineProps<{
/** 是否已授权 */
authorized: boolean;
/** 是否已绑经营店铺(有 ecShopId 才能调订单管线 API) */
bound: boolean;
status?: null | PddOrderSyncVO.ShopStatus;
}>();
const emit = defineEmits<{
open: [stage: OrderFlowStageKey];
}>();
const IconSync = createIconifyIcon('lucide:refresh-cw');
const IconConvert = createIconifyIcon('lucide:shuffle');
const IconArrow = createIconifyIcon('lucide:chevron-right');
const IconLinkOff = createIconifyIcon('lucide:unplug');
const IconLock = createIconifyIcon('lucide:shield-off');
type Tone = 'error' | 'idle' | 'off' | 'ok' | 'warn';
function formatRelative(time?: null | string) {
if (!time) return '';
const d = dayjs(time);
if (!d.isValid()) return '';
const mins = dayjs().diff(d, 'minute');
if (mins < 1) return '刚刚';
if (mins < 60) return `${mins} 分钟前`;
const hours = dayjs().diff(d, 'hour');
if (hours < 24) return `${hours} 小时前`;
const days = dayjs().diff(d, 'day');
if (days < 30) return `${days} 天前`;
return d.format('MM-DD');
}
function toneFromInc(status?: null | PddOrderSyncVO.ShopStatus): Tone {
const health = status?.incremental?.health;
if (health === 'PAUSED') return 'error';
if (health === 'LAGGING') return 'warn';
if (health === 'OK') return 'ok';
if (health === 'OFF' || !status?.incremental?.enabled) return 'off';
return 'idle';
}
function toneFromConvert(status?: null | PddOrderSyncVO.ShopStatus): Tone {
const summary = status?.convert?.lastSummary;
const st = status?.convert?.status;
if (st === 2 || (summary && (summary.includes('失败') || summary.includes('限流')))) {
return 'error';
}
if (summary) return 'ok';
return 'idle';
}
function toneLabel(tone: Tone) {
const map: Record<Tone, string> = {
ok: '正常',
warn: '滞后',
error: '异常',
off: '关闭',
idle: '待命',
};
return map[tone];
}
const syncTone = computed(() => toneFromInc(props.status));
const convertTone = computed(() => toneFromConvert(props.status));
const footerHint = computed(() => {
const syncInc = formatRelative(props.status?.incremental?.lastSuccessTime);
const syncFull = formatRelative(props.status?.lastFullSyncSuccessTime);
const parts: string[] = [];
if (syncInc) parts.push(`增量 ${syncInc}`);
if (syncFull) parts.push(`全量 ${syncFull}`);
return parts.length > 0 ? parts.join(' · ') : '点击管理同步与转换';
});
const blockedReason = computed(() => {
if (!props.authorized) return '未授权,无法拉订单';
if (!props.bound) return '未绑定经营店铺';
return '';
});
const canOpen = computed(() => props.authorized && props.bound);
function onOpen(stage: OrderFlowStageKey, e?: Event) {
e?.stopPropagation();
if (!canOpen.value) return;
emit('open', stage);
}
</script>
<template>
<div
v-if="!canOpen"
class="flow-blocked flex min-w-[220px] items-center gap-2 rounded-[12px] border border-dashed border-slate-200/90 bg-slate-50/80 px-3 py-2 dark:border-slate-700/60 dark:bg-slate-900/40"
>
<component
:is="!authorized ? IconLock : IconLinkOff"
class="size-4 shrink-0 text-slate-400"
/>
<div class="min-w-0">
<div class="text-xs font-medium text-slate-500 dark:text-slate-400">
订单数据流
</div>
<div class="truncate text-[11px] text-slate-400 dark:text-slate-500">
{{ blockedReason }}
</div>
</div>
</div>
<button
v-else
type="button"
class="flow-card group relative flex min-w-[240px] max-w-[320px] flex-col gap-1 rounded-[12px] border border-orange-200/70 bg-gradient-to-br from-orange-50/90 via-white to-amber-50/60 px-2.5 py-2 text-left shadow-[0_1px_2px_rgba(234,88,12,0.04)] transition hover:border-orange-300 hover:shadow-[0_4px_14px_rgba(234,88,12,0.08)] dark:border-orange-900/40 dark:from-orange-950/30 dark:via-slate-900/40 dark:to-amber-950/20 dark:hover:border-orange-700/50"
@click="onOpen('sync')"
>
<div class="flex items-center gap-1.5">
<span
class="rounded-full bg-orange-100/90 px-1.5 py-px text-[10px] font-semibold tracking-wide text-orange-800 dark:bg-orange-950/50 dark:text-orange-300"
>
订单
</span>
<span class="text-[10px] text-slate-400 dark:text-slate-500">
同步 → 转换
</span>
</div>
<div class="flex items-stretch gap-1">
<div
class="flow-node flex min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-[10px] px-1.5 py-1 transition hover:bg-white/80 dark:hover:bg-slate-800/60"
:class="`tone-${syncTone}`"
@click="onOpen('sync', $event)"
>
<span
class="flex size-6 shrink-0 items-center justify-center rounded-md bg-white/90 shadow-sm dark:bg-slate-800/80"
>
<component :is="IconSync" class="size-3.5" />
</span>
<div class="min-w-0">
<div class="text-[11px] font-semibold leading-tight text-slate-800 dark:text-slate-100">
同步
</div>
<div class="text-[10px] leading-tight opacity-90">
{{ toneLabel(syncTone) }}
</div>
</div>
</div>
<div class="flex shrink-0 items-center text-slate-300 dark:text-slate-600">
<component :is="IconArrow" class="size-4" />
</div>
<div
class="flow-node flex min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-[10px] px-1.5 py-1 transition hover:bg-white/80 dark:hover:bg-slate-800/60"
:class="`tone-${convertTone}`"
@click="onOpen('convert', $event)"
>
<span
class="flex size-6 shrink-0 items-center justify-center rounded-md bg-white/90 shadow-sm dark:bg-slate-800/80"
>
<component :is="IconConvert" class="size-3.5" />
</span>
<div class="min-w-0">
<div class="text-[11px] font-semibold leading-tight text-slate-800 dark:text-slate-100">
转换
</div>
<div class="text-[10px] leading-tight opacity-90">
{{ toneLabel(convertTone) }}
</div>
</div>
</div>
</div>
<div
class="truncate text-[10px] leading-tight text-slate-500 group-hover:text-orange-700/80 dark:text-slate-400 dark:group-hover:text-orange-300/80"
>
{{ footerHint }}
</div>
</button>
</template>
<style scoped>
.tone-ok {
color: rgb(5 150 105);
}
.tone-warn {
color: rgb(217 119 6);
}
.tone-error {
color: rgb(225 29 72);
}
.tone-off {
color: rgb(100 116 139);
}
.tone-idle {
color: rgb(148 163 184);
}
:global(.dark) .tone-ok {
color: rgb(52 211 153);
}
:global(.dark) .tone-warn {
color: rgb(251 191 36);
}
:global(.dark) .tone-error {
color: rgb(251 113 133);
}
:global(.dark) .tone-off,
:global(.dark) .tone-idle {
color: rgb(148 163 184);
}
</style>
@@ -1,7 +1,10 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { PddShopDTO, PddShopVO } from '#/api/channel/pdd/shop';
import type { PddOrderSyncVO } from '#/api/channel/pdd/order-sync';
import type { PageQueryDTO } from '#/types/common';
import type { OrderFlowStageKey } from './components/PddShopOrderFlowCell.vue';
import type { PipelineStageKey } from '#/views/ec/shop/list/components/ShopOrderPipelineDrawer.vue';
import { computed, ref } from 'vue';
@@ -10,16 +13,20 @@ import { Page } from '@vben/common-ui';
import { Button, Image, Space, Tag, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
getPddShopPageApi,
} from '#/api/channel/pdd/shop';
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
import { syncPddGoodsByShopApi } from '#/api/channel/pdd/goods';
import { batchPddOrderSyncStatusApi } from '#/api/channel/pdd/order-sync';
import { PermissionGate } from '#/components/permission';
import PddShopDetailModal from './components/PddShopDetailModal.vue';
import PddShopOrderFlowCell from './components/PddShopOrderFlowCell.vue';
import ShopOrderPipelineDrawer from '#/views/ec/shop/list/components/ShopOrderPipelineDrawer.vue';
defineOptions({ name: 'PddShopManagement' });
/** 渠道页只管同步/转换;BI 计算留在经营店铺 */
const CHANNEL_ORDER_STAGES: PipelineStageKey[] = ['sync', 'convert'];
const MERCHANT_TYPE_MAP: Record<number, string> = {
1: '个人',
2: '企业',
@@ -38,6 +45,11 @@ const AUTH_STATUS_MAP: Record<number, { color: string; text: string }> = {
const loading = ref(false);
const syncingShopId = ref<null | number>(null);
const shopDetailModalRef = ref<InstanceType<typeof PddShopDetailModal>>();
const pipelineDrawerRef =
ref<InstanceType<typeof ShopOrderPipelineDrawer>>();
/** 经营店 id → 同步/转换摘要 */
const orderFlowStatusMap = ref<Record<number, PddOrderSyncVO.ShopStatus>>({});
const searchForm = ref({
mallName: '',
@@ -77,9 +89,16 @@ const gridOptions: VxeGridProps<PddShopVO.Info> = {
minWidth: 140,
slots: { default: 'auth' },
},
{
title: '订单数据流',
minWidth: 280,
align: 'center' as const,
showOverflow: false,
slots: { default: 'orderFlow' },
},
{
field: 'lastSyncTime',
title: '店铺最近同步',
title: '店铺资料同步',
minWidth: 160,
},
{
@@ -98,7 +117,7 @@ const gridOptions: VxeGridProps<PddShopVO.Info> = {
height: 'auto',
border: true,
stripe: true,
rowConfig: { isHover: true, height: 72 },
rowConfig: { isHover: true, height: 118 },
showOverflow: true,
size: 'small',
toolbarConfig: {
@@ -144,8 +163,10 @@ const gridOptions: VxeGridProps<PddShopVO.Info> = {
},
};
const data = await getPddShopPageApi(params);
const records = data.records ?? [];
await loadOrderFlowStatus(records);
return {
items: data.records ?? [],
items: records,
total: data.total ?? 0,
};
} catch (error) {
@@ -231,11 +252,67 @@ function authTag(row: PddShopVO.Info) {
return AUTH_STATUS_MAP[status] ?? { color: 'default', text: String(status) };
}
function isAuthorized(row: PddShopVO.Info) {
return row.pddAuthId != null && row.auth?.status !== 0 && row.auth?.status !== 2;
}
function isBound(row: PddShopVO.Info) {
return row.ecShopId != null && row.ecShopId > 0;
}
async function loadOrderFlowStatus(records: PddShopVO.Info[]) {
const ecIds = [
...new Set(
records
.map((r) => r.ecShopId)
.filter((id): id is number => id != null && id > 0),
),
];
if (ecIds.length === 0) {
orderFlowStatusMap.value = {};
return;
}
try {
const list = await batchPddOrderSyncStatusApi(ecIds);
const map: Record<number, PddOrderSyncVO.ShopStatus> = {};
for (const item of list || []) {
map[item.shopId] = item;
}
orderFlowStatusMap.value = map;
} catch (error) {
console.error('加载订单数据流状态失败:', error);
orderFlowStatusMap.value = {};
}
}
function openShopDetail(row: PddShopVO.Info) {
if (!row?.id) return;
shopDetailModalRef.value?.open(row.id);
}
function openOrderFlow(row: PddShopVO.Info, stage: OrderFlowStageKey) {
if (!isAuthorized(row)) {
message.warning('该店铺尚未授权,无法管理订单数据流');
return;
}
if (!isBound(row) || !row.ecShopId) {
message.warning('请先在经营店铺中绑定该渠道店');
return;
}
pipelineDrawerRef.value?.open(
{
id: row.ecShopId,
name: row.mallName || `mall ${row.mallId ?? row.id}`,
},
stage,
{ stages: CHANNEL_ORDER_STAGES },
);
}
function onPipelineSuccess() {
gridApi.reload();
}
async function handleSyncGoods(row: PddShopVO.Info) {
if (!row?.id) return;
if (row.pddAuthId == null) {
@@ -304,11 +381,34 @@ async function handleSyncGoods(row: PddShopVO.Info) {
</div>
</template>
<template #orderFlow="{ row }: { row: PddShopVO.Info }">
<div class="flex w-full justify-center">
<PddShopOrderFlowCell
:authorized="isAuthorized(row)"
:bound="isBound(row)"
:status="
row.ecShopId != null
? orderFlowStatusMap[row.ecShopId]
: undefined
"
@open="(stage) => openOrderFlow(row, stage)"
/>
</div>
</template>
<template #action="{ row }: { row: PddShopVO.Info }">
<Space size="small" :wrap="false">
<Button type="link" size="small" @click="openShopDetail(row)">
详情
</Button>
<Button
v-if="isAuthorized(row) && isBound(row)"
type="link"
size="small"
@click="openOrderFlow(row, 'sync')"
>
订单数据流
</Button>
<PermissionGate code="channel:pdd:goods:sync">
<Button
type="link"
@@ -325,6 +425,10 @@ async function handleSyncGoods(row: PddShopVO.Info) {
</Grid>
<PddShopDetailModal ref="shopDetailModalRef" />
<ShopOrderPipelineDrawer
ref="pipelineDrawerRef"
@success="onPipelineSuccess"
/>
</Page>
</template>
@@ -337,4 +441,13 @@ async function handleSyncGoods(row: PddShopVO.Info) {
:deep(.pdd-shop-grid .vxe-body--column) {
vertical-align: middle;
}
:deep(.pdd-shop-grid .vxe-body--row) {
height: 118px !important;
}
:deep(.pdd-shop-grid .vxe-cell) {
max-height: none;
overflow: visible;
}
</style>
@@ -2,8 +2,8 @@
/**
* 店铺订单管线抽屉:同步 / 转换 / 计算 三阶段合一。
* 顶区状态+动作;历史全量任务用紧凑表;创建全量内联,不再套第二层弹窗。
* shopId 为经营店铺 id(API 约定);可由渠道店页传入仅含 id/name 的引用。
*/
import type { ShopVO } from '#/api/ec/shop/types';
import type { PddOrderSyncVO } from '#/api/channel/pdd/order-sync';
import type { PddOrderConvertVO } from '#/api/channel/pdd/order-convert';
import type { BiOrderStatCalcVO } from '#/api/bi/order-stat-calc';
@@ -56,7 +56,26 @@ import { useRealtimeStore } from '#/store';
defineOptions({ name: 'ShopOrderPipelineDrawer' });
type PipelineStageKey = 'calc' | 'convert' | 'sync';
export type PipelineStageKey = 'calc' | 'convert' | 'sync';
/** 管线抽屉店铺引用:至少经营店 id + 展示名 */
export type PipelineShopRef = {
id: number;
name: string;
};
export type PipelineDrawerOpenOptions = {
/** 可切换阶段;默认同步/转换/计算全开 */
stages?: PipelineStageKey[];
};
const ALL_STAGES: PipelineStageKey[] = ['sync', 'convert', 'calc'];
const STAGE_LABEL: Record<PipelineStageKey, string> = {
sync: '同步',
convert: '转换',
calc: '计算',
};
const emit = defineEmits<{ success: [] }>();
@@ -82,7 +101,8 @@ type FullTaskRow = {
};
const openFlag = ref(false);
const shop = ref<null | ShopVO.Info>(null);
const shop = ref<null | PipelineShopRef>(null);
const enabledStages = ref<PipelineStageKey[]>([...ALL_STAGES]);
const stage = ref<PipelineStageKey>('sync');
const pageLoading = ref(false);
@@ -122,11 +142,14 @@ const title = computed(() =>
shop.value ? `订单数据流 · ${shop.value.name}` : '订单数据流',
);
const stageOptions = [
{ label: '同步', value: 'sync' },
{ label: '转换', value: 'convert' },
{ label: '计算', value: 'calc' },
];
const stageOptions = computed(() =>
enabledStages.value.map((value) => ({
label: STAGE_LABEL[value],
value,
})),
);
const showStageTabs = computed(() => enabledStages.value.length > 1);
const hasActiveSyncTask = computed(() =>
syncTasks.value.some((t) => t.status === 'PENDING' || t.status === 'RUNNING'),
@@ -622,9 +645,18 @@ function handleClose() {
openFlag.value = false;
}
async function open(record: ShopVO.Info, initial: PipelineStageKey = 'sync') {
shop.value = record;
stage.value = initial;
async function open(
record: PipelineShopRef,
initial: PipelineStageKey = 'sync',
options?: PipelineDrawerOpenOptions,
) {
shop.value = { id: record.id, name: record.name };
const stages =
options?.stages && options.stages.length > 0
? options.stages
: [...ALL_STAGES];
enabledStages.value = stages;
stage.value = stages.includes(initial) ? initial : (stages[0] ?? 'sync');
syncInc.value = null;
syncTasks.value = [];
convertInc.value = null;
@@ -638,7 +670,7 @@ async function open(record: ShopVO.Info, initial: PipelineStageKey = 'sync') {
openFlag.value = true;
pageLoading.value = true;
try {
await loadStage(initial);
await loadStage(stage.value);
} finally {
pageLoading.value = false;
}
@@ -674,10 +706,17 @@ defineExpose({ open, close: handleClose });
>
<div class="flex h-full min-h-0 flex-col gap-4">
<Segmented
v-if="showStageTabs"
v-model:value="stage"
block
:options="stageOptions"
/>
<div
v-else
class="text-sm font-medium text-slate-700 dark:text-slate-200"
>
{{ STAGE_LABEL[stage] }}
</div>
<!-- 同步 -->
<div