feat: 删除商品增加友好提示

This commit is contained in:
2026-08-31 22:08:47 +08:00
parent e889bc043a
commit c586120861
9 changed files with 252 additions and 34 deletions
@@ -0,0 +1,128 @@
<script lang="ts" setup>
import type { ShopVO } from '#/api/ec/shop/types';
import { computed, ref } from 'vue';
import { Alert, Input, Modal, Spin, message } from 'ant-design-vue';
import {
deleteShopApi,
getShopDeleteImpactApi,
} from '#/api/ec/shop';
defineOptions({ name: 'ShopDeleteConfirmModal' });
const CONFIRM_TEXT = '确认删除';
const open = ref(false);
const loadingImpact = ref(false);
const deleting = ref(false);
const confirmInput = ref('');
const shopId = ref<number>();
const shopName = ref('');
const impact = ref<null | ShopVO.DeleteImpact>(null);
const canConfirm = computed(
() => confirmInput.value.trim() === CONFIRM_TEXT && !deleting.value,
);
const emit = defineEmits<{
success: [];
}>();
async function openModal(shop: { id: number; name: string }) {
shopId.value = shop.id;
shopName.value = shop.name;
confirmInput.value = '';
impact.value = null;
open.value = true;
loadingImpact.value = true;
try {
impact.value = await getShopDeleteImpactApi(shop.id);
} catch (error) {
console.error('获取删除影响失败:', error);
message.error('获取删除影响失败');
open.value = false;
} finally {
loadingImpact.value = false;
}
}
function handleCancel() {
if (deleting.value) return;
open.value = false;
}
async function handleOk() {
if (!canConfirm.value || shopId.value == null) {
return Promise.reject(new Error('confirm required'));
}
deleting.value = true;
try {
await deleteShopApi(shopId.value);
message.success('删除成功');
open.value = false;
emit('success');
} catch (error) {
console.error('删除店铺失败:', error);
message.error('删除店铺失败');
return Promise.reject(error);
} finally {
deleting.value = false;
}
}
defineExpose({ open: openModal });
</script>
<template>
<Modal
v-model:open="open"
title="删除店铺"
ok-text="永久删除"
ok-type="danger"
:ok-button-props="{ disabled: !canConfirm, loading: deleting }"
:cancel-button-props="{ disabled: deleting }"
:mask-closable="!deleting"
destroy-on-close
@ok="handleOk"
@cancel="handleCancel"
>
<Spin :spinning="loadingImpact">
<Alert
type="error"
show-icon
class="mb-4"
message="此操作不可恢复"
description="将永久删除该店铺及其下业务数据(订单明细随订单一并清除)。"
/>
<p class="mb-2 text-sm">
即将删除店铺
<strong>{{ shopName || impact?.shopName }}</strong>
(ID: {{ shopId }})
</p>
<ul class="mb-4 list-disc space-y-1 pl-5 text-sm text-muted-foreground">
<li>订单:{{ impact?.orderCount ?? '—' }} 条(含订单明细)</li>
<li>商品广告费:{{ impact?.adFeeCount ?? '—' }} 条</li>
<li>刷单费:{{ impact?.fakeOrdersFeeCount ?? '—' }} 条</li>
<li>月销量目标:{{ impact?.monthlyTargetCount ?? '—' }} 条</li>
<li>相关同步 / 计算任务等也会级联清除</li>
</ul>
<p class="mb-2 text-sm">
请在下方输入框中输入
<span class="font-semibold text-red-500">{{ CONFIRM_TEXT }}</span>
以确认删除:
</p>
<Input
v-model:value="confirmInput"
:placeholder="`请输入 ${CONFIRM_TEXT}`"
:disabled="deleting || loadingImpact"
allow-clear
@press-enter="handleOk"
/>
</Spin>
</Modal>
</template>
@@ -10,7 +10,7 @@ import { computed, onMounted, onUnmounted, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space, Steps, Tag } from 'ant-design-vue';
import { Button, message, Space, Steps, Tag } from 'ant-design-vue';
import dayjs from 'dayjs';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
@@ -19,7 +19,7 @@ import { batchPddOrderSyncStatusApi } from '#/api/channel/pdd/order-sync';
import { batchPddAdFeePipelineStatusApi } from '#/api/channel/pdd/goods-ad-fee-import';
import type { PddGoodsAdFeeImportVO } from '#/api/channel/pdd/goods-ad-fee-import';
import { getPlatformListApi } from '#/api/ec/platform';
import { deleteShopApi, getShopPageApi } from '#/api/ec/shop';
import { getShopPageApi } from '#/api/ec/shop';
import { PermissionGate } from '#/components/permission';
import {
syncVxeGridColumns,
@@ -30,6 +30,7 @@ import {
getPlatformTagColor,
} from '#/utils/platform-display';
import ShopDeleteConfirmModal from '../components/ShopDeleteConfirmModal.vue';
import ShopFormModal from './components/ShopFormModal.vue';
import ShopOrderPipelineDrawer from './components/ShopOrderPipelineDrawer.vue';
import ShopAdFeePipelineDrawer from './components/ShopAdFeePipelineDrawer.vue';
@@ -44,6 +45,7 @@ const PlusIcon = createIconifyIcon('lucide:plus');
const loading = ref(false);
const authorizing = ref(false);
const shopFormModalRef = ref();
const shopDeleteModalRef = ref<InstanceType<typeof ShopDeleteConfirmModal>>();
const pddShopDetailModalRef = ref();
const pipelineDrawerRef = ref<InstanceType<typeof ShopOrderPipelineDrawer>>();
const adFeePipelineDrawerRef = ref<InstanceType<typeof ShopAdFeePipelineDrawer>>();
@@ -612,15 +614,8 @@ function handleEdit(record: ShopListRow) {
shopFormModalRef.value?.open(true, asShopInfo(record));
}
async function handleDelete(record: ShopListRow) {
try {
await deleteShopApi(record.id);
message.success('删除成功');
refreshTable();
} catch (error) {
console.error('删除店铺失败:', error);
message.error('删除店铺失败');
}
function handleDelete(record: ShopListRow) {
shopDeleteModalRef.value?.open({ id: record.id, name: record.name });
}
function handleModalSuccess() {
@@ -865,18 +860,17 @@ onUnmounted(() => {
<Button size="small" @click="handleEdit(row)">编辑</Button>
</PermissionGate>
<PermissionGate code="ec:shop:delete">
<Popconfirm
title="确定要删除这个店铺吗?"
@confirm="handleDelete(row)"
>
<Button size="small" danger>删除</Button>
</Popconfirm>
<Button size="small" danger @click="handleDelete(row)">删除</Button>
</PermissionGate>
</Space>
</template>
</Grid>
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
<ShopDeleteConfirmModal
ref="shopDeleteModalRef"
@success="handleModalSuccess"
/>
<PddShopDetailModal ref="pddShopDetailModalRef" />
<ShopOrderPipelineDrawer
ref="pipelineDrawerRef"
@@ -14,15 +14,15 @@ import {
Input,
message,
Pagination,
Popconfirm,
Spin,
Tag,
} from 'ant-design-vue';
import { deleteShopApi, getShopPageApi } from '#/api/ec/shop';
import { getShopPageApi } from '#/api/ec/shop';
import { getPlatformListApi } from '#/api/ec/platform/apis';
import type { PlatformVO } from '#/api/ec/platform/types';
import ShopDeleteConfirmModal from '../components/ShopDeleteConfirmModal.vue';
import ShopFormModal from '../list/components/ShopFormModal.vue';
defineOptions({ name: 'ShopManagement' });
@@ -41,6 +41,7 @@ const searchName = ref('');
const platformOptions = ref<{ label: string; value: string }[]>([]);
const shopFormModalRef = ref();
const shopDeleteModalRef = ref<InstanceType<typeof ShopDeleteConfirmModal>>();
async function fetchShops() {
loading.value = true;
@@ -71,14 +72,8 @@ function handleEdit(record: ShopVO.Info) {
shopFormModalRef.value?.open(true, record);
}
async function handleDelete(record: ShopVO.Info) {
try {
await deleteShopApi(record.id);
message.success('删除成功');
void fetchShops();
} catch {
message.error('删除失败');
}
function handleDelete(record: ShopVO.Info) {
shopDeleteModalRef.value?.open({ id: record.id, name: record.name });
}
function handleModalSuccess() {
@@ -199,12 +194,9 @@ onMounted(async () => {
<Button size="small" type="link" @click="handleEdit(shop)">
编辑
</Button>
<Popconfirm
title="确定删除这个店铺?"
@confirm="handleDelete(shop)"
>
<Button size="small" type="link" danger>删除</Button>
</Popconfirm>
<Button size="small" type="link" danger @click="handleDelete(shop)">
删除
</Button>
</div>
</div>
</Card>
@@ -230,5 +222,9 @@ onMounted(async () => {
</div>
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
<ShopDeleteConfirmModal
ref="shopDeleteModalRef"
@success="handleModalSuccess"
/>
</Page>
</template>