index.js
3.98 KB
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
129
130
131
132
133
134
135
136
137
138
import React, {PureComponent} from 'react';
import './index.scss'
import {conf, start} from '../../api'
import {getQueryObj, linkToMiniApp, invokeMethod, parseUrl} from '../../../../common/utils';
import wxshare from '../../../../common/wxshare'
import wx from 'weixin-js-sdk';
import yaSDK from 'yoho-activity-sdk';
import config from '../../config';
import cookie from 'react-cookies';
import LazyLoad from 'react-lazy-load'
import {
Link
} from 'react-router-dom'
import Resource from '../components/resource';
import BottomButton from '../components/bottom-button';
const {actId} = getQueryObj();
export default class wheelSurf extends PureComponent {
constructor(props) {
document.title ='大转盘';
super(props);
this.state = {
initial: true,
pending: false, // 抽奖中
startEnd: false,
isEnding: false, // 即将停止
isLogin: false,
conf: {
loading: ''
}
};
this.init();
}
init = async () => {
let result = await conf({
act_id: +actId
});
if (result.code === 200) {
this.setState({
conf: result.data.conf
})
}
};
componentDidMount = () => {
window.addEventListener('scroll', this.handleScroll);
};
componentWillUnmount = () => {
window.removeEventListener('scroll', this.handleScroll);
};
start = async () => {
console.log('抽奖开始');
let uid = cookie.load('app_uid') || getQueryObj().uid || 0;
if(!uid || !parseInt(uid)){
return;
}
let result = await start({
actId,
uid: uid,
sessionKey: cookie.load('app_session_key') || getQueryObj().session_key || '',
sessionType: cookie.load('app_client_type') || '',
appVersion: cookie.load('app_version') || ''
});
if (result.code === 200) {
this.setState({
conf: result.data.conf
})
}
};
links = conf => {
let links = [];
if (conf.jump_btn_left_url) {
links.push({
url: conf.jump_btn_left_url,
bg: conf.jump_btn_left_bg
});
}
if (conf.jump_btn_middle_url) {
links.push({
url: conf.jump_btn_middle_url,
bg: conf.jump_btn_middle_bg
});
}
if (conf.jump_btn_right_url) {
links.push({
url: conf.jump_btn_right_url,
bg: conf.jump_btn_right_bg
});
}
return links;
};
render() {
const {conf, isEnding, isLogin} = this.state;
if (!conf.id) {
return (
<div className="home-wrap">
<img className="main-bg" src={this.state.conf.loading}/>
</div>
)
}
let links = this.links(conf);
return (
<div className="home-wrap">
<img className="main-bg" src={conf.main_bg}/>
{conf.rule_btn_bg ? (<Link to={`${config.routerPath}/rule.html`}><img className="rule-btn" src={conf.rule_btn_bg}/></Link>) : ''}
{conf.share_btn_bg ? (<img className="share-btn" src={conf.share_btn_bg}/>): ''}
<img className="wheel-bg" src={conf.wheel_bg}/>
<img className="wheel-bg-surf-layer" src={conf.wheel_bg}/>
<img onClick={()=>{this.start()}} className="start-btn-bg" src={conf.prize_btn_bg}/>
<BottomButton links={links}/>
<Resource code={conf.code || '11421760f4ea8b231c5b8269f4ff65bb'}/>
{isEnding ? (<img className="prize-hit-bg" src={conf.win_prize_bg}/>) : ''}
{isEnding ? (<img className="prize-hit-start-bg" src={conf.prize_btn_bg}/>) : ''}
</div>
)
}
}