diff --git a/.env b/.env index 3aa6b6f..389397f 100644 --- a/.env +++ b/.env @@ -1,10 +1,10 @@ # 所有环境的环境变量(命名必须以 VITE_ 开头) ## 项目标题 -VITE_APP_TITLE = 微商店 +VITE_APP_TITLE = 借还柜 ## 路由模式 hash 或 html5 VITE_ROUTER_HISTORY = hash ## 是否开启 console 调试工具 -VITE_CONSOLE = true +VITE_CONSOLE = false diff --git a/.vscode/settings.json b/.vscode/settings.json index 8bc8445..6fe2f5a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -52,7 +52,7 @@ ], "marscode.chatLanguage": "cn", "marscode.codeCompletionPro": { - "enableCodeCompletionPro": true + "enableCodeCompletionPro": false }, "marscode.enableInlineCommand": true } diff --git a/src/common/apis/shop/index.ts b/src/common/apis/shop/index.ts index 985f795..875e72d 100644 --- a/src/common/apis/shop/index.ts +++ b/src/common/apis/shop/index.ts @@ -1,5 +1,5 @@ import { request } from "@/http/axios" -import { ShopGoodsResponseData, SubmitOrderRequestData, SubmitOrderResponseData } from './type' +import { GetOrdersByOpenIdDTO, ShopGoodsResponseData, SubmitOrderRequestData, SubmitOrderResponseData } from './type' import { GetOpenIdRequestParams } from './type' @@ -22,9 +22,17 @@ export function submitOrderApi(data: SubmitOrderRequestData) { /** 获取微信openid */ export function getOpenIdApi(params: GetOpenIdRequestParams) { - return request({ + return request>({ url: "payment/getOpenId", method: "get", - params // 使用params传递code参数,对应Java的@RequestParam + params + }) +} + +/** 根据openid获取用户订单信息 */ +export function getOrdersByOpenIdApi(openid: string) { + return request>({ + url: `order/user/${openid}`, + method: "get" }) } \ No newline at end of file diff --git a/src/common/apis/shop/type.ts b/src/common/apis/shop/type.ts index 892c921..f38efcd 100644 --- a/src/common/apis/shop/type.ts +++ b/src/common/apis/shop/type.ts @@ -38,8 +38,7 @@ export interface WxJsApiPreCreateResponse { appId: string timeStamp: string nonceStr: string - /** @JsonProperty("package") */ - packageValue: string + package: string signType: string paySign: string } @@ -47,3 +46,29 @@ export interface WxJsApiPreCreateResponse { export interface GetOpenIdRequestParams { code: string } + +export interface ShopOrderEntity { + orderId: number + openid: string + totalAmount: number + status: number + payStatus: number + paymentMethod: string + payTime: string +} + +export interface ShopOrderGoodsEntity { + orderGoodsId: number + orderId: number + goodsId: number + quantity: number + price: number + totalAmount: number + status: number +} + +export interface GetOrdersByOpenIdDTO { + orders: ShopOrderEntity[] + orderGoods: ShopOrderGoodsEntity[] + goods: Goods[] +} diff --git a/src/pages/order/Success.vue b/src/pages/order/Success.vue new file mode 100644 index 0000000..fe50bf9 --- /dev/null +++ b/src/pages/order/Success.vue @@ -0,0 +1,74 @@ + + + + + \ No newline at end of file diff --git a/src/pages/product/components/checkout.vue b/src/pages/product/components/checkout.vue index 2c69339..ace407a 100644 --- a/src/pages/product/components/checkout.vue +++ b/src/pages/product/components/checkout.vue @@ -28,9 +28,9 @@ function callWxJsApi(paymentInfo: WxJsApiPreCreateResponse) { appId: paymentInfo.appId, timeStamp: paymentInfo.timeStamp, nonceStr: paymentInfo.nonceStr, - package: paymentInfo.packageValue.startsWith('prepay_id=') - ? paymentInfo.packageValue - : `prepay_id=${paymentInfo.packageValue}`, + package: paymentInfo.package.startsWith('prepay_id=') + ? paymentInfo.package + : `prepay_id=${paymentInfo.package}`, signType: paymentInfo.signType, paySign: paymentInfo.paySign }, @@ -81,16 +81,21 @@ async function handleSubmit() { // 调用提交订单接口 const { data } = await submitOrderApi(requestData) - await showConfirmDialog({ - title: "提交成功", - message: `订单号:${data.orderId},正在跳转支付...` - }) + // await showConfirmDialog({ + // title: "提交成功", + // message: `订单号:${data.orderId},正在跳转支付...` + // }) // 调用微信支付 if (data.paymentInfo) { await callWxJsApi(data.paymentInfo); // 支付成功后跳转 - router.push('/order-success'); + router.push({ + path: '/order-success', + query: { + orderId: data.orderId + } + }); } else { throw new Error('无法获取支付信息'); } diff --git a/src/pinia/stores/wx.ts b/src/pinia/stores/wx.ts index c5340bd..ac7f4f5 100644 --- a/src/pinia/stores/wx.ts +++ b/src/pinia/stores/wx.ts @@ -37,8 +37,8 @@ export const useWxStore = defineStore("wx", () => { // 调用获取 openid 的接口 const res = await getOpenIdApi({ code: params.code }) console.log('获取 openid 成功:', res) - if (res) { - openid.value = res + if (res && res.code == 0) { + openid.value = res.data } } catch (err) { console.error('获取 openid 失败:', err) diff --git a/src/router/index.ts b/src/router/index.ts index 3a52379..3b974ee 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -29,6 +29,14 @@ export const systemRoutes: RouteRecordRaw[] = [ /** 业务页面 */ export const routes: RouteRecordRaw[] = [ + { + path: '/order-success', + name: 'OrderSuccess', + component: () => import('@/pages/order/Success.vue'), + meta: { + requiresAuth: true + } + }, { path: "/product/checkout", component: () => import("@/pages/product/components/checkout.vue"), @@ -55,6 +63,14 @@ export const routes: RouteRecordRaw[] = [ ] /* export const routes: RouteRecordRaw[] = [ + { + path: '/order-success', + name: 'OrderSuccess', + component: () => import('@/pages/order/Success.vue'), + meta: { + requiresAuth: true + } + }, { path: "/login", component: () => import("@/pages/login/index.vue"),