index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="container">
  3. <web-view :src="pageUrl" v-if="pageUrl" update-title allow="fullscreen" @message="handleMessage"></web-view>
  4. <image src="@/static/images/course_expiration_img.png" mode="aspectFill"></image>
  5. <view>{{msg}}</view>
  6. </view>
  7. </template>
  8. <script>
  9. import {
  10. getRealLink,
  11. updateSopAppLink
  12. } from "@/api/courseAnswer.js"
  13. export default {
  14. data() {
  15. return {
  16. pageUrl:"",
  17. msg: '加载中...',
  18. userInfo: {}
  19. }
  20. },
  21. onLoad(option) {
  22. this.userInfo = uni.getStorageSync("userInfo") ? JSON.parse(uni.getStorageSync("userInfo")) : {}
  23. if (option.link) {
  24. this.getLink(option.link)
  25. this.getCourseRead(option.link)
  26. } else {
  27. this.msg = "link is not found"
  28. uni.showToast({
  29. title: "link is not found",
  30. icon: 'error'
  31. })
  32. }
  33. },
  34. onUnload() {
  35. // #ifdef APP-PLUS
  36. plus.navigator.setFullscreen(false);
  37. plus.screen.lockOrientation('portrait-primary');
  38. // #endif
  39. },
  40. onBackPress() {
  41. // #ifdef APP-PLUS
  42. // 返回时退出全屏
  43. plus.navigator.setFullscreen(false);
  44. plus.screen.lockOrientation('portrait-primary');
  45. // #endif
  46. },
  47. methods: {
  48. getCourseRead(id) {
  49. updateSopAppLink(id).then(res=>{
  50. if(res.code == 200) {
  51. this.$updateMsgDot()
  52. }
  53. })
  54. },
  55. handleMessage(event) {
  56. const info = event.detail.data[0]
  57. // #ifdef APP-PLUS
  58. if(info.login != 1) {
  59. this.$showLoginPage()
  60. return
  61. }
  62. if (info&&info.isFullscreen) {
  63. plus.screen.lockOrientation('landscape-primary');
  64. } else {
  65. plus.screen.lockOrientation('portrait-primary');
  66. }
  67. if(info&&info.productId) {
  68. uni.navigateTo({
  69. url: '/pages/user/integral/integralGoodsDetails?goodsId='+info.productId
  70. })
  71. }
  72. if(info&&info.pagesUrl) {
  73. uni.navigateTo({
  74. url: info.pagesUrl
  75. })
  76. }
  77. // #endif
  78. },
  79. getLink(sortLink) {
  80. this.msg = '加载中...'
  81. const userId = this.userInfo.userId || ''
  82. getRealLink({
  83. sortLink: sortLink
  84. }).then(res => {
  85. if (res.code == 200) {
  86. // 如果响应中包含真实链接,则跳转到真实链接
  87. this.pageUrl = res.realLink + "&userId="+userId+"&source=app&time=" + new Date().getTime()
  88. // console.log("this.pageUrl============",this.pageUrl)
  89. } else {
  90. this.msg = '课程已过期或链接无效'
  91. uni.showModal({
  92. title: '提示',
  93. content: '课程已过期或链接无效',
  94. showCancel: false,
  95. success: function(res) {
  96. if (res.confirm) {
  97. console.log('用户点击确定');
  98. } else if (res.cancel) {
  99. console.log('用户点击取消');
  100. }
  101. }
  102. });
  103. }
  104. }).catch(err => {
  105. this.msg = '发生错误,请稍后再试'
  106. uni.showToast({
  107. title: '发生错误,请稍后再试',
  108. icon: 'none'
  109. });
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style scoped lang="scss">
  116. .container {
  117. display: flex;
  118. flex-direction: column;
  119. align-items: center;
  120. padding-bottom: 88rpx;
  121. justify-content: center;
  122. font-family: PingFang SC, PingFang SC;
  123. font-weight: 400;
  124. font-size: 32rpx;
  125. color: #757575;
  126. line-height: 48rpx;
  127. text-align: center;
  128. image {
  129. width: 428rpx;
  130. height: 360rpx;
  131. margin-bottom: 30rpx;
  132. }
  133. }
  134. </style>