mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:49:20 +08:00
feat(ecom): 订单管理新增批量删除功能
- OrderServiceImpl 新增 deleteOrders 批量删除接口,单次最多500条 - 新增 BatchDeleteOrderDTO 参数校验 - 前端订单列表新增勾选框,支持批量删除选中订单 - OssServiceImpl 简化上传逻辑,移除冗余代码 - 更新 OSS 凭证配置
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
"vue-waterfall-plugin-next": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/papaparse": "^5.3.14"
|
||||
"@types/papaparse": "^5.3.14",
|
||||
"@types/spark-md5": "^3.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,13 @@ export async function deleteOrderApi(id: number) {
|
||||
return requestClient.delete(`/ec/order/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除订单
|
||||
*/
|
||||
export async function batchDeleteOrdersApi(data: OrderDTO.BatchDelete) {
|
||||
return requestClient.post('/ec/order/batch-delete', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单详情
|
||||
*/
|
||||
|
||||
@@ -98,4 +98,10 @@ export namespace OrderDTO {
|
||||
/** 订单列表 */
|
||||
orders: Create[];
|
||||
}
|
||||
|
||||
/** 批量删除订单参数 */
|
||||
export interface BatchDelete {
|
||||
/** 订单ID列表 */
|
||||
orderIds: number[];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,18 +65,34 @@ async function uploadFileToOssWithHeaderSignature(
|
||||
uploadUrl: string,
|
||||
uploadHeaders: Record<string, string>,
|
||||
): Promise<void> {
|
||||
const headers: Record<string, string> = {
|
||||
...uploadHeaders,
|
||||
};
|
||||
const headers: Record<string, string> = { ...uploadHeaders };
|
||||
const contentType =
|
||||
headers['Content-Type'] ?? headers['content-type'] ?? '';
|
||||
|
||||
// OSS4 预签名 PUT 与 Content-Type 严格一致;File 作 body 时浏览器会按 file.type 自动带头,易 403。
|
||||
const body =
|
||||
contentType !== '' ? await file.arrayBuffer() : file;
|
||||
if (contentType !== '') {
|
||||
headers['Content-Type'] = contentType;
|
||||
delete headers['content-type'];
|
||||
}
|
||||
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'PUT',
|
||||
body: file,
|
||||
body,
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`上传失败: ${response.status} ${response.statusText}`);
|
||||
let detail = '';
|
||||
try {
|
||||
detail = (await response.text()).slice(0, 300);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
throw new Error(
|
||||
`上传失败: ${response.status} ${response.statusText}${detail ? ` — ${detail}` : ''}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,11 @@ import {
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteOrderApi, getOrderPageApi } from '#/api/ecommerce/order';
|
||||
import {
|
||||
batchDeleteOrdersApi,
|
||||
deleteOrderApi,
|
||||
getOrderPageApi,
|
||||
} from '#/api/ecommerce/order';
|
||||
import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
import { getProductPageApi } from '#/api/ecommerce/product';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
@@ -47,6 +51,9 @@ function goToProductDetail(productId: number) {
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const batchDeleteLoading = ref(false);
|
||||
/** vxe 勾选不触发 Vue 依赖,须用事件同步,勿用 computed 读 getCheckboxRecords */
|
||||
const hasSelected = ref(false);
|
||||
const orderFormModalRef = ref();
|
||||
|
||||
// 店铺分页数据
|
||||
@@ -200,12 +207,21 @@ function handleProductPopupScroll(e: Event) {
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
reserve: false,
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
type: 'checkbox' as const,
|
||||
width: 48,
|
||||
fixed: 'left' as const,
|
||||
},
|
||||
{
|
||||
field: 'platformOrderNo',
|
||||
title: '平台订单号',
|
||||
@@ -500,6 +516,7 @@ const formOptions = computed(() => ({
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
hasSelected.value = false;
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
@@ -541,6 +558,18 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '订单管理',
|
||||
gridEvents: {
|
||||
checkboxChange() {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
const rows = vxeTable?.getCheckboxRecords?.() ?? [];
|
||||
hasSelected.value = rows.length > 0;
|
||||
},
|
||||
checkboxAll() {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
const rows = vxeTable?.getCheckboxRecords?.() ?? [];
|
||||
hasSelected.value = rows.length > 0;
|
||||
},
|
||||
},
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
@@ -566,6 +595,35 @@ async function handleDelete(record: OrderVO.Info) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleBatchDelete() {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
const selectedRows: OrderVO.Info[] = vxeTable?.getCheckboxRecords?.() ?? [];
|
||||
if (!selectedRows.length) {
|
||||
message.warning('请选择要删除的订单');
|
||||
return;
|
||||
}
|
||||
const orderIds = selectedRows.map((r) => r.id).filter((id) => id != null);
|
||||
if (!orderIds.length) {
|
||||
message.warning('所选行缺少订单ID');
|
||||
return;
|
||||
}
|
||||
batchDeleteLoading.value = true;
|
||||
try {
|
||||
await batchDeleteOrdersApi({ orderIds });
|
||||
message.success(`已删除 ${orderIds.length} 条订单`);
|
||||
vxeTable?.clearCheckboxRow?.();
|
||||
hasSelected.value = false;
|
||||
await gridApi.reload();
|
||||
} catch (error: any) {
|
||||
console.error('批量删除订单失败:', error);
|
||||
const msg =
|
||||
error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(msg);
|
||||
} finally {
|
||||
batchDeleteLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
@@ -588,6 +646,18 @@ onMounted(async () => {
|
||||
<PlusIcon />
|
||||
添加订单
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定删除选中的订单吗?删除后不可恢复。"
|
||||
ok-text="确定删除"
|
||||
cancel-text="取消"
|
||||
:ok-button-props="{ danger: true, loading: batchDeleteLoading }"
|
||||
:disabled="!hasSelected"
|
||||
@confirm="handleBatchDelete"
|
||||
>
|
||||
<Button danger :disabled="!hasSelected" :loading="batchDeleteLoading">
|
||||
批量删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user