import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import md5 from 'md5'
|
import moment from 'moment'
|
import Api from '@/api'
|
import './index.scss'
|
|
class Advert extends Component {
|
static propTpyes = {
|
config: PropTypes.object
|
}
|
|
state = {
|
timer: 5,
|
config: null,
|
loaded: false
|
}
|
|
setCookie = (cname, cvalue) => {
|
document.cookie = cname + '=' + cvalue
|
}
|
|
UNSAFE_componentWillMount () {
|
|
let param = {
|
func: 's_visitor_login',
|
timestamp: moment().format('YYYY-MM-DD HH:mm:ss') + '.000',
|
SessionUid: localStorage.getItem('SessionUid'),
|
TypeCharOne: 'mob'
|
}
|
|
param.LText = md5(window.btoa(localStorage.getItem('SessionUid') + param.timestamp))
|
param.secretkey = md5(param.LText + 'mingke' + param.timestamp)
|
|
Api.getTouristMsg(param).then((res) => {
|
if (res.status) {
|
// session
|
sessionStorage.setItem('UserID', res.UserID)
|
sessionStorage.setItem('LoginUID', res.LoginUID)
|
this.setCookie('UserID', res.UserID)
|
this.setCookie('LoginUID', res.LoginUID)
|
|
console.log(`UserID: ${res.UserID}`)
|
console.log(`LoginUID: ${res.LoginUID}`)
|
}
|
})
|
|
let _config = null
|
|
if (this.props.location.state && this.props.location.state.config) {
|
_config = this.props.location.state.config
|
}
|
|
if (!_config) {
|
this.props.history.replace({pathname: `/loading/${this.props.match.params.viewId}`})
|
return
|
}
|
|
this.setState({
|
config: _config
|
}, () => {
|
let img = new Image()
|
|
img.src = _config.advert
|
img.onload = () => {
|
this.setState({
|
loaded: true
|
}, () => {
|
setTimeout(this.resetTime, 1000)
|
})
|
}
|
img.onerror = () => {
|
this.changeview()
|
}
|
})
|
}
|
|
componentDidMount () {
|
if (window.GLOB.systemType === 'ios' && window.webkit) {
|
try {
|
window.webkit.messageHandlers.queryAppkey.postMessage(window.GLOB.appkey)
|
} catch {
|
console.log('H5 调用app的 queryAppkey 方法,传递当前系统的appkey')
|
}
|
} else if (window.GLOB.systemType === 'android' && window.android) {
|
try {
|
window.android.queryAppkey(window.GLOB.appkey)
|
} catch {
|
console.log('H5 调用app的 queryAppkey 方法,传递当前系统的appkey')
|
}
|
}
|
}
|
|
resetTime = () => {
|
const { timer } = this.state
|
|
if (timer > 1) {
|
this.setState({timer: timer - 1})
|
setTimeout(this.resetTime, 1000)
|
} else {
|
this.changeview()
|
}
|
}
|
|
changeview = () => {
|
const { config } = this.state
|
|
// if (window.GLOB.systemType === 'ios' && window.webkit) {
|
// let url = window.location.href.replace(/#(.*)/ig, `#/loading/${config.NextMenuID}`)
|
// window.webkit.messageHandlers.toMainPage.postMessage(JSON.stringify({url: url, isNavBar: false}))
|
// } else if (!window.webkit) {
|
// console.log('window.webkit error')
|
this.props.history.replace({pathname: `/loading/${config.NextMenuID}`})
|
// }
|
}
|
|
render () {
|
const { config, loaded, timer } = this.state
|
|
return (
|
<div className="advert-wrap" style={{backgroundImage: loaded ? `url(${config.advert})` : ''}}>
|
<span className="tip" onClick={this.changeview}>{timer} 跳过</span>
|
</div>
|
)
|
}
|
}
|
|
export default Advert
|