From 547db6124840d7b4452d820106d71b5857350d30 Mon Sep 17 00:00:00 2001 From: dqz Date: Tue, 4 Mar 2025 17:17:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/img/{31.jpg => 1.jpg} | Bin public/img/{32.jpg => 2.jpg} | Bin public/img/{33.jpg => 3.jpg} | Bin src/api/shop/category.ts | 66 +++++++++++ src/api/shop/goods.ts | 2 +- src/views/shop/goods/goods-form-modal.vue | 134 +++++++++++++++------- src/views/shop/goods/index.vue | 65 +++++++++-- 7 files changed, 217 insertions(+), 50 deletions(-) rename public/img/{31.jpg => 1.jpg} (100%) rename public/img/{32.jpg => 2.jpg} (100%) rename public/img/{33.jpg => 3.jpg} (100%) create mode 100644 src/api/shop/category.ts diff --git a/public/img/31.jpg b/public/img/1.jpg similarity index 100% rename from public/img/31.jpg rename to public/img/1.jpg diff --git a/public/img/32.jpg b/public/img/2.jpg similarity index 100% rename from public/img/32.jpg rename to public/img/2.jpg diff --git a/public/img/33.jpg b/public/img/3.jpg similarity index 100% rename from public/img/33.jpg rename to public/img/3.jpg diff --git a/src/api/shop/category.ts b/src/api/shop/category.ts new file mode 100644 index 0000000..4add2d1 --- /dev/null +++ b/src/api/shop/category.ts @@ -0,0 +1,66 @@ +import { http } from "@/utils/http"; + +export interface CategoryQuery extends BasePageQuery { + categoryName?: string; + sort?: number; +} + +/** 分类DTO */ +export interface CategoryDTO { + categoryId?: number; + categoryName?: string; + sort?: number; + description?: string; + creatorId?: number; + createTime?: Date; + updaterId?: number; + updateTime?: Date; + deleted?: number; +} + +/** 分类请求参数 */ +export interface CategoryRequest { + categoryName: string; + sort: number; + description?: string; +} + +/** 获取分类列表 */ +export const getCategoryListApi = (params?: CategoryQuery) => { + return http.request>>("get", "/shop/category/list", { + params + }); +}; + +/** 获取分类列表 */ +export const getCategoryAllApi = () => { + return http.request>>("get", "/shop/category/all", { + + }); +}; + +/** 新增分类 */ +export const addCategoryApi = (data: CategoryRequest) => { + return http.request>("post", "/shop/category", { + data + }); +}; + +/** 编辑分类 */ +export const updateCategoryApi = (categoryId: number, data: CategoryRequest) => { + return http.request>("put", `/shop/category/${categoryId}`, { + data + }); +}; + +/** 删除分类 */ +export const deleteCategoryApi = (categoryId: number) => { + return http.request>("delete", `/shop/category/${categoryId}`); +}; + +/** 批量导出分类 */ +export const exportCategoryExcelApi = (params: CategoryQuery, fileName: string) => { + return http.download("/shop/category/excel", fileName, { + params + }); +}; diff --git a/src/api/shop/goods.ts b/src/api/shop/goods.ts index 7461b52..d5501ad 100644 --- a/src/api/shop/goods.ts +++ b/src/api/shop/goods.ts @@ -59,7 +59,7 @@ export const updateGoodsApi = (goodsId: number, data: GoodsRequest) => { }; /** 删除商品 */ -export const deleteGoodsApi = (goodsId: number) => { +export const deleteGoodsApi = (goodsId: number | string) => { return http.request>("delete", `/shop/goods/${goodsId}`); }; diff --git a/src/views/shop/goods/goods-form-modal.vue b/src/views/shop/goods/goods-form-modal.vue index a6e4478..c2699ef 100644 --- a/src/views/shop/goods/goods-form-modal.vue +++ b/src/views/shop/goods/goods-form-modal.vue @@ -1,9 +1,12 @@ \ No newline at end of file + + + \ No newline at end of file diff --git a/src/views/shop/goods/index.vue b/src/views/shop/goods/index.vue index b40b41e..668c975 100644 --- a/src/views/shop/goods/index.vue +++ b/src/views/shop/goods/index.vue @@ -9,6 +9,8 @@ import AddFill from "@iconify-icons/ri/add-circle-line"; import Search from "@iconify-icons/ep/search"; import Refresh from "@iconify-icons/ep/refresh"; import GoodsFormModal from "./goods-form-modal.vue"; +import { ElMessage, ElMessageBox } from "element-plus"; +import { deleteGoodsApi } from "@/api/shop/goods"; defineOptions({ name: "ShopGoods" @@ -34,6 +36,7 @@ const pagination = ref({ // 加载数据 const loading = ref(false); const dataList = ref([]); +const multipleSelection = ref([]); const getList = async () => { try { @@ -45,6 +48,7 @@ const getList = async () => { }); dataList.value = data.rows; pagination.value.total = data.total; + } finally { loading.value = false; } @@ -77,6 +81,40 @@ const onCurrentChange = (val: number) => { // 初始化加载 getList(); + +const handleDelete = async (row: any) => { + try { + await deleteGoodsApi(row.goodsId); + ElMessage.success("删除成功"); + getList(); + } catch (error) { + console.error("删除失败", error); + } +}; + +const handleBulkDelete = async () => { + if (multipleSelection.value.length === 0) return; + + try { + await ElMessageBox.confirm( + `确认删除选中的${multipleSelection.value.length}项商品吗?`, + "警告", + { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" } + ); + + await deleteGoodsApi(multipleSelection.value.join(",")); + ElMessage.success("批量删除成功"); + multipleSelection.value = []; + getList(); + } catch (error) { + console.error("删除取消或失败", error); + } +}; + +// 在表格绑定选择事件 +const handleSelectionChange = (rows: any[]) => { + multipleSelection.value = rows.map(row => row.goodsId); +}; - - + + @@ -133,9 +174,13 @@ getList(); 编辑 - - 删除 - + + + @@ -143,6 +188,8 @@ getList(); :page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total" @size-change="onSizeChange" @current-change="onCurrentChange" /> + +