洛阳学员端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.2 KiB

4 months ago
4 months ago
  1. <template>
  2. <view class="">
  3. <web-view :src="$store.state.webViewUrl" @onPostMessage="postMessage" @message="postMessage" :webview-styles="webviewStyles"></web-view>
  4. <!-- <web-view src="http://192.168.1.44:92/vue/wxStudentCertificate3" @onPostMessage="postMessage" @message="postMessage"></web-view> -->
  5. </view>
  6. </template>
  7. <script>
  8. let polling = null
  9. let timerNum = 0
  10. import { order_info } from '@/config/api.js'
  11. export default {
  12. data() {
  13. return {
  14. iswxPay: false,
  15. webviewStyles: {
  16. progress: {
  17. color: '#3877ff'
  18. },
  19. },
  20. sweixin: null
  21. }
  22. },
  23. onLoad(options) {
  24. this.outTradeNo = options.outTradeNo
  25. this.initWx()
  26. this.order_infoFn()
  27. },
  28. onShow() {
  29. if(this.iswxPay) {
  30. timerNum = 0
  31. this.pollFn()
  32. }
  33. },
  34. onHide() {
  35. clearInterval(polling)
  36. polling = null
  37. },
  38. methods: {
  39. // 监听h5事件
  40. postMessage(res) {
  41. console.log('监听到了')
  42. let item = res.detail.data[0]
  43. console.log(res)
  44. console.log('监听到的发送事件')
  45. console.log(item)
  46. if(item.action=='ysb-wxPay') {
  47. // this.$u.toast('用户点击了微信支付')
  48. this.iswxPay = true
  49. this.wxPay(item)
  50. }else if(item.action=='ysb-paySuccess') {
  51. this.$u.toast('支付成功')
  52. this.iswxPay = false
  53. this.$store.dispatch('getUserInfo')
  54. setTimeout(()=>{
  55. uni.switchTab({
  56. url: '/pages/tabbar/learnCar/index'
  57. })
  58. },800)
  59. }
  60. },
  61. // 轮询定时
  62. pollFn() {
  63. polling = setInterval(async ()=>{
  64. timerNum ++
  65. if(timerNum>10) {
  66. clearInterval(polling)
  67. polling = null
  68. }
  69. await this.order_infoFn()
  70. },1000)
  71. },
  72. // 查询订单状态
  73. async order_infoFn() {
  74. const {data: res} = await order_info({outTradeNo:this.outTradeNo})
  75. if(res.status==10) {
  76. this.$u.toast('支付成功')
  77. clearInterval(polling)
  78. polling = null
  79. setTimeout(()=>{
  80. uni.switchTab({
  81. url: '/pages/tabbar/learnCar/index'
  82. })
  83. },1500)
  84. }
  85. console.log('订单状态')
  86. console.log(res)
  87. },
  88. // "action": "lyxc-wxPay",
  89. // "miniProgramType": 2,
  90. // "miniAppId": "gh_89b377cbc340",
  91. // "path": "/pages/wxPayOnly/wxPayOnly?channelNo=QD202404083509&orderNo=20240423170705024771&inpartNo=820198016000045&merchantName=中原智慧新校园&amount=1&redMsg=&payType=04"
  92. // 跳转到微信支付
  93. wxPay(item) {
  94. console.log(item)
  95. // #ifdef APP-PLUS
  96. this.sweixin ? this.sweixin.launchMiniProgram({
  97. path: item.path, //跳转小程序页面路径 pages/index/index
  98. type: item.miniProgramType, //可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
  99. id: item.miniAppId //小程序的原始id
  100. }) : plus.nativeUI.alert('当前环境不支持微信操作!');
  101. // #endif
  102. },
  103. // 初始化微信支付方法
  104. initWx() {
  105. // #ifdef APP-PLUS
  106. plus.share.getServices((s) => {
  107. var shares = {};
  108. for (var i = 0; i < s.length; i++) {
  109. var t = s[i];
  110. console.log("...........", t);
  111. shares[t.id] = t;
  112. }
  113. var sweixin = shares['weixin'];
  114. this.sweixin = sweixin
  115. }, function(e) {
  116. console.log("获取分享服务列表失败:" + e.message);
  117. });
  118. // #endif
  119. },
  120. }
  121. }
  122. </script>
  123. <style>
  124. </style>