48
48
<qrcode-vue :value =" qrCode.url" size =" 310" level =" L" />
49
49
</el-dialog >
50
50
51
- <!-- 展示形式:IFrame -->
52
- <el-dialog :title =" iframe.title" :visible.sync =" iframe.visible" width =" 800px" height =" 800px" append-to-body
53
- :close-on-press-escape =" false" >
54
- <iframe :src =" iframe.url" width =" 100%" />
55
- </el-dialog >
56
-
57
- <!-- 展示形式:Form -->
58
- <div ref =" formRef" v-html =" form.value" />
59
-
60
51
<!-- 展示形式:BarCode 条形码 -->
61
52
<el-dialog :title =" barCode.title" :visible.sync =" barCode.visible" width =" 500px" append-to-body
62
53
:close-on-press-escape =" false" >
@@ -146,14 +137,6 @@ export default {
146
137
title: ' ' ,
147
138
visible: false ,
148
139
},
149
- iframe: { // 展示形式:iframe
150
- url: ' ' ,
151
- title: ' ' ,
152
- visible: false
153
- },
154
- form: { // 展示形式:form
155
- html: ' ' ,
156
- },
157
140
barCode: { // 展示形式:条形码
158
141
channelCode: ' ' ,
159
142
value: ' ' ,
@@ -175,21 +158,24 @@ export default {
175
158
// 1.1 未传递订单编号
176
159
if (! this .id ) {
177
160
this .$message .error (' 未传递支付单号,无法查看对应的支付信息' );
178
- this .goBackToList ( );
161
+ this .goReturnUrl ( ' cancel ' );
179
162
return ;
180
163
}
181
164
getOrder (this .id ).then (response => {
182
165
// 1.2 无法查询到支付信息
183
166
if (! response .data ) {
184
167
this .$message .error (' 支付订单不存在,请检查!' );
185
- this .goBackToList ( );
168
+ this .goReturnUrl ( ' cancel ' );
186
169
return ;
187
170
}
188
- // 1.3 订单已支付
189
- // TODO 芋艿:已支付
190
- if (response .data .status !== PayOrderStatusEnum .WAITING .status ) {
191
- this .$message .error (' 支付订单不处于待支付状态,请检查!' );
192
- this .goBackToList ();
171
+ // 1.3 如果已支付、或者已关闭,则直接跳转
172
+ if (response .data .status === PayOrderStatusEnum .SUCCESS .status ) {
173
+ this .$message .success (' 支付成功' );
174
+ this .goReturnUrl (' success' );
175
+ return ;
176
+ } else if (response .data .status === PayOrderStatusEnum .CLOSED .status ) {
177
+ this .$message .error (' 无法支付,原因:订单已关闭' );
178
+ this .goReturnUrl (' close' );
193
179
return ;
194
180
}
195
181
@@ -218,15 +204,12 @@ export default {
218
204
submitOrder ({
219
205
id: this .id ,
220
206
channelCode: channelCode,
207
+ returnUrl: location .href , // 支付成功后,支付渠道跳转回当前页;再由当前页,跳转回 {@link returnUrl} 对应的地址
221
208
... this .buildSubmitParam (channelCode)
222
209
}).then (response => {
223
210
const data = response .data
224
- if (data .displayMode === PayDisplayModeEnum .IFRAME .mode ) {
225
- this .displayIFrame (channelCode, data)
226
- } else if (data .displayMode === PayDisplayModeEnum .URL .mode ) {
211
+ if (data .displayMode === PayDisplayModeEnum .URL .mode ) {
227
212
this .displayUrl (channelCode, data)
228
- } else if (data .displayMode === PayDisplayModeEnum .FORM .mode ) {
229
- this .displayForm (channelCode, data)
230
213
} else if (data .displayMode === PayDisplayModeEnum .QR_CODE .mode ) {
231
214
this .displayQrCode (channelCode, data)
232
215
}
@@ -239,53 +222,7 @@ export default {
239
222
},
240
223
/** 构建提交支付的额外参数 */
241
224
buildSubmitParam (channelCode ) {
242
- // ① 支付宝 PC 支付时,有多种展示形态
243
- if (channelCode === PayChannelEnum .ALIPAY_PC .code ) {
244
- // 情况【前置模式】:将二维码前置到商户的订单确认页的模式。需要商户在自己的页面中以 iframe 方式请求支付宝页面。具体支持的枚举值有以下几种:
245
- // 0:订单码-简约前置模式,对应 iframe 宽度不能小于 600px,高度不能小于 300px
246
- // return {
247
- // "channelExtras": {
248
- // "qr_pay_mode": "0"
249
- // }
250
- // }
251
- // 1:订单码-前置模式,对应iframe 宽度不能小于 300px,高度不能小于 600px
252
- // return {
253
- // "channelExtras": {
254
- // "qr_pay_mode": "1"
255
- // }
256
- // }
257
- // 3:订单码-迷你前置模式,对应 iframe 宽度不能小于 75px,高度不能小于 75px
258
- // return {
259
- // "channelExtras": {
260
- // "qr_pay_mode": "3"
261
- // }
262
- // }
263
- // 4:订单码-可定义宽度的嵌入式二维码,商户可根据需要设定二维码的大小
264
- // return {
265
- // "channelExtras": {
266
- // "qr_pay_mode": "4"
267
- // }
268
- // }
269
- // 情况【跳转模式】:跳转模式下,用户的扫码界面是由支付宝生成的,不在商户的域名下。支持传入的枚举值有
270
- return {
271
- " channelExtras" : {
272
- " qr_pay_mode" : " 2"
273
- }
274
- }
275
- // 情况【表单模式】:直接提交当前页面到支付宝
276
- // return {
277
- // displayMode: PayDisplayModeEnum.FORM.mode
278
- // }
279
- }
280
-
281
- // ② 支付宝 Wap 支付时,引导手机扫码支付
282
- if (channelCode === PayChannelEnum .ALIPAY_WAP .code ) {
283
- return {
284
- displayMode: PayDisplayModeEnum .QR_CODE .mode
285
- }
286
- }
287
-
288
- // ③ 支付宝 BarCode 支付时,需要传递 authCode 条形码
225
+ // ① 支付宝 BarCode 支付时,需要传递 authCode 条形码
289
226
if (channelCode === PayChannelEnum .ALIPAY_BAR .code ) {
290
227
return {
291
228
" channelExtras" : {
@@ -295,37 +232,12 @@ export default {
295
232
}
296
233
return {}
297
234
},
298
- /** 提交支付后,IFrame 内置 URL 的展示形式 */
299
- displayIFrame (channelCode , data ) {
300
- // TODO 芋艿:目前有点奇怪,支付宝总是会显示“支付环境存在风险”
301
- this .iframe = {
302
- title: ' 支付窗口' ,
303
- url: data .displayContent ,
304
- visible: true
305
- }
306
- this .submitLoading = false
307
- },
308
235
/** 提交支付后,URL 的展示形式 */
309
236
displayUrl (channelCode , data ) {
310
- // window.open(data.displayContent)window
237
+ // window.open(data.displayContent)
311
238
location .href = data .displayContent
312
239
this .submitLoading = false
313
240
},
314
- /** 提交支付后,Form 的展示形式 */
315
- displayForm (channelCode , data ) {
316
- // 渲染支付页面
317
- this .form = {
318
- value: data .displayContent
319
- }
320
- // 防抖避免重复支付
321
- this .$nextTick (() => {
322
- // 提交支付表单
323
- this .$refs .formRef .children [0 ].submit ();
324
- setTimeout (() => {
325
- this .submitLoading = false
326
- }, 1000 );
327
- });
328
- },
329
241
/** 提交支付后(支付宝扫码支付) */
330
242
displayQrCode (channelCode , data ) {
331
243
let title = ' 请使用手机浏览器“扫一扫”' ;
@@ -354,13 +266,13 @@ export default {
354
266
if (response .data .status === PayOrderStatusEnum .SUCCESS .status ) {
355
267
this .clearQueryInterval ();
356
268
this .$message .success (' 支付成功!' );
357
- this .goBackToList ();
269
+ this .goReturnUrl ();
358
270
}
359
271
// 已取消
360
272
if (response .data .status === PayOrderStatusEnum .CLOSED .status ) {
361
273
this .clearQueryInterval ();
362
274
this .$message .error (' 支付已关闭!' );
363
- this .goBackToList ();
275
+ this .goReturnUrl ();
364
276
}
365
277
})
366
278
}, 1000 * 2 )
@@ -377,14 +289,34 @@ export default {
377
289
clearInterval (this .interval )
378
290
this .interval = undefined
379
291
},
380
- /** 回到列表 **/
381
- goBackToList () {
382
- this .$tab .closePage ();
383
- this .$router .go (- 1 );
384
- // TODO 芋艿:需要优化;
385
- // this.$router.push({
386
- // path: this.returnUrl
387
- // });
292
+ /**
293
+ * 回到业务的 URL
294
+ *
295
+ * @param payResult 支付结果
296
+ * ① success:支付成功
297
+ * ② cancel:取消支付
298
+ * ③ close:支付已关闭
299
+ */
300
+ goReturnUrl (payResult ) {
301
+ // 未配置的情况下,只能关闭
302
+ if (! this .returnUrl ) {
303
+ this .$tab .closePage ();
304
+ return
305
+ }
306
+
307
+ const url = this .returnUrl .indexOf (' ?' ) >= 0
308
+ ? this .returnUrl + ' &payResult=' + payResult
309
+ : this .returnUrl + ' ?payResult=' + payResult
310
+ // 如果有配置,且是 http 开头,则浏览器跳转
311
+ if (this .returnUrl .indexOf (' http' ) === 0 ) {
312
+ location .href = url;
313
+ } else {
314
+ this .$tab .closePage (() => {
315
+ this .$router .push ({
316
+ path: url
317
+ });
318
+ });
319
+ }
388
320
}
389
321
}
390
322
};
0 commit comments