|
@@ -4,6 +4,8 @@ import { savePoint } from '@/services/common'
|
4
|
4
|
import withLayout from "@/layout";
|
5
|
5
|
import { Image } from "@tarojs/components";
|
6
|
6
|
import { queryLiveDetail } from "@/services/item";
|
|
7
|
+import { fetch } from '@/utils/request'
|
|
8
|
+import { API_VIDEO_DETAIL } from '@/constants/api'
|
7
|
9
|
import useParams from "@/utils/hooks/useParams";
|
8
|
10
|
import useShare from "@/utils/hooks/useShare";
|
9
|
11
|
import { getImgURL } from "@/utils/image";
|
|
@@ -13,9 +15,10 @@ import "./index.scss";
|
13
|
15
|
|
14
|
16
|
export default withLayout((props) => {
|
15
|
17
|
const { router, shareContent, trackData, person, page, setNavigationBarTitle } = props;
|
16
|
|
- const { id } = router.params;
|
|
18
|
+ const { id, type } = router.params;
|
17
|
19
|
|
18
|
20
|
const [data, setData] = useState({})
|
|
21
|
+ const [CanPlay, setCanPlay] = useState(false)
|
19
|
22
|
// 直播间信息
|
20
|
23
|
const livingRef = useRef()
|
21
|
24
|
|
|
@@ -38,16 +41,24 @@ export default withLayout((props) => {
|
38
|
41
|
);
|
39
|
42
|
|
40
|
43
|
const getData = () => {
|
41
|
|
- queryLiveDetail(id).then(res => {
|
42
|
|
- setData(res||{})
|
43
|
|
- setNavigationBarTitle(res?.name)
|
44
|
|
- if (res?.liveRoomParam) {
|
45
|
|
- const { livingid } = JSON.parse(res.liveRoomParam)
|
46
|
|
- getLivingCode(livingid).then((liveInfo) => {
|
47
|
|
- livingRef.current = liveInfo
|
48
|
|
- })
|
49
|
|
- }
|
50
|
|
- })
|
|
44
|
+ if(type === 'live') { // 直播
|
|
45
|
+ queryLiveDetail(id).then(res => {
|
|
46
|
+ setData(res||{})
|
|
47
|
+ setNavigationBarTitle(res?.name)
|
|
48
|
+ if (res?.liveRoomParam) {
|
|
49
|
+ const { livingid } = JSON.parse(res.liveRoomParam)
|
|
50
|
+ getLivingCode(livingid).then((liveInfo) => {
|
|
51
|
+ livingRef.current = liveInfo
|
|
52
|
+ })
|
|
53
|
+ }
|
|
54
|
+ })
|
|
55
|
+ } else { // 视频
|
|
56
|
+ fetch({url: `${API_VIDEO_DETAIL}/${id}`, method: 'get'}).then((res) => {
|
|
57
|
+ setData(res||{})
|
|
58
|
+ setNavigationBarTitle(res?.name)
|
|
59
|
+ livingRef.current = res
|
|
60
|
+ })
|
|
61
|
+ }
|
51
|
62
|
};
|
52
|
63
|
|
53
|
64
|
useEffect(() => {
|
|
@@ -61,36 +72,46 @@ export default withLayout((props) => {
|
61
|
72
|
}
|
62
|
73
|
}, [trackData, data])
|
63
|
74
|
|
64
|
|
- const handleLive = () => {
|
65
|
|
- if (!livingRef.current) {
|
66
|
|
- Taro.showToast({
|
67
|
|
- title: '查询直播凭证失败, 请退出重试',
|
68
|
|
- icon: 'none',
|
69
|
|
- })
|
70
|
|
- return;
|
|
75
|
+ const ended = () => {
|
|
76
|
+ return () => {
|
|
77
|
+ setCanPlay(false)
|
71
|
78
|
}
|
|
79
|
+ }
|
72
|
80
|
|
73
|
|
- // https://work.weixin.qq.com/api/doc/90000/90135/93635
|
74
|
|
- const { livingCode, status } = livingRef.current
|
75
|
|
-
|
76
|
|
- //
|
77
|
|
- if (status >= 3) {
|
78
|
|
- Taro.showToast({
|
79
|
|
- title: `直播活动已${status === 3 ? '过期' : '取消'}`,
|
80
|
|
- icon: 'none',
|
|
81
|
+ const handleLive = () => {
|
|
82
|
+ if(type === 'live') {
|
|
83
|
+ if (!livingRef.current) {
|
|
84
|
+ Taro.showToast({
|
|
85
|
+ title: '查询直播凭证失败, 请退出重试',
|
|
86
|
+ icon: 'none',
|
|
87
|
+ })
|
|
88
|
+ return;
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ // https://work.weixin.qq.com/api/doc/90000/90135/93635
|
|
92
|
+ const { livingCode, status } = livingRef.current
|
|
93
|
+
|
|
94
|
+ //
|
|
95
|
+ if (status >= 3) {
|
|
96
|
+ Taro.showToast({
|
|
97
|
+ title: `直播活动已${status === 3 ? '过期' : '取消'}`,
|
|
98
|
+ icon: 'none',
|
|
99
|
+ })
|
|
100
|
+ return;
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ // 如果已经结束的则播放回放
|
|
104
|
+ const replay = status === 2 ? '&replay=1' : ''
|
|
105
|
+
|
|
106
|
+ // 跳转到直播
|
|
107
|
+ Taro.navigateToMiniProgram({
|
|
108
|
+ // 固定跳转到微信企业直播
|
|
109
|
+ appId: 'wx7424030d69bde86e',
|
|
110
|
+ path: `pages/watch/index?living_code=${encodeURIComponent(livingCode)}${replay}`,
|
81
|
111
|
})
|
82
|
|
- return;
|
|
112
|
+ } else {
|
|
113
|
+ setCanPlay(true)
|
83
|
114
|
}
|
84
|
|
-
|
85
|
|
- // 如果已经结束的则播放回放
|
86
|
|
- const replay = status === 2 ? '&replay=1' : ''
|
87
|
|
-
|
88
|
|
- // 跳转到直播
|
89
|
|
- Taro.navigateToMiniProgram({
|
90
|
|
- // 固定跳转到微信企业直播
|
91
|
|
- appId: 'wx7424030d69bde86e',
|
92
|
|
- path: `pages/watch/index?living_code=${encodeURIComponent(livingCode)}${replay}`,
|
93
|
|
- })
|
94
|
115
|
}
|
95
|
116
|
|
96
|
117
|
useEffect(() => {
|
|
@@ -100,13 +121,30 @@ export default withLayout((props) => {
|
100
|
121
|
}, [id]);
|
101
|
122
|
//
|
102
|
123
|
return <view className="liveDetail">
|
103
|
|
- {data.liveActivityId && <><Image mode='aspectFill' src={getImgURL(data.detailTypeImg)} className='liveImg'></Image>
|
|
124
|
+ {
|
|
125
|
+ type === 'video' && data.videoUrl && CanPlay &&
|
|
126
|
+ <view className="myVideo">
|
|
127
|
+ <video
|
|
128
|
+ src={data.videoUrl}
|
|
129
|
+ enable-danmu
|
|
130
|
+ danmu-btn
|
|
131
|
+ show-center-play-btn={false}
|
|
132
|
+ show-play-btn
|
|
133
|
+ controls
|
|
134
|
+ autoplay
|
|
135
|
+ onended={ended()}
|
|
136
|
+ picture-in-picture-mode={['push', 'pop']}
|
|
137
|
+ object-fit='contain'
|
|
138
|
+ ></video>
|
|
139
|
+ </view>
|
|
140
|
+ }
|
|
141
|
+ {(data.liveActivityId || data.videoId) && <><Image mode='aspectFill' src={getImgURL(data.detailTypeImg || data.videImg)} className='liveImg'></Image>
|
104
|
142
|
<view className='liveDetail-menu flex-h'>
|
105
|
143
|
<view className='flex-item'>
|
106
|
144
|
<view onClick={() => { Taro.navigateTo({ url: `/pages/index/buildingDetail/index?id=${data.buildingId}` }) }}><text className="iconfont icon-fenxiang"></text><text>查看楼盘</text></view>
|
107
|
145
|
</view>
|
108
|
146
|
<view className='flex-item'>
|
109
|
|
- <view onClick={handleLive}><text className="iconfont icon-camera"></text><text>观看直播</text></view>
|
|
147
|
+ <view onClick={handleLive}><text className="iconfont icon-camera"></text><text>观看{type === 'live' ? '直播' : '视频'}</text></view>
|
110
|
148
|
</view>
|
111
|
149
|
<view className='flex-item'>
|
112
|
150
|
<button openType="share"><text className="iconfont icon-fenxiang"></text><text>分享好友</text></button>
|