Authored by 李奇

登录相关sdk api升级

@@ -25,6 +25,7 @@ export default class wheelSurf extends PureComponent { @@ -25,6 +25,7 @@ export default class wheelSurf extends PureComponent {
25 startType: true, 25 startType: true,
26 isLogin: false, 26 isLogin: false,
27 dayLeftTimesTip: '', 27 dayLeftTimesTip: '',
  28 + showRemain: false,
28 29
29 conf: { 30 conf: {
30 loading: '' 31 loading: ''
@@ -50,49 +51,80 @@ export default class wheelSurf extends PureComponent { @@ -50,49 +51,80 @@ export default class wheelSurf extends PureComponent {
50 this.state.query = yaSDK.getQueryObj() || {}; 51 this.state.query = yaSDK.getQueryObj() || {};
51 52
52 let user = await yaSDK.getUser(); 53 let user = await yaSDK.getUser();
53 - let {uid, sessionKey, sessionType, appVersion} = user; 54 + let {uid, sessionKey} = user;
54 55
55 this.state.user = user; 56 this.state.user = user;
56 57
57 - if (uid) { 58 + let setLogin = userInfo => {
58 this.setState({ 59 this.setState({
59 - uid,  
60 - isLogin: !!uid 60 + uid: userInfo.uid,
  61 + isLogin: true
61 }); 62 });
62 63
63 switch (yaSDK.env) { 64 switch (yaSDK.env) {
64 case 'h5': 65 case 'h5':
65 if (!cookie.load('uid')) { 66 if (!cookie.load('uid')) {
66 - cookie.save('uid', uid);  
67 - cookie.save('app_session_key', sessionKey, { path: '/' });  
68 - cookie.save('app_client_type', sessionType, { path: '/' });  
69 - cookie.save('app_version', appVersion, { path: '/' }); 67 + cookie.save('uid', userInfo.uid);
  68 + cookie.save('app_session_key', userInfo.sessionKey, { path: '/' });
  69 + cookie.save('app_client_type', userInfo.sessionType, { path: '/' });
  70 + cookie.save('app_version', userInfo.appVersion, { path: '/' });
70 } 71 }
71 break; 72 break;
72 73
73 case 'miniprogram': 74 case 'miniprogram':
74 - cookie.save('uid', uid);  
75 - cookie.save('app_session_key', sessionKey, { path: '/' });  
76 - cookie.save('app_client_type', sessionType, { path: '/' }); 75 + cookie.save('uid', userInfo.uid);
  76 + cookie.save('app_session_key', userInfo.sessionKey, { path: '/' });
  77 + cookie.save('app_client_type', userInfo.sessionType, { path: '/' });
77 cookie.save('app_version', '6.6.0', { path: '/' }); 78 cookie.save('app_version', '6.6.0', { path: '/' });
78 break; 79 break;
79 80
80 case 'app': 81 case 'app':
81 - cookie.save('uid', uid);  
82 - cookie.save('app_session_key', sessionKey, { path: '/' });  
83 - cookie.save('app_client_type', sessionType, { path: '/' });  
84 - cookie.save('app_version', appVersion, { path: '/' }); 82 + cookie.save('uid', userInfo.uid);
  83 + cookie.save('app_session_key', userInfo.sessionKey, { path: '/' });
  84 + cookie.save('app_client_type', userInfo.sessionType, { path: '/' });
  85 + cookie.save('app_version', userInfo.appVersion, { path: '/' });
85 break; 86 break;
86 87
87 default: 88 default:
88 break; 89 break;
89 90
90 } 91 }
  92 + };
  93 +
  94 + let updateCount = async (user) => {
  95 + let result = await conf({
  96 + uid: user.uid,
  97 + act_id: +this.state.query.actId
  98 + });
  99 +
  100 + if (result && result.code === 200) {
  101 + this.setState({
  102 + remainCount: result.data.residueCount,
  103 + showRemain: true
  104 + });
  105 + }
  106 + };
  107 +
  108 + if (uid && sessionKey) {
  109 + setLogin(user);
91 } else { 110 } else {
92 cookie.remove('uid'); 111 cookie.remove('uid');
93 cookie.remove('app_session_key'); 112 cookie.remove('app_session_key');
94 cookie.remove('app_client_type'); 113 cookie.remove('app_client_type');
95 cookie.remove('app_version'); 114 cookie.remove('app_version');
  115 +
  116 + // fix android can't auto reload page after login
  117 + if (yaSDK.env === 'app') {
  118 + let timer = setInterval(async () => {
  119 + let user = await yaSDK.getUser();
  120 +
  121 + if (user.uid && user.sessionKey) {
  122 + clearInterval(timer);
  123 + setLogin(user);
  124 + updateCount(user);
  125 + }
  126 + }, 2000);
  127 + }
96 } 128 }
97 129
98 let params = {act_id: +this.state.query.actId}; 130 let params = {act_id: +this.state.query.actId};
@@ -114,6 +146,7 @@ export default class wheelSurf extends PureComponent { @@ -114,6 +146,7 @@ export default class wheelSurf extends PureComponent {
114 epPrize: result.data.emptyPrize, 146 epPrize: result.data.emptyPrize,
115 totalParts: result.data.prize, 147 totalParts: result.data.prize,
116 remainCount: result.data.residueCount, 148 remainCount: result.data.residueCount,
  149 + showRemain: +uid > 0,
117 dayLeftTimesTip: result.data.conf.btm_tip_one, 150 dayLeftTimesTip: result.data.conf.btm_tip_one,
118 startType: result.data.startType !== false, 151 startType: result.data.startType !== false,
119 startErrorMsg: result.data.errorMsg || '' 152 startErrorMsg: result.data.errorMsg || ''
@@ -143,7 +176,7 @@ export default class wheelSurf extends PureComponent { @@ -143,7 +176,7 @@ export default class wheelSurf extends PureComponent {
143 176
144 delete query['openby:yohobuy']; 177 delete query['openby:yohobuy'];
145 178
146 - conf[key] = `${url}?${queryString.stringify(query)}` 179 + conf[key] = `${url}?${queryString.stringify(query)}`;
147 180
148 console.log(conf[key]) 181 console.log(conf[key])
149 }); 182 });
@@ -358,7 +391,7 @@ export default class wheelSurf extends PureComponent { @@ -358,7 +391,7 @@ export default class wheelSurf extends PureComponent {
358 }; 391 };
359 392
360 render() { 393 render() {
361 - let {conf, slowEnding, isLogin, startEnded, remainCount} = this.state; 394 + let {conf, slowEnding, isLogin, startEnded, remainCount, showRemain} = this.state;
362 395
363 if (!conf.id) { 396 if (!conf.id) {
364 return ( 397 return (
@@ -380,7 +413,7 @@ export default class wheelSurf extends PureComponent { @@ -380,7 +413,7 @@ export default class wheelSurf extends PureComponent {
380 <img className="wheel-bg" id="rotateWheel" src={conf.wheel_bg}/> 413 <img className="wheel-bg" id="rotateWheel" src={conf.wheel_bg}/>
381 <img onClick={()=>{this.start()}} className="start-btn-bg" src={conf.prize_btn_bg}/> 414 <img onClick={()=>{this.start()}} className="start-btn-bg" src={conf.prize_btn_bg}/>
382 { 415 {
383 - isLogin ? 416 + isLogin && showRemain ?
384 (<div className="tips"> 417 (<div className="tips">
385 <p className="tip-1">{`今日剩余次数:${remainCount}次`}</p> 418 <p className="tip-1">{`今日剩余次数:${remainCount}次`}</p>
386 </div>) : '' 419 </div>) : ''
@@ -16,7 +16,7 @@ export default class Prize extends PureComponent { @@ -16,7 +16,7 @@ export default class Prize extends PureComponent {
16 prizes: [], 16 prizes: [],
17 pending: true, 17 pending: true,
18 showModal: false, 18 showModal: false,
19 - modalTip: '请联系客服请联系客服请联系客服请联系客服请联系客服请联系客服请联系客服请联系客服请联系客服请联系客服', 19 + modalTip: '请保持信息畅通,我们的客服人员会在2个工作日联系您!',
20 modalBtnText: '确定' 20 modalBtnText: '确定'
21 }; 21 };
22 } 22 }