paypal-button.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div class="pay-wrapper">
  3. <div class="pay-msg">
  4. <div class="row">Pay ${{amount || 0}}</div>
  5. <div class="msg">Generate Giveaways</div>
  6. </div>
  7. <div class="pay-btn">
  8. <iframe
  9. class="iframe-pay"
  10. ref="iframe"
  11. :src="`https://art-weapp.oss-cn-hangzhou.aliyuncs.com/chromeExtension/paypal.html?amount=${amount}`"></iframe>
  12. </div>
  13. </div>
  14. </template>
  15. <script setup>
  16. import { onMounted, ref, defineProps, defineEmits } from "vue";
  17. let iframe = ref(null);
  18. const props = defineProps({
  19. amount: {
  20. type: Number,
  21. default: 0,
  22. },
  23. });
  24. const emits = defineEmits(["payPalFinsh"]);
  25. onMounted(() => {
  26. window.addEventListener("message", function (event) {
  27. if (event.data && event.data.actionType) {
  28. switch (event.data.actionType) {
  29. case "payCallBack":
  30. console.log(
  31. "payCallBack",
  32. event.data.orderData,
  33. event.data.transaction
  34. );
  35. emits("payPalFinsh", event.data);
  36. break;
  37. case "iframeLoaded":
  38. iframe.value.contentWindow.postMessage(
  39. { actionType: "setAmount", amount: props.amount },
  40. "*"
  41. );
  42. break;
  43. }
  44. }
  45. });
  46. });
  47. </script>
  48. <style lang="scss" scoped>
  49. .pay-wrapper {
  50. width: 100%;
  51. height: 68px;
  52. background-color: #fff;
  53. position: absolute;
  54. left: 0;
  55. bottom: 0;
  56. box-shadow: 0px -2px 20px 0px #00000026;
  57. border-bottom-right-radius: 16px;
  58. padding: 12px 30px;
  59. box-sizing: border-box;
  60. display: flex;
  61. align-items: center;
  62. justify-content: flex-end;
  63. .pay-msg {
  64. text-align: right;
  65. margin-right: 25px;
  66. .row {
  67. font-weight: 600;
  68. font-size: 17px;
  69. }
  70. .msg {
  71. font-size: 13px;
  72. color: rgba($color: #000000, $alpha: .54);
  73. }
  74. }
  75. .pay-btn {
  76. width: 206px;
  77. height: 48px;
  78. iframe {
  79. border: medium none;
  80. width: 100%;
  81. height: 100%;
  82. }
  83. }
  84. }
  85. </style>