Commit c9f13cb3 by wangshuo

与APP交互

parent ee07b94a
...@@ -40,7 +40,7 @@ class Banner extends Component { ...@@ -40,7 +40,7 @@ class Banner extends Component {
} }
componentWillUnmount() { componentWillUnmount() {
window.removeEventListener('scroll', throttle(this.calcNavActive, 100))
} }
...@@ -57,28 +57,31 @@ class Banner extends Component { ...@@ -57,28 +57,31 @@ class Banner extends Component {
} }
let el = document.querySelector(`#${navs[_index].id}`) let el = document.querySelector(`#${navs[_index].id}`)
let nav = document.querySelector('#main-nav') let nav = document.querySelector('#main-nav')
let top = el.offsetTop if(el) {
let top = el.offsetTop
if (y <= this.navTop) {
nav.classList.remove('fixed')
} else {
!nav.classList.contains('fixed') && nav.classList.add('fixed')
}
if (swipeDirection === 'up') { if (y <= this.navTop) {
if (y + 30 + 30 >= top) { nav.classList.remove('fixed')
this.setState({ } else {
index: _index !nav.classList.contains('fixed') && nav.classList.add('fixed')
})
} }
} else {
if (y + 30 + 20 <= top) { if (swipeDirection === 'up') {
this.setState({ if (y + 30 + 30 >= top) {
index: _index this.setState({
}) index: _index
})
}
} else {
if (y + 30 + 20 <= top) {
this.setState({
index: _index
})
}
} }
this.prevY = y
} }
this.prevY = y
} }
toSection = (i, e) => { toSection = (i, e) => {
......
...@@ -114,9 +114,9 @@ class CollectBlessing extends Component { ...@@ -114,9 +114,9 @@ class CollectBlessing extends Component {
} }
{ {
index === 0 && (!isLogin || !isSign) && index === 0 && (!isLogin || !isSign) &&
<Link to='/passport' className="collect-blessing__content"> <span onClick={toLogin} className="collect-blessing__content">
点击<br/>签到 点击<br/>签到
</Link> </span>
} }
{ {
index === 1 && index === 1 &&
......
...@@ -221,39 +221,45 @@ class CourseList extends Component { ...@@ -221,39 +221,45 @@ class CourseList extends Component {
} }
toReceiveCoupon(id, key = '') { toReceiveCoupon(id, key = '') {
http.post(`${API.home}/sys/activity/coupon/receive`, { const {isLogin, toLogin} = this.props;
course_id: id if(isLogin) {
}).then(res => { http.post(`${API.home}/sys/activity/coupon/receive`, {
const { code, msg } = res.data; course_id: id
if(code === 200) { }).then(res => {
Toast.info('领取成功~', 2, null, false); const { code, msg } = res.data;
let obj = {}; if(code === 200) {
obj[key] = { Toast.info('领取成功~', 2, null, false);
isMore: this.state[key]['isMore'], let obj = {};
course: this.state[key]['course'].map(item => { obj[key] = {
if(item.course_id === id) { isMore: this.state[key]['isMore'],
return Object.assign({}, item, { course: this.state[key]['course'].map(item => {
course_status: 2 if(item.course_id === id) {
}); return Object.assign({}, item, {
} course_status: 2
return item; });
}), }
courseList: this.state[key]['courseList'].map(item => { return item;
if(item.course_id === id) { }),
return Object.assign({}, item, { courseList: this.state[key]['courseList'].map(item => {
course_status: 2 if(item.course_id === id) {
}); return Object.assign({}, item, {
} course_status: 2
return item; });
}), }
return item;
}),
}
this.setState({
...obj
});
} else {
Toast.info(msg, 2, null, false);
} }
this.setState({ });
...obj }else{
}); toLogin();
} else { }
Toast.info(msg, 2, null, false);
}
});
} }
......
...@@ -46,6 +46,12 @@ class BlessingPreheat extends Component { ...@@ -46,6 +46,12 @@ class BlessingPreheat extends Component {
} }
fetchUserBlessing() { fetchUserBlessing() {
// 判断登录未登录 根据this.state.userInfo.isLogin
if(getParam('version')) {
// app 平台
}else{
// H5
}
const { userInfo } = this.state; const { userInfo } = this.state;
http.get(`${API.home}/sys/user/blessing`).then(res => { http.get(`${API.home}/sys/user/blessing`).then(res => {
const { code, data } = res.data; const { code, data } = res.data;
...@@ -91,7 +97,7 @@ class BlessingPreheat extends Component { ...@@ -91,7 +97,7 @@ class BlessingPreheat extends Component {
handleToShow = (key, isLogin = false) => { handleToShow = (key, isLogin = false) => {
const { history } = this.props; const { history } = this.props;
if(isLogin) { if(isLogin) {
history.push('/passport') this.toLogin();
}else { }else {
let obj = {}; let obj = {};
obj[key] = true; obj[key] = true;
...@@ -102,20 +108,25 @@ class BlessingPreheat extends Component { ...@@ -102,20 +108,25 @@ class BlessingPreheat extends Component {
} }
handleToShowInvite = () => { handleToShowInvite = () => {
QRCode.toDataURL('http://m.julyedu.com/invite', { const { userInfo } = this.state;
width: 120, if(userInfo.isLogin) {
height: 120, QRCode.toDataURL('http://m.julyedu.com/invite', {
margin: 1 width: 120,
}) height: 120,
.then(url => { margin: 1
this.setState({ })
inviteUrl: url, .then(url => {
inviteVisible: true this.setState({
inviteUrl: url,
inviteVisible: true
});
})
.catch(err => {
console.error(err)
}); });
}) } else {
.catch(err => { this.toLogin();
console.error(err) }
});
} }
handleToShowNotice = () => { handleToShowNotice = () => {
...@@ -137,15 +148,14 @@ class BlessingPreheat extends Component { ...@@ -137,15 +148,14 @@ class BlessingPreheat extends Component {
console.error(err) console.error(err)
}); });
}else if(errno === 4030 || errno === 4040) { }else if(errno === 4030 || errno === 4040) {
location.href = `http://passport.julyedu.com/login?redirect=${encodeURI(document.URL)}`; this.toLogin();
} }
}); });
} }
toLogin = () => { toLogin = () => {
let plat = getParam('version');
const { history } = this.props; const { history } = this.props;
if(!plat) { if(!getParam('version')) {
history.push('/passport'); history.push('/passport');
}else{ }else{
SendMessageToApp("toLogin"); SendMessageToApp("toLogin");
...@@ -190,7 +200,7 @@ class BlessingPreheat extends Component { ...@@ -190,7 +200,7 @@ class BlessingPreheat extends Component {
{/* 精品课程特惠专区 */} {/* 精品课程特惠专区 */}
<ListHeader id={'best-courses'} text="精品课程特惠专区" styles={{margin: '30px 0 15px'}} /> <ListHeader id={'best-courses'} text="精品课程特惠专区" styles={{margin: '30px 0 15px'}} />
<CourseList isFormal={isFormal} /> <CourseList isFormal={isFormal} isLogin={userInfo.isLogin} toLogin={this.toLogin}/>
{ {
isRule && isRule &&
...@@ -254,7 +264,7 @@ class BlessingPreheat extends Component { ...@@ -254,7 +264,7 @@ class BlessingPreheat extends Component {
<div className="test__record" onClick={() => this.handleToShow('showRecordList', true)}> <div className="test__record" onClick={() => this.handleToShow('showRecordList', true)}>
测试记录> 测试记录>
</div> </div>
<LevelTest></LevelTest> <LevelTest isLogin={userInfo.isLogin} toLogin={this.toLogin}></LevelTest>
<RankList></RankList> <RankList></RankList>
......
import React, { Component } from 'react' import React, { Component } from 'react'
import './index.scss' import './index.scss'
import listFrame from './../listFrame/index'; import listFrame from './../listFrame/index';
import { http} from "@/utils" import { http, SendMessageToApp} from "@/utils"
class LevelTest extends Component { class LevelTest extends Component {
constructor(props) { constructor(props) {
...@@ -35,19 +35,28 @@ class LevelTest extends Component { ...@@ -35,19 +35,28 @@ class LevelTest extends Component {
} }
componentDidMount() { componentDidMount() {
http.get(`${API.home}/sys/ai_test/get_user_testinfo`).then(res => { const {isLogin} = this.props;
let {code, data: {user_test_total, user_residue_number}} = res.data; if(isLogin) {
if(code === 200) { http.get(`${API.home}/sys/ai_test/get_user_testinfo`).then(res => {
this.setState({ let {code, data: {user_test_total, user_residue_number}} = res.data;
testNumber: user_test_total, if(code === 200) {
number: user_residue_number this.setState({
}) testNumber: user_test_total,
} number: user_residue_number
}); })
}
});
}
} }
startTest = () => { startTest = () => {
console.log('startTest'); const {history, isLogin, toLogin} = this.props;
if(isLogin) {
history.push('/levelTest/testing');
}else{
toLogin();
}
} }
render() { render() {
...@@ -56,6 +65,7 @@ class LevelTest extends Component { ...@@ -56,6 +65,7 @@ class LevelTest extends Component {
number, number,
prizeListUrl, prizeListUrl,
} = this.state; } = this.state;
const {isLogin} = this.props;
return ( return (
<> <>
<div className="level__test_module"> <div className="level__test_module">
...@@ -63,7 +73,11 @@ class LevelTest extends Component { ...@@ -63,7 +73,11 @@ class LevelTest extends Component {
<img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/test_icon.png" /> <img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/test_icon.png" />
<div className="button__text"> <div className="button__text">
<p>点击测试</p> <p>点击测试</p>
<span>(剩余{number}次)</span> {
isLogin && (
<span>(剩余{number}次)</span>
)
}
</div> </div>
</div> </div>
<div className='test__number'> <div className='test__number'>
......
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