|
@@ -8,6 +8,7 @@ import {
|
|
|
ionicStandaloneModules,
|
|
|
AlertController,
|
|
|
ToastController,
|
|
|
+ LoadingController,
|
|
|
} from '../../../modules/ionic-standalone.modules';
|
|
|
declare var wx: any;
|
|
|
|
|
@@ -36,12 +37,14 @@ export class PayCompComponent implements OnInit {
|
|
|
user: Parse.Object = Parse.User.current()!;
|
|
|
timer: any; //定时查询
|
|
|
accountLog?: Parse.Object; // 充值记录
|
|
|
+ loading:any //等待
|
|
|
constructor(
|
|
|
private accServ: AccountService,
|
|
|
private toastController: ToastController,
|
|
|
private alertCtrl: AlertController,
|
|
|
private http: HttpClient,
|
|
|
- private activRoute: ActivatedRoute
|
|
|
+ private activRoute: ActivatedRoute,
|
|
|
+ private loadingCtrl: LoadingController,
|
|
|
) {}
|
|
|
|
|
|
ngOnInit() {
|
|
@@ -215,23 +218,38 @@ export class PayCompComponent implements OnInit {
|
|
|
/* 支付宝支付 */
|
|
|
async openAlipay() {
|
|
|
if (this.isDisabled) return;
|
|
|
+ this.loading = await this.loadingCtrl.create({
|
|
|
+ message: '正在操作',
|
|
|
+ });
|
|
|
+ this.loading.present();
|
|
|
try {
|
|
|
this.isDisabled = true;
|
|
|
await this.getOrderId();
|
|
|
let data: any = await this.getAliPayUrl();
|
|
|
console.log(data);
|
|
|
- // window.open(data.pay_url, "newW");
|
|
|
- // 创建一个临时的div元素来解析HTML字符串
|
|
|
+
|
|
|
const tempDiv = document.createElement('div');
|
|
|
tempDiv.innerHTML = data.pay_url; // 假设data.pay_url是完整的HTML字符串
|
|
|
const formElement = tempDiv.querySelector('form');
|
|
|
if (formElement) {
|
|
|
+ // 阻止默认行为,避免页面刷新
|
|
|
+ formElement.addEventListener('submit', (event) => {
|
|
|
+ event.preventDefault();
|
|
|
+ });
|
|
|
+ // 添加隐藏的iframe来提交表单
|
|
|
+ const iframe = document.createElement('iframe');
|
|
|
+ iframe.style.display = 'none';
|
|
|
+ document.body.appendChild(iframe);
|
|
|
+ formElement.target = iframe.name;
|
|
|
+
|
|
|
document.body.appendChild(formElement);
|
|
|
formElement.submit();
|
|
|
document.body.removeChild(formElement); // 提交后移除表单元素
|
|
|
} else {
|
|
|
console.error('未找到表单元素');
|
|
|
+ this.loading?.dismiss();
|
|
|
}
|
|
|
+
|
|
|
this.timer = setInterval(async () => {
|
|
|
console.log('支付结果轮询');
|
|
|
let AccountLog = new Parse.Query('AccountLog');
|
|
@@ -240,6 +258,8 @@ export class PayCompComponent implements OnInit {
|
|
|
AccountLog.equalTo('payType', 'aliPay');
|
|
|
AccountLog.equalTo('isVerified', true);
|
|
|
let result = await AccountLog.first();
|
|
|
+ this.loading?.dismiss();
|
|
|
+
|
|
|
if (result && result.id) {
|
|
|
clearInterval(this.timer);
|
|
|
this.timer = null;
|
|
@@ -256,6 +276,7 @@ export class PayCompComponent implements OnInit {
|
|
|
}
|
|
|
}, 1000);
|
|
|
} catch (err: any) {
|
|
|
+ this.loading?.dismiss();
|
|
|
this.isDisabled = false;
|
|
|
let alert = await this.alertCtrl.create({
|
|
|
header: '异常错误',
|