king
2020-12-30 e003a8ee8843aa60b0b7135f413b2b99857acff9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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