Commit 123868be by 姜雷

修改登录逻辑

parent 79571db0
......@@ -4,6 +4,8 @@ import {
BASE_SERVER_URL,
CUSTOMER_SERVER_URL,
SCHOOL_MAIN_URL,
LogoutCode,
SuccessCode,
} from '../constants/index';
export type ResponseDataEntity<T> = {
......@@ -33,9 +35,15 @@ const createFetch = (basePath: string) => {
},
url: basePath + entity.url,
}).then(({ data }: ResponseEntity) => {
if (data.code === 1000) {
if (data.code === SuccessCode) {
return data;
}
if (data.code === LogoutCode) {
Taro.redirectTo({
url: '/pages/Login/Login',
});
throw data;
}
Taro.showToast({
title: data.msg,
icon: 'none',
......
.checkTelephone {
width: 100%;
height: 100%;
overflow: hidden;
// background: url('../../images/login/bg@2x.png') center;
background-size: cover;
}
.loginBox {
width: 634px;
height: 538px;
margin: 180px auto 0;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 8px;
padding: 50px 40px 0;
line-height: 88px;
.loginBox-input {
box-sizing: border-box;
background-color: #fff;
width: 100%;
height: 88px;
padding: 0 20px;
font-size: 30px;
margin-bottom: 50px;
border-radius: 8px;
color: #ff9000;
}
.loginBox-input::-webkit-input-placeholder {
/* WebKit browsers */
color: #d9a842;
}
.loginBox-button {
font-size: 28px;
width: 100%;
height: 88px;
background-color: #ff9000;
color: #fff;
border: none;
outline: none;
border-radius: 8px;
}
.loginBox-button.big {
font-size: 34px;
}
.loginBox-button.fetching {
background-color: #ccc;
}
.loginBox-vcodeBox {
display: flex;
}
.vcodeBox-input-wrap {
flex: 1;
margin-right: 20px;
}
.vcodeBox-button-wrap {
text-align: center;
width: 200px;
height: 88px;
}
.countDownText {
color: #ff9000;
font-size: 30px;
}
}
.imgVcodeBox-wrap {
.imgVcodeBox-content {
width: 380px;
height: 332px;
}
.imgVcodeBox {
display: flex;
margin-bottom: 60px;
justify-content: space-between;
}
.imgVcodeBox-item {
width: 180px;
height: 88px;
background-color: #ffebcc;
border-radius: 8px;
}
.loginBox-input {
background-color: #ffebcc;
color: #d9a842;
}
}
import { ComponentClass } from 'react';
import Taro, { Component } from '@tarojs/taro';
import { View, Text, Button, Input } from '@tarojs/components';
import './CheckTelephone.scss';
type PageOwnProps = {};
type PageState = {
count: number;
timer: null;
fetching: boolean;
tel: string;
code: string;
sending: boolean;
vcode: string;
imgCode: string;
imgVcode: string;
dialogVisible: boolean;
};
interface CheckTelephone {
state: PageState;
}
class CheckTelephone extends Component {
constructor(props) {
super(props);
this.state = {
timer: null,
fetching: false,
tel: '',
code: '',
count: 60,
sending: false,
vcode: '',
imgCode: '',
imgVcode: '',
dialogVisible: false,
};
}
fetchImageVcode = () => {
console.log('in fetchImageVcode');
};
registerUser = () => {
Taro.navigateTo({
url: '/pages/Register/Register',
});
};
render() {
const { sending, count } = this.state;
return (
<View className='checkTelephone'>
<View className='loginBox'>
<Input
className='loginBox-input'
type='text'
placeholder='输入您的手机号'
/>
<View className='loginBox-vcodeBox'>
<View className='vcodeBox-input-wrap'>
<Input
className='loginBox-input'
type='text'
placeholder='请输入短信验证码'
/>
</View>
<View className='vcodeBox-button-wrap'>
{sending && <Text className='countDownText'>{{ count }}s</Text>}
<Button
v-else
className='loginBox-button'
onClick={this.fetchImageVcode}>
获取验证码
</Button>
</View>
</View>
<Button className='loginBox-button big' onClick={this.registerUser}>
登 录
</Button>
{/* // <ks-Dialog
// class="imgVcodeBox-wrap"
// :visible.sync="dialogVisible"
// top="180px"
// >
// <View class="imgVcodeBox-content">
// <View class="imgVcodeBox">
// <View class="imgVcodeBox-item">
// <input
// class="loginBox-input"
// type="text"
// v-model="imgCode"
// maxlength="6"
// />
// </View>
// <CodeView class="imgVcodeBox-item" :value="imgVcode"></CodeView>
// </View>
// <button v-if="fetching" class="loginBox-button big fetching">
// 确认
// </button>
// <button v-else class="loginBox-button big" @click="fetchVcode">
// 确认
// </button>
// </View>
// </ks-Dialog> */}
</View>
</View>
);
}
}
export default CheckTelephone as ComponentClass<PageOwnProps, PageState>;
......@@ -5,11 +5,12 @@ import { View, Button, Input, Navigator } from '@tarojs/components';
import './Login.scss';
import { appLogin } from '../../api/customer';
import { connect } from '@tarojs/redux';
import { updateUserInfo } from '../../store/rootReducers/userinfo';
import { LoginInfoVo } from '../../api/baseClass';
import { updateUserInfo, UserState } from '../../store/rootReducers/userinfo';
import { NotRegisterCode } from '../../constants/index';
type PageDispatchProps = {
updateUserInfo: (e: LoginInfoVo) => void;
userinfo: UserState;
updateUserInfo: (e: UserState) => void;
};
type PageState = {
......@@ -23,9 +24,9 @@ interface Login {
}
@connect(
() => ({}),
({ userinfo }) => ({ userinfo }),
dispatch => ({
updateUserInfo(data: LoginInfoVo) {
updateUserInfo(data: UserState) {
dispatch(updateUserInfo(data));
},
}),
......@@ -64,24 +65,33 @@ class Login extends Component {
loginHandle(): void {
if (this.validataLoginData()) {
const { updateUserInfo, userinfo } = this.props;
const { account, pwd } = this.state;
console.log('in loginHandle');
appLogin({
loginAccount: account,
password: pwd,
code: userinfo.code,
})
.then(res => {
const data = res.data;
console.log(data);
this.props.updateUserInfo({
...data,
token: data.wxToken,
});
Taro.navigateTo({
updateUserInfo(data);
Taro.redirectTo({
url: '/pages/Home/Home',
});
})
.catch(console.error);
.catch(err => {
console.log(err);
if (err.code && err.code === NotRegisterCode) {
updateUserInfo({
customerPhone: account,
});
Taro.navigateTo({
url: '/pages/Register/Register',
});
}
});
}
}
......
......@@ -18,9 +18,10 @@ import { connect } from '@tarojs/redux';
import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo';
import { wxUserRegister } from '../../api/customer';
import { replaceIllegalPwd } from '../../utils/pwd';
import { Customer } from '@/types/Customer/Customer';
type PageStateProps = {
userinfo: UserState;
userinfo: Customer;
};
type PageDispatchProps = {
updateUserInfo: (e: UserState) => void;
......@@ -61,9 +62,10 @@ class Register extends Component {
constructor(props: IProps) {
super(props);
const { customerPhone } = props.userinfo;
this.state = {
name: '',
cellphone: '',
cellphone: customerPhone,
vcode: '',
pwd: '',
checkPwd: '',
......
......@@ -3,11 +3,11 @@ import Taro, { Component, Config } from '@tarojs/taro';
import { View } from '@tarojs/components';
import './index.scss';
import { LoginReponse } from '../../api/wx';
import { connect } from '@tarojs/redux';
import { updateUserInfo, UserState } from '../../store/rootReducers/userinfo';
import { appLogin } from '../../api/customer';
import { NotRegisterCode } from '@/constants';
type PageDispatchProps = {
updateUserInfo: (e: UserState | { token: string }) => void;
......@@ -67,35 +67,25 @@ class Index extends Component {
Taro.login()
.then(res => {
console.log(res);
const code = res.code;
updateUserInfo({
code,
});
appLogin({
code: res.code,
})
.then((res: LoginReponse) => {
const { register, wxToken, ...userInfo } = res.data;
console.log(wxToken);
if (register) {
updateUserInfo({
...userInfo,
token: wxToken,
});
Taro.redirectTo({
url: '/pages/Home/Home',
});
} else {
updateUserInfo({
token: wxToken,
});
Taro.hideLoading();
Taro.redirectTo({
url: '/pages/Login/Login',
});
}
.then(res => {
const data = res.data;
updateUserInfo(data);
Taro.redirectTo({
url: '/pages/Home/Home',
});
})
.catch(err => {
console.log(err);
this.setState({
errorText: err.msg,
Taro.hideLoading();
Taro.redirectTo({
url: '/pages/Login/Login',
});
});
})
......
import Action from '../../types/Store/Actions';
import { Customer } from '../../types/Customer/Customer';
export type UserState = StoreState<Customer>;
export type UserState = StoreState<Customer & { code: string }>;
export const INITIAL_STATE = {
login: false,
code: '',
areaId: 0,
areaName: '',
birthDay: '',
......@@ -36,7 +36,6 @@ export const INITIAL_STATE = {
updateAt: '',
updateLoginDate: '',
version: '',
wxToken: '',
};
export const updateUserInfo = (entity: UserState): Action => ({
......
......@@ -30,5 +30,4 @@ export type Customer = {
updateAt: string;
updateLoginDate: string;
version: string;
wxToken: string;
};
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