index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 {getRealLink,updateSopAppLink} from "@/api/courseAnswer.js"
  10. export default {
  11. data() {
  12. return {
  13. pageUrl:"",
  14. msg: '加载中...',
  15. userInfo: {}
  16. }
  17. },
  18. onLoad(option) {
  19. this.userInfo = uni.getStorageSync("userInfo") ? JSON.parse(uni.getStorageSync("userInfo")) : {};
  20. let link = option.link
  21. if (link) {
  22. this.getLink(link)
  23. this.getCourseRead(link)
  24. } else {
  25. this.msg = "链接地址空的"
  26. uni.showToast({
  27. title: "链接地址空的",
  28. icon: 'error'
  29. })
  30. }
  31. },
  32. onUnload() {
  33. // #ifdef APP-PLUS
  34. plus.navigator.setFullscreen(false);
  35. plus.screen.lockOrientation('portrait-primary');
  36. // #endif
  37. },
  38. onBackPress() {
  39. // #ifdef APP-PLUS
  40. // 返回时退出全屏
  41. plus.navigator.setFullscreen(false);
  42. plus.screen.lockOrientation('portrait-primary');
  43. // #endif
  44. },
  45. methods: {
  46. getCourseRead(id) {
  47. updateSopAppLink(id).then(res=>{
  48. if(res.code == 200) {
  49. this.$updateMsgDot()
  50. }
  51. })
  52. },
  53. handleMessage(event) {
  54. const info = event.detail.data[0]
  55. // #ifdef APP-PLUS
  56. if(info.login != 1) {
  57. // 退出登录
  58. let IMUserID = uni.getStorageSync('IMUserID');
  59. //Igexin.unbindAlias(IMUserID);
  60. uni.removeStorage({key: "IMUserID"});
  61. uni.setStorageSync("AppToken",null);
  62. uni.removeStorage({ key: 'IMToken' });
  63. uni.removeStorageSync("onLaunch",null)
  64. uni.removeStorageSync("imUnread",null);
  65. uni.removeStorageSync("companyUser");
  66. uni.removeStorageSync("CompanyUserToken");
  67. uni.$emit("refreshUserInfo");
  68. let pages = getCurrentPages();
  69. let url = pages[ pages.length - 1]; //当前页页面实例
  70. //如果登录界面已打开,自动关闭
  71. if(url!=undefined&&url.route=="pages/auth/loginIndex"){
  72. return;
  73. }
  74. uni.navigateTo({
  75. url: '/pages/auth/loginIndex'
  76. });
  77. return
  78. }
  79. if (info&&info.isFullscreen) {
  80. plus.screen.lockOrientation('landscape-primary');
  81. } else {
  82. plus.screen.lockOrientation('portrait-primary');
  83. }
  84. if(info&&info.productId) {
  85. uni.navigateTo({
  86. url: '/pages/user/integral/integralGoodsDetails?goodsId='+info.productId
  87. })
  88. }
  89. console.log("event===info===",info)
  90. if(info&&info.pagesUrl) {
  91. uni.navigateTo({
  92. url: info.pagesUrl
  93. })
  94. }
  95. // #endif
  96. },
  97. getLink(sortLink) {
  98. this.msg = '加载中...'
  99. const userId = this.userInfo.userId || ''
  100. getRealLink({sortLink: sortLink}).then(res => {
  101. if (res.code == 200) {
  102. // 如果响应中包含真实链接,则跳转到真实链接
  103. let pageUrl= res.realLink + "&userId="+userId+"&source=app&time=" + new Date().getTime();
  104. this.pageUrl = pageUrl;
  105. console.log("this.pageUrl)====",this.pageUrl)
  106. } else {
  107. this.msg = '课程已过期或链接无效'
  108. uni.showModal({
  109. title: '提示',
  110. content: '课程已过期或链接无效',
  111. showCancel: false,
  112. success: function(res) {
  113. if (res.confirm) {
  114. console.log('用户点击确定');
  115. } else if (res.cancel) {
  116. console.log('用户点击取消');
  117. }
  118. }
  119. });
  120. }
  121. }).catch(err => {
  122. this.msg = '发生错误,请稍后再试'
  123. uni.showToast({
  124. title: '发生错误,请稍后再试',
  125. icon: 'none'
  126. });
  127. })
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped lang="scss">
  133. .container {
  134. display: flex;
  135. flex-direction: column;
  136. align-items: center;
  137. padding-bottom: 88rpx;
  138. justify-content: center;
  139. font-family: PingFang SC, PingFang SC;
  140. font-weight: 400;
  141. font-size: 32rpx;
  142. color: #757575;
  143. line-height: 48rpx;
  144. text-align: center;
  145. image {
  146. width: 428rpx;
  147. height: 360rpx;
  148. margin-bottom: 30rpx;
  149. }
  150. }
  151. </style>