ソースを参照

[add] bug fix

wenliming 3 年 前
コミット
645bff1342

+ 25 - 1
library/paypal.html

@@ -27,6 +27,11 @@
         <!-- Set up a container element for the button -->
         <div id="paypal-button-container"></div>
         <script>
+            let isDOMContentLoaded = false;
+            let isOnMessage = false;
+            document.addEventListener("DOMContentLoaded", function () {
+                isDOMContentLoaded = true;
+            })
             function loadAsyncScript(src, callback = function () {}) { // 同步加载js
                 const head = document.getElementsByTagName('head')[0];
                 const script = document.createElement('script');
@@ -61,7 +66,26 @@
             let paypalClientId = getQueryString('paypalClientId');
             let src = `https://www.paypal.com/sdk/js?client-id=${paypalClientId}&currency=USD`;
             loadAsyncScript(src, () => {
+                if(isDOMContentLoaded) {
+                    loadPaypal();
+                } else {
+                    document.addEventListener("DOMContentLoaded", function () {
+                        isDOMContentLoaded = true;
+                        if(!isOnMessage) {
+                            loadPaypal()
+                        }
+                    })
+                    setTimeout(() => {
+                        if(!isOnMessage) {
+                            loadPaypal()
+                        }
+                    }, 600)
+                }
+            })
+
+            function loadPaypal() {
                 let amount = 0;
+                isOnMessage = true;
                 window.parent.postMessage({ actionType: "iframeLoaded" }, "*");
                 window.addEventListener("message", function (event) {
                     if (event.data && event.data.actionType) {
@@ -73,7 +97,7 @@
                             }
                     }
                 });
-            })
+            }
 
             function initPaypal(amount) {
                 let dom = document.getElementById('paypal-button-container');

+ 36 - 19
src/view/components/give-dialog.vue

@@ -1,7 +1,7 @@
 <template>
     <div class="overlay" v-if="visible">
         <div class="content"
-            :style="{height: showPreview ? previewDialogHeight + 'px' : dialogHeight +'px' }">
+            :style="{height: dialogHeight +'px' }">
             <div class="head">
                 <div class="left">
                     <div class="close-btn" @click="close">
@@ -157,7 +157,6 @@ let visible = ref(false);
 let showPreview = ref(false);
 let openAntiBot = ref(false);
 let dialogHeight = ref(680);
-let previewDialogHeight = ref(680);
 let submitIng = ref(false);
 let atUserList = ref([]);
 let iptErrMsgTxt = ref('');
@@ -228,14 +227,14 @@ const close = () => {
     }
 };
 
-// const setPreviewDialogHeight = () => {
-//     let clientHeight = document.documentElement.clientHeight;
-//     let gapSafe = 40;
+const setDialogHeight = () => {
+    let clientHeight = document.documentElement.clientHeight;
+    let gapSafe = 40;
 
-//     if(previewDialogHeight.value > clientHeight - gapSafe) {
-//         previewDialogHeight.value = clientHeight - gapSafe;
-//     }
-// };
+    if(dialogHeight.value > clientHeight - gapSafe) {
+        dialogHeight.value = clientHeight - gapSafe;
+    }
+};
 
 const getPayAmount = (amountValue, cb) => {
     payCalcFee({
@@ -361,15 +360,33 @@ const payPalFinsh = (params) => {
         loadingInstance.close();
         if(res.code == 0) {
             //支付状态 0:未支付,1:支付成功,2:支付失败,3:已关闭,4:已退款
-            if(res.data && res.data.payStatus == 1) {
-                emits("payPalFinsh", {publishRes});
-                showPreview.value = false;
-                initParams();
-            } else {
-                ElMessage({
-                    message: 'pay error',
-                    type: 'warning',
-                })
+            if(res.data) {
+                let payStatus = res.data.payStatus;
+                switch (payStatus) {
+                    case 1:
+                        emits("payPalFinsh", {publishRes});
+                        showPreview.value = false;
+                        initParams();
+                        break;
+                    case 2:
+                        ElMessage({
+                            message: 'Pay Fail',
+                            type: 'warning',
+                        })
+                        break;
+                    case 3:
+                        ElMessage({
+                            message: 'Pay Exceptions',
+                            type: 'warning',
+                        })
+                        break;
+                    case 4:
+                        ElMessage({
+                            message: 'Pay Exceptions',
+                            type: 'warning',
+                        })
+                        break;
+                }
             }
         }
     }).catch(() => {
@@ -466,8 +483,8 @@ const setFrontConfig = () => {
 }
 
 onMounted(() => {
-    // setPreviewDialogHeight();
     setFrontConfig();
+    setDialogHeight();
     setPayConfig();
     document.onkeydown = function(e){    
         var keyNum=window.event ? e.keyCode :e.which;

+ 1 - 1
src/view/components/paypal-button.vue

@@ -35,7 +35,7 @@ const props = defineProps({
         default: () => {
             return {
                 paypalClientId: '',
-                paypalHtml: ''
+                paypalHtml: 'https://d1mcov78iir8kk.cloudfront.net/website/paypal.html'
             }
         }
     }