效果如下
html
div class="layui-inline">
<a class="layui-btn layui-btn-danger batchUnlock"><i class="layui-icon layui-icon-key"></i>批量解锁</a>
</div>
js
//批量解锁锁定的账号 使用封装后的ajax
$(".batchUnlock").click(function (){
const checkStatus = table.checkStatus('userTable');
let accounts = "";
const dataLength = checkStatus.data.length;
if(dataLength>0){
for(let i = 0;i<dataLength;i++){
accounts += checkStatus.data[i].account+ ",";
}
layer.confirm('确定要解锁选中的用户?',{icon: 3, title: '提示信息'},function (index){
layer.msg('请求后台')
const ajax = new $ax(Feng.ctxPath + "/mgr/unlock", function (accounts) {
Feng.success("批量解锁账号成功!");
}, function (data) {
Feng.error("批量解锁账号失败!" + data.responseJSON.message + "!");
});
ajax.set("accounts", accounts);
ajax.start();
admin.refresh();
table.reload(MgrUser.tableId);
})
}
});
springboot后台代码
@RequestMapping("/unlock")
@ResponseBody
public ResponseData unlock(@RequestParam String accounts) {
log.info("批量解除锁定账号接口,请求参数:{}",accounts);
ResponseData responseData = new ResponseData();
if (ToolUtil.isEmpty(accounts)) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
}
try {
//把请求参数转为list
List<String> accountList = Arrays.asList(accounts.split(","));
Map<String, AtomicInteger> passwordRetryCache = redisUtil.getCacheMap(CommonContanst.passwordCacheKey);
for (int i = 0; i < accountList.size(); i++) {
if(passwordRetryCache.containsKey(accountList.get(i))){
passwordRetryCache.put(accountList.get(i), new AtomicInteger(0));
redisUtil.deleteObject(CommonContanst.passwordCacheKey);
}
}
responseData.setCode(200);
responseData.setMessage("成功");
}catch (Exception e){
log.info("批量解除锁定账号接口,系统异常:{}",e.getMessage());
responseData.setCode(500);
responseData.setMessage(e.getMessage());
}
log.info("批量解除锁定账号接口,响应结果:{}",JSON.toJSONString(responseData));
return responseData;
}