Skip to content

Commit

Permalink
修复登录部分bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Sep 3, 2019
1 parent 259e49d commit 82442bb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ const StepOne = props => {
}, []);
return (
<>
<p className="tips">
&emsp;&emsp;暂时不支持验证码登录,请输入手机号和密码
</p>

<p className="input">
+86
<input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ import { VcodeBox, Container } from "./style";
const maxLength = 4;
const StepTwo = props => {
const { phone, triggerLogin } = props;
const [triggered, setTriggered] = useState(false);
const [cursorIndex, setCursorIndex] = useState(0);
const [vcode, setVcode] = useState("");
const [timer, setTimer] = useState(60);
const inputRef = useRef();

useEffect(() => {
inputRef.current.focus();
let theTimer;
if (!theTimer) {
theTimer = setInterval(() => {
setTimer(timer => timer - 1);
if(timer <= 0) clearTimeout(theTimer);
}, 1000);
}
return () => {
clearTimeout(theTimer);
};
}, [vcode]);
}, [timer]);

useEffect(() => {
if (vcode.length === 4) {
if (vcode.length === 4 && !triggered) {
triggerLogin(vcode);
setTriggered(true);
}
}, [vcode, triggerLogin]);
}, [vcode, triggerLogin, triggered]);

const onChangeVcode = e => {
if(!e.target.value) return;
const val = e.target.value;
if (!val) {
return;
}
setVcode(val);
setCursorIndex(val.split("").length);
};
Expand Down Expand Up @@ -63,7 +63,7 @@ const StepTwo = props => {
key={idx}
className={`line ${cursorIndex === idx ? "animated" : ""}`}
>
{vcode.split("")[idx]}
{vcode[idx]}
</label>
))}
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/application/User/Login/store/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
sentVcodeRequest,
loginByVcodeRequest
} from "../../../../api/request";
import { CHANGE_USER_INFO, CHANGE_SENT_STATUS } from "./constants";
import { CHANGE_USER_INFO, CHANGE_SENT_STATUS, CHANGE_IS_LOGIN } from "./constants";

export const saveUserInfo = data => ({
type: CHANGE_USER_INFO,
Expand All @@ -15,6 +15,11 @@ export const saveSentStatus = data => ({
data
});

export const changeIslogin = data => ({
type: CHANGE_IS_LOGIN,
data
});

export const loginByPhone = (phone, password) => {
return dispatch => {
loginByPhoneRequest(phone, password)
Expand Down Expand Up @@ -51,4 +56,4 @@ export const sentVcode = phone => {
console.log("请求失败!");
});
};
};
};
2 changes: 2 additions & 0 deletions src/application/User/Login/store/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const CHANGE_USER_INFO = "user/login/CHANGE_USER_INFO";

export const CHANGE_SENT_STATUS = "user/login/CHANGE_SENT_STATUS";

export const CHANGE_IS_LOGIN = "user/login/CHANGE_IS_LOGIN";
5 changes: 4 additions & 1 deletion src/application/User/Login/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { fromJS } from "immutable";

const defaultState = fromJS({
userInfo: {},
sentStatus: false
sentStatus: false,
isLogin: false
});

export default (state = defaultState, action) => {
Expand All @@ -12,6 +13,8 @@ export default (state = defaultState, action) => {
return state.set("userInfo", action.data);
case actionTypes.CHANGE_SENT_STATUS:
return state.set("sentStatus", action.data);
case actionTypes.CHANGE_IS_LOGIN:
return state.set("isLogin", action.data);
default:
return state;
}
Expand Down

0 comments on commit 82442bb

Please sign in to comment.