mirror of
https://gitee.com/bootx/dax-pay-h5.git
synced 2025-10-14 22:20:31 +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) {
|
export function getOrderAndConfig(orderNo, checkoutType) {
|
||||||
return http.request({
|
return http.request<Result<CheckoutOrderAndConfigResult>>({
|
||||||
url: '/unipay/checkout/getOrderAndConfig',
|
url: '/unipay/checkout/getOrderAndConfig',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: {
|
params: {
|
||||||
|
@@ -16,12 +16,14 @@
|
|||||||
<van-field label="标题" :model-value="orderAndConfig.order.title" readonly />
|
<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.bizOrderNo" readonly />
|
||||||
<van-field label="支付号" :model-value="orderAndConfig.order.orderNo" 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>
|
||||||
|
|
||||||
<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-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-space>
|
||||||
</van-cell-group>
|
</van-cell-group>
|
||||||
</div>
|
</div>
|
||||||
@@ -30,13 +32,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import {
|
import type {
|
||||||
CheckoutItemConfigResult,
|
CheckoutItemConfigResult,
|
||||||
CheckoutOrderAndConfigResult,
|
CheckoutOrderAndConfigResult,
|
||||||
checkoutPay,
|
CheckoutPayParam,
|
||||||
CheckoutPayParam
|
|
||||||
} from './CheckoutPay.api'
|
} from './CheckoutPay.api'
|
||||||
import { getOrderAndConfig } from './CheckoutPay.api'
|
import {
|
||||||
|
checkoutPay
|
||||||
|
, getOrderAndConfig,
|
||||||
|
} from './CheckoutPay.api'
|
||||||
|
|
||||||
import { CheckoutTypeEnum } from '@/enums/daxpay/DaxPayEnum'
|
import { CheckoutTypeEnum } from '@/enums/daxpay/DaxPayEnum'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
|
|
||||||
@@ -52,7 +57,6 @@ const orderAndConfig = ref<CheckoutOrderAndConfigResult>({
|
|||||||
groupConfigs: [],
|
groupConfigs: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化
|
* 初始化
|
||||||
*/
|
*/
|
||||||
@@ -68,7 +72,7 @@ async function initData() {
|
|||||||
await getOrderAndConfig(orderNo, CheckoutTypeEnum.H5).then(({ data }) => {
|
await getOrderAndConfig(orderNo, CheckoutTypeEnum.H5).then(({ data }) => {
|
||||||
orderAndConfig.value = data
|
orderAndConfig.value = data
|
||||||
}).catch((res) => {
|
}).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) {
|
if (orderAndConfig.value.config.h5AutoUpgrade) {
|
||||||
@@ -87,7 +91,8 @@ function goAggregate() {
|
|||||||
}
|
}
|
||||||
else if (ua.includes('Alipay')) {
|
else if (ua.includes('Alipay')) {
|
||||||
router.push({ path: `/aggregate/alipay/${orderNo}`, replace: true })
|
router.push({ path: `/aggregate/alipay/${orderNo}`, replace: true })
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
show.value = true
|
show.value = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,13 +100,13 @@ function goAggregate() {
|
|||||||
/**
|
/**
|
||||||
* 发起支付
|
* 发起支付
|
||||||
*/
|
*/
|
||||||
function pay(config: CheckoutItemConfigResult){
|
function pay(config: CheckoutItemConfigResult) {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
const from = {
|
const from = {
|
||||||
orderNo: orderNo,
|
orderNo,
|
||||||
itemId: config.id
|
itemId: config.id,
|
||||||
} as CheckoutPayParam
|
} as CheckoutPayParam
|
||||||
checkoutPay(from).then(({data}) => {
|
checkoutPay(from).then(({ data }) => {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
// 跳转到支付页面
|
// 跳转到支付页面
|
||||||
location.replace(data.payBody)
|
location.replace(data.payBody)
|
||||||
|
@@ -16,9 +16,9 @@
|
|||||||
<van-field label="标题" :model-value="aggregateInfo.order.title" readonly />
|
<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.bizOrderNo" readonly />
|
||||||
<van-field label="支付号" :model-value="aggregateInfo.order.orderNo" 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-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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -28,11 +28,12 @@ import { useRoute } from 'vue-router'
|
|||||||
|
|
||||||
import { CheckoutAggregateEnum } from '@/enums/daxpay/DaxPayEnum'
|
import { CheckoutAggregateEnum } from '@/enums/daxpay/DaxPayEnum'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
import {
|
import type {
|
||||||
AggregateOrderAndConfigResult, aggregatePay, CheckoutAggregatePayParam,
|
AggregateOrderAndConfigResult, CheckoutAggregatePayParam,
|
||||||
CheckoutAuthCodeParam,
|
CheckoutAuthCodeParam} from '@/views/daxpay/checkout/CheckoutPay.api';
|
||||||
} from '@/views/daxpay/checkout/CheckoutPay.api'
|
import { aggregatePay
|
||||||
import { auth, generateAuthUrl, getAggregateConfig } from '@/views/daxpay/checkout/CheckoutPay.api'
|
auth, generateAuthUrl, getAggregateConfig } from '@/views/daxpay/checkout/CheckoutPay.api'
|
||||||
|
|
||||||
|
|
||||||
import type { WxJsapiSignResult } from '@/views/daxpay/cashier/CashierCode.api'
|
import type { WxJsapiSignResult } from '@/views/daxpay/cashier/CashierCode.api'
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ function init() {
|
|||||||
const url = res.data
|
const url = res.data
|
||||||
location.replace(url)
|
location.replace(url)
|
||||||
}).catch((res) => {
|
}).catch((res) => {
|
||||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -91,14 +92,14 @@ async function initData() {
|
|||||||
getAggregateConfig(orderNo, CheckoutAggregateEnum.WECHAT).then(({ data }) => {
|
getAggregateConfig(orderNo, CheckoutAggregateEnum.WECHAT).then(({ data }) => {
|
||||||
aggregateInfo.value = data
|
aggregateInfo.value = data
|
||||||
}).catch((res) => {
|
}).catch((res) => {
|
||||||
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
router.push({ name: 'ErrorResult', query: { msg: res.message }, replace: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
// 认证获取OpenId
|
// 认证获取OpenId
|
||||||
await auth(authParam.value).then(({ data }) => {
|
await auth(authParam.value).then(({ data }) => {
|
||||||
openId.value = data.openId as string
|
openId.value = data.openId as string
|
||||||
}).catch((res) => {
|
}).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) {
|
if (aggregateInfo.value.aggregateConfig.autoLaunch) {
|
||||||
|
Reference in New Issue
Block a user