From 3d20683d7626fb1198271466b566d14dff8fa405 Mon Sep 17 00:00:00 2001 From: fuchao <2577131060@qq.com> Date: Fri, 28 Nov 2025 16:16:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9Aloading=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=97=B6=E6=9C=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/clients/payment.ts | 4 +- api/modules/user.ts | 5 +- api/request.ts | 2 +- pages/user/recharge/index.vue | 305 +++++++++++++++++----------------- 4 files changed, 160 insertions(+), 156 deletions(-) diff --git a/api/clients/payment.ts b/api/clients/payment.ts index 56743ec..b850de8 100644 --- a/api/clients/payment.ts +++ b/api/clients/payment.ts @@ -6,6 +6,8 @@ import { createRequestClient } from '../request'; import { SERVICE_MAP } from '../config'; export const paymentClient = createRequestClient({ - baseURL: SERVICE_MAP.PAYMENT, + baseURL: SERVICE_MAP.MAIN, + // baseURL: SERVICE_MAP.PAYMENT, + loading: false }); diff --git a/api/modules/user.ts b/api/modules/user.ts index 4223cb4..75d9628 100644 --- a/api/modules/user.ts +++ b/api/modules/user.ts @@ -1,5 +1,6 @@ // api/modules/user.ts import { mainClient } from '@/api/clients/main' +import { paymentClient } from '@/api/clients/payment' import type { IApiResponse } from '@/api/types' import type { IUserInfo, @@ -196,7 +197,7 @@ export async function submitFeedback(data: IFeedbackForm) { */ export async function verifyGooglePay(productId: number, purchaseToken: string, orderSn: string) { console.log(productId, purchaseToken, orderSn); - const res = await mainClient.request({ + const res = await paymentClient.request({ url: 'pay/googlepay/googleVerify', method: 'POST', data: { productId, purchaseToken, orderSn } @@ -278,7 +279,7 @@ export async function getTransactionDetailsList(current : number, limit : number */ export async function getPlaceOrder(data: object) { - const res = await mainClient.request({ + const res = await paymentClient.request({ url: '/book/buyOrder/placeOrder', method: 'POST', data: data diff --git a/api/request.ts b/api/request.ts index 3f5f7a9..9603301 100644 --- a/api/request.ts +++ b/api/request.ts @@ -23,7 +23,7 @@ export function createRequestClient(cfg: ICreateClientConfig) { const intercepted = requestInterceptor(final as IRequestOptions); // 全局处理请求 loading - const loading = !cfg.loading ? true : cfg.loading // 接口请求参数不传loading,默认显示loading + const loading = cfg.loading ?? true // 接口请求参数不传loading,默认显示loading if (loading) { uni.showLoading({ mask: true }) reqCount++ diff --git a/pages/user/recharge/index.vue b/pages/user/recharge/index.vue index 8f8b806..aee74f1 100644 --- a/pages/user/recharge/index.vue +++ b/pages/user/recharge/index.vue @@ -117,6 +117,52 @@ const orderSn = ref('') + /** + * 获取使用环境 + */ + const getDevName = () => { + if (uni.getSystemInfoSync().platform === "android") { + qudao.value = 'Google' + isAndroid.value = true; + console.log('运行Android上') + } else { + qudao.value = 'Google' + console.log('运行iOS上') + } + getData() + } + + /** + * 获取充值列表数据 + */ + const getData = async () => { + try { + rechargeList.value = await getBookBuyConfigList(type.value, qudao.value) + console.log(rechargeList.value.bookBuyConfigList, '充值列表'); + // 默认选择第一个金额 + aloneItem.value = rechargeList.value.bookBuyConfigList[0] + } catch (error) { + console.error('获取订单列表失败:', error) + } + } + + /** + * 点击支付按钮 + */ + + const paymentButton = async () => { + if (!state.value) { + uni.showToast({ + title: t('order.readAgreeServices'), + icon: 'none' + }) + return + } + getPlaceOrderObj() + } + // 节流支付按钮 + const handleRecharge = useThrottle(paymentButton); + /** * 获取订单编号 */ @@ -132,31 +178,17 @@ productId: priceTypeId.value // 商品id } try { + // uni.hideLoading() const res = await getPlaceOrder(data) orderSn.value = res.orderSn console.log(orderSn.value, '获取订单号'); + uni.showLoading({ title: '生成订单中...' }) getGooglePay() } catch (error) { console.error('获取订单号失败', error) } } - /** - * 获取使用环境 - */ - const getDevName = () => { - - if (uni.getSystemInfoSync().platform === "android") { - qudao.value = 'Google' - isAndroid.value = true; - console.log('运行Android上') - } else { - qudao.value = 'Google' - console.log('运行iOS上') - } - getData() - } - // 点击金额 const chosPric = (item : any) => { console.log(item, '金额每项'); @@ -177,17 +209,115 @@ const showAgreement = () => { agreemenState.value = true } + /** - * 获取充值列表数据 + * 初始化 */ - const getData = async () => { + const getGooglePay = () => { + googlePay.init({ + }, (e : any) => { + console.log('init', e); + if (e.code == 0) { + isConnected.value = true; + console.log('init成功了'); + getQuerySku() + // 初始化成功 + } else { + console.log('init失败了'); + // 初始化失败 + isConnected.value = false; + } + }); + } + + /** + * 查询sku + */ + const getQuerySku = () => { + const id = aloneItem.value.priceTypeId + console.log(id, '获取每项'); + googlePay.querySku( + { + inapp: [id], // 与subs二选一, 参数为商品ID(字符串)数组 + }, + (e : any) => { + if (e.code == 0) { + // 查询成功. + console.log('querySku查询成功', e); + getPayAll() + uni.hideLoading() + } else { + console.log('查询失败', e); + uni.showToast({ + title: '请求失败,请检查您的网络', + icon: 'error' + }) + } + } + ) + } + + /** + * 发起支付 + */ + const getPayAll = () => { + console.log(aloneItem.value.priceTypeId, orderSn.value, '发起支付传入产品id,订单id'); + googlePay.payAll( + { + productId: aloneItem.value.priceTypeId, // 产品id + accountId: orderSn.value // 订单编号 + }, + (e : any) => { + if (e.code == 0) { + purchaseToken.value = e.data[0].original.purchaseToken + // 支付成功 + console.log(e, 'payAll方法成功返参'); + getConsume() + } else { + uni.showToast({ title: '支付失败', icon: 'error' }) + console.log(e, 'e'); + // 支付失败 + } + }, + ) + } + + /** + * 消耗品 确认交易 + */ + const getConsume = () => { + googlePay.consume( + { + purchaseToken: purchaseToken.value, // 来自支付结果的original.purchaseToken (或 original.token) + }, + (e : any) => { + if (e.code == 0) { + console.log(e, '确认交易成功'); + uni.showToast({ title: '即将返回我的页面', icon: 'none' }) + // 确认成功 + googleVerify() + } else { + console.log(e, '确认交易失败'); + // 确认失败 + } + }, + ); + } + + /** + * 校验订单 + */ + const googleVerify = async () => { + uni.hideLoading() + console.log(typeof aloneItem.value.priceTypeId, typeof purchaseToken.value, typeof orderSn.value); try { - rechargeList.value = await getBookBuyConfigList(type.value, qudao.value) - console.log(rechargeList.value.bookBuyConfigList, '充值列表'); - // 默认选择第一个金额 - aloneItem.value = rechargeList.value.bookBuyConfigList[0] + const obj = await verifyGooglePay(aloneItem.value.priceTypeId, purchaseToken.value, orderSn.value) + uni.switchTab({ + url: '/pages/user/index' + }) + console.log(obj, '校验订单'); } catch (error) { - console.error('获取订单列表失败:', error) + console.error('校验订单失败:', error) } } @@ -227,135 +357,6 @@ // payType.value = val; } - /** - * 点击支付按钮 - */ - - const paymentButton = async () => { - if (!state.value) { - uni.showToast({ - title: t('order.readAgreeServices'), - icon: 'none' - }) - return - } - getPlaceOrderObj() - uni.showLoading({ title: '生成订单中...' }) - } - // 节流支付按钮 - const handleRecharge = useThrottle(paymentButton); - - /** - * 初始化 - */ - const getGooglePay = () => { - googlePay.init({ - }, (e : any) => { - console.log('init', e); - if (e.code == 0) { - isConnected.value = true; - getQuerySku() - // 初始化成功 - } else { - // 初始化失败 - isConnected.value = false; - } - }); - } - - /** - * 查询sku - */ - const getQuerySku = () => { - const id = aloneItem.value.priceTypeId - console.log(id, '获取每项'); - googlePay.querySku( - { - inapp: [id], // 与subs二选一, 参数为商品ID(字符串)数组 - }, - (e : any) => { - if (e.code == 0) { - // 查询成功. - console.log('querySku查询成功', e); - uni.hideLoading() - getPayAll() - } else { - console.log('查询失败', e); - uni.showToast({ - title: 'No product found.', - icon: 'none', - duration: 2000 - }) - // 查询失败 - } - } - ) - } - - /** - * 发起支付 - */ - const getPayAll = () => { - console.log(aloneItem.value.priceTypeId, orderSn.value, '发起支付传入产品id,订单id'); - googlePay.payAll( - { - productId: aloneItem.value.priceTypeId, // 产品id - accountId: orderSn.value // 订单编号 - }, - (e : any) => { - if (e.code == 0) { - purchaseToken.value = e.data[0].original.purchaseToken - // 支付成功 - console.log(e, 'payAll方法成功返参'); - getConsume() - } else { - uni.showToast({ title: '支付失败', icon: 'success' }) - console.log(e, 'e'); - // 支付失败 - } - }, - ) - } - - /** - * 消耗品 确认交易 - */ - const getConsume = () => { - googlePay.consume( - { - purchaseToken: purchaseToken.value, // 来自支付结果的original.purchaseToken (或 original.token) - }, - (e : any) => { - if (e.code == 0) { - console.log(e, '确认交易成功'); - // 确认成功 - googleVerify() - } else { - console.log(e, '确认交易失败'); - // 确认失败 - } - }, - ); - } - - /** - * 校验订单 - */ - const googleVerify = async () => { - console.log(typeof aloneItem.value.priceTypeId, typeof purchaseToken.value, typeof orderSn.value); - try { - const obj = await verifyGooglePay(aloneItem.value.priceTypeId, purchaseToken.value, orderSn.value) - uni.switchTab({ - url: '/pages/user/index' - }) - console.log(obj, '校验订单'); - } catch (error) { - console.error('校验订单失败:', error) - } - } - - - onMounted(() => { getDevName(); getActivityDescriptionData() From ef2c63784feb7617cdc24d26fc002d7dd797c558 Mon Sep 17 00:00:00 2001 From: fuchao <2577131060@qq.com> Date: Fri, 28 Nov 2025 17:42:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=9B=BD=E9=99=85=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locale/en.json | 4 +++- locale/zh-Hans.json | 3 ++- pages/user/index.vue | 2 +- pages/user/recharge/index.vue | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/locale/en.json b/locale/en.json index 7a8d9c4..d618002 100644 --- a/locale/en.json +++ b/locale/en.json @@ -211,7 +211,9 @@ "yearCard": "Yearly", "days": "days", "selectPackage": "Please select a package", - "consumptionRecord": "Consumption record" + "consumptionRecord": "Consumption record", + "returnMine": "I'm about to return to my page" + }, "book": { "title": "My Books", diff --git a/locale/zh-Hans.json b/locale/zh-Hans.json index 25c4fcf..620442c 100644 --- a/locale/zh-Hans.json +++ b/locale/zh-Hans.json @@ -212,7 +212,8 @@ "yearCard": "年卡", "days": "天", "selectPackage": "请选择套餐", - "consumptionRecord": "消费记录" + "consumptionRecord": "消费记录", + "returnMine": "即将返回我的页面" }, "book": { "title": "我的书单", diff --git a/pages/user/index.vue b/pages/user/index.vue index 0ef938e..21d6091 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -425,7 +425,7 @@ border-radius: 50rpx; color: #fffbf6; padding: 10rpx 32rpx; - background-image: linear-gradient(90deg, #3ab3ae 0%, #d5ecdd 200%); + background: #007bff; } .assets { diff --git a/pages/user/recharge/index.vue b/pages/user/recharge/index.vue index aee74f1..3237fa8 100644 --- a/pages/user/recharge/index.vue +++ b/pages/user/recharge/index.vue @@ -182,7 +182,7 @@ const res = await getPlaceOrder(data) orderSn.value = res.orderSn console.log(orderSn.value, '获取订单号'); - uni.showLoading({ title: '生成订单中...' }) + uni.showLoading({ title: t('order.orderCreating') }) getGooglePay() } catch (error) { console.error('获取订单号失败', error) @@ -249,7 +249,7 @@ } else { console.log('查询失败', e); uni.showToast({ - title: '请求失败,请检查您的网络', + title: t('global.networkConnectionError'), icon: 'error' }) } @@ -274,7 +274,7 @@ console.log(e, 'payAll方法成功返参'); getConsume() } else { - uni.showToast({ title: '支付失败', icon: 'error' }) + uni.showToast({ title: t('user.paymentFailed'), icon: 'error' }) console.log(e, 'e'); // 支付失败 } @@ -293,7 +293,7 @@ (e : any) => { if (e.code == 0) { console.log(e, '确认交易成功'); - uni.showToast({ title: '即将返回我的页面', icon: 'none' }) + uni.showToast({ title: t('user.returnMine'), icon: 'none' }) // 确认成功 googleVerify() } else {