12
12
</el-descriptions >
13
13
</el-card >
14
14
15
-
16
15
<!-- 支付选择框 -->
17
16
<el-card style =" margin-top : 10px " v-loading =" submitLoading" element-loading-text =" 提交支付中..." >
18
17
<!-- 支付宝 -->
42
41
</div >
43
42
</el-card >
44
43
45
- <!-- 支付二维码 -->
44
+ <!-- 展示形式:二维码 -->
46
45
<el-dialog :title =" qrCode.title" :visible.sync =" qrCode.visible" width =" 350px" append-to-body
47
46
:close-on-press-escape =" false" >
48
47
<qrcode-vue :value =" qrCode.url" size =" 310" level =" H" />
49
48
</el-dialog >
50
49
50
+ <!-- 展示形式:iframe -->
51
+ <el-dialog :title =" iframe.title" :visible.sync =" iframe.visible" width =" 800px" height =" 800px" append-to-body
52
+ :close-on-press-escape =" false" >
53
+ <iframe :src =" iframe.url" width =" 100%" />
54
+ </el-dialog >
55
+
51
56
<!-- 阿里支付 -->
52
57
<div ref =" alipayWap" v-html =" alipayHtml.value" />
53
58
57
62
import QrcodeVue from ' qrcode.vue'
58
63
import { DICT_TYPE , getDictDatas } from " @/utils/dict" ;
59
64
import { getOrder , submitOrder } from ' @/api/pay/order' ;
60
- import { PayChannelEnum , PayOrderStatusEnum } from " @/utils/constants" ;
65
+ import {PayChannelEnum , PayDisplayModeEnum , PayOrderStatusEnum } from " @/utils/constants" ;
61
66
62
67
export default {
63
68
name: " PayOrderSubmit" ,
@@ -83,11 +88,16 @@ export default {
83
88
mock: require (" @/assets/images/pay/icon/mock.svg" ),
84
89
},
85
90
submitLoading: false , // 提交支付的 loading
86
- qrCode: { // 支付二维码
91
+ qrCode: { // 展示形式:二维码
87
92
url: ' ' ,
88
93
title: ' ' ,
89
94
visible: false ,
90
95
},
96
+ iframe: { // 展示形式:iframe
97
+ url: ' ' ,
98
+ title: ' ' ,
99
+ visible: false
100
+ },
91
101
interval: undefined , // 定时任务,轮询是否完成支付
92
102
alipayHtml: ' ' // 阿里支付的 HTML
93
103
};
@@ -146,21 +156,65 @@ export default {
146
156
this .submitLoading = true
147
157
submitOrder ({
148
158
id: this .id ,
149
- channelCode: channelCode
159
+ channelCode: channelCode,
160
+ ... this .buildSubmitParam (channelCode)
150
161
}).then (response => {
151
- const invokeResponse = response .data .invokeResponse
152
- // 不同的支付,调用不同的策略
153
- if (channelCode === PayChannelEnum .ALIPAY_QR .code ) {
154
- this .submitAfterAlipayQr (invokeResponse)
155
- } else if (channelCode === PayChannelEnum .ALIPAY_PC .code
156
- || channelCode === PayChannelEnum .ALIPAY_WAP .code ) {
157
- this .submitAfterAlipayPc (invokeResponse)
162
+ const data = response .data
163
+ if (data .displayMode === ' iframe' ) {
164
+ this .displayIFrame (channelCode, data)
165
+ } else if (data .displayMode === ' url' ) {
166
+ this .displayUrl (channelCode, data)
158
167
}
168
+ // 不同的支付,调用不同的策略
169
+ // if (channelCode === PayChannelEnum.ALIPAY_QR.code) {
170
+ // this.submitAfterAlipayQr(invokeResponse)
171
+ // } else if (channelCode === PayChannelEnum.ALIPAY_PC.code
172
+ // || channelCode === PayChannelEnum.ALIPAY_WAP.code) {
173
+ // this.submitAfterAlipayPc(invokeResponse)
174
+ // }
159
175
160
176
// 打开轮询任务
161
177
this .createQueryInterval ()
162
178
})
163
179
},
180
+ /** 构建提交支付的额外参数 */
181
+ buildSubmitParam (channelCode ) {
182
+ // 支付宝网页支付时,有多种展示形态
183
+ if (channelCode === PayChannelEnum .ALIPAY_PC .code ) {
184
+ // 情况【前置模式】:将二维码前置到商户的订单确认页的模式。需要商户在自己的页面中以 iframe 方式请求支付宝页面。具体支持的枚举值有以下几种:
185
+ // 0:订单码-简约前置模式,对应 iframe 宽度不能小于 600px,高度不能小于 300px
186
+ // return {
187
+ // "channelExtras": {
188
+ // "qr_pay_mode": "0"
189
+ // }
190
+ // }
191
+ // 1:订单码-前置模式,对应iframe 宽度不能小于 300px,高度不能小于 600px
192
+ // return {
193
+ // "channelExtras": {
194
+ // "qr_pay_mode": "1"
195
+ // }
196
+ // }
197
+ // 3:订单码-迷你前置模式,对应 iframe 宽度不能小于 75px,高度不能小于 75px
198
+ // return {
199
+ // "channelExtras": {
200
+ // "qr_pay_mode": "3"
201
+ // }
202
+ // }
203
+ // 4:订单码-可定义宽度的嵌入式二维码,商户可根据需要设定二维码的大小
204
+ // return {
205
+ // "channelExtras": {
206
+ // "qr_pay_mode": "2"
207
+ // }
208
+ // }
209
+ // 情况【跳转模式】:跳转模式下,用户的扫码界面是由支付宝生成的,不在商户的域名下。支持传入的枚举值有
210
+ return {
211
+ " channelExtras" : {
212
+ " qr_pay_mode" : " 2"
213
+ }
214
+ }
215
+ }
216
+ return {}
217
+ },
164
218
/** 提交支付后(支付宝扫码支付) */
165
219
submitAfterAlipayQr (invokeResponse ) {
166
220
this .qrCode = {
@@ -170,6 +224,19 @@ export default {
170
224
}
171
225
this .submitLoading = false
172
226
},
227
+ displayIFrame (channelCode , data ) {
228
+ // this.iframe = {
229
+ // title: '支付窗口',
230
+ // url: data.displayContent,
231
+ // visible: true
232
+ // }
233
+ window .open (data .displayContent )
234
+ },
235
+ /** 提交支付后,URL 的展示形式 */
236
+ displayUrl (channelCode , data ) {
237
+ window .open (data .displayContent )
238
+ this .submitLoading = false
239
+ },
173
240
/** 提交支付后(支付宝 PC 网站支付) */
174
241
submitAfterAlipayPc (invokeResponse ) {
175
242
// 渲染支付页面
@@ -188,6 +255,9 @@ export default {
188
255
},
189
256
/** 轮询查询任务 */
190
257
createQueryInterval () {
258
+ if (! this .interval ) {
259
+ return
260
+ }
191
261
this .interval = setInterval (() => {
192
262
getOrder (this .id ).then (response => {
193
263
// 已支付
0 commit comments