diff --git a/src/apis/order.ts b/src/apis/order.ts new file mode 100644 index 0000000..e5ff40b --- /dev/null +++ b/src/apis/order.ts @@ -0,0 +1,25 @@ +import http from "../utils/http"; +import type { + // OrderListItem, + OrderDetail, + OrderPageParams, + OrderPageResponse, +} from "@/types/order"; + +// 获取订单列表 +export const getOrderList = (params: OrderPageParams) => { + return http({ + url: "/order/page", + method: "get", + params, + }); +}; + +// 获取订单详情 +export const getOrderDetail = (id: number, userId: number) => { + return http({ + url: `/order/${id}`, + method: "get", + params: { userId }, + }); +}; diff --git a/src/apis/product.ts b/src/apis/product.ts index 29a1c78..8937d69 100644 --- a/src/apis/product.ts +++ b/src/apis/product.ts @@ -1,14 +1,41 @@ import http from "../utils/http"; +import type { + // ProductListItem, + ProductCategory, + ProductDetail, + ProductPageParams, + ProductPageResponse, +} from "@/types/product"; -export const addProduct = (data: { - name: string; - price: number; - description: string; - image: string; -}) => { - return http({ - url: "/product", - method: "post", - data, +// 获取商品列表 +export const getProductList = (params: ProductPageParams) => { + return http({ + url: "/product/page", + method: "get", + params, + }); +}; + +// 获取商品分类 +export const getProductCategories = () => { + return http({ + url: "/product/category", + method: "get", + }); +}; + +// 获取子分类 +export const getProductSubCategories = (id: number) => { + return http({ + url: `/product/category/${id}`, + method: "get", + }); +}; + +// 获取商品详情 +export const getProductDetail = (id: number) => { + return http({ + url: `/product/${id}`, + method: "get", }); }; diff --git a/src/apis/shoppingcart.ts b/src/apis/shoppingcart.ts new file mode 100644 index 0000000..4b618e6 --- /dev/null +++ b/src/apis/shoppingcart.ts @@ -0,0 +1,47 @@ +import http from "../utils/http"; +import type { ShoppingCartItem, ShoppingCartDTO } from "@/types/shoppingcart"; + +// 获取用户购物车列表 +export const getUserCartList = (userId: number) => { + return http({ + url: "/cart", + method: "get", + params: { userId }, + }); +}; + +// 添加商品到购物车 +export const addCart = (data: ShoppingCartDTO) => { + return http({ + url: "/cart", + method: "post", + data, + }); +}; + +// 更新购物车商品数量 +export const updateCartCount = (data: ShoppingCartDTO) => { + return http({ + url: "/cart/count", + method: "put", + data, + }); +}; + +// 更新购物车商品勾选状态 +export const updateCartChecked = (data: ShoppingCartDTO) => { + return http({ + url: "/cart/checked", + method: "put", + data, + }); +}; + +// 删除购物车商品 +export const deleteCart = (id: number, userId: number) => { + return http({ + url: `/cart/${id}`, + method: "delete", + params: { userId }, + }); +}; diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index 4a101bc..6337076 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -66,16 +66,19 @@ const goToProfile = () => { 商品分类购买商品 购物车 我的订单 { 商品分类购买商品 购物车 + +
+ + + +
+ +
+ +
+ +
+ + + + + + + + + + + + + + +
+ + +
+ +
+
+
+
+ + + +
+

订单信息

+ + + {{ currentOrder.orderNo }} + + + {{ formatDate(currentOrder.createTime) }} + + + {{ getOrderStatusText(currentOrder.status) }} + + + {{ getPayTypeText(currentOrder.payType) }} + + + ¥{{ currentOrder.totalAmount.toFixed(2) }} + + + ¥{{ currentOrder.payAmount.toFixed(2) }} + + + +

收货信息

+ + + {{ currentOrder.receiverName }} + + + {{ currentOrder.receiverPhone }} + + + {{ currentOrder.receiverAddress }} + + + +

商品信息

+
+ + + + + + + + + + + + + + + +
+
+ + +
+
+ + + + + diff --git a/src/pages/product/DetailPage.vue b/src/pages/product/DetailPage.vue new file mode 100644 index 0000000..9196b7b --- /dev/null +++ b/src/pages/product/DetailPage.vue @@ -0,0 +1,383 @@ + + + + + diff --git a/src/pages/product/ProductPage.vue b/src/pages/product/ProductPage.vue new file mode 100644 index 0000000..cffcf78 --- /dev/null +++ b/src/pages/product/ProductPage.vue @@ -0,0 +1,596 @@ + + + + + diff --git a/src/pages/shoppingcart/ContentPage.vue b/src/pages/shoppingcart/ContentPage.vue new file mode 100644 index 0000000..a497308 --- /dev/null +++ b/src/pages/shoppingcart/ContentPage.vue @@ -0,0 +1,407 @@ + + + + + diff --git a/src/router/index.ts b/src/router/index.ts index 0889fa2..3f6a9c3 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -30,10 +30,10 @@ function formatPathFromComponentName(name: string): string { * @param filePath Path to the component file * @returns Component name without extension */ -function getComponentNameFromPath(filePath: string): string { - // Get the file name from the path - return filePath.split("/").pop() || ""; -} +// function getComponentNameFromPath(filePath: string): string { +// // Get the file name from the path +// return filePath.split("/").pop() || ""; +// } /** * Generate route path from full file path, preserving directory structure @@ -71,15 +71,17 @@ function generateRoutesFromPages(): RouteRecordRaw[] { const pages = import.meta.glob("@/pages/**/*.vue"); for (const path in pages) { - const componentName = getComponentNameFromPath(path); + // const componentName = getComponentNameFromPath(path); const routePath = generateRoutePathFromFilePath(path); // Special case for home page - const finalPath = routePath.toLowerCase() === "/home" ? "/" : routePath; + const finalPath = routePath.toLowerCase().endsWith("/home") + ? routePath.slice(0, -5) + : routePath; routes.push({ path: finalPath, - name: componentName, + name: routePath, component: pages[path], }); } @@ -97,6 +99,11 @@ const extraRoutes: RouteRecordRaw[] = [ name: "UserProfile", component: () => import("@/pages/user/ProfilePage.vue"), }, + { + path: "/product/detail/:id", + name: "ProductDetail", + component: () => import("@/pages/product/DetailPage.vue"), + }, // 可以在这里添加其他需要特殊配置的路由 ]; diff --git a/src/types/order.ts b/src/types/order.ts new file mode 100644 index 0000000..0d2a90a --- /dev/null +++ b/src/types/order.ts @@ -0,0 +1,64 @@ +// 订单列表项 +export interface OrderListItem { + id: number; + orderNo: string; + totalAmount: number; + payAmount: number; + status: number; + statusText: string; + createTime: string; + productCount: number; +} + +// 订单详情 +export interface OrderDetail { + id: number; + orderNo: string; + userId: number; + totalAmount: number; + payAmount: number; + freightAmount: number; + payType: number; + status: number; + receiverName: string; + receiverPhone: string; + receiverAddress: string; + payTime: string; + deliveryTime: string; + receiveTime: string; + createTime: string; + orderItems: OrderItem[]; +} + +// 订单项 +export interface OrderItem { + id: number; + orderId: number; + orderNo: string; + productId: number; + skuId: number; + productName: string; + skuName: string; + productImage: string; + price: number; + quantity: number; + totalPrice: number; + createTime: string; + updateTime: string; +} + +// 订单分页请求参数 +export interface OrderPageParams { + page: number; + size: number; + userId: number; + status?: number; +} + +// 订单分页响应数据 +export interface OrderPageResponse { + list: OrderListItem[]; + total: number; + page: number; + size: number; +} diff --git a/src/types/product.ts b/src/types/product.ts new file mode 100644 index 0000000..d130d90 --- /dev/null +++ b/src/types/product.ts @@ -0,0 +1,70 @@ +// 商品列表项 +export interface ProductListItem { + id: number; + name: string; + mainImage: string; + price: number; + sales: number; + status: number; + categoryName: string; +} + +// 商品详情 +export interface ProductDetail { + id: number; + categoryId: number; + categoryName: string; + name: string; + subtitle: string; + mainImage: string; + subImages: string; + description: string; + price: number; + stock: number; + sales: number; + status: number; + sort: number; + createTime: string; + updateTime: string; + skuList: ProductSku[]; +} + +// 商品SKU +export interface ProductSku { + id: number; + productId: number; + skuName: string; + skuCode: string; + price: number; + stock: number; + specJson: string; +} + +// 商品分类 +export interface ProductCategory { + id: number; + parentId: number; + name: string; + sort: number; + icon: string; + level: number; + createTime: string; + updateTime: string; +} + +// 商品分页请求参数 +export interface ProductPageParams { + page: number; + size: number; + categoryId?: number; + name?: string; + status?: number; +} + +// 商品分页响应数据 +export interface ProductPageResponse { + list: ProductListItem[]; + total: number; + page: number; + size: number; +} diff --git a/src/types/shoppingcart.ts b/src/types/shoppingcart.ts new file mode 100644 index 0000000..7a42499 --- /dev/null +++ b/src/types/shoppingcart.ts @@ -0,0 +1,24 @@ +// 购物车项目 +export interface ShoppingCartItem { + id: number; + userId: number; + productId: number; + skuId: number; + count: number; + checked: number; // 0-未勾选 1-已勾选 + productName: string; + productImage: string; + skuName: string; + price: number; + specJson: string; +} + +// 购物车DTO +export interface ShoppingCartDTO { + id?: number; + userId: number; + productId: number; + skuId: number; + count?: number; + checked?: number; +}