feat: 调整店铺同步交互改用抽屉

This commit is contained in:
2026-08-11 09:53:35 +08:00
parent 58671f3bd6
commit 2fbc539b30
2 changed files with 42 additions and 28 deletions
@@ -5,11 +5,10 @@ import type { Dayjs } from 'dayjs';
import { computed, onBeforeUnmount, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import {
Button,
DatePicker,
Drawer,
Form,
message,
Progress,
@@ -32,14 +31,18 @@ import {
togglePddIncrementalSyncApi,
} from '#/api/ecommerce/pdd/order-sync';
defineOptions({ name: 'PddOrderSyncDrawer' });
interface Emits {
(e: 'success'): void;
}
const emit = defineEmits<Emits>();
const openFlag = ref(false);
const shop = ref<null | ShopVO.Info>(null);
const loading = ref(false);
const submitting = ref(false);
const mode = ref<'day' | 'full' | 'incremental'>('full');
const confirmDate = ref<Dayjs>(dayjs().subtract(1, 'day'));
const range = ref<[Dayjs, Dayjs]>([
@@ -50,19 +53,7 @@ const incremental = ref<null | PddOrderSyncVO.IncrementalStatus>(null);
const fullTask = ref<null | PddOrderSyncVO.FullTask>(null);
let pollTimer: null | ReturnType<typeof setInterval> = null;
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[560px]',
onCancel() {
stopPoll();
modalApi.close();
},
onConfirm() {
handleSubmit();
},
});
const modalTitle = computed(() =>
const drawerTitle = computed(() =>
shop.value ? `同步拼多多订单 - ${shop.value.name}` : '同步拼多多订单',
);
@@ -166,7 +157,7 @@ async function pollFullTask(taskId: number) {
task.status === 'CANCELLED'
) {
stopPoll();
modalApi.setState({ confirmLoading: false });
submitting.value = false;
loading.value = false;
if (task.status === 'SUCCESS') {
message.success(
@@ -207,7 +198,7 @@ async function handleResumeFull() {
if (!fullTask.value) return;
try {
loading.value = true;
modalApi.setState({ confirmLoading: true });
submitting.value = true;
const task = await resumePddFullSyncTaskApi(fullTask.value.id);
fullTask.value = task;
message.success('已续跑入队');
@@ -216,7 +207,7 @@ async function handleResumeFull() {
console.error('续跑全量任务失败:', error);
message.error('续跑全量任务失败');
loading.value = false;
modalApi.setState({ confirmLoading: false });
submitting.value = false;
}
}
@@ -236,7 +227,7 @@ async function handleSubmit() {
}
try {
loading.value = true;
modalApi.setState({ confirmLoading: true });
submitting.value = true;
if (mode.value === 'full') {
const task = await createPddFullSyncTaskApi({
@@ -269,11 +260,16 @@ async function handleSubmit() {
} finally {
if (mode.value !== 'full') {
loading.value = false;
modalApi.setState({ confirmLoading: false });
submitting.value = false;
}
}
}
function handleClose() {
stopPoll();
openFlag.value = false;
}
async function open(record: ShopVO.Info) {
shop.value = record;
mode.value = 'full';
@@ -281,18 +277,27 @@ async function open(record: ShopVO.Info) {
range.value = [dayjs().subtract(90, 'day'), dayjs().subtract(1, 'day')];
fullTask.value = null;
incremental.value = null;
submitting.value = false;
loading.value = false;
stopPoll();
modalApi.open();
openFlag.value = true;
await Promise.all([loadIncrementalStatus(), loadLatestFullTask()]);
}
onBeforeUnmount(() => stopPoll());
defineExpose({ open });
defineExpose({ open, close: handleClose });
</script>
<template>
<Modal :title="modalTitle" content-class="px-5 py-4">
<Drawer
v-model:open="openFlag"
:title="drawerTitle"
width="560"
destroy-on-close
:mask-closable="!isFullActive"
@close="handleClose"
>
<!-- 状态面板 -->
<div class="mb-4 space-y-3">
<div class="rounded border border-slate-200 p-3 dark:border-[hsl(240deg_3.7%_22%)]">
@@ -401,5 +406,14 @@ defineExpose({ open });
按订单更新时间拉取自上次游标以来的变更,用于发货/售后等状态同步。
</p>
</Form>
</Modal>
<template #footer>
<div class="flex justify-end gap-2">
<Button @click="handleClose">关闭</Button>
<Button type="primary" :loading="submitting" @click="handleSubmit">
开始同步
</Button>
</div>
</template>
</Drawer>
</template>
@@ -19,7 +19,7 @@ import { batchPddOrderSyncStatusApi } from '#/api/ecommerce/pdd/order-sync';
import { getPlatformListApi } from '#/api/ecommerce/platform';
import { deleteShopApi, getShopPageApi } from '#/api/ecommerce/shop';
import PddOrderSyncModal from './components/PddOrderSyncModal.vue';
import PddOrderSyncDrawer from './components/PddOrderSyncDrawer.vue';
import PddShopDetailModal from './components/PddShopDetailModal.vue';
import ShopFormModal from './components/ShopFormModal.vue';
@@ -33,7 +33,7 @@ const loading = ref(false);
const authorizing = ref(false);
const shopFormModalRef = ref();
const pddShopDetailModalRef = ref();
const pddOrderSyncModalRef = ref();
const pddOrderSyncDrawerRef = ref();
/** shopId -> 同步摘要 */
const syncStatusMap = ref<Record<number, PddOrderSyncVO.ShopStatus>>({});
@@ -367,7 +367,7 @@ function handleSyncPddOrders(record: ShopVO.Info) {
message.warning('请先完成拼多多授权绑定后再同步订单');
return;
}
pddOrderSyncModalRef.value?.open(record);
pddOrderSyncDrawerRef.value?.open(record);
}
function clearAuthPoll() {
@@ -526,7 +526,7 @@ onUnmounted(() => {
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
<PddShopDetailModal ref="pddShopDetailModalRef" />
<PddOrderSyncModal ref="pddOrderSyncModalRef" @success="handleModalSuccess" />
<PddOrderSyncDrawer ref="pddOrderSyncDrawerRef" @success="handleModalSuccess" />
</Page>
</template>