移除旧版本静态模板
This commit is contained in:
+250
-209
@@ -1,242 +1,283 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>权限管理</title>
|
||||
<link rel="stylesheet" href="/static/component/pear/css/pear.css" />
|
||||
<title>权限</title>
|
||||
{% include 'view/includes/links.html' %}
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<form class="layui-form" action="">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label">用户名</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="realName" placeholder="" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label">性别</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="realName" placeholder="" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label">邮箱</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="realName" placeholder="" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-inline">
|
||||
<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
|
||||
<i class="layui-icon layui-icon-search"></i>
|
||||
查询
|
||||
</button>
|
||||
<button type="reset" class="pear-btn pear-btn-md">
|
||||
<i class="layui-icon layui-icon-refresh"></i>
|
||||
重置
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">权限名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="powerName" placeholder="" class="layui-input">
|
||||
</div>
|
||||
<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="power_query">
|
||||
<i class="layui-icon layui-icon-search"></i>
|
||||
查询
|
||||
</button>
|
||||
<button type="reset" class="pear-btn pear-btn-md">
|
||||
<i class="layui-icon layui-icon-refresh"></i>
|
||||
重置
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<table id="power-table" lay-filter="power-table"></table>
|
||||
<table id="tables" lay-filter="tables"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/html" id="power-toolbar">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
|
||||
|
||||
<script type="text/html" id="toolbar">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add">
|
||||
<i class="layui-icon layui-icon-add-1"></i>
|
||||
新增
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
|
||||
<button class="pear-btn pear-btn-md" lay-event="toolbar-remove">
|
||||
<i class="layui-icon layui-icon-delete"></i>
|
||||
删除
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-success pear-btn-md" lay-event="expandAll">
|
||||
<i class="layui-icon layui-icon-spread-left"></i>
|
||||
展开
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-success pear-btn-md" lay-event="foldAll">
|
||||
<i class="layui-icon layui-icon-shrink-right"></i>
|
||||
折叠
|
||||
</button>
|
||||
</script>
|
||||
<script type="text/html" id="tool">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool-edit"><i
|
||||
class="layui-icon layui-icon-edit"></i>
|
||||
</button>
|
||||
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove"><i
|
||||
class="layui-icon layui-icon-delete"></i>
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="power-bar">
|
||||
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
|
||||
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="power-type">
|
||||
{{ " {{#if (d.powerType == '0') { }}
|
||||
<span>目录</span>
|
||||
{{# }else if(d.powerType == '1'){ }}
|
||||
<span>菜单</span>
|
||||
{{# }else if(d.powerType == '2'){ }}
|
||||
<span>按钮</span>
|
||||
{{# } }}"|safe }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="power-enable">
|
||||
<input type="checkbox" name="enable" value="{{ "{{d.id}}"|safe }}" lay-skin="switch" lay-text="启用|禁用" lay-filter="user-enable" {{ "{{ d.enable== true ? 'checked' : '' }}"|safe }} />
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="icon">
|
||||
<i class="layui-icon {{ "{{d.icon}}" |safe}}"></i>
|
||||
</script>
|
||||
|
||||
<script src="/static/component/layui/layui.js"></script>
|
||||
<script src="/static/component/pear/pear.js"></script>
|
||||
{% include 'view/includes/scripts.html' %}
|
||||
<script>
|
||||
layui.use(['table','form','jquery','treetable'],function () {
|
||||
let table = layui.table;
|
||||
let form = layui.form;
|
||||
let $ = layui.jquery;
|
||||
let treetable = layui.treetable;
|
||||
layui.use(['table', 'form', 'jquery', 'treetable', 'popup', 'dtree', 'iconPicker'], function() {
|
||||
let table = layui.table;
|
||||
let form = layui.form;
|
||||
let $ = layui.jquery;
|
||||
let treetable = layui.treetable;
|
||||
let popup = layui.popup;
|
||||
let iconPicker = layui.iconPicker;
|
||||
let dtree = layui.dtree;
|
||||
|
||||
let MODULE_PATH = "operate/";
|
||||
|
||||
window.render = function(){
|
||||
treetable.render({
|
||||
treeColIndex: 1,
|
||||
treeSpid: 0,
|
||||
treeIdName: 'powerId',
|
||||
treePidName: 'parentId',
|
||||
skin:'line',
|
||||
treeDefaultClose: true,
|
||||
toolbar:'#power-toolbar',
|
||||
elem: '#power-table',
|
||||
url: '/static/admin/data/power.json',
|
||||
page: false,
|
||||
cols: [
|
||||
[
|
||||
{type: 'checkbox'},
|
||||
{field: 'powerName', minWidth: 200, title: '权限名称'},
|
||||
{field: 'icon', title: '图标',templet:'#icon'},
|
||||
{field: 'powerType', title: '权限类型',templet:'#power-type'},
|
||||
{field: 'enable', title: '是否可用',templet:'#power-enable'},
|
||||
{field: 'sort', title: '排序'},
|
||||
{title: '操作',templet: '#power-bar', width: 150, align: 'center'}
|
||||
]
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
render();
|
||||
|
||||
table.on('tool(power-table)',function(obj){
|
||||
if (obj.event === 'remove') {
|
||||
window.remove(obj);
|
||||
} else if (obj.event === 'edit') {
|
||||
window.edit(obj);
|
||||
const get_columns = () => [
|
||||
[
|
||||
{type: 'checkbox'},
|
||||
{field: 'powerName', minWidth: 200, title: '权限名称'},
|
||||
{field: 'icon', title: '图标', templet: (d) => `<i class="layui-icon ${d.icon}"></i>`},
|
||||
{
|
||||
field: 'powerType', title: '权限类型', templet: (d) => {
|
||||
if (d.powerType === 0) {
|
||||
return `<span>目录</span>`;
|
||||
} else if (d.powerType === 1) {
|
||||
return `<span>菜单</span>`;
|
||||
} else if (d.powerType === 2) {
|
||||
return `<span>按钮</span>`;
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'enable', title: '是否可用', templet: (d) => {
|
||||
// TODO 修改禁用启动逻辑
|
||||
return `<input type="checkbox" name="enable" value="${d.powerId}" lay-skin="switch" lay-text="启用|禁用" lay-filter="tool-switch" ${d.enable ===
|
||||
true ? 'checked=checked' : ''}>`;
|
||||
},
|
||||
},
|
||||
{field: 'sort', title: '排序'},
|
||||
{title: '操作', templet: '#tool', width: 150, align: 'center'},
|
||||
],
|
||||
];
|
||||
|
||||
treetable.render({
|
||||
treeColIndex: 1,
|
||||
treeSpid: 0,
|
||||
treeIdName: 'powerId',
|
||||
treePidName: 'parentId',
|
||||
skin: 'line',
|
||||
method: 'get',
|
||||
treeDefaultClose: true,
|
||||
toolbar: '#toolbar',
|
||||
elem: '#tables',
|
||||
url: '/api/v1/rights/rights',
|
||||
page: false,
|
||||
cols: get_columns(),
|
||||
});
|
||||
|
||||
table.on('toolbar(power-table)', function(obj){
|
||||
if(obj.event === 'add'){
|
||||
window.add();
|
||||
} else if(obj.event === 'refresh'){
|
||||
window.refresh();
|
||||
} else if(obj.event === 'batchRemove'){
|
||||
window.batchRemove(obj);
|
||||
} else if(obj.event === 'expandAll'){
|
||||
treetable.expandAll("#power-table");
|
||||
} else if(obj.event === 'foldAll'){
|
||||
treetable.foldAll("#power-table");
|
||||
}
|
||||
form.on('submit(power_query)', function(data) {
|
||||
var keyword = data.field.powerName;
|
||||
var $tds = $('#tables').next('.treeTable').find('.layui-table-body tbody tr td');
|
||||
if (!keyword) {
|
||||
$tds.css('background-color', 'transparent');
|
||||
layer.msg('请输入关键字', {icon: 5});
|
||||
return;
|
||||
}
|
||||
var searchCount = 0;
|
||||
$tds.each(function() {
|
||||
$(this).css('background-color', 'transparent');
|
||||
if ($(this).text().indexOf(keyword) >= 0) {
|
||||
$(this).css('background-color', 'rgba(250,230,160,0.5)');
|
||||
if (searchCount === 0) {
|
||||
$('body,html').stop(true);
|
||||
$('body,html').animate({scrollTop: $(this).offset().top - 150}, 500);
|
||||
}
|
||||
searchCount++;
|
||||
}
|
||||
});
|
||||
if (searchCount === 0) {
|
||||
layer.msg('没有匹配结果', {icon: 5});
|
||||
} else {
|
||||
treetable.expandAll('#tables');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
table.on('tool(tables)', function(obj) {
|
||||
if (obj.event === 'tool-remove') {
|
||||
window.tool_remove(obj);
|
||||
} else if (obj.event === 'tool-edit') {
|
||||
window.tool_edit(obj);
|
||||
}
|
||||
});
|
||||
|
||||
table.on('toolbar(tables)', function(obj) {
|
||||
if (obj.event === 'toolbar-add') {
|
||||
window.toolbar_add();
|
||||
} else if (obj.event === 'refresh') {
|
||||
window.refresh();
|
||||
} else if (obj.event === 'toolbar-remove') {
|
||||
window.toolbar_remove(obj);
|
||||
}
|
||||
});
|
||||
|
||||
form.on('switch(tool-switch)', function(obj) {
|
||||
let operate;
|
||||
if (obj.elem.checked) {
|
||||
operate = 1; /*启用*/
|
||||
} else {
|
||||
operate = 0; /*禁用*/
|
||||
}
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: '/api/v1/rights/power/' + this.value + '/status',
|
||||
data: JSON.stringify({powerId: this.value, operate: operate}),
|
||||
dataType: 'json',
|
||||
contentType: 'application/json',
|
||||
type: 'put',
|
||||
success: function(result) {
|
||||
layer.close(loading);
|
||||
if (result.success) {
|
||||
popup.success(result.message);
|
||||
} else {
|
||||
popup.failure(result.message);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
window.toolbar_add = function() {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '新增',
|
||||
shade: 0.1,
|
||||
area: ['450px', '500px'],
|
||||
content: '/rights/add',
|
||||
});
|
||||
};
|
||||
|
||||
window.tool_edit = function(obj) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '修改',
|
||||
shade: 0.1,
|
||||
area: ['450px', '500px'],
|
||||
content: '/rights/power/' + obj.data['powerId'],
|
||||
});
|
||||
};
|
||||
window.tool_remove = function(obj) {
|
||||
layer.confirm('确定要删除该权限', {icon: 3, title: '提示'}, function(index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: '/api/v1/rights/power/' + obj.data['powerId'],
|
||||
dataType: 'json',
|
||||
type: 'delete',
|
||||
success: function(result) {
|
||||
layer.close(loading);
|
||||
if (result.success) {
|
||||
popup.success(result.message, function() {
|
||||
console.log(obj);
|
||||
obj.del();
|
||||
});
|
||||
} else {
|
||||
popup.failure(result.message);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
window.add = function(){
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '新增',
|
||||
shade: 0.1,
|
||||
area: ['450px', '500px'],
|
||||
content: MODULE_PATH + 'add.html'
|
||||
});
|
||||
}
|
||||
window.toolbar_remove = function(obj) {
|
||||
let data = table.checkStatus(obj.config.id).data;
|
||||
if (data.length === 0) {
|
||||
layer.msg('未选中数据', {
|
||||
icon: 3,
|
||||
time: 1000,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
var ids = [];
|
||||
var hasCheck = table.checkStatus('tables');
|
||||
var hasCheckData = hasCheck.data;
|
||||
if (hasCheckData.length > 0) {
|
||||
$.each(hasCheckData, function(index, element) {
|
||||
ids.push(element.id);
|
||||
});
|
||||
}
|
||||
layer.confirm('确定要删除选中权限', {
|
||||
icon: 3,
|
||||
title: '提示',
|
||||
}, function(index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: '/api/v1/rights/rights',
|
||||
data: {ids: ids},
|
||||
dataType: 'json',
|
||||
type: 'delete',
|
||||
success: function(result) {
|
||||
layer.close(loading);
|
||||
if (result.success) {
|
||||
popup.success(result.msg, function() {
|
||||
console.log(obj);
|
||||
obj.del();
|
||||
});
|
||||
} else {
|
||||
popup.failure(result.msg);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
window.edit = function(obj){
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '修改',
|
||||
shade: 0.1,
|
||||
area: ['450px', '500px'],
|
||||
content: MODULE_PATH + 'edit.html'
|
||||
});
|
||||
}
|
||||
window.remove = function(obj){
|
||||
layer.confirm('确定要删除该权限', {icon: 3, title:'提示'}, function(index){
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: MODULE_PATH+"remove/"+obj.data['powerId'],
|
||||
dataType:'json',
|
||||
type:'delete',
|
||||
success:function(result){
|
||||
layer.close(loading);
|
||||
if(result.success){
|
||||
layer.msg(result.msg,{icon:1,time:1000},function(){
|
||||
obj.del();
|
||||
});
|
||||
}else{
|
||||
layer.msg(result.msg,{icon:2,time:1000});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
window.batchRemove = function(obj) {
|
||||
let data = table.checkStatus(obj.config.id).data;
|
||||
if (data.length === 0) {
|
||||
layer.msg("未选中数据", {
|
||||
icon: 3,
|
||||
time: 1000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
let ids = "";
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
ids += data[i].powerId + ",";
|
||||
}
|
||||
ids = ids.substr(0, ids.length - 1);
|
||||
layer.confirm('确定要删除这些权限', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function(index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: MODULE_PATH + "batchRemove/" + ids,
|
||||
dataType: 'json',
|
||||
type: 'delete',
|
||||
success: function(result) {
|
||||
layer.close(loading);
|
||||
if (result.success) {
|
||||
layer.msg(result.msg, {
|
||||
icon: 1,
|
||||
time: 1000
|
||||
}, function() {
|
||||
table.reload('user-table');
|
||||
});
|
||||
} else {
|
||||
layer.msg(result.msg, {
|
||||
icon: 2,
|
||||
time: 1000
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
iconPicker.render({
|
||||
// 选择器,推荐使用input
|
||||
elem: '#add_icon',
|
||||
// 数据类型:fontClass/unicode,推荐使用fontClass
|
||||
type: 'fontClass',
|
||||
// 是否开启搜索:true/false
|
||||
search: true,
|
||||
// 是否开启分页
|
||||
page: true,
|
||||
// 每页显示数量,默认12
|
||||
limit: 12,
|
||||
// 点击回调
|
||||
click: function(data) {
|
||||
console.log(data);
|
||||
},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user