解决验证码登录方式防抖操作

This commit is contained in:
red-deng-deng 2021-12-15 17:52:37 +08:00
parent 77ba2cf3ce
commit 5aac48d596
3 changed files with 47 additions and 21 deletions

View File

@ -96,30 +96,50 @@ function FormDom(props) {
}
//发送短信验证码
const sendCode=()=>{
let startTime=localStorage.getItem('now');
console.log(100,startTime);
if(!startTime){
sendCodeApi();
}else{
let stopTime=startTime*1+60000;//一分钟后的时间戳
let currentime=new Date().getTime(); //点击获取当前的时间戳
if(currentime-startTime<=stopTime-startTime){//一分钟内
Notify.clear();
Notify.warn('发送过于频繁,请稍后再试');
console.log(109,currentime-startTime<=stopTime-startTime);
}else{
localStorage.removeItem('now');
sendCodeApi();
}
}
}
const sendCodeApi=()=>{
let data={
mobile:phone
}
postsendLoginCode(data).then(res=>{
handelResponse(res,(response,msg)=>{
let clickNow=new Date().getTime();//当前时间
localStorage.setItem('now',clickNow);
let timer=60;
let timecount=setInterval(()=>{
let timerId=timer--;
if(timerId>0){
setYzmcode(timerId+'s');
setDisabled(true);
}else{
setYzmcode('获取验证码');
setDisabled(false);
clearInterval(timecount);
}
},1000);
},(err)=>{
Notify.error(err)
localStorage.setItem('now',new Date().getTime());
})
}).catch(err=>{
});
let timer=60;
let timecount=setInterval(()=>{
let timerId=timer--;
if(timerId>0){
setYzmcode(timerId+'s');
setDisabled(true);
}else{
setYzmcode('获取验证码');
setDisabled(false);
clearInterval(timecount);
}
},1000);
}
const changephone=(e)=>{
let reg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;

View File

@ -98,10 +98,9 @@ export default class acclistDom extends React.Component{
this.getAutnMan(this.props.deldata.id); //下级
setTimeout(()=>{
if(this.state.levelAuth){
this.setState({authperson:this.state.levelAuthdata,loadshow:true});
this.setState({authperson:this.state.levelAuthdata,loadshow:true,authWay:1});
}else{
this.setState({authperson:this.state.downLeveldata,loadshow:true});
this.setState({authperson:this.state.downLeveldata,loadshow:true,authWay:0});
}
},300);
}

View File

@ -55,8 +55,10 @@ export default class tree extends React.Component{
handelResponse(res,(response,msg)=>{
const menu_data=response.filter(item=>item.children.length>0);
if(_self.props.enum==0){//新增){
_self.setState({checked:true});
let checkList=[];
menu_data.forEach(item=>{
checkList.push(item.id);
if(item.children){
item.children.forEach(item1=>{
@ -70,9 +72,17 @@ export default class tree extends React.Component{
}
})
_self.setState({
checked:true,checkedKeys:checkList
checkedKeys:checkList
})
}else{
_self.setState({checked:true});
menu_data.forEach(it=>{
if(_self.props.rules.indexOf(it.id)==-1){
_self.setState({checked:false})
return false
}
})
_self.setState({checkedKeys:_self.props.rules});
}
_self.setState({menu_data});
})
@ -80,9 +90,6 @@ export default class tree extends React.Component{
}
componentWillMount(){
this.getMenuFn();
if(this.props.enum==1){
this.setState({checkedKeys:this.props.rules});
}
}
render(){
const { checkedKeys, disabledCheckedKeys } = this.state;