googlePayment_app.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="wallet_app" v-if="show">
  3. <view class="wallet_footer" :style="{ 'height': footerHeight + 'px' }">
  4. <view class="close">
  5. <view class="close_icon" @click.stop="close">
  6. <uni-icons type="closeempty" size="28" color="var(--text-01)"></uni-icons>
  7. </view>
  8. </view>
  9. <!-- <iframe :src="fullUrl"></iframe> -->
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import { systemInfo, Toast, openUrl } from "@/utils"
  15. import { SHOP_SUBMIT_PAY } from '@/api'
  16. export default {
  17. props: {
  18. paramsObj: { type: Object }
  19. },
  20. data() {
  21. return {
  22. webview: null,
  23. show: false,
  24. footerHeight: 0,
  25. googleParams: {},
  26. // srcUrl: 'http://192.168.5.103:4000/static/hybrid/html/google.html',
  27. srcUrl: 'https://get.vavabuy.com/google.html',
  28. }
  29. },
  30. methods: {
  31. open() {
  32. this.show = true;
  33. this.$nextTick(() => {
  34. this.fetchPaymentInfo()
  35. })
  36. },
  37. close() {
  38. this.webview && this.webview.close();
  39. this.webview = null;
  40. this.show = false
  41. },
  42. getRequest(url) {
  43. let theRequest = new Object();
  44. let index = url.indexOf("?");
  45. if (index != -1) {
  46. let str = url.substring(index + 1);
  47. let strs = str.split("&");
  48. for (let i = 0; i < strs.length; i++) {
  49. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  50. }
  51. }
  52. return theRequest;
  53. },
  54. async initWebViewBelowElement(eventData) {
  55. console.log(21121);
  56. try {
  57. let wvPath = '/static/hybrid/html/google.html';
  58. let wv = plus.webview.create("", wvPath, {
  59. 'uni-app': 'none',
  60. position: 'fixed',
  61. background: 'transparent',
  62. left: '24px',
  63. right: '24px',
  64. top: this.footerHeight + 48 + 28 + 'px',
  65. overflowY: 'auto',
  66. });
  67. wv.loadURL(wvPath);
  68. wv.overrideUrlLoading({ mode: 'reject' }, (e) => {
  69. console.log('回调地址',JSON.stringify(e));
  70. if (e.url && e.url.includes('pay.google.com')) return openUrl(e.url);
  71. let { str } = this.getRequest(e.url);
  72. str = unescape(str)
  73. return this.handleBack(str)
  74. });
  75. wv.evalJS(`
  76. window.dispatchEvent(new CustomEvent('appMessage',
  77. { detail: ${JSON.stringify(eventData)} }))`);
  78. this.$root.$scope.$getAppWebview().append(wv);
  79. this.webview = wv;
  80. } catch (error) {
  81. console.error(error);
  82. }
  83. },
  84. async fetchPaymentInfo() {
  85. const params = this.paramsObj ? this.paramsObj : {}
  86. try {
  87. const res = await SHOP_SUBMIT_PAY({
  88. payType: 'airwallex',
  89. ...params
  90. })
  91. const { id, client_secret, amount, currency, countryCode } = res.data;
  92. const paramsData = {
  93. intent_id: id,
  94. client_secret: client_secret,
  95. amount: {
  96. value: amount,
  97. currency,
  98. },
  99. countryCode: countryCode
  100. }
  101. this.googleParams = paramsData;
  102. this.initWebViewBelowElement({ type: 'pay', ...this.googleParams })
  103. }
  104. catch (error) {
  105. console.log('----- fetch info error ----- ', JSON.stringify(error))
  106. Toast(error.msg)
  107. }
  108. },
  109. handleBack(str) {
  110. console.log('----- 收到消息 -----', str);
  111. }
  112. },
  113. async mounted() {
  114. const res = await systemInfo();
  115. this.footerHeight = res.windowHeight / 2;
  116. /* this.$nextTick(() => {
  117. this.fetchPaymentInfo()
  118. }) */
  119. }
  120. }
  121. </script>
  122. <style lang="less" scoped>
  123. .wallet_app {
  124. position: fixed;
  125. top: 0;
  126. left: 0;
  127. right: 0;
  128. bottom: 0;
  129. z-index: 9999999;
  130. background-color: rgba(0, 0, 0, .5);
  131. display: flex;
  132. align-items: flex-end;
  133. .wallet_footer {
  134. width: 100%;
  135. background-color: #fff;
  136. padding: 24px;
  137. border-radius: 10px 10px 0 0;
  138. .close {
  139. height: 28px;
  140. display: flex;
  141. justify-content: flex-end;
  142. }
  143. }
  144. }
  145. </style>