| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <template>
- <view class="container">
- <web-view ref="webviewRef" :src="pageUrl" v-if="pageUrl" update-title allow="fullscreen" @message="handleMessage"></web-view>
- <image src="@/static/images/course_expiration_img.png" mode="aspectFill"></image>
- <view>{{msg}}</view>
- </view>
- </template>
- <script>
- import {getRealLink,updateSopAppLink} from "@/api/courseAnswer.js"
- //import {getUserLiveInfo} from '@/api/living.js'
- export default {
- data() {
- return {
- pageUrl:"",
- msg: '加载中...',
- userInfo: {}
- }
- },
- onLoad(option) {
- // console.log('------userData',uni.getStorageSync('userInfo'))
- this.userInfo = uni.getStorageSync("userInfo") ? JSON.parse(uni.getStorageSync("userInfo")) : {};
- //this.getUserLiveInfo()
- // const userId = this.userInfo.userId || ''
- const liveId = option.liveId
- if (liveId) {
- const baseUrl ="https://liveapp.zkhj6.com/appweb/pages_live/living?liveId="+liveId+'&source=app'
- // const baseUrl = "http://192.168.110.151:1911/appweb/pages_live/living?liveId=" + liveId
- // 用一个集合传参到 living(web-view 内 H5 与原生 storage 隔离)
- const payload = {
- source: 'app',
- liveToken: uni.getStorageSync('liveToken') || '',
- //liveUserId:uni.getStorageSync('liveUserId') || '',
- userInfo: uni.getStorageSync('userInfo') || '',
- // userData: uni.getStorageSync('userData') || '',
- userData: uni.getStorageSync('userInfo') || '',
- hasSubscribed:uni.getStorageSync('subscribe_status_' + liveId)?'true':'false'
- }
- // console.log('【【【【【【',uni.getStorageSync('liveToken'));
- // console.log('【【【【【【',payload);
- // console.log("event===info===",payload.liveToken)
- this.pageUrl = baseUrl + '&payload=' + encodeURIComponent(JSON.stringify(payload))
- //this.getLink(link)
- //this.getCourseRead(link)
- } else {
- this.msg="缺少直播Id"
- uni.showToast({
- title: "缺少直播Id",
- icon: 'error'
- })
- }
- },
- onUnload() {
- // #ifdef APP-PLUS
- plus.navigator.setFullscreen(false);
- plus.screen.lockOrientation('portrait-primary');
- // #endif
- },
- onBackPress() {
- // #ifdef APP-PLUS
- // 返回时退出全屏
- plus.navigator.setFullscreen(false);
- plus.screen.lockOrientation('portrait-primary');
- // #endif
- },
- methods: {
- getUserLiveInfo(){
- getUserLiveInfo().then((res) => {
- if (res.code == 200) {
- const liveUserId=res.user.userId
- uni.setStorageSync('liveUserId', liveUserId)
- //console.log('liveUser', res.user)
- } else {
- uni.showToast({
- icon: 'none',
- title: '请求失败'
- })
- }
- },
- (rej) => {}
- )
- },
- getCourseRead(id) {
- updateSopAppLink(id).then(res=>{
- if(res.code == 200) {
- this.$updateMsgDot()
- }
- })
- },
- handleMessage(event) {
- console.log('点击事件',event)
- const info = event.detail.data[0]
- // #ifdef APP-PLUS
- // if(info.login != 1) {
- // // 退出登录
- // let IMUserID = uni.getStorageSync('IMUserID');
- // //Igexin.unbindAlias(IMUserID);
- // uni.removeStorage({key: "IMUserID"});
- // uni.setStorageSync("AppToken",null);
- // uni.setStorageSync("liveToken",null);
- // uni.removeStorage({ key: 'IMToken' });
- // uni.removeStorageSync("onLaunch",null)
- // uni.removeStorageSync("imUnread",null);
- // uni.removeStorageSync("companyUser");
- // uni.removeStorageSync("CompanyUserToken");
-
- // uni.$emit("refreshUserInfo");
- // let pages = getCurrentPages();
-
- // let url = pages[ pages.length - 1]; //当前页页面实例
- // //如果登录界面已打开,自动关闭
- // if(url!=undefined&&url.route=="pages/auth/loginIndex"){
- // return;
- // }
- // uni.navigateTo({
- // url: '/pages/auth/loginIndex'
- // });
- // return
- // }
- // if (info&&info.isFullscreen) {
- // plus.screen.lockOrientation('landscape-primary');
- // } else {
- // plus.screen.lockOrientation('portrait-primary');
- // }
- //立即购买
- if(info&&info.pagesUrl) {
- if(info.isBack){
- uni.navigateBack()
- }else{
- console.log('+++++++++++++++++++++++++++++')
- uni.navigateTo({
- url: info.pagesUrl
- })
- }
-
- }
- // //
- // if(info&&info.productId) {
- // uni.navigateTo({
- // url: info.pagesUrl
- // })
- // }
- // console.log("event===info===",info)
- // if(info&&info.pagesUrl) {
- // uni.navigateTo({
- // url: info.pagesUrl
- // })
- // }
- // #endif
- },
- getLink(sortLink) {
- this.msg = '加载中...'
- const userId = this.userInfo.userId || ''
- getRealLink({sortLink: sortLink}).then(res => {
- if (res.code == 200) {
- // 如果响应中包含真实链接,则跳转到真实链接
- let pageUrl= res.realLink + "&userId="+userId+"&source=app&time=" + new Date().getTime();
- this.pageUrl = pageUrl;
- } else {
- this.msg = '课程已过期或链接无效'
- uni.showModal({
- title: '提示',
- content: '课程已过期或链接无效',
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定');
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- }
- }).catch(err => {
- this.msg = '发生错误,请稍后再试'
- uni.showToast({
- title: '发生错误,请稍后再试',
- icon: 'none'
- });
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .container {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding-bottom: 88rpx;
- justify-content: center;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 32rpx;
- color: #757575;
- line-height: 48rpx;
- text-align: center;
- image {
- width: 428rpx;
- height: 360rpx;
- margin-bottom: 30rpx;
- }
- }
- </style>
|