fix: 优化提示异常问题

This commit is contained in:
bootx
2025-05-11 15:19:31 +08:00
parent 107919fecc
commit e8dc8b6a93
6 changed files with 61 additions and 48 deletions

View File

@@ -6,7 +6,7 @@ VITE_PUBLIC_PATH=/
# 跨域代理,可以配置多个,请注意不要换行
# VITE_PROXY=[["/server","http://daxpay-api.test.yibeiguangnian.cn/"]]
VITE_PROXY=[["/server","http://192.168.11.229:19999/"]]
VITE_PROXY=[["/server","http://127.0.0.1:19999/"]]
# API 接口地址
VITE_GLOB_API_URL=

View File

@@ -69,9 +69,6 @@ const orderTime = reactive({
if (interval > 0) {
orderTime.totalTme = Math.floor(interval / 1000)
}
else {
console.log('失效了')
}
},
// 获取分秒
getMinter: () => {
@@ -107,12 +104,8 @@ watch(
function init() {
// 获取订单和配置信息
getAggregateConfig(orderNo, 'alipay').then(async ({ data, code, msg }) => {
if (code !== 0) {
// 如果异常,跳转异常页面
router.replace({
name: 'payFail',
query: { msg },
})
if (code) {
router.replace({ name: 'payFail', query: { msg } })
return
}
show.value = true
@@ -145,11 +138,7 @@ function pay() {
aggregatePay(from)
.then(({ data, code, msg }) => {
if (code !== 0) {
// 如果异常,跳转异常页面
router.replace({
name: 'payFail',
query: { msg },
})
router.replace({ name: 'payFail', query: { msg } })
return
}
loading.value = false

View File

@@ -185,7 +185,11 @@ function init() {
*/
async function wxAuth() {
// 认证获取OpenId
await auth(authParam.value).then(({ data }) => {
await auth(authParam.value).then(({ data, code, msg }) => {
if (code) {
router.push({ name: 'payFail', query: { msg }, replace: true })
return
}
openId.value = data.openId as string
}).catch((res) => {
router.push({ name: 'payFail', query: { msg: res.message }, replace: true })
@@ -204,13 +208,17 @@ function pay() {
openId: openId.value,
} as AggregatePayParam
aggregatePay(from)
.then(({ data }) => {
.then(({ data, code, msg }) => {
if (code) {
router.push({ name: 'payFail', query: { msg }, replace: true })
return
}
// 根据类型拉起对应的支付。 支持跳转和jsapi
if (orderAndConfig.value?.aggregateConfig.callType === GatewayCallTypeEnum.jsapi){
if (orderAndConfig.value?.aggregateConfig.callType === GatewayCallTypeEnum.jsapi) {
const json = JSON.parse(data.payBody)
jsapiPay(json)
}
if (orderAndConfig.value?.aggregateConfig.callType === GatewayCallTypeEnum.link){
if (orderAndConfig.value?.aggregateConfig.callType === GatewayCallTypeEnum.link) {
location.replace(data.payBody as any)
}
})

View File

@@ -192,11 +192,7 @@ function payClick() {
payOrder(form as any)
.then(({ data, code, msg }) => {
if (code !== 0) {
// 如果异常,跳转错误页面
router.replace({
name: 'payFail',
query: { msg },
})
router.replace({ name: 'payFail', query: { msg } })
return
}
loading.value = false
@@ -281,12 +277,8 @@ onUnmounted(() => {
*/
function init() {
getOrderAndConfig(orderNo).then(({ data, code, msg }) => {
if (code !== 0) {
// 如果异常,跳转异常页面
router.replace({
name: 'payFail',
query: { msg },
})
if (code) {
router.replace({ name: 'payFail', query: { msg } })
return
}
// 如果自动升级聚合支付, 判断是否在对应环境中, 自动进行升级
@@ -300,10 +292,8 @@ function init() {
orderTime.getDownTotalTime(data.order.expiredTime) // 计算倒计时
orderTime.getMinter() // 先执行一下 解决进入页面一秒后才显示倒计时
resume() // 开启倒计时
}).catch(() => {
})
.catch((error) => {
console.log(error)
})
}
</script>

View File

@@ -99,9 +99,13 @@ function initData() {
// 获取信息
loading.value = true
getCashierCodeConfig(code, CashierCodeTypeEnum.ALIPAY)
.then(({ data }) => {
.then((res) => {
if (res.code) {
router.push({ name: 'payFail', query: { msg: res.msg } })
return
}
loading.value = false
cashierInfo.value = data as any
cashierInfo.value = res.data as any
})
.catch((res) => {
router.push({ name: 'payFail', query: { msg: res.message } })
@@ -124,10 +128,14 @@ function pay() {
cashierType: AggregateEnum.ALI,
description: description.value,
} as CashierPayParam
cashierPay(from).then(({ data }) => {
cashierPay(from).then((res) => {
if (res.code) {
router.replace({ name: 'payFail', query: { msg: res.msg } })
return
}
loading.value = false
// 跳转到H5/付款码支付页面
location.replace(data.payBody)
location.replace(res.data.payBody)
})
}
</script>

View File

@@ -112,8 +112,13 @@ onMounted(() => {
async function init() {
loading.value = true
getCashierCodeConfig(cashierCode, AggregateEnum.WECHAT)
.then(({ data }) => {
.then((res) => {
if (res.code) {
router.replace({ name: 'payFail', query: { msg: res.msg } })
return
}
loading.value = false
const data = res.data
cashierInfo.value = data as any
// 判断是否需要获取OpenId
if (data.needOpenId) {
@@ -121,20 +126,29 @@ async function init() {
if (!authCode) {
// 重定向跳转到微信授权地址
generateAuthUrl(cashierCode, CashierCodeTypeEnum.WECHAT_PAY).then((res) => {
if (res.code) {
router.replace({ name: 'payFail', query: { msg: res.msg } })
return
}
const url = res.data
location.replace(url)
}).catch((res) => {
router.push({ name: 'payFail', query: { msg: res.message } })
router.replace({ name: 'payFail', query: { msg: res.message } })
})
}
else {
// 认证获取OpenId
auth({ cashierCode: cashierCode as string, cashierType: CashierCodeTypeEnum.WECHAT_PAY, authCode: authCode as string }).then(({ data }) => {
openId.value = data.openId as string
show.value = true
}).catch((res) => {
router.push({ name: 'payFail', query: { msg: res.message }, replace: true })
})
auth({ cashierCode: cashierCode as string, cashierType: CashierCodeTypeEnum.WECHAT_PAY, authCode: authCode as string })
.then((res) => {
if (res.code) {
router.push({ name: 'payFail', query: { msg: res.msg } })
return
}
openId.value = res.data.openId as string
show.value = true
}).catch((res) => {
router.push({ name: 'payFail', query: { msg: res.message }, replace: true })
})
}
}
else {
@@ -165,15 +179,19 @@ function pay() {
description: description.value,
} as CashierPayParam
cashierPay(from)
.then(({ data }) => {
.then((res) => {
if (res.code) {
router.push({ name: 'payFail', query: { msg: res.msg } })
return
}
loading.value = false
// 根据类型拉起对应的支付。 支持跳转和jsapi
if (cashierInfo.value?.callType === GatewayCallTypeEnum.jsapi) {
const json = JSON.parse(data.payBody)
const json = JSON.parse(res.data.payBody)
jsapiPay(json)
}
if (cashierInfo.value?.callType === GatewayCallTypeEnum.link) {
location.replace(data.payBody as any)
location.replace(res.data.payBody as any)
}
})
}