洛阳学员端
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.

119 lines
3.0 KiB

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