mirror of
https://gitee.com/bootx/dax-pay-h5
synced 2026-08-11 15:15:34 +08:00
refactor(daxpay): 重构收银台相关代码
- 修改路由配置,统一使用 orderNo替代 appId 和 orderId -重命名相关组件和文件,优化目录结构 - 更新错误提示信息,使其更加友好 - 新增 CheckoutPay.api.ts 文件,定义收银台相关 API 接口
This commit is contained in:
@@ -51,25 +51,25 @@ export const DaxPayRoute: RouteRecordRaw = {
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/checkout/:code',
|
||||
path: '/checkout/:orderNo',
|
||||
name: 'ChannelCashier',
|
||||
component: () => import('@/views/daxpay/cashier/ChannelCheckout.vue'),
|
||||
component: () => import('@/views/daxpay/checkout/CheckoutPay.vue'),
|
||||
meta: {
|
||||
title: '结算台',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/alipay/checkout/:appId/:orderId',
|
||||
path: '/alipay/checkout/:appId/:orderNo',
|
||||
name: 'AlipayCashier',
|
||||
component: () => import('@/views/daxpay/cashier/alipay/AlipayCheckout.vue'),
|
||||
component: () => import('@/views/daxpay/checkout/alipay/AliAggregate.vue'),
|
||||
meta: {
|
||||
title: '支付宝结算台',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/wechat/checkout/:appId/:orderId',
|
||||
path: '/wechat/checkout/:appId/:orderNo',
|
||||
name: 'WechatCheckout',
|
||||
component: () => import('@/views/daxpay/cashier/wechat/WechatCheckout.vue'),
|
||||
component: () => import('@/views/daxpay/checkout/wechat/WechatAggregate.vue'),
|
||||
meta: {
|
||||
title: '微信结算台',
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ else if (ua.includes('Alipay')) {
|
||||
router.push({ path: `/cashier/alipay/${code}`, replace: true })
|
||||
}
|
||||
else {
|
||||
router.push({ name: 'ErrorResult', query: { msg: '请使用支付宝、微信等支付程序进行扫码支付' }, replace: true })
|
||||
router.push({ name: 'ErrorResult', query: { msg: '请使用支付宝、微信等软件进行扫码支付' }, replace: true })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
187
src/views/daxpay/checkout/CheckoutPay.api.ts
Normal file
187
src/views/daxpay/checkout/CheckoutPay.api.ts
Normal file
@@ -0,0 +1,187 @@
|
||||
import { http } from '@/utils/http/axios'
|
||||
import type { Result } from '#/axios'
|
||||
import {AuthResult} from "@/views/daxpay/auth/ChannelAuth.api";
|
||||
|
||||
/**
|
||||
* 获取收银台订单和配置信息
|
||||
*/
|
||||
export function getOrderAndConfig(orderNo, checkoutType){
|
||||
return http.request({
|
||||
url: '/unipay/checkout/getOrderAndConfig',
|
||||
method: 'GET',
|
||||
params: {
|
||||
orderNo,
|
||||
checkoutType
|
||||
}
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取聚合支付配置
|
||||
*/
|
||||
export function getAggregateConfig(orderNo, aggregateType){
|
||||
return http.request<Result<AggregateOrderAndConfigResult>>({
|
||||
url: '/unipay/checkout/getAggregateConfig',
|
||||
method: 'GET',
|
||||
params: {
|
||||
orderNo,
|
||||
aggregateType
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
/**
|
||||
* 获取收银台所需授权链接, 用于获取OpenId一类的信息
|
||||
*/
|
||||
export function generateAuthUrl(param: CheckoutAuthUrlParam){
|
||||
return http.request<Result<string>>({
|
||||
url: '/unipay/checkout/generateAuthUrl',
|
||||
method: 'post',
|
||||
data: param
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取授权结果
|
||||
*/
|
||||
export function auth(param: CheckoutAuthCodeParam){
|
||||
return http.request<AuthResult>({
|
||||
url: '/unipay/checkout/auth',
|
||||
method: 'post',
|
||||
data: param
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 发起支付
|
||||
*/
|
||||
export function pay(param: CheckoutPayParam){
|
||||
return http.request<Result<CheckoutPayResult>>({
|
||||
url: '/unipay/checkout/pay',
|
||||
method: 'post',
|
||||
data: param
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 收银台认证链接生成参数
|
||||
*/
|
||||
export interface CheckoutAuthUrlParam {
|
||||
/**
|
||||
* 要支付的订单号
|
||||
*/
|
||||
orderNo?: string;
|
||||
/**
|
||||
* 聚合支付类型
|
||||
*/
|
||||
aggregateType?: string;
|
||||
}
|
||||
/**
|
||||
* 获取收银台认证结果参数
|
||||
*/
|
||||
export interface CheckoutAuthCodeParam {
|
||||
/**
|
||||
* 要支付的订单号
|
||||
*/
|
||||
orderNo?: string;
|
||||
/**
|
||||
* 聚合支付类型
|
||||
*/
|
||||
aggregateType?: string;
|
||||
/**
|
||||
* 认证Code
|
||||
*/
|
||||
authCode?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 收银台支付参数
|
||||
*/
|
||||
export interface CheckoutPayParam{
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
orderNo?: string;
|
||||
/**
|
||||
* 支付配置项ID
|
||||
*/
|
||||
itemId?: string;
|
||||
/**
|
||||
* 唯一标识
|
||||
*/
|
||||
openId?: string;
|
||||
/**
|
||||
* 付款码
|
||||
*/
|
||||
barCode?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收银台聚合支付配置
|
||||
*/
|
||||
export interface AggregateOrderAndConfigResult{
|
||||
|
||||
/**
|
||||
* 订单信息
|
||||
*/
|
||||
order: CheckoutOrderResult;
|
||||
/**
|
||||
* 收银台配置信息
|
||||
*/
|
||||
config: CheckoutConfigResult;
|
||||
/**
|
||||
* 收银台聚合配置信息
|
||||
*/
|
||||
aggregateConfig: AggregateConfigResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单信息
|
||||
*/
|
||||
export interface CheckoutOrderResult{
|
||||
/** 商户订单号 */
|
||||
bizOrderNo?: string;
|
||||
/** 订单号 */
|
||||
orderNo?: string;
|
||||
/** 标题 */
|
||||
title?: string;
|
||||
/** 描述 */
|
||||
description?: string;
|
||||
/** 金额(元) */
|
||||
amount?: string;
|
||||
|
||||
}
|
||||
/**
|
||||
* 收银台配置信息
|
||||
*/
|
||||
export interface CheckoutConfigResult{
|
||||
/** 收银台名称 */
|
||||
name?: string;
|
||||
/** PC收银台是否同时显示聚合收银码 */
|
||||
aggregateShow?: boolean;
|
||||
/** h5收银台自动升级聚合支付 */
|
||||
h5AutoUpgrade?: boolean;
|
||||
}
|
||||
/**
|
||||
* 收银台聚合配置信息
|
||||
*/
|
||||
export interface AggregateConfigResult{
|
||||
/** 支付类型 */
|
||||
type?: string;
|
||||
/** 通道 */
|
||||
channel?: string;
|
||||
/** 支付方式 */
|
||||
payMethod?: string;
|
||||
/** 自动拉起支付 */
|
||||
autoLaunch?: boolean;
|
||||
}
|
||||
/**
|
||||
* 收银台支付结果
|
||||
*/
|
||||
export interface CheckoutPayResult{
|
||||
/**
|
||||
* 链接
|
||||
*/
|
||||
url?: string;
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
payStatus?: string;
|
||||
}
|
||||
@@ -6,17 +6,17 @@ import { useRoute } from 'vue-router'
|
||||
import router from '@/router'
|
||||
|
||||
const route = useRoute()
|
||||
const { appId, orderId } = route.params
|
||||
const { code: orderNo } = route.params
|
||||
|
||||
const ua = navigator.userAgent
|
||||
if (ua.includes('MicroMessenger')) {
|
||||
router.push({ path: `/wechat/checkout/${appId}/${orderId}`, replace: true })
|
||||
router.push({ path: `/wechat/checkout/${orderNo}`, replace: true })
|
||||
}
|
||||
else if (ua.includes('Alipay')) {
|
||||
router.push({ path: `/alipay/checkout/${appId}/${orderId}`, replace: true })
|
||||
router.push({ path: `/alipay/checkout/${orderNo}`, replace: true })
|
||||
}
|
||||
else {
|
||||
router.push({ name: 'ErrorResult', query: { msg: '请使用支付宝、微信等支付程序进行扫码支付' }, replace: true })
|
||||
router.push({ name: 'ErrorResult', query: { msg: '请使用支付宝、微信等软件进行扫码支付' }, replace: true })
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -31,9 +31,10 @@ import {
|
||||
|
||||
import { CashierTypeEnum } from '@/enums/daxpay/DaxPayEnum'
|
||||
import router from '@/router'
|
||||
import {getAggregateConfig} from "@/views/daxpay/checkout/CheckoutPay.api";
|
||||
|
||||
const route = useRoute()
|
||||
const { appId, orderId } = route.params
|
||||
const { orderNo } = route.params
|
||||
|
||||
const loading = ref<boolean>(false)
|
||||
const cashierInfo = ref<CashierTypeConfigResult>({})
|
||||
@@ -49,11 +50,11 @@ onMounted(() => {
|
||||
* 初始化数据
|
||||
*/
|
||||
function initData() {
|
||||
// getCashierInfo(CashierTypeEnum.ALIPAY, appId as string).then(({ data }) => {
|
||||
// cashierInfo.value = data
|
||||
// }).catch((res) => {
|
||||
// router.push({ name: 'ErrorResult', query: { msg: res.message } })
|
||||
// })
|
||||
getAggregateConfig(orderNo, wechat).then(({ data }) => {
|
||||
cashierInfo.value = data
|
||||
}).catch((res) => {
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message } })
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
Reference in New Issue
Block a user