| | |
| | | |
| | | <script> |
| | | import { getGoodsSimilarlyVideos, savePlayRecord, changeCollect, changeThumbsUp } from "@/api/video.js" |
| | | |
| | | import { getSessionId, userAction ,userShare } from "@/api/userAction.js"; |
| | | export default { |
| | | data() { |
| | | return { |
| | |
| | | // 右滑返回首页相关 |
| | | touchStartX: 0, |
| | | touchEndX: 0, |
| | | minSwipeDistance: 100 // 最小滑动距离 |
| | | minSwipeDistance: 100 ,// 最小滑动距离 |
| | | pageSessionNo:"", |
| | | actionParam:{ |
| | | sessionId:'', |
| | | actionType:"PAGE", |
| | | joinType:"SELF", |
| | | pageCode:"RECOMMEND_VIDEO_RIGHT_VIDEO", |
| | | pageParams:"{}", |
| | | pageStatus:"JOIN", |
| | | pageType:"DETAIL" |
| | | }, |
| | | shareParam:{ |
| | | pageCode:"RECOMMEND_VIDEO_RIGHT_VIDEO", |
| | | shareOption:"{}", |
| | | pageType:"DETAIL" |
| | | }, |
| | | shareId:'', |
| | | } |
| | | }, |
| | | onLoad(options) { |
| | | if(options.shareId){ |
| | | this.actionParam.shareId = options.shareId; |
| | | this.actionParam.joinType = 'SHARE' |
| | | console.log('触发onLoad') |
| | | uni.setStorage({ |
| | | key: 'shareId', |
| | | data: options.shareId, |
| | | success: function () { |
| | | console.log('缓存shareId成功'); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | this.actionParam.pageParams = JSON.stringify(options) |
| | | |
| | | // 获取传递的商品信息 |
| | | if (options.goodsId) { |
| | | this.loadSimilarVideos(options.goodsId, options.currentVideoId); |
| | |
| | | const videoContext = uni.createVideoContext(`video${this.currentIndex}`, this); |
| | | videoContext.play(); |
| | | } |
| | | getSessionId().then(res=>{ |
| | | this.pageSessionNo = res.data.data |
| | | this.actionParam.sessionId = res.data.data |
| | | if(this.pageSessionNo){ |
| | | let param = Object.assign({}, this.actionParam); |
| | | param.sessionId = this.pageSessionNo |
| | | userAction(param) |
| | | } |
| | | }) |
| | | }, |
| | | onHide() { |
| | | // 页面隐藏时暂停视频 |
| | |
| | | const videoContext = uni.createVideoContext(`video${this.currentIndex}`, this); |
| | | videoContext.pause(); |
| | | } |
| | | this.startHidenTime = Date.now() |
| | | let param = Object.assign({}, this.actionParam); |
| | | this.sendOnShow = true; |
| | | param.pageStatus = "LEAVE" |
| | | userAction(param) |
| | | }, |
| | | onShareAppMessage(e){ |
| | | const userInfo = storage.getUserInfo(); |
| | | if (!userInfo) { |
| | | console.log("未登录不能分享"); |
| | | return |
| | | } |
| | | const videoInfo = e.target.dataset.obj; |
| | | return new Promise((resolve) => { |
| | | this.shareId = ''; |
| | | let shareObj ={ |
| | | videoId:videoInfo.id, |
| | | userId:userInfo.id |
| | | } |
| | | this.shareParam.shareOption = JSON.stringify(shareObj) |
| | | userShare(this.shareParam).then(res => { |
| | | this.shareId = res.data.data; |
| | | resolve({ |
| | | title: videoInfo.title, |
| | | path: `/pages/tabbar/index/home?videoId=${videoInfo.id}&userId=${userInfo.id}&shareId=${this.shareId}`, |
| | | imageUrl: videoInfo.coverUrl, |
| | | success(e) { |
| | | console.log("分享成功", e); |
| | | }, |
| | | fail(e) { |
| | | console.log('分享失败', e); |
| | | } |
| | | }); |
| | | }).catch(err => { |
| | | // 处理错误情况,例如使用默认参数 |
| | | console.error('获取分享ID失败', err); |
| | | resolve({ |
| | | title: videoInfo.title, |
| | | path: `/pages/tabbar/index/home?videoId=${videoInfo.id}&userId=${userInfo.id}`, |
| | | imageUrl: videoInfo.coverUrl |
| | | }); |
| | | }); |
| | | }); |
| | | }, |
| | | methods: { |
| | | // 加载相似视频 |