Layui表格批量操作数据

效果如下

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;
    }
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值