|
116 | 116 |
|
117 | 117 | <script lang="ts" setup>
|
118 | 118 | import QrcodeVue from 'qrcode.vue'
|
119 |
| -import { getOrder, submitOrder } from '@/api/pay/order' |
| 119 | +import * as PayOrderApi from '@/api/pay/order' |
120 | 120 | import { PayChannelEnum, PayDisplayModeEnum, PayOrderStatusEnum } from '@/utils/constants'
|
121 | 121 | import { formatDate } from '@/utils/formatTime'
|
122 | 122 | import { useTagsViewStore } from '@/store/modules/tagsView'
|
@@ -224,34 +224,31 @@ const barCode = ref({
|
224 | 224 | })
|
225 | 225 |
|
226 | 226 | /** 获得支付信息 */
|
227 |
| -const getDetail = () => { |
| 227 | +const getDetail = async () => { |
228 | 228 | // 1.1 未传递订单编号
|
229 | 229 | if (!id.value) {
|
230 | 230 | message.error('未传递支付单号,无法查看对应的支付信息')
|
231 | 231 | goReturnUrl('cancel')
|
232 | 232 | return
|
233 | 233 | }
|
234 |
| - getOrder(id.value).then((data) => { |
235 |
| - // 1.2 无法查询到支付信息 |
236 |
| - if (!data) { |
237 |
| - message.error('支付订单不存在,请检查!') |
238 |
| - goReturnUrl('cancel') |
239 |
| - return |
240 |
| - } |
241 |
| - // 1.3 如果已支付、或者已关闭,则直接跳转 |
242 |
| - if (data.status === PayOrderStatusEnum.SUCCESS.status) { |
243 |
| - message.success('支付成功') |
244 |
| - goReturnUrl('success') |
245 |
| - return |
246 |
| - } else if (data.status === PayOrderStatusEnum.CLOSED.status) { |
247 |
| - message.error('无法支付,原因:订单已关闭') |
248 |
| - goReturnUrl('close') |
249 |
| - return |
250 |
| - } |
251 |
| -
|
252 |
| - // 2. 可以展示 |
253 |
| - payOrder.value = data |
254 |
| - }) |
| 234 | + const data = await PayOrderApi.getOrder(id.value) |
| 235 | + payOrder.value = data |
| 236 | + // 1.2 无法查询到支付信息 |
| 237 | + if (!data) { |
| 238 | + message.error('支付订单不存在,请检查!') |
| 239 | + goReturnUrl('cancel') |
| 240 | + return |
| 241 | + } |
| 242 | + // 1.3 如果已支付、或者已关闭,则直接跳转 |
| 243 | + if (data.status === PayOrderStatusEnum.SUCCESS.status) { |
| 244 | + message.success('支付成功') |
| 245 | + goReturnUrl('success') |
| 246 | + return |
| 247 | + } else if (data.status === PayOrderStatusEnum.CLOSED.status) { |
| 248 | + message.error('无法支付,原因:订单已关闭') |
| 249 | + goReturnUrl('close') |
| 250 | + return |
| 251 | + } |
255 | 252 | }
|
256 | 253 |
|
257 | 254 | /** 提交支付 */
|
@@ -290,38 +287,38 @@ const submit = (channelCode) => {
|
290 | 287 | submit0(channelCode)
|
291 | 288 | }
|
292 | 289 |
|
293 |
| -const submit0 = (channelCode) => { |
| 290 | +const submit0 = async (channelCode) => { |
294 | 291 | submitLoading.value = true
|
295 |
| - submitOrder({ |
296 |
| - id: id.value, |
297 |
| - channelCode: channelCode, |
298 |
| - returnUrl: location.href, // 支付成功后,支付渠道跳转回当前页;再由当前页,跳转回 {@link returnUrl} 对应的地址 |
299 |
| - ...buildSubmitParam(channelCode) |
300 |
| - }) |
301 |
| - .then((data) => { |
302 |
| - // 直接返回已支付的情况,例如说扫码支付 |
303 |
| - if (data.status === PayOrderStatusEnum.SUCCESS.status) { |
304 |
| - clearQueryInterval() |
305 |
| - message.success('支付成功!') |
306 |
| - goReturnUrl('success') |
307 |
| - return |
308 |
| - } |
| 292 | + try { |
| 293 | + const formData = { |
| 294 | + id: id.value, |
| 295 | + channelCode: channelCode, |
| 296 | + returnUrl: location.href, // 支付成功后,支付渠道跳转回当前页;再由当前页,跳转回 {@link returnUrl} 对应的地址 |
| 297 | + ...buildSubmitParam(channelCode) |
| 298 | + } |
| 299 | + const data = await PayOrderApi.submitOrder(formData) |
| 300 | + // 直接返回已支付的情况,例如说扫码支付 |
| 301 | + if (data.status === PayOrderStatusEnum.SUCCESS.status) { |
| 302 | + clearQueryInterval() |
| 303 | + message.success('支付成功!') |
| 304 | + goReturnUrl('success') |
| 305 | + return |
| 306 | + } |
309 | 307 |
|
310 |
| - // 展示对应的界面 |
311 |
| - if (data.displayMode === PayDisplayModeEnum.URL.mode) { |
312 |
| - displayUrl(channelCode, data) |
313 |
| - } else if (data.displayMode === PayDisplayModeEnum.QR_CODE.mode) { |
314 |
| - displayQrCode(channelCode, data) |
315 |
| - } else if (data.displayMode === PayDisplayModeEnum.APP.mode) { |
316 |
| - displayApp(channelCode) |
317 |
| - } |
| 308 | + // 展示对应的界面 |
| 309 | + if (data.displayMode === PayDisplayModeEnum.URL.mode) { |
| 310 | + displayUrl(channelCode, data) |
| 311 | + } else if (data.displayMode === PayDisplayModeEnum.QR_CODE.mode) { |
| 312 | + displayQrCode(channelCode, data) |
| 313 | + } else if (data.displayMode === PayDisplayModeEnum.APP.mode) { |
| 314 | + displayApp(channelCode) |
| 315 | + } |
318 | 316 |
|
319 |
| - // 打开轮询任务 |
320 |
| - createQueryInterval() |
321 |
| - }) |
322 |
| - .catch(() => { |
323 |
| - submitLoading.value = false |
324 |
| - }) |
| 317 | + // 打开轮询任务 |
| 318 | + createQueryInterval() |
| 319 | + } finally { |
| 320 | + submitLoading.value = false |
| 321 | + } |
325 | 322 | }
|
326 | 323 |
|
327 | 324 | /** 构建提交支付的额外参数 */
|
@@ -385,21 +382,20 @@ const createQueryInterval = () => {
|
385 | 382 | if (interval.value) {
|
386 | 383 | return
|
387 | 384 | }
|
388 |
| - interval.value = setInterval(() => { |
389 |
| - getOrder(id.value).then((data) => { |
390 |
| - // 已支付 |
391 |
| - if (data.status === PayOrderStatusEnum.SUCCESS.status) { |
392 |
| - clearQueryInterval() |
393 |
| - message.success('支付成功!') |
394 |
| - goReturnUrl('success') |
395 |
| - } |
396 |
| - // 已取消 |
397 |
| - if (data.status === PayOrderStatusEnum.CLOSED.status) { |
398 |
| - clearQueryInterval() |
399 |
| - message.error('支付已关闭!') |
400 |
| - goReturnUrl('close') |
401 |
| - } |
402 |
| - }) |
| 385 | + interval.value = setInterval(async () => { |
| 386 | + const data = await PayOrderApi.getOrder(id.value) |
| 387 | + // 已支付 |
| 388 | + if (data.status === PayOrderStatusEnum.SUCCESS.status) { |
| 389 | + clearQueryInterval() |
| 390 | + message.success('支付成功!') |
| 391 | + goReturnUrl('success') |
| 392 | + } |
| 393 | + // 已取消 |
| 394 | + if (data.status === PayOrderStatusEnum.CLOSED.status) { |
| 395 | + clearQueryInterval() |
| 396 | + message.error('支付已关闭!') |
| 397 | + goReturnUrl('close') |
| 398 | + } |
403 | 399 | }, 1000 * 2)
|
404 | 400 | }
|
405 | 401 |
|
|
0 commit comments