layer之table用法

jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>权限管理</title>
<jsp:include page="../common.jsp"></jsp:include>
<script src="/blog/custom-js/admin-role.js"></script>
</head>
<body>
	<div class="layui-container">
		<div class="layui-input-inline">
			<input type="text" id="rolename" name="rolename" class="layui-input">
		</div>
		<div class="layui-input-inline">
			<button class="layui-btn" data-type="searchRole">查询</button>
			<button class="layui-btn" data-type="addRole">新增</button>
		</div>
	</div>
	<div class="layui-container">
		<table class="layui-hide" id="tab" lay-filter="tb"></table>
	</div>
	<shiro:hasRole name="superadmin">
		<script type="text/html" id="doit">
  		<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
  		<a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
		<a class="layui-btn layui-btn-xs" lay-event="pms">授权</a>
		</script>
	</shiro:hasRole>
</body>
</html>
js文件

layui.use('table', function() {
	var table = layui.table;
	table.on('checkbox(tb)', function(obj) {
		console.info(obj)
	});
	// 监听工具条
	table.on('tool(tb)', function(obj) {
		var data = obj.data;
		if (obj.event === 'del') {
			parent.layer.confirm('真的删除《<span>' + data.rolename
					+ '</span>》这个角色吗?', function(index) {
				$.ajax({
					type : "GET",
					url : '/blog/admin-role/del',
					dataType : "json",
					success : function(data) {
						/* 数据库操作 */
						obj.del();
					},
					error : function(data) {
						parent.layer.msg(data.responseText);
					}
				});
				parent.layer.close(index);
			});
		} else if (obj.event === 'edit') {
			// parent.layer.alert('编辑行:<br>' + JSON.stringify(data))
			parent.layer.open({
				type : 2,
				area : [ '700px', '450px' ],
				fixed : false, // 不固定
				maxmin : true,
				content : '/blog/admin-role/edit?id=' + data.id
			});
		} else if (obj.event === 'pms') {
			parent.layer.open({
				title : '角色授权',
				type : 2,
				area : [ '700px', '450px' ],
				fixed : false, // 不固定
				maxmin : true,
				content : "/blog/admin-role/pms?roleid=" + data.id,
				btn : [ '  修  改  ',
						'  取  消  ' ],
				yes : function(index,layero) {
					//surePms();
					//弹出层页面的js函数
					$(layero).find("iframe")[0].contentWindow.surePms();
					parent.layer.close(index);
				},
				btn1 : function() {
				},
				success : function(layero) {
					var btn = layero.find('.layui-layer-btn');
					btn.css('text-align', 'center');
				}
			});
		}
	});
	table.render({
		elem : '#tab',
		url : '/blog/admin-role/data',
		cellMinWidth : 50,
		method : 'post',
		cols : [ [ {
			field : 'id',
			title : 'ID',
			align : 'center',
			sort : true
		}, {
			field : 'rolename',
			align : 'center',
			title : '用户名'
		}, {
			field : 'createdate',
			align : 'center',
			title : '创建时间',
			sort : true
		}, {
			field : 'remark',
			align : 'center',
			title : '描述'
		}, {
			align : 'center',
			fixed : 'right',
			toolbar : '#doit'
		} ] ],
		id : 'tabReload',
		page : true,
		curr : 1,
		limits : [ 10, 20, 30, 1 ],
		groups : 3,
		limit : 10
	});
	/* data-type 自定义函数 */
	var $ = layui.$, active = {
		searchRole : function() {
			var rolename = $('#rolename');
			table.reload('tabReload', {
				page : {
					curr : 1
				},
				where : {
					rolename : rolename.val(),
					page : 1
				}
			});
		},
		addRole : function() {
			parent.layer.open({
				type : 2,
				area : [ '700px', '450px' ],
				fixed : false, // 不固定
				maxmin : true,
				content : '/blog/admin-role/add.html'
			});
		}
	};
	$('.layui-btn').on('click', function() {
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});
	table.init();
});



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值