diff --git a/api/modules/order.ts b/api/modules/order.ts new file mode 100644 index 0000000..3fd6fe8 --- /dev/null +++ b/api/modules/order.ts @@ -0,0 +1,63 @@ +// api/modules/order.ts +import { mainClient } from '@/api/clients/main' +import type { IApiResponse } from '@/api/types' +import type { + ICreateOrderParams, + IGooglePayVerifyParams, + ICreateOrderResponse +} from '@/types/order' +import type { IUserInfo } from '@/types/user' + +/** + * 订单相关 API + */ +export const orderApi = { + /** + * 创建订单 + * @param data 订单数据 + */ + async createOrder(data: ICreateOrderParams) { + const res = await mainClient.request>({ + url: 'bookAbroad/order/placeOrder', + method: 'POST', + data + }) + return res + }, + + /** + * 验证 Google Pay 支付 + * @param params 支付验证参数 + */ + async verifyGooglePay(params: IGooglePayVerifyParams) { + const res = await mainClient.request({ + url: 'pay/googlepay/googleVerify', + method: 'POST', + data: params + }) + return res + }, + + /** + * 获取用户信息(包含虚拟币余额) + */ + async getUserInfo() { + const res = await mainClient.request>({ + url: 'common/user/getUserInfo', + method: 'POST' + }) + return res + }, + + /** + * 刷新用户信息 + * @param userId 用户ID + */ + async refreshUserInfo(userId: number) { + const res = await mainClient.request>({ + url: `book/user/info/${userId}`, + method: 'POST' + }) + return res + } +} diff --git a/components/book/BookCardIndex.vue b/components/book/BookCardIndex.vue index 184707a..f854793 100644 --- a/components/book/BookCardIndex.vue +++ b/components/book/BookCardIndex.vue @@ -75,11 +75,11 @@ const displayStats = computed(() => { if (!props.showStats) return '' if (props.book.readCount && props.book.readCount > 0) { - return `${props.book.readCount}${t('home.readingCount')}` + return `${props.book.readCount}${t('bookHome.readingCount')}` } if (props.book.buyCount && props.book.buyCount > 0) { - return `${props.book.buyCount}${t('home.purchased')}` + return `${props.book.buyCount}${t('bookHome.purchased')}` } return '' diff --git a/locale/en.json b/locale/en.json index ad9ba65..ea87230 100644 --- a/locale/en.json +++ b/locale/en.json @@ -231,6 +231,30 @@ "language": "Book language", "readAudio": "Loading audio..." }, + "bookOrder": { + "title": "Order Confirmation", + "bookInfo": "Book Information", + "amount": "Amount", + "paymentMethod": "Payment Method", + "googlePay": "Google Pay", + "virtualCoin": "Virtual Coin", + "balance": "Balance", + "confirm": "Confirm Order", + "creating": "Creating order...", + "processing": "Processing payment...", + "paymentSuccess": "Payment successful", + "paymentFailed": "Payment failed", + "paymentCancelled": "Payment cancelled", + "insufficientBalance": "Insufficient virtual coin balance", + "googlePayNotAvailable": "Google Pay not available", + "productNotFound": "Product not found", + "orderCreateFailed": "Failed to create order", + "verificationFailed": "Payment verification failed", + "pleaseWait": "Please wait...", + "doNotRepeat": "Please do not submit repeatedly", + "notMuch": "Insufficient balance", + "orderTitle": "Order Confirmation" + }, "bookDetails": { "title": "Book Details", "title_comment": "Reviews", @@ -257,7 +281,7 @@ "deleteText": "Delete this comment?", "deleteSuccess": "Deleted" }, - "home": { + "bookHome": { "block1": "My Books", "block2": "Recommended", "more": "More", @@ -275,7 +299,7 @@ "workOrder": { "submit_success": "Submitted successfully" }, - "course": { + "courseHome": { "title": "Course", "watchHistory": "Watch History", "tryListen": "Try Listening", diff --git a/locale/zh-Hans.json b/locale/zh-Hans.json index acd4c5a..6cc1dfd 100644 --- a/locale/zh-Hans.json +++ b/locale/zh-Hans.json @@ -258,7 +258,31 @@ "deleteText": "确定删除此评论吗?", "deleteSuccess": "删除成功" }, - "home": { + "bookOrder": { + "title": "订单确认", + "bookInfo": "图书信息", + "amount": "金额", + "paymentMethod": "支付方式", + "googlePay": "Google Pay", + "virtualCoin": "虚拟币", + "balance": "余额", + "confirm": "确认下单", + "creating": "创建订单中...", + "processing": "支付处理中...", + "paymentSuccess": "支付成功", + "paymentFailed": "支付失败", + "paymentCancelled": "支付已取消", + "insufficientBalance": "虚拟币余额不足", + "googlePayNotAvailable": "Google Pay 不可用", + "productNotFound": "商品未找到", + "orderCreateFailed": "订单创建失败", + "verificationFailed": "支付验证失败", + "pleaseWait": "请稍候...", + "doNotRepeat": "请勿重复提交", + "notMuch": "虚拟币余额不足", + "orderTitle": "订单确认" + }, + "bookHome": { "block1": "我的书单", "block2": "推荐图书", "more": "更多", @@ -276,7 +300,7 @@ "workOrder": { "submit_success": "提交成功" }, - "course": { + "courseHome": { "title": "课程", "watchHistory": "观看记录", "tryListen": "精彩试听", diff --git a/pages.json b/pages.json index ad9fe6d..3401bab 100644 --- a/pages.json +++ b/pages.json @@ -5,12 +5,6 @@ "style": { "navigationBarTitleText": "%index.title%" } - }, { - "path": "pages/component/component", - "style": { - "navigationBarTitleText": "%index.component%", - "enablePullDownRefresh": false - } }, { "path": "pages/login/login", "style": { @@ -107,7 +101,7 @@ "path": "pages/book/search", "style": { "navigationStyle": "custom", - "navigationBarTitleText": "%home.searchPlaceholder%" + "navigationBarTitleText": "%bookHome.searchPlaceholder%" } }, { "path": "pages/book/listen/index", @@ -121,6 +115,12 @@ "navigationStyle": "custom", "navigationBarTitleText": "%listen.title%" } + }, { + "path": "pages/book/order", + "style": { + "navigationStyle": "custom", + "navigationBarTitleText": "%order.orderTitle%" + } } ], "tabBar": { diff --git a/pages/book/detail.vue b/pages/book/detail.vue index dcee6e7..09a8ced 100644 --- a/pages/book/detail.vue +++ b/pages/book/detail.vue @@ -18,17 +18,17 @@ - {{ readCount }}{{ $t('home.readingCount') }} + {{ readCount }}{{ $t('bookHome.readingCount') }} - {{ listenCount }}{{ $t('home.listenCount') }} + {{ listenCount }}{{ $t('bookHome.listenCount') }} - {{ buyCount }}{{ $t('home.purchased') }} + {{ buyCount }}{{ $t('bookHome.purchased') }} diff --git a/pages/book/index.vue b/pages/book/index.vue index b377ee3..6614d5a 100644 --- a/pages/book/index.vue +++ b/pages/book/index.vue @@ -7,7 +7,7 @@ light clearable class="search-bar" - :placeholder="$t('home.searchPlaceholder')" + :placeholder="$t('bookHome.searchPlaceholder')" @search="handleSearch" /> @@ -25,13 +25,13 @@ - {{ $t('home.block1') }} + {{ $t('bookHome.block1') }} - {{ $t('home.more') }} + {{ $t('bookHome.more') }} @@ -50,7 +50,7 @@ - {{ $t('home.block2') }} + {{ $t('bookHome.block2') }} - {{ $t('home.activityTitle') }} + {{ $t('bookHome.activityTitle') }} { */ const formatStats = (book: IBookWithStats): string => { if (book.readCount && book.readCount > 0) { - return `${book.readCount}${t('home.readingCount')}` + return `${book.readCount}${t('bookHome.readingCount')}` } if (book.buyCount && book.buyCount > 0) { - return `${book.buyCount}${t('home.purchased')}` + return `${book.buyCount}${t('bookHome.purchased')}` } return '' diff --git a/pages/book/order.vue b/pages/book/order.vue index e69de29..ef585b5 100644 --- a/pages/book/order.vue +++ b/pages/book/order.vue @@ -0,0 +1,721 @@ + + + + + diff --git a/pages/book/search.vue b/pages/book/search.vue index 45378f2..a4d2a8e 100644 --- a/pages/book/search.vue +++ b/pages/book/search.vue @@ -158,11 +158,11 @@ const formatPrice = (book: IBookWithStats): string => { */ const formatStats = (book: IBookWithStats): string => { if (book.readCount && book.readCount > 0) { - return `${book.readCount}${t('home.readingCount')}` + return `${book.readCount}${t('bookHome.readingCount')}` } if (book.buyCount && book.buyCount > 0) { - return `${book.buyCount}${t('home.purchased')}` + return `${book.buyCount}${t('bookHome.purchased')}` } return '' diff --git a/pages/course/index.vue b/pages/course/index.vue index 91206fc..8895d09 100644 --- a/pages/course/index.vue +++ b/pages/course/index.vue @@ -7,7 +7,7 @@ light clearable class="search-bar" - :placeholder="$t('course.searchPlaceholder')" + :placeholder="$t('courseHome.searchPlaceholder')" @search="handleSearch" /> @@ -64,7 +64,7 @@ - {{ $t('course.watchHistory') }} + {{ $t('courseHome.watchHistory') }} - {{ $t('course.tryListen') }} + {{ $t('courseHome.tryListen') }} - {{ $t('course.buy') }} + {{ $t('courseHome.buy') }} - {{ $t('course.moreTryListen') }}{{ $t('courseHome.moreTryListen') }} diff --git a/types/order.d.ts b/types/order.d.ts new file mode 100644 index 0000000..68cc5b3 --- /dev/null +++ b/types/order.d.ts @@ -0,0 +1,67 @@ +// types/order.d.ts + +/** + * 订单创建参数接口 + */ +export interface ICreateOrderParams { + paymentMethod: '4' | '5' // 支付方式: 4-虚拟币, 5-Google Pay + orderMoney: number | string // 订单金额 + abroadBookId: number // 图书ID + orderType: 'abroadBook' // 订单类型 +} + +/** + * Google Pay 验证参数接口 + */ +export interface IGooglePayVerifyParams { + purchaseToken: string // 购买凭证 + orderSn: string // 订单号 + productId: string // 产品ID +} + +/** + * 订单创建响应接口 + */ +export interface ICreateOrderResponse { + code: number + orderSn: string // 订单号 + msg?: string +} + +/** + * Google Pay SKU 信息接口 + */ +export interface IGooglePaySku { + productId: string + type: string + price: string + price_amount_micros: number + price_currency_code: string + title: string + description: string +} + +/** + * Google Pay 支付结果接口 + */ +export interface IGooglePayResult { + code: number + data?: Array<{ + original: { + purchaseToken: string + orderId: string + packageName: string + productId: string + purchaseTime: number + purchaseState: number + } + }> +} + +/** + * 支付方式选项接口 + */ +export interface IPaymentOption { + value: '4' | '5' + name: string +}