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

125 lines
3.2 KiB

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