index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="container">
  3. <web-view ref="webviewRef" :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. //import {getUserLiveInfo} from '@/api/living.js'
  11. export default {
  12. data() {
  13. return {
  14. pageUrl:"",
  15. msg: '加载中...',
  16. userInfo: {}
  17. }
  18. },
  19. onLoad(option) {
  20. // console.log('------userData',uni.getStorageSync('userInfo'))
  21. this.userInfo = uni.getStorageSync("userInfo") ? JSON.parse(uni.getStorageSync("userInfo")) : {};
  22. //this.getUserLiveInfo()
  23. // const userId = this.userInfo.userId || ''
  24. const liveId = option.liveId
  25. if (liveId) {
  26. const baseUrl ="https://liveapp.zkhj6.com/appweb/pages_live/living?liveId="+liveId+'&source=app'
  27. // const baseUrl = "http://192.168.110.151:1911/appweb/pages_live/living?liveId=" + liveId
  28. // 用一个集合传参到 living(web-view 内 H5 与原生 storage 隔离)
  29. const payload = {
  30. source: 'app',
  31. liveToken: uni.getStorageSync('liveToken') || '',
  32. //liveUserId:uni.getStorageSync('liveUserId') || '',
  33. userInfo: uni.getStorageSync('userInfo') || '',
  34. // userData: uni.getStorageSync('userData') || '',
  35. userData: uni.getStorageSync('userInfo') || '',
  36. hasSubscribed:uni.getStorageSync('subscribe_status_' + liveId)?'true':'false'
  37. }
  38. // console.log('【【【【【【',uni.getStorageSync('liveToken'));
  39. // console.log('【【【【【【',payload);
  40. // console.log("event===info===",payload.liveToken)
  41. this.pageUrl = baseUrl + '&payload=' + encodeURIComponent(JSON.stringify(payload))
  42. //this.getLink(link)
  43. //this.getCourseRead(link)
  44. } else {
  45. this.msg="缺少直播Id"
  46. uni.showToast({
  47. title: "缺少直播Id",
  48. icon: 'error'
  49. })
  50. }
  51. },
  52. onUnload() {
  53. // #ifdef APP-PLUS
  54. plus.navigator.setFullscreen(false);
  55. plus.screen.lockOrientation('portrait-primary');
  56. // #endif
  57. },
  58. onBackPress() {
  59. // #ifdef APP-PLUS
  60. // 返回时退出全屏
  61. plus.navigator.setFullscreen(false);
  62. plus.screen.lockOrientation('portrait-primary');
  63. // #endif
  64. },
  65. methods: {
  66. getUserLiveInfo(){
  67. getUserLiveInfo().then((res) => {
  68. if (res.code == 200) {
  69. const liveUserId=res.user.userId
  70. uni.setStorageSync('liveUserId', liveUserId)
  71. //console.log('liveUser', res.user)
  72. } else {
  73. uni.showToast({
  74. icon: 'none',
  75. title: '请求失败'
  76. })
  77. }
  78. },
  79. (rej) => {}
  80. )
  81. },
  82. getCourseRead(id) {
  83. updateSopAppLink(id).then(res=>{
  84. if(res.code == 200) {
  85. this.$updateMsgDot()
  86. }
  87. })
  88. },
  89. handleMessage(event) {
  90. console.log('点击事件',event)
  91. const info = event.detail.data[0]
  92. // #ifdef APP-PLUS
  93. // if(info.login != 1) {
  94. // // 退出登录
  95. // let IMUserID = uni.getStorageSync('IMUserID');
  96. // //Igexin.unbindAlias(IMUserID);
  97. // uni.removeStorage({key: "IMUserID"});
  98. // uni.setStorageSync("AppToken",null);
  99. // uni.setStorageSync("liveToken",null);
  100. // uni.removeStorage({ key: 'IMToken' });
  101. // uni.removeStorageSync("onLaunch",null)
  102. // uni.removeStorageSync("imUnread",null);
  103. // uni.removeStorageSync("companyUser");
  104. // uni.removeStorageSync("CompanyUserToken");
  105. // uni.$emit("refreshUserInfo");
  106. // let pages = getCurrentPages();
  107. // let url = pages[ pages.length - 1]; //当前页页面实例
  108. // //如果登录界面已打开,自动关闭
  109. // if(url!=undefined&&url.route=="pages/auth/loginIndex"){
  110. // return;
  111. // }
  112. // uni.navigateTo({
  113. // url: '/pages/auth/loginIndex'
  114. // });
  115. // return
  116. // }
  117. // if (info&&info.isFullscreen) {
  118. // plus.screen.lockOrientation('landscape-primary');
  119. // } else {
  120. // plus.screen.lockOrientation('portrait-primary');
  121. // }
  122. //立即购买
  123. if(info&&info.pagesUrl) {
  124. if(info.isBack){
  125. uni.navigateBack()
  126. }else{
  127. console.log('+++++++++++++++++++++++++++++')
  128. uni.navigateTo({
  129. url: info.pagesUrl
  130. })
  131. }
  132. }
  133. // //
  134. // if(info&&info.productId) {
  135. // uni.navigateTo({
  136. // url: info.pagesUrl
  137. // })
  138. // }
  139. // console.log("event===info===",info)
  140. // if(info&&info.pagesUrl) {
  141. // uni.navigateTo({
  142. // url: info.pagesUrl
  143. // })
  144. // }
  145. // #endif
  146. },
  147. getLink(sortLink) {
  148. this.msg = '加载中...'
  149. const userId = this.userInfo.userId || ''
  150. getRealLink({sortLink: sortLink}).then(res => {
  151. if (res.code == 200) {
  152. // 如果响应中包含真实链接,则跳转到真实链接
  153. let pageUrl= res.realLink + "&userId="+userId+"&source=app&time=" + new Date().getTime();
  154. this.pageUrl = pageUrl;
  155. } else {
  156. this.msg = '课程已过期或链接无效'
  157. uni.showModal({
  158. title: '提示',
  159. content: '课程已过期或链接无效',
  160. showCancel: false,
  161. success: function(res) {
  162. if (res.confirm) {
  163. console.log('用户点击确定');
  164. } else if (res.cancel) {
  165. console.log('用户点击取消');
  166. }
  167. }
  168. });
  169. }
  170. }).catch(err => {
  171. this.msg = '发生错误,请稍后再试'
  172. uni.showToast({
  173. title: '发生错误,请稍后再试',
  174. icon: 'none'
  175. });
  176. })
  177. }
  178. }
  179. }
  180. </script>
  181. <style scoped lang="scss">
  182. .container {
  183. display: flex;
  184. flex-direction: column;
  185. align-items: center;
  186. padding-bottom: 88rpx;
  187. justify-content: center;
  188. font-family: PingFang SC, PingFang SC;
  189. font-weight: 400;
  190. font-size: 32rpx;
  191. color: #757575;
  192. line-height: 48rpx;
  193. text-align: center;
  194. image {
  195. width: 428rpx;
  196. height: 360rpx;
  197. margin-bottom: 30rpx;
  198. }
  199. }
  200. </style>