Commit b103a56c by xuzhenghua

ui问题

parents 6a329e43 5fe4637c
...@@ -63,6 +63,9 @@ class App extends Component { ...@@ -63,6 +63,9 @@ class App extends Component {
if (cookie.get('uid') && this.props.user.hasError) { if (cookie.get('uid') && this.props.user.hasError) {
this.getUser() this.getUser()
} }
if(location.pathname==='/passport'){
window.localStorage.setItem('binding_redirect', JSON.stringify(this.previousLocation))
}
const {pathname, state} = location const {pathname, state} = location
if (pathname.startsWith('/passport')) { if (pathname.startsWith('/passport')) {
location.state = { location.state = {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
.close { .close {
position: absolute; position: absolute;
bottom: -88px; bottom: -74px;
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
font-size: 36px; font-size: 36px;
......
...@@ -26,7 +26,7 @@ class Activity extends Component { ...@@ -26,7 +26,7 @@ class Activity extends Component {
getGift = () => { getGift = () => {
if(this.props.user.hasError) { if(this.props.user.hasError) {
this.props.history.push('/passport'); this.props.history.push('/passport', {from: this.props.location.pathname});
} else { } else {
Toast.info('领取成功,你可前往七月在线官网/APP进行查看', 2); Toast.info('领取成功,你可前往七月在线官网/APP进行查看', 2);
localStorage.setItem('lingqu', 1); localStorage.setItem('lingqu', 1);
......
...@@ -34,7 +34,7 @@ class ReserveCourse extends Component { ...@@ -34,7 +34,7 @@ class ReserveCourse extends Component {
const {code, data, msg} = res.data; const {code, data, msg} = res.data;
if (code === 200) { if (code === 200) {
this.setState({ this.setState({
courseData: data.filter((item, index) => index < 4), courseData: JSON.stringify(data) == '{}' ? []:data.filter((item, index) => index < 4),
courseDataAll: data courseDataAll: data
}) })
} else { } else {
...@@ -172,7 +172,7 @@ function CourseList(props) { ...@@ -172,7 +172,7 @@ function CourseList(props) {
} }
{ {
item.is_buy === 1 && item.is_buy === 1 &&
<button <button
className="to-expand-buy2" className="to-expand-buy2"
onClick={() => expandPaywk(item.course_id, item.start_timestamp,item.final_start_time)} onClick={() => expandPaywk(item.course_id, item.start_timestamp,item.final_start_time)}
>立即付尾款</button> >立即付尾款</button>
......
...@@ -24,11 +24,11 @@ ...@@ -24,11 +24,11 @@
li{ li{
flex: 1; flex: 1;
width: 63px; width: 63px;
height: 30px; height: 40px;
font-size: 11px; font-size: 11px;
color: #fff; color: #fff;
text-align: center; text-align: center;
line-height: 30px; line-height: 40px;
&.active{ &.active{
background: #FF42F9; background: #FF42F9;
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
.iconfont { .iconfont {
margin: 16px 0 0; margin: 16px 0 0;
font-size: 24px; font-size: 28px;
color: #fff; color: #fff;
cursor: pointer; cursor: pointer;
} }
......
...@@ -75,7 +75,7 @@ class LevelTest extends Component { ...@@ -75,7 +75,7 @@ class LevelTest extends Component {
<> <>
<div className="level__test_module"> <div className="level__test_module">
<div className='start__test' onClick={this.startTest}> <div className='start__test' onClick={this.startTest}>
<img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/test_icon.png" /> <img className='test-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>
</div> </div>
......
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
font-size:12px; font-size:12px;
} }
} }
.test-img {
width: 14px;
height: 14px;
}
} }
.test__number { .test__number {
......
import React, { Component } from 'react' import React, { Component } from 'react'
import './index.scss' import './index.scss'
import { Tabs, Toast } from "antd-mobile" import { Tabs, Toast } from "antd-mobile"
import { getParam, http, SendMessageToApp } from "@/utils" import { getParam, http, SendMessageToApp, browser } from "@/utils"
import { Popup } from "@common/index" import { Popup } from "@common/index"
import QRCode from 'qrcode' import QRCode from 'qrcode'
import { uniqBy } from 'lodash' import { uniqBy } from 'lodash'
...@@ -12,12 +12,15 @@ import { withRouter } from 'react-router-dom' ...@@ -12,12 +12,15 @@ import { withRouter } from 'react-router-dom'
@connect(state => ({user: state.user})) @connect(state => ({user: state.user}))
class Live extends Component { class Live extends Component {
popupInstance = null
state = { state = {
tabs: [], tabs: [],
lives: {}, lives: {},
preheatLives: [], preheatLives: [],
today: '', today: '',
isApp: getParam('version') isApp: getParam('version'),
QRCodeUrl: '',
} }
...@@ -69,22 +72,33 @@ class Live extends Component { ...@@ -69,22 +72,33 @@ class Live extends Component {
} }
toLiveRoom = id => { toLiveRoom = id => {
const {history,isLogin} = this.props; const {history, isLogin} = this.props
if (this.state.isApp) { if (this.state.isApp) {
if(isLogin){ if (isLogin) {
SendMessageToApp('toLiveRoom', id) SendMessageToApp('toLiveRoom', id)
}else { } else {
SendMessageToApp("toLogin") SendMessageToApp("toLogin")
} }
} else { } else {
if(isLogin){ if (isLogin) {
window.location.href = `${window.location.protocol}//www.julyedu.com/live/m_room/${id}` window.location.href = `${window.location.protocol}//www.julyedu.com/live/m_room/${id}`
}else { } else {
history.push('/passport') history.push('/passport')
} }
} }
} }
saveImage = () => {
let version = getParam('version')
version = typeof version === 'string' ? version.replace('.', '').replace('.', '').slice(0, 3) : ''
const {QRCodeUrl} = this.state
if (version && parseInt(version) < 451) {
Toast.info('当前不支持此功能,升级到最新版本app可以点击保存二维码!', 2, null, false)
} else {
SendMessageToApp('generateQRCode', QRCodeUrl)
}
}
makeSubscribe = id => { makeSubscribe = id => {
const {user, history} = this.props const {user, history} = this.props
if (user.hasError) { if (user.hasError) {
...@@ -94,11 +108,29 @@ class Live extends Component { ...@@ -94,11 +108,29 @@ class Live extends Component {
.then(res => { .then(res => {
const {data} = res const {data} = res
if (data.errno == 200) { if (data.errno == 200) {
this.setState(() => ({
QRCodeUrl: data.data.url,
}))
QRCode.toDataURL(data.data.url, (err, url) => { QRCode.toDataURL(data.data.url, (err, url) => {
Popup({ if (!this.popupInstance) {
title: '扫码关注“七月在线”服务号即可预约', this.popupInstance = Popup({
content: <img id={'live-qr-code'} src={url} alt=""/> title: '扫码关注“七月在线”服务号即可预约',
}) content: (
<>
<img id={'live-qr-code'} src={url} alt=""/>
{
browser.isAndroidApp ? (
<button className={'save-image'} onClick={this.saveImage}>保存二维码</button>
) : null
}
</>
),
close: () => new Promise(resolve => {
this.popupInstance = null
resolve()
})
})
}
}) })
} else { } else {
Toast.info(data.msg, 2, null, false) Toast.info(data.msg, 2, null, false)
...@@ -136,27 +168,29 @@ class Live extends Component { ...@@ -136,27 +168,29 @@ class Live extends Component {
{ {
todayLives.map((item, index) => { todayLives.map((item, index) => {
return ( return (
<LiveContent item={item} key={index} makeSubscribe={this.makeSubscribe} toLiveRoom={this.toLiveRoom}/> <LiveContent item={item} key={index} makeSubscribe={this.makeSubscribe}
toLiveRoom={this.toLiveRoom}/>
)
})
}
</div>
)
})
: tabs.map((item, index) => {
const todayLives = preheatLives[item.title]
return (
<div key={index}>
{
todayLives.map((item, index) => {
return (
<LiveContent item={item} key={index} makeSubscribe={this.makeSubscribe}
toLiveRoom={this.toLiveRoom}/>
) )
}) })
} }
</div> </div>
) )
}) })
:tabs.map((item, index) => {
const todayLives = preheatLives[item.title]
return (
<div key={index}>
{
todayLives.map((item, index) => {
return (
<LiveContent item={item} key={index} makeSubscribe={this.makeSubscribe} toLiveRoom={this.toLiveRoom}/>
)
})
}
</div>
)
})
} }
</Tabs> </Tabs>
...@@ -201,7 +235,9 @@ function LiveContent({item, makeSubscribe, toLiveRoom}) { ...@@ -201,7 +235,9 @@ function LiveContent({item, makeSubscribe, toLiveRoom}) {
</div> </div>
{ {
item['on_live'] item['on_live']
? <button className={'on-living'} onClick={() => {toLiveRoom(item['room_url'])}}>正在直播</button> ? <button className={'on-living'} onClick={() => {
toLiveRoom(item['room_url'])
}}>正在直播</button>
: :
item['is_end'] item['is_end']
? <button className={'subscribed'}>已结束</button> ? <button className={'subscribed'}>已结束</button>
......
...@@ -227,12 +227,27 @@ ...@@ -227,12 +227,27 @@
.content { .content {
display: flex; display: flex;
justify-content: center; flex-direction: column;
align-items: center;
img { img {
width: 120px; width: 120px;
height: 120px; height: 120px;
margin-top: 10px;
} }
} }
.save-image {
width: 133px;
height: 30px;
margin-top: 16px;
background: rgba(83, 39, 250, 1);
border-radius: 15px;
font-size: 14px;
color: #fff;
-webkit-appearance: none;
outline: 0;
border: none;
}
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
height: 33px; height: 33px;
border: 1px solid rgba(255, 246, 4, 1); border: 1px solid rgba(255, 246, 4, 1);
border-radius: 0 0 6px 6px; border-radius: 0 0 6px 6px;
.am-tabs-default-bar { .am-tabs-default-bar {
.am-tabs-default-bar-tab:nth-of-type(3) { .am-tabs-default-bar-tab:nth-of-type(3) {
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
display: none; display: none;
} }
} }
.am-tabs-default-bar-tab { .am-tabs-default-bar-tab {
height: auto; height: auto;
line-height: 1; line-height: 1;
&::after { &::after {
content: ''; content: '';
display: block; display: block;
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
.prize__content { .prize__content {
display: flex; display: flex;
flex-wrap: nowrap; flex-wrap: nowrap;
padding: 10px 7px 0; padding: 10px 7px 0 0;
overflow-y: auto; overflow-y: auto;
} }
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
background-image: url('https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/prize-border.png'); background-image: url('https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/prize-border.png');
background-size: cover; background-size: cover;
overflow: hidden; overflow: hidden;
img { img {
display: block; display: block;
width: 100%; width: 100%;
......
...@@ -41,6 +41,7 @@ export default class RecordPopup extends Component { ...@@ -41,6 +41,7 @@ export default class RecordPopup extends Component {
</div> </div>
<div className="table__body"> <div className="table__body">
{ {
recordList.length>0?
recordList.map((item, index) => { recordList.map((item, index) => {
return (<div className="tr__container" key={index}> return (<div className="tr__container" key={index}>
<span className="tr">{item.submit_time}</span> <span className="tr">{item.submit_time}</span>
...@@ -54,12 +55,13 @@ export default class RecordPopup extends Component { ...@@ -54,12 +55,13 @@ export default class RecordPopup extends Component {
</span> </span>
</div> </div>
) )
}) }):
<div className={'notdata'}>暂无测试记录</div>
} }
</div> </div>
</div> </div>
</div> </div>
</div> </div>
) )
} }
......
...@@ -14,10 +14,9 @@ ...@@ -14,10 +14,9 @@
.gift__record { .gift__record {
width: 300px; width: 300px;
height: 250px;
background: rgba(255, 255, 255, 1); background: rgba(255, 255, 255, 1);
border-radius: 5px; border-radius: 5px;
padding: 18px 24px 0 24px; padding: 18px 24px 30px 24px;
position: relative; position: relative;
span.tr { span.tr {
display: flex; display: flex;
...@@ -60,7 +59,6 @@ ...@@ -60,7 +59,6 @@
} }
.table__body { .table__body {
width: 250px; width: 250px;
height: 102px;
border: 1px solid rgba(207, 219, 229, 0.4); border: 1px solid rgba(207, 219, 229, 0.4);
border-radius: 0px 0px 1px 1px; border-radius: 0px 0px 1px 1px;
box-sizing: border-box; box-sizing: border-box;
...@@ -78,10 +76,15 @@ ...@@ -78,10 +76,15 @@
} }
} }
} }
.notdata{
text-align: center;
color: #999999;
line-height: 35px;
}
.close__button { .close__button {
width: 32px; width: 24px;
height: 32px; height: 24px;
border-radius: 50%; border-radius: 50%;
position: absolute; position: absolute;
left: 50%; left: 50%;
...@@ -92,7 +95,7 @@ ...@@ -92,7 +95,7 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
i { i {
font-size: 32px; font-size: 24px;
color: #fff; color: #fff;
} }
} }
......
...@@ -11,7 +11,7 @@ export default class SharePopup extends Component { ...@@ -11,7 +11,7 @@ export default class SharePopup extends Component {
} }
}}> }}>
{ {
browser.isWeixin && browser.isWeixin &&
<div className="share__row"> <div className="share__row">
<img src='https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/throw_icon.png' /> <img src='https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/throw_icon.png' />
</div> </div>
...@@ -19,7 +19,7 @@ export default class SharePopup extends Component { ...@@ -19,7 +19,7 @@ export default class SharePopup extends Component {
<div className="share__content"> <div className="share__content">
<p className="share__text">分享活动页到朋友圈、qq、微博分别</p> <p className="share__text">分享活动页到朋友圈、qq、微博分别</p>
<div className='share__rule'> <div className='share__rule'>
<img src='https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/add2.png' /> <img className={'share__add2'} src='https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/add2.png' />
<span>(每个平台每天一次)</span> <span>(每个平台每天一次)</span>
</div> </div>
</div> </div>
......
...@@ -45,5 +45,8 @@ ...@@ -45,5 +45,8 @@
font-size: 12px; font-size: 12px;
color: #525C65; color: #525C65;
} }
.share__add2{
width: 95px;
}
} }
} }
\ No newline at end of file
...@@ -400,8 +400,9 @@ class FinalDepositOrder extends Component { ...@@ -400,8 +400,9 @@ class FinalDepositOrder extends Component {
getBalanceOffset = () => { getBalanceOffset = () => {
let originalTotalPrice = this.getOriginTotalPrice() let originalTotalPrice = this.getOriginTotalPrice()
let offset = parseFloat(this.state.user_account) - parseFloat(originalTotalPrice) let currentPrice = this.moneyOff(originalTotalPrice)
offset = offset >= 0 ? originalTotalPrice : this.state.user_account let offset = parseFloat(this.state.user_account) - parseFloat(currentPrice)
offset = offset >= 0 ? currentPrice : this.state.user_account
return offset return offset
} }
......
import React, { Component } from 'react'; import React, { Component } from 'react'
import './binding-tel.scss' import './binding-tel.scss'
import { withFormik, Field, Form } from "formik"; import { withFormik, Field, Form } from "formik"
import { http, getParam } from "@/utils"; import { http, getParam } from "@/utils"
import { compose } from "redux"; import { compose } from "redux"
import { connect } from "react-redux"; import { connect } from "react-redux"
import { setCurrentUser } from "@/store/userAction"; import { setCurrentUser } from "@/store/userAction"
import Captcha from '@/common/Captcha' import Captcha from '@/common/Captcha'
import { HeaderBar } from '@/common' import { HeaderBar } from '@/common'
...@@ -13,147 +13,148 @@ import { HeaderBar } from '@/common' ...@@ -13,147 +13,148 @@ import { HeaderBar } from '@/common'
import ClearableInput from '../common/clearableInputWithCountryCodes' import ClearableInput from '../common/clearableInputWithCountryCodes'
import Button from '../common/Button' import Button from '../common/Button'
import VeriCodeInput from '../common/veriCodeInput' import VeriCodeInput from '../common/veriCodeInput'
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile"
import { isEmpty } from "lodash"; import { isEmpty } from "lodash"
class BindingTel extends Component { class BindingTel extends Component {
state = { state = {
validate: null, validate: null,
captchaInstance: null captchaInstance: null
} }
getCaptchaInstance = instance => { getCaptchaInstance = instance => {
this.setState({ this.setState({
captchaInstance: instance captchaInstance: instance
}) })
} }
onVerify = (err, data) => { onVerify = (err, data) => {
if (err) { if (err) {
console.log(err) console.log(err)
} else { } else {
this.setState({ this.setState({
validate: data.validate validate: data.validate
}) })
}
} }
}
render() { render() {
const { const {
values, values,
errors, errors,
country country
} = this.props } = this.props
return ( return (
<> <>
<HeaderBar title={'绑定手机号'} arrow={true}/> <HeaderBar title={'绑定手机号'} arrow={true}/>
<div className={'binding-tel'}> <div className={'binding-tel'}>
<p className={'title'}>为提高您的账号安全,请绑定手机号</p> <p className={'title'}>为提高您的账号安全,请绑定手机号</p>
<Form> <Form>
<Field <Field
name='tel' name='tel'
render={({field, form}) => { render={({field, form}) => {
return ( return (
<ClearableInput <ClearableInput
{...field} {...field}
setFieldValue={form.setFieldValue} setFieldValue={form.setFieldValue}
placeholder={'请输入需要绑定的手机号'} placeholder={'请输入需要绑定的手机号'}
wrapperClass={'tel'} wrapperClass={'tel'}
country={country} country={country}
/> />
) )
}} }}
/> />
<Field <Field
name='veriCode' name='veriCode'
render={({field}) => { render={({field}) => {
return ( return (
<VeriCodeInput <VeriCodeInput
{...field} {...field}
className={'verification'} className={'verification'}
icon={<i className={'iconfont iconduanxin'} icon={<i className={'iconfont iconduanxin'}
style={{fontSize: '20px', left: '12px'}} style={{fontSize: '20px', left: '12px'}}
/>} />}
placeholder={'验证码'} placeholder={'验证码'}
account={values.tel} account={values.tel}
tel={values.tel} tel={values.tel}
challenge={this.state.validate} challenge={this.state.validate}
instance={this.state.captchaInstance} instance={this.state.captchaInstance}
action={'auth'} action={'auth'}
country={country} country={country}
/> />
) )
}} }}
/> />
<Captcha onVerify={this.onVerify} getInstance={this.getCaptchaInstance}/> <Captcha onVerify={this.onVerify} getInstance={this.getCaptchaInstance}/>
<Button className={'complete-btn'} <Button className={'complete-btn'}
active={values.tel && values.veriCode && isEmpty(errors)}>完成</Button> active={values.tel && values.veriCode && isEmpty(errors)}>完成</Button>
</Form> </Form>
</div> </div>
</> </>
); )
} }
} }
const formikConfig = { const formikConfig = {
mapPropsToValues() { mapPropsToValues() {
return { return {
tel: '', tel: '',
veriCode: '' veriCode: ''
} }
}, },
validateOnChange: true, validateOnChange: true,
validate(values) { validate(values) {
let errors = {} let errors = {}
if (!/\d/.test(values.tel)) { if (!/\d/.test(values.tel)) {
errors.tel = '请输入正确的手机号' errors.tel = '请输入正确的手机号'
} }
if (!values.veriCode) { if (!values.veriCode) {
errors.veriCode = '请填写验证码' errors.veriCode = '请填写验证码'
}
return errors
},
handleSubmit(values, {props}) {
http.post(`${API['passport-api']}/bind_mobile`, {
phone_num: values.tel,
phone_code: values.veriCode,
mkey: getParam('mkey'),
area_code: '00' + props.country.num,
plat: 5
}).then(res => {
const data = res.data
if (data.errno == 200) {
if (data.data['is_set_pwd']) {
const {history} = props
history.replace(`/passport/set-password`, {
user: {
hasError: false,
data: {
uid: data.data.uid
},
msg: data.data.msg,
stage: 'binding'
}
})
} else {
location.assign(data.data['jump_url'])
} }
return errors
},
handleSubmit(values, {props}) {
http.post(`${API['passport-api']}/bind_mobile`, {
phone_num: values.tel,
phone_code: values.veriCode,
mkey: getParam('mkey'),
area_code: '00'+props.country.num,
plat: 5
}).then(res => {
const data = res.data
if (data.errno == 200) {
if (data.data['is_set_pwd']) {
props.setCurrentUser({
hasError: false,
data: {
uid: data.data.uid
},
msg: data.data.msg,
stage: 'binding'
})
props.history.replace(`/passport/set-password`)
} else {
location.assign(data.data['jump_url'])
}
} else {
} else { Toast.info(data.msg, 2, null, false)
Toast.info(data.msg, 2, null, false) }
} })
}) }
}
} }
export default compose( export default compose(
connect( connect(
state => ({country: state.country}), state => ({country: state.country}),
{setCurrentUser} {setCurrentUser}
), ),
withFormik(formikConfig), withFormik(formikConfig),
)(BindingTel); )(BindingTel)
...@@ -23,6 +23,7 @@ class Passport extends Component { ...@@ -23,6 +23,7 @@ class Passport extends Component {
redirectURL = '/' redirectURL = '/'
count = 1 count = 1
blackList = new Set(['/passport/binding-tel', '/passport/set-password'])
constructor(props) { constructor(props) {
super(props) super(props)
...@@ -85,7 +86,7 @@ class Passport extends Component { ...@@ -85,7 +86,7 @@ class Passport extends Component {
routeWhenUserLoggedIn = () => { routeWhenUserLoggedIn = () => {
let {hasError} = this.props.user let {hasError} = this.props.user
if (!hasError) { if (!hasError && !this.blackList.has(this.props.location.pathname)) {
const redirectURI = getParam('redirect') const redirectURI = getParam('redirect')
redirectURI ? (window.location.href = redirectURI) : this.props.history.go(-this.count) redirectURI ? (window.location.href = redirectURI) : this.props.history.go(-this.count)
} }
...@@ -108,7 +109,9 @@ class Passport extends Component { ...@@ -108,7 +109,9 @@ class Passport extends Component {
<Route path={match.url + '/account-login'} component={AccountLogin}/> <Route path={match.url + '/account-login'} component={AccountLogin}/>
<Route path={match.url + '/forgot-password'} component={ForgotPassword}/> <Route path={match.url + '/forgot-password'} component={ForgotPassword}/>
<Route path={match.url + '/forgot-password-email'} component={ForgotPasswordEmail}/> <Route path={match.url + '/forgot-password-email'} component={ForgotPasswordEmail}/>
<Route path={match.url + '/set-password'} component={SetPassword}/> <Route path={match.url + '/set-password'} render={props => {
return <SetPassword {...props} count={this.count}/>
}}/>
<Route path={match.url + '/binding-tel'} component={BindingTel}/> <Route path={match.url + '/binding-tel'} component={BindingTel}/>
</Switch> </Switch>
</div> </div>
...@@ -123,4 +126,4 @@ export default compose( ...@@ -123,4 +126,4 @@ export default compose(
null null
), ),
WithFullSize WithFullSize
)(Passport) )(Passport)
\ No newline at end of file
import React, { Component } from 'react'; import React, { Component } from 'react'
import './set-password.scss' import './set-password.scss'
import { withFormik, Form, Field } from "formik"; import { withFormik, Form, Field } from "formik"
import PasswordInput from '../common/passwordInput' import PasswordInput from '../common/passwordInput'
import Button from '../common/Button' import Button from '../common/Button'
import classnames from 'classnames' import classnames from 'classnames'
import { compose } from 'redux' import { compose } from 'redux'
import { HeaderBar } from "@/common"; import { HeaderBar } from "@/common"
import { http, api } from "@/utils"; import { http } from "@/utils"
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile"
import { encrypt } from "@/components/passport/encryption"; import { encrypt } from "@/components/passport/encryption"
import { Link } from "react-router-dom"; import { Link } from "react-router-dom"
import { isEmpty } from "lodash"; import { isEmpty } from "lodash"
import { connect } from "react-redux"; import { connect } from "react-redux"
import { setCurrentUser } from '@/store/userAction'
class SetPassword extends Component { class SetPassword extends Component {
render() { render() {
let {values, errors, location} = this.props let {values, errors, location} = this.props
let {from} = location.state || {from: {pathname: '/'}} let {from} = location.state || {from: {pathname: '/'}}
return ( return (
<> <>
<HeaderBar arrow={true} title={'设置密码'}/> <HeaderBar arrow={true} title={'设置密码'}/>
<div className={'set-password'}> <div className={'set-password'}>
<p className='title'>密码需要包含6-16位字母及数字</p> <p className='title'>密码需要包含6-16位字母及数字</p>
<Form> <Form>
<Field <Field
name='password' name='password'
render={({field}) => { render={({field}) => {
return ( return (
<PasswordInput <PasswordInput
autoComplete={'on'} autoComplete={'on'}
placeholder={'设置密码'} placeholder={'设置密码'}
onChange={this.handleChange} onChange={this.handleChange}
{...field} {...field}
/> />
) )
}} }}
/> />
<Button className={'btn-active'} <Button className={'btn-active'}
active={values.password && values.agreement && isEmpty(errors)}>完成</Button> active={values.password && values.agreement && isEmpty(errors)}>完成</Button>
<label htmlFor="agreement" className='user-agreement'> <label htmlFor="agreement" className='user-agreement'>
<Field type='checkbox' <Field type='checkbox'
name='agreement' name='agreement'
id='agreement' id='agreement'
className={classnames([ className={classnames([
this.props.values.agreement ? 'iconfont iconiconfront-3' : 'disagree' this.props.values.agreement ? 'iconfont iconiconfront-3' : 'disagree'
])} ])}
/> />
同意<span>《七月在线用户使用协议》</span> 同意<span>《七月在线用户使用协议》</span>
</label> </label>
</Form> </Form>
<div className="skip" <div className="skip"
style={{display: from && from.pathname.includes('forgot-password') ? 'none' : 'block'}}> style={{display: from && from.pathname.includes('forgot-password') ? 'none' : 'block'}}>
<Link replace to='/passport/account-login'>跳过</Link> <Link replace to='/passport/account-login'>跳过</Link>
</div> </div>
</div> </div>
</> </>
); )
} }
} }
const formikConfig = { const formikConfig = {
mapPropsToValues() { mapPropsToValues() {
return { return {
password: '', password: '',
agreement: true agreement: true
} }
}, },
handleSubmit: (values, {props}) => { handleSubmit: (values, {props}) => {
let from = props.location.state && props.location.state.from || {pathname: '/'} let from = props.location.state && props.location.state.from || {pathname: '/'}
if (from.pathname.includes('forgot-password')) { if (from.pathname.includes('forgot-password')) {
forgotPasswordReset(values, props); forgotPasswordReset(values, props)
} else { } else {
bindMobileSetPassword(values, props) bindMobileSetPassword(values, props)
} }
}, },
validateOnChange: false, validateOnChange: false,
validate: values => { validate: values => {
let errors = {} let errors = {}
const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/; const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/
if (!re.test(values.password)) { if (!re.test(values.password)) {
errors.password = '密码需要包含6-16位字母及数字' errors.password = '密码需要包含6-16位字母及数字'
Toast.info(errors.password, 2, null, false) Toast.info(errors.password, 2, null, false)
} }
if (!values.agreement) { if (!values.agreement) {
errors.agreement = '您须同意《七月在线用户使用协议》' errors.agreement = '您须同意《七月在线用户使用协议》'
Toast.info(errors.agreement, 2, null, false) Toast.info(errors.agreement, 2, null, false)
}
return errors
} }
return errors
}
} }
function forgotPasswordReset(values, props) { function forgotPasswordReset(values, props) {
let key = sessionStorage.getItem('r_type') === 'email' ? 'email' : 'tel' let key = sessionStorage.getItem('r_type') === 'email' ? 'email' : 'tel'
let requestKey = key === 'email' ? 'email' : 'phone' let requestKey = key === 'email' ? 'email' : 'phone'
http.post(`${API['passport-api']}/account/up_pass_by_${requestKey}`, { http.post(`${API['passport-api']}/account/up_pass_by_${requestKey}`, {
[requestKey]: sessionStorage.getItem(key), [requestKey]: sessionStorage.getItem(key),
password: encrypt(values.password) password: encrypt(values.password)
})
.then(res => {
if (res.data.errno == 200) {
Toast.info('密码设置成功')
setTimeout(function () {
props.history.replace('/passport/account-login')
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
}) })
.then(res => {
if (res.data.errno == 200) {
Toast.info('密码设置成功')
setTimeout(function () {
props.history.replace('/passport/account-login')
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
})
} }
function bindMobileSetPassword(values, props) { function bindMobileSetPassword(values, props) {
http.post(`${API['passport-api']}/bind_mobile/set_pwd_new`, { http.post(`${API['passport-api']}/bind_mobile/set_pwd_new`, {
uid: props.user.data.uid, uid: props.user.data.uid,
password: encrypt(values.password) password: encrypt(values.password)
})
.then(res => {
if (res.data.errno == 200) {
const {location, history} = props
Toast.info('密码设置成功')
let from = location.state && location.state.from || {pathname: '/'}
let local_redirect_url = JSON.parse(window.localStorage.getItem('binding_redirect'))
setTimeout(function () {
if (local_redirect_url) {
const {pathname, search, hash} = local_redirect_url
history.replace(pathname + search + hash)
} else {
history.replace(from.pathname)
}
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
}) })
.then(res => {
if (res.data.errno == 200) {
Toast.info('密码设置成功')
let from = props.location.state && props.location.state.from || {pathname: '/'}
setTimeout(function () {
props.history.replace(from.pathname)
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
})
} }
export default compose( export default compose(
connect( connect(
state => ({user: state.user}), state => ({user: state.user}),
null {setCurrentUser}
), ),
withFormik(formikConfig) withFormik(formikConfig)
)(SetPassword); )(SetPassword)
\ No newline at end of file
...@@ -83,7 +83,9 @@ const browser = (function () { ...@@ -83,7 +83,9 @@ const browser = (function () {
isWeixin: /MicroMessenger/i.test(ua), isWeixin: /MicroMessenger/i.test(ua),
isAndroid: /Android/i.test(ua), isAndroid: /Android/i.test(ua),
isIOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(ua), isIOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(ua),
isIPad: /iPad/i.test(ua) isIPad: /iPad/i.test(ua),
isAndroidApp: /Android/i.test(ua) && getParam('version'),
isIOSApp: /iPhone/i.test(ua) && getParam('version')
} }
})() })()
......
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