Commit 445dec72 by zhanghaozhe

Merge branch 'live' into 11-11

parents f3e1141d f5187301
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
.close { .close {
position: absolute; position: absolute;
bottom: -88px; bottom: -74px;
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
font-size: 36px; font-size: 36px;
......
import React, { Component } from 'react' import React, { Component } from 'react'
import './index.scss' import './index.scss'
import { Tabs, Toast } from "antd-mobile" import { Tabs, Toast } from "antd-mobile"
import { getParam, http, SendMessageToApp } from "@/utils" import { getParam, http, SendMessageToApp, browser } from "@/utils"
import { Popup } from "@common/index" import { Popup } from "@common/index"
import QRCode from 'qrcode' import QRCode from 'qrcode'
import { uniqBy } from 'lodash' import { uniqBy } from 'lodash'
...@@ -12,12 +12,15 @@ import { withRouter } from 'react-router-dom' ...@@ -12,12 +12,15 @@ import { withRouter } from 'react-router-dom'
@connect(state => ({user: state.user})) @connect(state => ({user: state.user}))
class Live extends Component { class Live extends Component {
popupInstance = null
state = { state = {
tabs: [], tabs: [],
lives: {}, lives: {},
preheatLives: [], preheatLives: [],
today: '', today: '',
isApp: getParam('version') isApp: getParam('version'),
QRCodeUrl: '',
} }
...@@ -69,22 +72,33 @@ class Live extends Component { ...@@ -69,22 +72,33 @@ class Live extends Component {
} }
toLiveRoom = id => { toLiveRoom = id => {
const {history,isLogin} = this.props; const {history, isLogin} = this.props
if (this.state.isApp) { if (this.state.isApp) {
if(isLogin){ if (isLogin) {
SendMessageToApp('toLiveRoom', id) SendMessageToApp('toLiveRoom', id)
}else { } else {
SendMessageToApp("toLogin") SendMessageToApp("toLogin")
} }
} else { } else {
if(isLogin){ if (isLogin) {
window.location.href = `${window.location.protocol}//www.julyedu.com/live/m_room/${id}` window.location.href = `${window.location.protocol}//www.julyedu.com/live/m_room/${id}`
}else { } else {
history.push('/passport') history.push('/passport')
} }
} }
} }
saveImage = () => {
let version = getParam('version')
version = typeof version === 'string' ? version.replace('.', '').replace('.', '').slice(0, 3) : ''
const {QRCodeUrl} = this.state
if (version && parseInt(version) < 451) {
Toast.info('当前不支持此功能,升级到最新版本app可以点击保存二维码!', 2, null, false)
} else {
SendMessageToApp('generateQRCode', QRCodeUrl)
}
}
makeSubscribe = id => { makeSubscribe = id => {
const {user, history} = this.props const {user, history} = this.props
if (user.hasError) { if (user.hasError) {
...@@ -94,11 +108,29 @@ class Live extends Component { ...@@ -94,11 +108,29 @@ class Live extends Component {
.then(res => { .then(res => {
const {data} = res const {data} = res
if (data.errno == 200) { if (data.errno == 200) {
this.setState(() => ({
QRCodeUrl: data.data.url,
}))
QRCode.toDataURL(data.data.url, (err, url) => { QRCode.toDataURL(data.data.url, (err, url) => {
Popup({ if (!this.popupInstance) {
title: '扫码关注“七月在线”服务号即可预约', this.popupInstance = Popup({
content: <img id={'live-qr-code'} src={url} alt=""/> title: '扫码关注“七月在线”服务号即可预约',
}) content: (
<>
<img id={'live-qr-code'} src={url} alt=""/>
{
browser.isAndroidApp ? (
<button className={'save-image'} onClick={this.saveImage}>保存二维码</button>
) : null
}
</>
),
close: () => new Promise(resolve => {
this.popupInstance = null
resolve()
})
})
}
}) })
} else { } else {
Toast.info(data.msg, 2, null, false) Toast.info(data.msg, 2, null, false)
...@@ -136,27 +168,29 @@ class Live extends Component { ...@@ -136,27 +168,29 @@ class Live extends Component {
{ {
todayLives.map((item, index) => { todayLives.map((item, index) => {
return ( return (
<LiveContent item={item} key={index} makeSubscribe={this.makeSubscribe} toLiveRoom={this.toLiveRoom}/> <LiveContent item={item} key={index} makeSubscribe={this.makeSubscribe}
toLiveRoom={this.toLiveRoom}/>
)
})
}
</div>
)
})
: tabs.map((item, index) => {
const todayLives = preheatLives[item.title]
return (
<div key={index}>
{
todayLives.map((item, index) => {
return (
<LiveContent item={item} key={index} makeSubscribe={this.makeSubscribe}
toLiveRoom={this.toLiveRoom}/>
) )
}) })
} }
</div> </div>
) )
}) })
:tabs.map((item, index) => {
const todayLives = preheatLives[item.title]
return (
<div key={index}>
{
todayLives.map((item, index) => {
return (
<LiveContent item={item} key={index} makeSubscribe={this.makeSubscribe} toLiveRoom={this.toLiveRoom}/>
)
})
}
</div>
)
})
} }
</Tabs> </Tabs>
...@@ -201,7 +235,9 @@ function LiveContent({item, makeSubscribe, toLiveRoom}) { ...@@ -201,7 +235,9 @@ function LiveContent({item, makeSubscribe, toLiveRoom}) {
</div> </div>
{ {
item['on_live'] item['on_live']
? <button className={'on-living'} onClick={() => {toLiveRoom(item['room_url'])}}>正在直播</button> ? <button className={'on-living'} onClick={() => {
toLiveRoom(item['room_url'])
}}>正在直播</button>
: :
item['is_end'] item['is_end']
? <button className={'subscribed'}>已结束</button> ? <button className={'subscribed'}>已结束</button>
......
...@@ -227,12 +227,27 @@ ...@@ -227,12 +227,27 @@
.content { .content {
display: flex; display: flex;
justify-content: center; flex-direction: column;
align-items: center;
img { img {
width: 120px; width: 120px;
height: 120px; height: 120px;
margin-top: 10px;
} }
} }
.save-image {
width: 133px;
height: 30px;
margin-top: 16px;
background: rgba(83, 39, 250, 1);
border-radius: 15px;
font-size: 14px;
color: #fff;
-webkit-appearance: none;
outline: 0;
border: none;
}
} }
...@@ -83,7 +83,9 @@ const browser = (function () { ...@@ -83,7 +83,9 @@ const browser = (function () {
isWeixin: /MicroMessenger/i.test(ua), isWeixin: /MicroMessenger/i.test(ua),
isAndroid: /Android/i.test(ua), isAndroid: /Android/i.test(ua),
isIOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(ua), isIOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(ua),
isIPad: /iPad/i.test(ua) isIPad: /iPad/i.test(ua),
isAndroidApp: /Android/i.test(ua) && getParam('version'),
isIOSApp: /iPhone/i.test(ua) && getParam('version')
} }
})() })()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment