优化了页面显示效果,实现了商品删除功能
This commit is contained in:
@@ -161,6 +161,7 @@ import {
|
||||
saveProduct,
|
||||
updateProduct,
|
||||
updateProductStatus,
|
||||
deleteProductAPI,
|
||||
} from "@/apis/product";
|
||||
import { getUserList } from "@/apis/user"; // 导入获取用户列表的API
|
||||
import { ProductListItem, ProductCategory, ProductDTO } from "@/types/product";
|
||||
@@ -365,7 +366,7 @@ const toggleProductStatus = async (product: ProductListItem) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 删除商品(这里我们暂时用下架代替删除)
|
||||
// 删除商品
|
||||
const deleteProduct = async (product: ProductListItem) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
@@ -378,15 +379,15 @@ const deleteProduct = async (product: ProductListItem) => {
|
||||
},
|
||||
);
|
||||
|
||||
// 实际应用中应该调用删除API,这里我们使用下架来代替
|
||||
const response = await updateProductStatus(product.id, 0);
|
||||
// 调用删除商品API
|
||||
const response = await deleteProductAPI(product.id);
|
||||
|
||||
if (response.code === 200) {
|
||||
// 从本地数据中过滤掉已下架的商品
|
||||
// 从本地数据中删除商品
|
||||
products.value = products.value.filter((p) => p.id !== product.id);
|
||||
ElMessage.success("操作成功");
|
||||
ElMessage.success("删除成功");
|
||||
} else {
|
||||
ElMessage.error(response.message || "操作失败");
|
||||
ElMessage.error(response.message || "删除失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("删除商品错误:", error);
|
||||
|
||||
Reference in New Issue
Block a user