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://daxpay-api.test.yibeiguangnian.cn/"]]
VITE_PROXY=[["/server","http://192.168.11.229:19999/"]] VITE_PROXY=[["/server","http://127.0.0.1:19999/"]]
# API 接口地址 # API 接口地址
VITE_GLOB_API_URL= VITE_GLOB_API_URL=

View File

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

View File

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

View File

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

View File

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

View File

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