feat(ecom): 订单管理新增批量删除功能

- OrderServiceImpl 新增 deleteOrders 批量删除接口,单次最多500条
- 新增 BatchDeleteOrderDTO 参数校验
- 前端订单列表新增勾选框,支持批量删除选中订单
- OssServiceImpl 简化上传逻辑,移除冗余代码
- 更新 OSS 凭证配置
This commit is contained in:
小蟑螂
2026-05-05 16:20:28 +08:00
parent 31dc0cb2a1
commit a1953d5447
12 changed files with 203 additions and 198 deletions
+2 -1
View File
@@ -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>
+8
View File
@@ -678,6 +678,9 @@ importers:
'@types/papaparse':
specifier: ^5.3.14
version: 5.3.16
'@types/spark-md5':
specifier: ^3.0.5
version: 3.0.5
internal/lint-configs/commitlint-config:
dependencies:
@@ -4051,6 +4054,9 @@ packages:
'@types/sortablejs@1.15.8':
resolution: {integrity: sha512-b79830lW+RZfwaztgs1aVPgbasJ8e7AXtZYHTELNXZPsERt4ymJdjV4OccDbHQAvHrCcFpbF78jkm0R6h/pZVg==}
'@types/spark-md5@3.0.5':
resolution: {integrity: sha512-lWf05dnD42DLVKQJZrDHtWFidcLrHuip01CtnC2/S6AMhX4t9ZlEUj4iuRlAnts0PQk7KESOqKxeGE/b6sIPGg==}
'@types/triple-beam@1.3.5':
resolution: {integrity: sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==}
@@ -13003,6 +13009,8 @@ snapshots:
'@types/sortablejs@1.15.8': {}
'@types/spark-md5@3.0.5': {}
'@types/triple-beam@1.3.5': {}
'@types/trusted-types@2.0.7': {}