首页 > 其他分享 >批量删除 前后端

批量删除 前后端

时间:2023-03-10 12:13:29浏览次数:34  
标签:function 批量 删除 admin 前后 vv data id

<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>欢迎页面-X-admin2.2</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">

<style>
.div-pagination-mz {
margin-top: 5px;
margin-left: 10px;
}

.div-pagination-mz .page_total {
float: left;
width: auto;
margin-top: 20px;
margin-right: 3px;
}

.div-pagination-mz .pagination span {
font-weight: bold;
}

.div-pagination-mz .pagination .active span {
background-color: #1b7e5a;
border-color: #1b7e5a;
}

</style>
</head>
<body>
<div class="x-nav">
<span class="layui-breadcrumb">
<a href="">首页</a>
<a href="">演示</a>
<a>
<cite>导航元素</cite></a>
</span>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
onclick="location.reload()" title="刷新">
<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body ">
<form class="layui-form layui-col-space5">
<div class="layui-inline layui-show-xs-block">
<input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="start">
</div>
<div class="layui-inline layui-show-xs-block">
<input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="end">
</div>
<div class="layui-inline layui-show-xs-block">
<input type="text" name="search" placeholder="请输入登录名" value="{$search}" autocomplete="off"
class="layui-input">
</div>
<div class="layui-inline layui-show-xs-block">
<button class="layui-btn" lay-submit="admin-list" lay-filter="sreach">
<i class="layui-icon">&#xe615;</i></button>
</div>
</form>
</div>
<div class="layui-card-header">
<button class="layui-btn layui-btn-danger" lay-event="deleteAll" onclick="delAll()"><i
class="layui-icon"></i>批量删除
</button>
<button class="layui-btn" onclick="xadmin.open('添加用户','admin-add',650,550)"><i
class="layui-icon"></i>添加
</button>
</div>
<div class="layui-card-body ">
<table class="layui-table layui-form">
<thead>
<tr>
<th style="width: 10px">
<input type="checkbox" name="" lay-skin="primary">
</th>
<th>ID</th>
<th>登录名</th>
<th>邮箱</th>
<th>角色</th>
<th>加入时间</th>
<th>状态</th>
<th>操作</th>
</thead>
<tbody>
{volist name="data" id="vv"}
<tr>
<td style="width: 10px">
<input type="checkbox" name="ck[]" value="{$vv.admin_id}" lay-skin="primary">
</td>
<td>{$vv.admin_id}</td>
<td>{$vv.username}</td>
<td>{$vv.admin_email}</td>
<td>{$vv.admin_role_id}</td>
<td>{$vv.create_time}</td>
<td class="td-status">
<span class="layui-btn layui-btn-normal layui-btn-mini">{$vv.admin_status}</span>
</td>
<td class="td-manage">
<a onclick="member_stop(this,{$vv.admin_id})" href="javascript:;"
title="{$vv.admin_status}">
<i class="layui-icon">&#xe601;</i>
</a>
<a title="编辑" onclick="xadmin.open('编辑','admin-edit?admin_id={$vv.admin_id}')"
href="javascript:;">
<i class="layui-icon">&#xe642;</i>
</a>
<a title="删除" onclick="member_del(this,{$vv.admin_id})" href="javascript:;">
<i class="layui-icon">&#xe640;</i>
</a>
</td>
</tr>
{/volist}
</tbody>
</table>
</div>
</div>
</div>
<div class="div-pagination-mz">
{$data|raw}
</div>
</div>
</div>
</body>
<script>
layui.use(['laydate', 'form'], function () {
var laydate = layui.laydate;
var form = layui.form;

//执行一个laydate实例
laydate.render({
elem: '#start' //指定元素
});

//执行一个laydate实例
laydate.render({
elem: '#end' //指定元素
});
});

/*用户-停用*/
function member_stop(obj, id) {
layer.confirm('确认要修改状态吗?', function (index) {
if ($(obj).attr('title') == '正常') {
//发异步把用户状态进行更改
$.ajax({
url: "editStatus",
type: "post",
dataType: "json",
async: false,
data: {
id: id,
status: 2
},
success: function (data) {
if (data.code) {
location.href = '';
}
}
})
} else {
$.ajax({
url: "editStatus",
type: "post",
dataType: "json",
async: false,
data: {
id: id,
status: 1
},
success: function (data) {
if (data.code) {
location.href = '';
}
}
})
}
});
}

/*用户-删除*/
function member_del(obj, id) {
layer.confirm('确认要删除吗?', function (index) {
//发异步删除数据
$(obj).parents("tr").remove();
$.ajax({
type: "post",
url: "/deleteAdmin",
dataType: "json",
data: {"admin_id": id},
async: false,
success: function (data) {
if (data.code) {
location.href = '';
}
}
});
layer.msg('已删除!', {icon: 1, time: 1000});
});
}

function delAll(argument) {
layer.confirm('确认要删除吗?', function (index) {
var ck = $("input[name='ck[]']:checked");
if (ck.length == 0) {
alert('请选择要删除的对象');
return false;
}
//定义空数组存入
var arr = [];
$(ck).each(function (i) {
arr.push($(this).val());
})
$.ajax({
//批量删除接口
url: "deleteMore",
dataType: "json",
type: "post",
data: {
'ck[]': arr,
},
success: function (res) {
if(res.code==200){
$("input[name='ck[]']:checked").parents('tr').remove();
}
layer.msg('已删除!', {icon: 1, time: 1000});
}
})
layer.msg('已删除!', {icon: 1, time: 1000});
});
}
</script>
</html>


后端 php的处理
public function deleteMore(Request $request){
$result = $this->request->param();
$res = (UserModel::getInstance())->whereIn('admin_id',$result['ck'])->delete();
if($res){
return $this->success(200,'删除成功','');
}else{
return $this->fail(400,'删除失败','');
}
}

Route::post('deleteMore','app\controller\admin\Admin/deleteMore');

写了这么多次 还是要记录的


标签:function,批量,删除,admin,前后,vv,data,id
From: https://www.cnblogs.com/abcdefghi123/p/17202939.html

相关文章