mirror of
https://gitee.com/bootx/dax-pay-h5.git
synced 2025-10-13 21:50:26 +00:00
refactor(daxpay): 优化代码结构和类型定义
-调整代码格式和缩进,提高可读性
This commit is contained in:
@@ -7,7 +7,7 @@ import type { PayResult } from '@/views/daxpay/cashier/CashierCode.api'
|
||||
* 获取收银台订单和配置信息
|
||||
*/
|
||||
export function getOrderAndConfig(orderNo, checkoutType) {
|
||||
return http.request({
|
||||
return http.request<Result<CheckoutOrderAndConfigResult>>({
|
||||
url: '/unipay/checkout/getOrderAndConfig',
|
||||
method: 'GET',
|
||||
params: {
|
||||
|
@@ -16,12 +16,14 @@
|
||||
<van-field label="标题" :model-value="orderAndConfig.order.title" readonly />
|
||||
<van-field label="订单号" :model-value="orderAndConfig.order.bizOrderNo" readonly />
|
||||
<van-field label="支付号" :model-value="orderAndConfig.order.orderNo" readonly />
|
||||
<van-field label="描述" rows="2" type="textarea" :model-value="orderAndConfig.order.description" readonly />
|
||||
<van-field label="描述" rows="2" type="textarea" :model-value="orderAndConfig.order.description" readonly />
|
||||
</van-cell-group>
|
||||
|
||||
<van-cell-group inset :title="group.name" v-for="group in orderAndConfig.groupConfigs" :key="group.id">
|
||||
<van-cell-group v-for="group in orderAndConfig.groupConfigs" :key="group.id" inset :title="group.name">
|
||||
<van-space direction="vertical" fill>
|
||||
<van-button @click="pay(config)" type="primary" v-for="config in group.items" :key="config.id" block>{{ config.name }}</van-button>
|
||||
<van-button v-for="config in group.items" :key="config.id" type="primary" block @click="pay(config)">
|
||||
{{ config.name }}
|
||||
</van-button>
|
||||
</van-space>
|
||||
</van-cell-group>
|
||||
</div>
|
||||
@@ -30,13 +32,16 @@
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import {
|
||||
import type {
|
||||
CheckoutItemConfigResult,
|
||||
CheckoutOrderAndConfigResult,
|
||||
checkoutPay,
|
||||
CheckoutPayParam
|
||||
CheckoutPayParam,
|
||||
} from './CheckoutPay.api'
|
||||
import { getOrderAndConfig } from './CheckoutPay.api'
|
||||
import {
|
||||
checkoutPay
|
||||
, getOrderAndConfig,
|
||||
} from './CheckoutPay.api'
|
||||
|
||||
import { CheckoutTypeEnum } from '@/enums/daxpay/DaxPayEnum'
|
||||
import router from '@/router'
|
||||
|
||||
@@ -52,7 +57,6 @@ const orderAndConfig = ref<CheckoutOrderAndConfigResult>({
|
||||
groupConfigs: [],
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
@@ -68,7 +72,7 @@ async function initData() {
|
||||
await getOrderAndConfig(orderNo, CheckoutTypeEnum.H5).then(({ data }) => {
|
||||
orderAndConfig.value = data
|
||||
}).catch((res) => {
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||
})
|
||||
// 判断是否自动升级为聚合控制台
|
||||
if (orderAndConfig.value.config.h5AutoUpgrade) {
|
||||
@@ -87,7 +91,8 @@ function goAggregate() {
|
||||
}
|
||||
else if (ua.includes('Alipay')) {
|
||||
router.push({ path: `/aggregate/alipay/${orderNo}`, replace: true })
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
show.value = true
|
||||
}
|
||||
}
|
||||
@@ -95,13 +100,13 @@ function goAggregate() {
|
||||
/**
|
||||
* 发起支付
|
||||
*/
|
||||
function pay(config: CheckoutItemConfigResult){
|
||||
function pay(config: CheckoutItemConfigResult) {
|
||||
loading.value = true
|
||||
const from = {
|
||||
orderNo: orderNo,
|
||||
itemId: config.id
|
||||
orderNo,
|
||||
itemId: config.id,
|
||||
} as CheckoutPayParam
|
||||
checkoutPay(from).then(({data}) => {
|
||||
checkoutPay(from).then(({ data }) => {
|
||||
loading.value = false
|
||||
// 跳转到支付页面
|
||||
location.replace(data.payBody)
|
||||
|
@@ -16,9 +16,9 @@
|
||||
<van-field label="标题" :model-value="aggregateInfo.order.title" readonly />
|
||||
<van-field label="订单号" :model-value="aggregateInfo.order.bizOrderNo" readonly />
|
||||
<van-field label="支付号" :model-value="aggregateInfo.order.orderNo" readonly />
|
||||
<van-field label="描述" rows="2" type="textarea" :model-value="aggregateInfo.order.description" readonly />
|
||||
<van-field label="描述" rows="2" type="textarea" :model-value="aggregateInfo.order.description" readonly />
|
||||
</van-cell-group>
|
||||
<van-submit-bar safe-area-inset-bottom :price="(aggregateInfo.order.amount || 0)*100" button-text="支付" @submit="pay" />
|
||||
<van-submit-bar safe-area-inset-bottom :price="(aggregateInfo.order.amount || 0) * 100" button-text="支付" @submit="pay" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -28,11 +28,12 @@ import { useRoute } from 'vue-router'
|
||||
|
||||
import { CheckoutAggregateEnum } from '@/enums/daxpay/DaxPayEnum'
|
||||
import router from '@/router'
|
||||
import {
|
||||
AggregateOrderAndConfigResult, aggregatePay, CheckoutAggregatePayParam,
|
||||
CheckoutAuthCodeParam,
|
||||
} from '@/views/daxpay/checkout/CheckoutPay.api'
|
||||
import { auth, generateAuthUrl, getAggregateConfig } from '@/views/daxpay/checkout/CheckoutPay.api'
|
||||
import type {
|
||||
AggregateOrderAndConfigResult, CheckoutAggregatePayParam,
|
||||
CheckoutAuthCodeParam} from '@/views/daxpay/checkout/CheckoutPay.api';
|
||||
import { aggregatePay
|
||||
auth, generateAuthUrl, getAggregateConfig } from '@/views/daxpay/checkout/CheckoutPay.api'
|
||||
|
||||
|
||||
import type { WxJsapiSignResult } from '@/views/daxpay/cashier/CashierCode.api'
|
||||
|
||||
@@ -72,7 +73,7 @@ function init() {
|
||||
const url = res.data
|
||||
location.replace(url)
|
||||
}).catch((res) => {
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||
})
|
||||
}
|
||||
else {
|
||||
@@ -91,14 +92,14 @@ async function initData() {
|
||||
getAggregateConfig(orderNo, CheckoutAggregateEnum.WECHAT).then(({ data }) => {
|
||||
aggregateInfo.value = data
|
||||
}).catch((res) => {
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||
})
|
||||
|
||||
// 认证获取OpenId
|
||||
await auth(authParam.value).then(({ data }) => {
|
||||
openId.value = data.openId as string
|
||||
}).catch((res) => {
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||
})
|
||||
// 判断是否自动拉起支付
|
||||
if (aggregateInfo.value.aggregateConfig.autoLaunch) {
|
||||
|
Reference in New Issue
Block a user