style(jinja2):修改模板的复用方式

This commit is contained in:
zhengxinonly
2022-05-24 18:53:37 +08:00
parent d54eb4dc3e
commit 9fc2eb0ae3
24 changed files with 2954 additions and 2963 deletions
-48
View File
@@ -1,48 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{#页面标题#}
{% block title %}
<title>Pear Admin Flask</title>
{% endblock %}
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
{# 头部导入的 Script,主要为样式 #}
{% block header_script %}
<link rel="stylesheet" href="/static/admin/component/pear/css/pear.css"/>
{% endblock %}
</head>
{#pear 后台边框#}
<body class="pear-container">
{#页面的主题内容,用于页面进行改写#}
{% block body %}
{% endblock %}
{# 当前页面需要依赖的 JavaScript #}
{% block footer_script %}
<script src="/static/admin/component/layui/layui.js"></script>
<script src="/static/admin/component/pear/pear.js"></script>
<script>
/******************数据解析********************************/
function parserTableData (data) {
/* 将服务器返回的 json 数据解析为 layui 表格需要的格式 */
return {
'code': data.code, //解析接口状态
'msg': data.message, //解析提示文本
'count': data.result.total, //解析数据长度
'data': data.result.items, //解析数据列表
}
}
</script>
{% endblock %}
{# 当前页面自己编写的 JavaScript #}
{% block models_script %}
{% endblock %}
</body>
</html>
+12
View File
@@ -1,2 +1,14 @@
<script src="/static/admin/component/layui/layui.js"></script> <script src="/static/admin/component/layui/layui.js"></script>
<script src="/static/admin/component/pear/pear.js"></script> <script src="/static/admin/component/pear/pear.js"></script>
<script>
/******************数据解析********************************/
function parserTableData(data) {
/* 将服务器返回的 json 数据解析为 layui 表格需要的格式 */
return {
'code': data.code, /*解析接口状态*/
'msg': data.message, /*解析提示文本*/
'count': data.result.total, /*解析数据长度*/
'data': data.result.items, /*解析数据列表*/
};
}
</script>
+111 -106
View File
@@ -1,12 +1,11 @@
{% extends 'admin/base.html' %} <!DOCTYPE html>
{% block title %} <html lang="en">
<head>
<title>部门新增</title> <title>部门新增</title>
{% endblock %} {% include 'admin/common/header.html' %}
<body class="pear-container">
{#搜索框布局#}
{% block body %} <div class="layui-card">
{#搜索框布局#}
<div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<form class="layui-form" action=""> <form class="layui-form" action="">
<div class="layui-form-item"> <div class="layui-form-item">
@@ -28,19 +27,18 @@
</div> </div>
</form> </form>
</div> </div>
</div> </div>
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
{#表格字段渲染#} {#表格字段渲染#}
<table id="tables" lay-filter="tables"></table> <table id="tables" lay-filter="tables"></table>
</div> </div>
</div> </div>
{% endblock %}
{% block models_script %} {% include 'admin/common/footer.html' %}
{#表格工具栏,需要在表格中绑定,且需要自定义事件#} {#表格工具栏,需要在表格中绑定,且需要自定义事件#}
<script type="text/html" id="toolbar"> <script type="text/html" id="toolbar">
{% if authorize("admin:dept:edit") %} {% if authorize("admin:dept:edit") %}
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add"> <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add">
<i class="layui-icon layui-icon-add-1"></i> <i class="layui-icon layui-icon-add-1"></i>
@@ -53,18 +51,18 @@
删除 删除
</button> </button>
{% endif %} {% endif %}
</script> </script>
{#操作字段,需要在表格中使用#} {#操作字段,需要在表格中使用#}
<script type="text/html" id="tool"> <script type="text/html" id="tool">
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool_edit"> <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool_edit">
<i class="layui-icon layui-icon-edit"></i> <i class="layui-icon layui-icon-edit"></i>
</button> </button>
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool_remove"> <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool_remove">
<i class="layui-icon layui-icon-delete"></i> <i class="layui-icon layui-icon-delete"></i>
</button> </button>
</script> </script>
{#表格内的切换按钮#} {#表格内的切换按钮#}
<script type="text/html" id="dept-status"> <script type="text/html" id="dept-status">
<input type="checkbox" <input type="checkbox"
name="status" name="status"
value="{{ "{{ d.deptId }}" }}" value="{{ "{{ d.deptId }}" }}"
@@ -72,33 +70,33 @@
lay-text="启用|禁用" lay-text="启用|禁用"
lay-filter="dept_enable" lay-filter="dept_enable"
{{ "{{# if(d.status==1){ }} checked {{# } }}" }}> {{ "{{# if(d.status==1){ }} checked {{# } }}" }}>
</script> </script>
<script> <script>
layui.use(['table', 'form', 'jquery', 'treetable', 'popup'], function () { layui.use(['table', 'form', 'jquery', 'treetable', 'popup'], function() {
let table = layui.table let table = layui.table;
let form = layui.form let form = layui.form;
let $ = layui.jquery let $ = layui.jquery;
let treetable = layui.treetable let treetable = layui.treetable;
let popup = layui.popup let popup = layui.popup;
let MODULE_PATH = '/dept/' let MODULE_PATH = '/dept/';
const get_columns = () => [ const get_columns = () => [
[ [
{ type: 'checkbox' }, {type: 'checkbox'},
{ field: 'deptName', minWidth: 200, title: '部门名称' }, {field: 'deptName', minWidth: 200, title: '部门名称'},
{ field: 'leader', title: '负责人' }, {field: 'leader', title: '负责人'},
{ field: 'phone', title: '联系方式' }, {field: 'phone', title: '联系方式'},
{ field: 'email', title: '邮箱' }, {field: 'email', title: '邮箱'},
{ field: 'address', title: '详细地址' }, {field: 'address', title: '详细地址'},
{ field: 'status', title: '状态', templet: '#dept-status' }, {field: 'status', title: '状态', templet: '#dept-status'},
{ field: 'sort', title: '排序', width: 100 }, {field: 'sort', title: '排序', width: 100},
{ title: '操作', templet: '#tool', width: 120, align: 'center' }, {title: '操作', templet: '#tool', width: 120, align: 'center'},
], ],
] ];
{#定义表格渲染函数#} {#定义表格渲染函数#}
window.render = function () { window.render = function() {
/*树形表格渲染*/ /*树形表格渲染*/
treetable.render({ treetable.render({
treeColIndex: 1, treeColIndex: 1,
@@ -113,137 +111,144 @@
url: '/api/v1/dept/department', /*数据来源接口*/ url: '/api/v1/dept/department', /*数据来源接口*/
page: false, page: false,
cols: get_columns(),/*表格渲染的数据*/ cols: get_columns(),/*表格渲染的数据*/
}) });
} };
/*查询表单按钮被点击的事件*/ /*查询表单按钮被点击的事件*/
form.on('submit(form_search)', function (data) { form.on('submit(form_search)', function(data) {
let keyword = $.trim(data.field.deptName) let keyword = $.trim(data.field.deptName);
/*获取所有的公司节点*/ /*获取所有的公司节点*/
let $tds = $('#tables').next('.treeTable').find('.layui-table-body tbody tr td') let $tds = $('#tables').next('.treeTable').find('.layui-table-body tbody tr td');
if (!keyword) { if (!keyword) {
$tds.css('background-color', 'transparent') $tds.css('background-color', 'transparent');
layer.msg('请输入关键字', { icon: 5 }) layer.msg('请输入关键字', {icon: 5});
return false return false;
} }
/*本地查询并且标注高亮*/ /*本地查询并且标注高亮*/
let searchCount = 0 let searchCount = 0;
$tds.each(function () { $tds.each(function() {
$(this).css('background-color', 'transparent') $(this).css('background-color', 'transparent');
if ($(this).text().indexOf(keyword) >= 0) { if ($(this).text().indexOf(keyword) >= 0) {
$(this).css('background-color', 'rgba(250,230,160,0.5)') $(this).css('background-color', 'rgba(250,230,160,0.5)');
if (searchCount === 0) { if (searchCount === 0) {
$('body,html').stop(true) $('body,html').stop(true);
$('body,html').animate({ scrollTop: $(this).offset().top - 150 }, 500) $('body,html').animate({scrollTop: $(this).offset().top - 150}, 500);
} }
searchCount++ searchCount++;
} }
}) });
if (searchCount === 0) { if (searchCount === 0) {
layer.msg('没有匹配结果', { icon: 5 }) layer.msg('没有匹配结果', {icon: 5});
} else { } else {
treetable.expandAll('#tables') treetable.expandAll('#tables');
} }
return false return false;
}) });
render() render();
/*表格的操作栏*/ /*表格的操作栏*/
table.on('tool(tables)', function (obj) { table.on('tool(tables)', function(obj) {
if (obj.event === 'tool_remove') { if (obj.event === 'tool_remove') {
/*移出事件*/ /*移出事件*/
window.tool_remove(obj) window.tool_remove(obj);
} else if (obj.event === 'tool_edit') { } else if (obj.event === 'tool_edit') {
/*编辑事件*/ /*编辑事件*/
window.tool_edit(obj) window.tool_edit(obj);
} }
}) });
/*表格的工具栏*/ /*表格的工具栏*/
table.on('toolbar(tables)', function (obj) { table.on('toolbar(tables)', function(obj) {
{#console.log(obj)#} {#console.log(obj)#}
if (obj.event === 'toolbar-add') { if (obj.event === 'toolbar-add') {
window.toolbar_add() window.toolbar_add();
} else if (obj.event === 'refresh') { } else if (obj.event === 'refresh') {
window.refresh() window.refresh();
} else if (obj.event === 'toolbar-remove') { } else if (obj.event === 'toolbar-remove') {
{#window.toolbar_remove(obj)#} {#window.toolbar_remove(obj)#}
layer.msg('禁止批量删除') layer.msg('禁止批量删除');
return false return false;
{#console.log(table.checkStatus(obj.config.id).data)#} {#console.log(table.checkStatus(obj.config.id).data)#}
} }
}) });
/*切换选择状态*/ /*切换选择状态*/
form.on('switch(dept_enable)', function (obj) { form.on('switch(dept_enable)', function(obj) {
let operate let operate;
if (obj.elem.checked) { if (obj.elem.checked) {
operate = 1 operate = 1;
} else { } else {
operate = 0 operate = 0;
} }
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/dept/department/' + this.value + '/status', url: '/api/v1/dept/department/' + this.value + '/status',
data: JSON.stringify({ deptId: this.value, operate: operate }), data: JSON.stringify({deptId: this.value, operate: operate}),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message) popup.success(result.message);
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
}) });
window.toolbar_add = function () { window.toolbar_add = function() {
layer.open({ layer.open({
type: 2, type: 2,
title: '新增', title: '新增',
shade: 0.1, shade: 0.1,
area: ['450px', '500px'], /*新增窗口的大小*/ area: ['450px', '500px'], /*新增窗口的大小*/
content: '/dept/add', /*新增窗口从那里来*/ content: '/dept/add', /*新增窗口从那里来*/
}) });
} };
window.tool_edit = function (obj) { window.tool_edit = function(obj) {
layer.open({ layer.open({
type: 2, type: 2,
title: '修改', title: '修改',
shade: 0.1, shade: 0.1,
area: ['450px', '500px'], area: ['450px', '500px'],
content: MODULE_PATH + 'edit?deptId=' + obj.data['deptId'], /*编辑修改窗口从那里来*/ content: MODULE_PATH + 'edit?deptId=' + obj.data['deptId'], /*编辑修改窗口从那里来*/
}) });
} };
window.tool_remove = function (obj) { window.tool_remove = function(obj) {
layer.confirm('确定要删除该部门', { icon: 3, title: '提示' }, function (index) { layer.confirm('确定要删除该部门', {icon: 3, title: '提示'}, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/dept/department/' + obj.data['deptId'], url: '/api/v1/dept/department/' + obj.data['deptId'],
dataType: 'json', dataType: 'json',
type: 'delete', type: 'delete',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message, function () { popup.success(result.message, function() {
obj.del() obj.del();
}) });
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
}) });
} };
});
</script>
</body>
</html>
})
</script>
{% endblock %}
+37 -34
View File
@@ -1,12 +1,15 @@
{% extends 'admin/base.html' %} <!DOCTYPE html>
<html lang="en">
{% block title %} <head>
<title>部门管理</title> <title>部门管理</title>
{% endblock %} <title>部门新增</title>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
{% block body %} <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<form class="layui-form" action=""> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
{% include 'admin/common/header.html' %}
<body class="pear-container">
<form class="layui-form" action="">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="layui-form-item"> <div class="layui-form-item">
@@ -79,49 +82,49 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% block models_script %} {% include 'admin/common/footer.html' %}
<script> <script>
layui.use(['form', 'jquery', 'dtree'], function () { layui.use(['form', 'jquery', 'dtree'], function() {
let form = layui.form let form = layui.form;
let $ = layui.jquery let $ = layui.jquery;
let dtree = layui.dtree let dtree = layui.dtree;
/*添加数据 渲染下拉选择组件*/ /*添加数据 渲染下拉选择组件*/
dtree.renderSelect({ dtree.renderSelect({
elem: '#selectParent', elem: '#selectParent',
url: '/api/v1/dept/departments', url: '/api/v1/dept/department/',
method: 'get', method: 'get',
selectInputName: { nodeId: 'parentId', context: 'parentName' }, selectInputName: {nodeId: 'parentId', context: 'parentName'},
skin: 'layui', skin: 'layui',
dataFormat: 'list', dataFormat: 'list',
response: { treeId: 'deptId', parentId: 'parentId', title: 'deptName' }, response: {treeId: 'deptId', parentId: 'parentId', title: 'deptName'},
selectInitVal: '1', selectInitVal: '1',
}) });
/*添加数据 表单组件,提交按钮之后触发的事件*/ /*添加数据 表单组件,提交按钮之后触发的事件*/
form.on('submit(dept-save)', function (data) { form.on('submit(dept-save)', function(data) {
$.ajax({ $.ajax({
url: '/api/v1/dept/departments', url: '/api/v1/dept/department/',
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'post', type: 'post',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name)) parent.layer.close(parent.layer.getFrameIndex(window.name));
parent.render() parent.render();
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+27 -30
View File
@@ -1,12 +1,11 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>部门修改</title> <title>部门修改</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
<body class="pear-container">
{% block body %} <form class="layui-form" action="">
<form class="layui-form" action="">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="layui-form-item layui-hide"> <div class="layui-form-item layui-hide">
@@ -90,38 +89,36 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% include 'admin/common/footer.html' %}
{% block models_script %} <script>
<script > layui.use(['form', 'jquery'], function() {
layui.use(['form', 'jquery'], function () { let form = layui.form;
let form = layui.form let $ = layui.jquery;
let $ = layui.jquery
// 修改数据 当点击更新之后,获取数据 // 修改数据 当点击更新之后,获取数据
form.on('submit(dept-update)', function (data) { form.on('submit(dept-update)', function(data) {
$.ajax({ $.ajax({
url: '/api/v1/dept/department/' + data.field.deptId, url: '/api/v1/dept/department/' + data.field.deptId,
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
parent.render() parent.render();
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
});
}) </script>
</script> </body>
{% endblock %} </html>
+101 -100
View File
@@ -1,19 +1,20 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>图片上传</title> <title>图片上传</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<table id="tables" lay-filter="tables"></table> <table id="tables" lay-filter="tables"></table>
</div> </div>
</div> </div>
{% endblock %}
{% block models_script %}
<script type="text/html" id="toolbar"> {% include 'admin/common/footer.html' %}
<script type="text/html" id="toolbar">
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="toolbar-add"> <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="toolbar-add">
<i class="layui-icon layui-icon-add-1"></i> <i class="layui-icon layui-icon-add-1"></i>
新增 新增
@@ -22,19 +23,18 @@
<i class="layui-icon layui-icon-delete"></i> <i class="layui-icon layui-icon-delete"></i>
删除 删除
</button> </button>
</script> </script>
<script type="text/html" id="tool"> <script type="text/html" id="tool">
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove"> <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove">
<i class="layui-icon layui-icon-delete"></i> <i class="layui-icon layui-icon-delete"></i>
</button> </button>
</script> </script>
<script>
<script> layui.use(['table', 'form', 'jquery', 'element', 'form', 'upload'], function() {
layui.use(['table', 'form', 'jquery', 'element', 'form', 'upload'], function () { let table = layui.table;
let table = layui.table let form = layui.form;
let form = layui.form let $ = layui.jquery;
let $ = layui.jquery let upload = layui.upload;
let upload = layui.upload
const get_columns = () => [ const get_columns = () => [
[ [
@@ -61,7 +61,7 @@
unresize: true, unresize: true,
align: 'center', align: 'center',
templet: (d) => { templet: (d) => {
return `<img class="tool-photo" style="max-width: 100%;height: 100%;cursor: pointer;" lay-event="photo" src="${d.href}"></i>` return `<img class="tool-photo" style="max-width: 100%;height: 100%;cursor: pointer;" lay-event="photo" src="${d.href}"></i>`;
}, },
}, },
@@ -92,7 +92,7 @@
width: 200, width: 200,
}, },
], ],
] ];
table.render({ table.render({
parseData: parserTableData, /* 服务器返回的数据格式与 layui 不一致,需要进行转化*/ parseData: parserTableData, /* 服务器返回的数据格式与 layui 不一致,需要进行转化*/
@@ -107,38 +107,38 @@
layEvent: 'refresh', layEvent: 'refresh',
icon: 'layui-icon-refresh', icon: 'layui-icon-refresh',
}, 'filter', 'print', 'exports'], }, 'filter', 'print', 'exports'],
}) });
table.on('tool(tables)', function (obj) { table.on('tool(tables)', function(obj) {
if (obj.event === 'tool-remove') { if (obj.event === 'tool-remove') {
window.remove(obj) window.remove(obj);
} else if (obj.event === 'photo') { } else if (obj.event === 'photo') {
window.photo(obj) window.photo(obj);
} }
}) });
table.on('toolbar(tables)', function (obj) { table.on('toolbar(tables)', function(obj) {
if (obj.event === 'toolbar-add') { if (obj.event === 'toolbar-add') {
window.add() window.add();
} else if (obj.event === 'refresh') { } else if (obj.event === 'refresh') {
window.refresh() window.refresh();
} else if (obj.event === 'toolbar-remove') { } else if (obj.event === 'toolbar-remove') {
window.batchRemove(obj) window.batchRemove(obj);
} }
}) });
//弹出窗设置 自己设置弹出百分比 //弹出窗设置 自己设置弹出百分比
function screen (width, height) { function screen(width, height) {
if (typeof width !== 'number' || width === 0) { if (typeof width !== 'number' || width === 0) {
width = $(window).width() * 0.8 width = $(window).width() * 0.8;
} }
if (typeof height !== 'number' || height === 0) { if (typeof height !== 'number' || height === 0) {
height = $(window).height() - 20 height = $(window).height() - 20;
} }
return [width + 'px', height + 'px'] return [width + 'px', height + 'px'];
} }
window.add = function () { window.add = function() {
layer.open({ layer.open({
type: 2, type: 2,
maxmin: true, maxmin: true,
@@ -146,110 +146,110 @@
shade: 0.1, shade: 0.1,
area: screen(), area: screen(),
content: 'file/photo/add', content: 'file/photo/add',
}) });
} };
window.remove = function (obj) { window.remove = function(obj) {
layer.confirm('确定要删除该图片', { layer.confirm('确定要删除该图片', {
icon: 3, icon: 3,
title: '提示', title: '提示',
}, function (index) { }, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/file/photo/' + obj.data['id'], url: '/api/v1/file/photo/' + obj.data['id'],
data: { id: obj.data['id'] }, data: {id: obj.data['id']},
dataType: 'json', dataType: 'json',
type: 'delete', type: 'delete',
success: function (res) { success: function(res) {
layer.close(loading) layer.close(loading);
if (res.success) { if (res.success) {
layer.msg(res.message, { layer.msg(res.message, {
icon: 1, icon: 1,
time: 1000, time: 1000,
}, function () { }, function() {
obj.del() obj.del();
}) });
} else { } else {
layer.msg(res.message, { layer.msg(res.message, {
icon: 2, icon: 2,
time: 1000, time: 1000,
}) });
} }
}, },
}) });
}) });
} };
window.batchRemove = function (obj) { window.batchRemove = function(obj) {
let data = table.checkStatus(obj.config.id).data let data = table.checkStatus(obj.config.id).data;
if (data.length === 0) { if (data.length === 0) {
layer.msg('未选中数据', { layer.msg('未选中数据', {
icon: 3, icon: 3,
time: 1000, time: 1000,
}) });
return false return false;
} }
var ids = [] var ids = [];
var hasCheck = table.checkStatus('tables') var hasCheck = table.checkStatus('tables');
var hasCheckData = hasCheck.data var hasCheckData = hasCheck.data;
if (hasCheckData.length > 0) { if (hasCheckData.length > 0) {
$.each(hasCheckData, function (index, element) { $.each(hasCheckData, function(index, element) {
ids.push(element.id) ids.push(element.id);
}) });
} }
layer.confirm('确定要删除这些图片', { layer.confirm('确定要删除这些图片', {
icon: 3, icon: 3,
title: '提示', title: '提示',
}, function (index) { }, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/file/photos', url: '/api/v1/file/photos',
data: { ids: ids }, data: {ids: ids},
dataType: 'json', dataType: 'json',
type: 'POST', type: 'POST',
success: function (res) { success: function(res) {
layer.close(loading) layer.close(loading);
if (res.success) { if (res.success) {
layer.msg(res.message, { layer.msg(res.message, {
icon: 1, icon: 1,
time: 1000, time: 1000,
}, function () { }, function() {
table.reload('tables') table.reload('tables');
}) });
} else { } else {
layer.msg(res.message, { layer.msg(res.message, {
icon: 2, icon: 2,
time: 1000, time: 1000,
}) });
} }
}, },
}) });
}) });
} };
window.refresh = function () { window.refresh = function() {
table.reload('tables') table.reload('tables');
} };
// 查看大图 // 查看大图
window.photo = function (obj) { window.photo = function(obj) {
if (!obj.data.href || obj.data.href === '') { if (!obj.data.href || obj.data.href === '') {
layer.msg('图片地址错误!') layer.msg('图片地址错误!');
return return;
} }
var auto_img = {} var auto_img = {};
var img = new Image() var img = new Image();
img.src = obj.data.href img.src = obj.data.href;
img.onload = function () { img.onload = function() {
var max_height = $(window).height() - 100 var max_height = $(window).height() - 100;
var max_width = $(window).width() var max_width = $(window).width();
var rate1 = max_height / img.height var rate1 = max_height / img.height;
var rate2 = max_width / img.width var rate2 = max_width / img.width;
var rate3 = 1 var rate3 = 1;
var rate = Math.min(rate1, rate2, rate3) var rate = Math.min(rate1, rate2, rate3);
auto_img.height = img.height * rate auto_img.height = img.height * rate;
auto_img.width = img.width * rate auto_img.width = img.width * rate;
layer.open({ layer.open({
type: 1, type: 1,
title: false, title: false,
@@ -257,10 +257,11 @@
skin: 'layui-layer-nobg', //没有背景色 skin: 'layui-layer-nobg', //没有背景色
shadeClose: true, shadeClose: true,
content: `<img src="${obj.data['href']}" width="${auto_img.width}px" height="${auto_img.height}px">`, content: `<img src="${obj.data['href']}" width="${auto_img.width}px" height="${auto_img.height}px">`,
}) });
} };
} };
}) });
</script> </script>
{% endblock %} </body>
</html>
+26 -27
View File
@@ -1,11 +1,11 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>新增图片</title> <title>新增图片</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<div class="layui-row layui-col-space15"> <div class="layui-row layui-col-space15">
<div class="layui-col-md12"> <div class="layui-col-md12">
<div class="layui-card"> <div class="layui-card">
<div class="layui-tab-content"> <div class="layui-tab-content">
@@ -24,17 +24,15 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{% endblock %}
{% include 'admin/common/footer.html' %}
{% block models_script %} <script>
<script> layui.use(['jquery', 'element', 'form', 'upload'], function() {
layui.use(['jquery', 'element', 'form', 'upload'], function () { var $ = layui.jquery;
var $ = layui.jquery var element = layui.element;
var element = layui.element var form = layui.form;
var form = layui.form var upload = layui.upload;
var upload = layui.upload
//选完文件后不自动上传 //选完文件后不自动上传
upload.render({ upload.render({
elem: '#select-img' elem: '#select-img'
@@ -43,17 +41,18 @@
, exts: 'jpg|png|gif|bmp|jpeg' , exts: 'jpg|png|gif|bmp|jpeg'
, size: 1000 , size: 1000
, bindAction: '#logo-upload-button' , bindAction: '#logo-upload-button'
, done: function (res) { , done: function(res) {
if (res.success) { if (res.success) {
layer.msg(res.message, { icon: 1, time: 500 }, function () { layer.msg(res.message, {icon: 1, time: 500}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
window.parent.location.reload() window.parent.location.reload();
}) });
} else { } else {
layer.msg(res.message, { icon: 2 }) layer.msg(res.message, {icon: 2});
} }
}, },
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+37 -36
View File
@@ -1,13 +1,13 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>日志</title> <title>日志</title>
{% include 'admin/common/header.html' %}
<link rel="stylesheet" href="/static/admin/admin/css/other/console2.css"/> <link rel="stylesheet" href="/static/admin/admin/css/other/console2.css"/>
{% endblock %} </head>
<body class="pear-container">
<div class="layui-card">
{% block body %}
<div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<div class="layui-tab layui-tab-card"> <div class="layui-tab layui-tab-card">
<ul class="layui-tab-title"> <ul class="layui-tab-title">
@@ -19,46 +19,46 @@
<table style="margin-top: 10px;" id="log-login-table" lay-filter="log-login-table"></table> <table style="margin-top: 10px;" id="log-login-table" lay-filter="log-login-table"></table>
</div> </div>
<div class="layui-tab-item"> <div class="layui-tab-item">
<table style="margin-top: 10px;" id="log-access-table" lay-filter="log-access-table"></table> <table style="margin-top: 10px;" id="log-access-table"
lay-filter="log-access-table"></table>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{% endblock %}
{% block models_script %}
<script type="text/html" id="log-createTime"> {% include 'admin/common/footer.html' %}
<script type="text/html" id="log-createTime">
{{ ' {{layui.util.toDateString(d.create_at, "yyyy-MM-dd HH:mm:ss")}' |safe }}} {{ ' {{layui.util.toDateString(d.create_at, "yyyy-MM-dd HH:mm:ss")}' |safe }}}
</script> </script>
<script type="text/html" id="log-status"> <script type="text/html" id="log-status">
{{ '{{#if (d.success == true) { }} {{ '{{#if (d.success == true) { }}
<span style="color: green">成功</span> <span style="color: green">成功</span>
{{# }else if(d.success == false){ }} {{# }else if(d.success == false){ }}
<span style="color: red">失败</span> <span style="color: red">失败</span>
{{# } }}'|safe }} {{# } }}'|safe }}
</script> </script>
<script>
layui.use(['table', 'form', 'jquery', 'element', 'util'], function() {
let table = layui.table;
let form = layui.form;
<script> let MODULE_PATH = '/logs/';
layui.use(['table', 'form', 'jquery', 'element', 'util'], function () {
let table = layui.table
let form = layui.form
let MODULE_PATH = '/logs/'
const get_columns = () => [ const get_columns = () => [
[ [
{ title: 'ID', field: 'id', align: 'center' }, {title: 'ID', field: 'id', align: 'center'},
{ title: '请求方式', field: 'method', align: 'center' }, {title: '请求方式', field: 'method', align: 'center'},
{ title: '接口', field: 'url', align: 'center' }, {title: '接口', field: 'url', align: 'center'},
{ title: '浏览器', field: 'user_agent', align: 'center' }, {title: '浏览器', field: 'user_agent', align: 'center'},
{ title: '操作地址', field: 'ip', align: 'center' }, {title: '操作地址', field: 'ip', align: 'center'},
{ title: '访问时间', field: 'create_at', templet: '#log-createTime', align: 'center' }, {title: '访问时间', field: 'create_at', templet: '#log-createTime', align: 'center'},
{ title: '操作人ID', field: 'uid', align: 'center' }, {title: '操作人ID', field: 'uid', align: 'center'},
{ title: '描述', field: 'desc', align: 'center' }, {title: '描述', field: 'desc', align: 'center'},
{ title: '访问状态', templet: '#log-status', align: 'center' }, {title: '访问状态', templet: '#log-status', align: 'center'},
], ],
] ];
table.render({ table.render({
parseData: parserTableData, parseData: parserTableData,
@@ -68,7 +68,7 @@
cols: get_columns(), cols: get_columns(),
skin: 'line', skin: 'line',
toolbar: false, toolbar: false,
}) });
table.render({ table.render({
parseData: parserTableData, parseData: parserTableData,
@@ -78,7 +78,8 @@
cols: get_columns(), cols: get_columns(),
skin: 'line', skin: 'line',
toolbar: false, toolbar: false,
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+126 -127
View File
@@ -1,12 +1,11 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>权限</title> <title>权限</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
<body class="pear-container">
{% block body %} <div class="layui-card">
<div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<form class="layui-form" action=""> <form class="layui-form" action="">
<div class="layui-form-item"> <div class="layui-form-item">
@@ -25,16 +24,16 @@
</div> </div>
</form> </form>
</div> </div>
</div> </div>
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<table id="tables" lay-filter="tables"></table> <table id="tables" lay-filter="tables"></table>
</div> </div>
</div> </div>
{% endblock %}
{% block models_script %}
<script type="text/html" id="toolbar"> {% include 'admin/common/footer.html' %}
<script type="text/html" id="toolbar">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add"> <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add">
<i class="layui-icon layui-icon-add-1"></i> <i class="layui-icon layui-icon-add-1"></i>
新增 新增
@@ -43,39 +42,38 @@
<i class="layui-icon layui-icon-delete"></i> <i class="layui-icon layui-icon-delete"></i>
删除 删除
</button> </button>
</script> </script>
<script type="text/html" id="tool"> <script type="text/html" id="tool">
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool-edit"><i <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool-edit"><i
class="layui-icon layui-icon-edit"></i> class="layui-icon layui-icon-edit"></i>
</button> </button>
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove"><i <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove"><i
class="layui-icon layui-icon-delete"></i> class="layui-icon layui-icon-delete"></i>
</button> </button>
</script> </script>
<script>
<script> layui.use(['table', 'form', 'jquery', 'treetable', 'popup', 'dtree', 'iconPicker'], function() {
layui.use(['table', 'form', 'jquery', 'treetable', 'popup', 'dtree', 'iconPicker'], function () { let table = layui.table;
let table = layui.table let form = layui.form;
let form = layui.form let $ = layui.jquery;
let $ = layui.jquery let treetable = layui.treetable;
let treetable = layui.treetable let popup = layui.popup;
let popup = layui.popup let iconPicker = layui.iconPicker;
let iconPicker = layui.iconPicker let dtree = layui.dtree;
let dtree = layui.dtree
const get_columns = () => [ const get_columns = () => [
[ [
{ type: 'checkbox' }, {type: 'checkbox'},
{ field: 'powerName', minWidth: 200, title: '权限名称' }, {field: 'powerName', minWidth: 200, title: '权限名称'},
{ field: 'icon', title: '图标', templet: (d) => `<i class="layui-icon ${d.icon}"></i>` }, {field: 'icon', title: '图标', templet: (d) => `<i class="layui-icon ${d.icon}"></i>`},
{ {
field: 'powerType', title: '权限类型', templet: (d) => { field: 'powerType', title: '权限类型', templet: (d) => {
if (d.powerType === 0) { if (d.powerType === 0) {
return `<span>目录</span>` return `<span>目录</span>`;
} else if (d.powerType === 1) { } else if (d.powerType === 1) {
return `<span>菜单</span>` return `<span>菜单</span>`;
} else if (d.powerType === 2) { } else if (d.powerType === 2) {
return `<span>按钮</span>` return `<span>按钮</span>`;
} }
}, },
}, },
@@ -83,13 +81,13 @@
field: 'enable', title: '是否可用', templet: (d) => { field: 'enable', title: '是否可用', templet: (d) => {
// TODO 修改禁用启动逻辑 // TODO 修改禁用启动逻辑
return `<input type="checkbox" name="enable" value="${d.powerId}" lay-skin="switch" lay-text="启用|禁用" lay-filter="tool-switch" ${d.enable === return `<input type="checkbox" name="enable" value="${d.powerId}" lay-skin="switch" lay-text="启用|禁用" lay-filter="tool-switch" ${d.enable ===
true ? 'checked=checked' : ''}>` true ? 'checked=checked' : ''}>`;
}, },
}, },
{ field: 'sort', title: '排序' }, {field: 'sort', title: '排序'},
{ title: '操作', templet: '#tool', width: 150, align: 'center' }, {title: '操作', templet: '#tool', width: 150, align: 'center'},
], ],
] ];
treetable.render({ treetable.render({
treeColIndex: 1, treeColIndex: 1,
@@ -104,163 +102,163 @@
url: '/api/v1/rights/rights', url: '/api/v1/rights/rights',
page: false, page: false,
cols: get_columns(), cols: get_columns(),
}) });
form.on('submit(power_query)', function (data) { form.on('submit(power_query)', function(data) {
var keyword = data.field.powerName var keyword = data.field.powerName;
var $tds = $('#tables').next('.treeTable').find('.layui-table-body tbody tr td') var $tds = $('#tables').next('.treeTable').find('.layui-table-body tbody tr td');
if (!keyword) { if (!keyword) {
$tds.css('background-color', 'transparent') $tds.css('background-color', 'transparent');
layer.msg('请输入关键字', { icon: 5 }) layer.msg('请输入关键字', {icon: 5});
return return;
} }
var searchCount = 0 var searchCount = 0;
$tds.each(function () { $tds.each(function() {
$(this).css('background-color', 'transparent') $(this).css('background-color', 'transparent');
if ($(this).text().indexOf(keyword) >= 0) { if ($(this).text().indexOf(keyword) >= 0) {
$(this).css('background-color', 'rgba(250,230,160,0.5)') $(this).css('background-color', 'rgba(250,230,160,0.5)');
if (searchCount === 0) { if (searchCount === 0) {
$('body,html').stop(true) $('body,html').stop(true);
$('body,html').animate({ scrollTop: $(this).offset().top - 150 }, 500) $('body,html').animate({scrollTop: $(this).offset().top - 150}, 500);
} }
searchCount++ searchCount++;
} }
}) });
if (searchCount === 0) { if (searchCount === 0) {
layer.msg('没有匹配结果', { icon: 5 }) layer.msg('没有匹配结果', {icon: 5});
} else { } else {
treetable.expandAll('#tables') treetable.expandAll('#tables');
} }
return false return false;
}) });
table.on('tool(tables)', function (obj) { table.on('tool(tables)', function(obj) {
if (obj.event === 'tool-remove') { if (obj.event === 'tool-remove') {
window.tool_remove(obj) window.tool_remove(obj);
} else if (obj.event === 'tool-edit') { } else if (obj.event === 'tool-edit') {
window.tool_edit(obj) window.tool_edit(obj);
} }
}) });
table.on('toolbar(tables)', function (obj) { table.on('toolbar(tables)', function(obj) {
if (obj.event === 'toolbar-add') { if (obj.event === 'toolbar-add') {
window.toolbar_add() window.toolbar_add();
} else if (obj.event === 'refresh') { } else if (obj.event === 'refresh') {
window.refresh() window.refresh();
} else if (obj.event === 'toolbar-remove') { } else if (obj.event === 'toolbar-remove') {
window.toolbar_remove(obj) window.toolbar_remove(obj);
} }
}) });
form.on('switch(tool-switch)', function (obj) { form.on('switch(tool-switch)', function(obj) {
let operate let operate;
if (obj.elem.checked) { if (obj.elem.checked) {
operate = 1 /*启用*/ operate = 1; /*启用*/
} else { } else {
operate = 0 /*禁用*/ operate = 0; /*禁用*/
} }
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/rights/power/' + this.value + '/status', url: '/api/v1/rights/power/' + this.value + '/status',
data: JSON.stringify({ powerId: this.value, operate: operate }), data: JSON.stringify({powerId: this.value, operate: operate}),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message) popup.success(result.message);
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
}) });
window.toolbar_add = function () { window.toolbar_add = function() {
layer.open({ layer.open({
type: 2, type: 2,
title: '新增', title: '新增',
shade: 0.1, shade: 0.1,
area: ['450px', '500px'], area: ['450px', '500px'],
content: '/rights/add', content: '/rights/add',
}) });
} };
window.tool_edit = function (obj) { window.tool_edit = function(obj) {
layer.open({ layer.open({
type: 2, type: 2,
title: '修改', title: '修改',
shade: 0.1, shade: 0.1,
area: ['450px', '500px'], area: ['450px', '500px'],
content: '/rights/power/' + obj.data['powerId'], content: '/rights/power/' + obj.data['powerId'],
}) });
} };
window.tool_remove = function (obj) { window.tool_remove = function(obj) {
layer.confirm('确定要删除该权限', { icon: 3, title: '提示' }, function (index) { layer.confirm('确定要删除该权限', {icon: 3, title: '提示'}, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/rights/power/' + obj.data['powerId'], url: '/api/v1/rights/power/' + obj.data['powerId'],
dataType: 'json', dataType: 'json',
type: 'delete', type: 'delete',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message, function () { popup.success(result.message, function() {
console.log(obj) console.log(obj);
obj.del() obj.del();
}) });
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
}) });
} };
window.toolbar_remove = function (obj) { window.toolbar_remove = function(obj) {
let data = table.checkStatus(obj.config.id).data let data = table.checkStatus(obj.config.id).data;
if (data.length === 0) { if (data.length === 0) {
layer.msg('未选中数据', { layer.msg('未选中数据', {
icon: 3, icon: 3,
time: 1000, time: 1000,
}) });
return false return false;
} }
var ids = [] var ids = [];
var hasCheck = table.checkStatus('tables') var hasCheck = table.checkStatus('tables');
var hasCheckData = hasCheck.data var hasCheckData = hasCheck.data;
if (hasCheckData.length > 0) { if (hasCheckData.length > 0) {
$.each(hasCheckData, function (index, element) { $.each(hasCheckData, function(index, element) {
ids.push(element.id) ids.push(element.id);
}) });
} }
layer.confirm('确定要删除选中权限', { layer.confirm('确定要删除选中权限', {
icon: 3, icon: 3,
title: '提示', title: '提示',
}, function (index) { }, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/rights/rights', url: '/api/v1/rights/rights',
data: { ids: ids }, data: {ids: ids},
dataType: 'json', dataType: 'json',
type: 'delete', type: 'delete',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.msg, function () { popup.success(result.msg, function() {
console.log(obj) console.log(obj);
obj.del() obj.del();
}) });
} else { } else {
popup.failure(result.msg) popup.failure(result.msg);
} }
}, },
}) });
}) });
} };
iconPicker.render({ iconPicker.render({
// 选择器,推荐使用input // 选择器,推荐使用input
@@ -274,10 +272,11 @@
// 每页显示数量,默认12 // 每页显示数量,默认12
limit: 12, limit: 12,
// 点击回调 // 点击回调
click: function (data) { click: function(data) {
console.log(data) console.log(data);
}, },
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+53 -52
View File
@@ -1,11 +1,11 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>权限</title> <title>权限</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<form class="layui-form" action=""> <form class="layui-form" action="">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="main-container"> <div class="main-container">
@@ -83,71 +83,70 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% block models_script %}
<script>
layui.use(['form', 'jquery', 'iconPicker', 'dtree'], function () { {% include 'admin/common/footer.html' %}
let form = layui.form <script>
let $ = layui.jquery layui.use(['form', 'jquery', 'iconPicker', 'dtree'], function() {
let iconPicker = layui.iconPicker let form = layui.form;
let dtree = layui.dtree let $ = layui.jquery;
let iconPicker = layui.iconPicker;
let dtree = layui.dtree;
dtree.renderSelect({ dtree.renderSelect({
elem: '#selectParent', elem: '#selectParent',
url: '/api/v1/rights/rights', url: '/api/v1/rights/rights',
method: 'get', method: 'get',
selectInputName: { nodeId: 'parentId', context: 'powerName' }, selectInputName: {nodeId: 'parentId', context: 'powerName'},
skin: 'layui', skin: 'layui',
dataFormat: 'list', dataFormat: 'list',
response: { treeId: 'powerId', parentId: 'parentId', title: 'powerName' }, //修改response中返回数据的定义 response: {treeId: 'powerId', parentId: 'parentId', title: 'powerName'}, //修改response中返回数据的定义
selectInitVal: '0', selectInitVal: '0',
}) });
form.on('radio(powerType)', function () { form.on('radio(powerType)', function() {
if (this.value == '0') { if (this.value == '0') {
$('#powerUrlItem').hide() $('#powerUrlItem').hide();
$('#powerCodeItem').hide() $('#powerCodeItem').hide();
$('#openTypeItem').hide() $('#openTypeItem').hide();
$('#powerUrl').val('') $('#powerUrl').val('');
$('#powerCode').val('') $('#powerCode').val('');
$('#openType').val('') $('#openType').val('');
} else if (this.value == '1') { } else if (this.value == '1') {
$('#powerUrlItem').show() $('#powerUrlItem').show();
$('#powerCodeItem').show() $('#powerCodeItem').show();
$('#openTypeItem').show() $('#openTypeItem').show();
} else if (this.value == '2') { } else if (this.value == '2') {
$('#powerUrlItem').hide() $('#powerUrlItem').hide();
$('#openTypeItem').hide() $('#openTypeItem').hide();
$('#powerCodeItem').show() $('#powerCodeItem').show();
$('#powerUrl').val('') $('#powerUrl').val('');
$('#openType').val('') $('#openType').val('');
} }
}) });
form.on('submit(power-save)', function (data) { form.on('submit(power-save)', function(data) {
data.field.icon = 'layui-icon ' + data.field.icon data.field.icon = 'layui-icon ' + data.field.icon;
$.ajax({ $.ajax({
url: '/api/v1/rights/power/0', url: '/api/v1/rights/power/0',
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'post', type: 'post',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
parent.render() parent.render();
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
iconPicker.render({ iconPicker.render({
// 选择器,推荐使用input // 选择器,推荐使用input
@@ -161,10 +160,12 @@
// 每页显示数量,默认12 // 每页显示数量,默认12
limit: 12, limit: 12,
// 点击回调 // 点击回调
click: function (data) { click: function(data) {
console.log(data) console.log(data);
}, },
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+71 -70
View File
@@ -1,11 +1,12 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>权限编辑</title> <title>权限编辑</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
<body class="pear-container">
{% block body %} <form class="layui-form" action="">
<form class="layui-form" action="">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="layui-form-item layui-hide"> <div class="layui-form-item layui-hide">
@@ -93,75 +94,74 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% block models_script %} {% include 'admin/common/footer.html' %}
<script> <script>
layui.use(['form', 'jquery', 'iconPicker', 'dtree'], function () { layui.use(['form', 'jquery', 'iconPicker', 'dtree'], function() {
let form = layui.form let form = layui.form;
let $ = layui.jquery let $ = layui.jquery;
let iconPicker = layui.iconPicker let iconPicker = layui.iconPicker;
let dtree = layui.dtree let dtree = layui.dtree;
dtree.renderSelect({ dtree.renderSelect({
elem: '#selectParent', elem: '#selectParent',
url: '/api/v1/rights/rights', url: '/api/v1/rights/rights',
method: 'get', method: 'get',
selectInputName: { nodeId: 'parentId', context: 'powerName' }, selectInputName: {nodeId: 'parentId', context: 'powerName'},
skin: 'layui', skin: 'layui',
dataFormat: 'list', dataFormat: 'list',
response: { treeId: 'powerId', parentId: 'parentId', title: 'powerName' }, response: {treeId: 'powerId', parentId: 'parentId', title: 'powerName'},
selectInitVal: "{{ power.parent_id }}", selectInitVal: "{{ power.parent_id }}",
}) });
form.on('radio(powerType)', function (data) { form.on('radio(powerType)', function(data) {
if (this.value == '0') { if (this.value == '0') {
{#目录#} {#目录#}
$('#powerUrlItem').hide() $('#powerUrlItem').hide();
$('#powerCodeItem').hide() $('#powerCodeItem').hide();
$('#openTypeItem').hide() $('#openTypeItem').hide();
$('#powerUrl').val('') $('#powerUrl').val('');
$('#powerCode').val('') $('#powerCode').val('');
$('#openType').val('') $('#openType').val('');
} else if (this.value == '1') { } else if (this.value == '1') {
{#菜单#} {#菜单#}
$('#powerUrlItem').show() $('#powerUrlItem').show();
$('#powerCodeItem').show() $('#powerCodeItem').show();
$('#openTypeItem').show() $('#openTypeItem').show();
} else if (this.value == '2') { } else if (this.value == '2') {
{#按钮#} {#按钮#}
$('#powerUrlItem').hide() $('#powerUrlItem').hide();
$('#openTypeItem').hide() $('#openTypeItem').hide();
$('#powerCodeItem').show() $('#powerCodeItem').show();
$('#powerUrl').val('') $('#powerUrl').val('');
$('#openType').val('') $('#openType').val('');
} }
}) });
form.on('submit(power-save)', function (data) { form.on('submit(power-save)', function(data) {
data.field.icon = 'layui-icon ' + data.field.icon data.field.icon = 'layui-icon ' + data.field.icon;
console.log(data.field) console.log(data.field);
$.ajax({ $.ajax({
url: '/api/v1/rights/power/' + data.field.powerId, url: '/api/v1/rights/power/' + data.field.powerId,
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
parent.render() parent.render();
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
iconPicker.render({ iconPicker.render({
elem: '#edit_icon', elem: '#edit_icon',
@@ -169,35 +169,36 @@
search: true, search: true,
page: true, page: true,
limit: 12, limit: 12,
click: function (data) { click: function(data) {
console.log(data) console.log(data);
}, },
}) });
iconPicker.checkIcon('icon', "{{ icon }}") iconPicker.checkIcon('icon', "{{ icon }}");
window.init = function (type) { window.init = function(type) {
if (type == '0') { if (type == '0') {
$('#powerUrlItem').hide() $('#powerUrlItem').hide();
$('#powerCodeItem').hide() $('#powerCodeItem').hide();
$('#openTypeItem').hide() $('#openTypeItem').hide();
$('#powerUrl').val('') $('#powerUrl').val('');
$('#powerCode').val('') $('#powerCode').val('');
$('#openType').val('') $('#openType').val('');
} else if (type == '1') { } else if (type == '1') {
$('#powerUrlItem').show() $('#powerUrlItem').show();
$('#powerCodeItem').show() $('#powerCodeItem').show();
$('#openTypeItem').show() $('#openTypeItem').show();
} else if (type == '2') { } else if (type == '2') {
$('#powerUrlItem').hide() $('#powerUrlItem').hide();
$('#openTypeItem').hide() $('#openTypeItem').hide();
$('#powerCodeItem').show() $('#powerCodeItem').show();
$('#powerUrl').val('') $('#powerUrl').val('');
$('#openType').val('') $('#openType').val('');
}
} }
};
window.init("{{ power.type }}") window.init("{{ power.type }}");
}) });
</script> </script>
{% endblock %} </body>
</html>
+113 -111
View File
@@ -1,11 +1,12 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>角色管理</title> <title>角色管理</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<form class="layui-form" action=""> <form class="layui-form" action="">
<div class="layui-form-item"> <div class="layui-form-item">
@@ -28,16 +29,16 @@
</div> </div>
</form> </form>
</div> </div>
</div> </div>
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<table id="tables" lay-filter="tables"></table> <table id="tables" lay-filter="tables"></table>
</div> </div>
</div> </div>
{% endblock %}
{% block models_script %}
<script type="text/html" id="toolbar"> {% include 'admin/common/footer.html' %}
<script type="text/html" id="toolbar">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add"> <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add">
<i class="layui-icon layui-icon-add-1"></i> <i class="layui-icon layui-icon-add-1"></i>
新增 新增
@@ -46,8 +47,8 @@
<i class="layui-icon layui-icon-delete"></i> <i class="layui-icon layui-icon-delete"></i>
删除 删除
</button> </button>
</script> </script>
<script type="text/html" id="tool"> <script type="text/html" id="tool">
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool-edit"><i <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool-edit"><i
class="layui-icon layui-icon-edit"></i> class="layui-icon layui-icon-edit"></i>
</button> </button>
@@ -57,30 +58,29 @@
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove"><i <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove"><i
class="layui-icon layui-icon-delete"></i> class="layui-icon layui-icon-delete"></i>
</button> </button>
</script> </script>
<script type="text/html" id="tool-switch"> <script type="text/html" id="tool-switch">
<input type="checkbox" name="enable" value="{{ "{{d.id}}" }}" lay-skin="switch" lay-text="启用|禁用" <input type="checkbox" name="enable" value="{{ "{{d.id}}" }}" lay-skin="switch" lay-text="启用|禁用"
lay-filter="tool-switch" {{ "{{# if(d.enable==1){ }} checked {{# } }}" }}> lay-filter="tool-switch" {{ "{{# if(d.enable==1){ }} checked {{# } }}" }}>
</script> </script>
<script>
<script> layui.use(['table', 'form', 'jquery', 'popup', 'common'], function() {
layui.use(['table', 'form', 'jquery', 'popup', 'common'], function () { let table = layui.table;
let table = layui.table let form = layui.form;
let form = layui.form let $ = layui.jquery;
let $ = layui.jquery let popup = layui.popup;
let popup = layui.popup
const get_columns = () => [ const get_columns = () => [
[ [
{ type: 'checkbox' }, {type: 'checkbox'},
{ title: '角色名', field: 'roleName', align: 'center', width: 100 }, {title: '角色名', field: 'roleName', align: 'center', width: 100},
{ title: 'Key值', field: 'roleCode', align: 'center' }, {title: 'Key值', field: 'roleCode', align: 'center'},
{ title: '描述', field: 'details', align: 'center' }, {title: '描述', field: 'details', align: 'center'},
{ title: '是否可用', field: 'enable', align: 'center', templet: '#tool-switch' }, {title: '是否可用', field: 'enable', align: 'center', templet: '#tool-switch'},
{ title: '排序', field: 'sort', align: 'center' }, {title: '排序', field: 'sort', align: 'center'},
{ title: '操作', toolbar: '#tool', align: 'center', width: 195 }, {title: '操作', toolbar: '#tool', align: 'center', width: 195},
], ],
] ];
table.render({ table.render({
parseData: parserTableData, parseData: parserTableData,
@@ -95,158 +95,160 @@
layEvent: 'refresh', layEvent: 'refresh',
icon: 'layui-icon-refresh', icon: 'layui-icon-refresh',
}, 'filter', 'print', 'exports'], }, 'filter', 'print', 'exports'],
}) });
table.on('tool(tables)', function (obj) { table.on('tool(tables)', function(obj) {
if (obj.event === 'tool-remove') { if (obj.event === 'tool-remove') {
window.tool_remove(obj) window.tool_remove(obj);
} else if (obj.event === 'tool-edit') { } else if (obj.event === 'tool-edit') {
window.tool_edit(obj) window.tool_edit(obj);
} else if (obj.event === 'tool-power') { } else if (obj.event === 'tool-power') {
window.tool_power(obj) window.tool_power(obj);
} }
}) });
table.on('toolbar(tables)', function (obj) { table.on('toolbar(tables)', function(obj) {
if (obj.event === 'toolbar-add') { if (obj.event === 'toolbar-add') {
window.toolbar_add() window.toolbar_add();
} else if (obj.event === 'refresh') { } else if (obj.event === 'refresh') {
window.refresh() window.refresh();
} else if (obj.event === 'toolbar-remove') { } else if (obj.event === 'toolbar-remove') {
window.toolbar_remove(obj) window.toolbar_remove(obj);
} }
}) });
form.on('submit(role-query)', function (data) { form.on('submit(role-query)', function(data) {
table.reload('tables', { where: data.field }) table.reload('tables', {where: data.field});
return false return false;
}) });
form.on('switch(tool-switch)', function (obj) { form.on('switch(tool-switch)', function(obj) {
let operate let operate;
if (obj.elem.checked) { if (obj.elem.checked) {
operate = 1 operate = 1;
} else { } else {
operate = 0 operate = 0;
} }
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/roles/role/' + this.value + '/status', url: '/api/v1/roles/role/' + this.value + '/status',
data: JSON.stringify({ roleId: this.value, operate: operate }), data: JSON.stringify({roleId: this.value, operate: operate}),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }) layer.msg(result.message, {icon: 1, time: 1000});
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
}) });
window.toolbar_add = function () { window.toolbar_add = function() {
layer.open({ layer.open({
type: 2, type: 2,
title: '新增', title: '新增',
shade: 0.1, shade: 0.1,
area: ['500px', '500px'], area: ['500px', '500px'],
content: '/admin/role/add', content: '/admin/role/add',
}) });
} };
window.tool_power = function (obj) { window.tool_power = function(obj) {
layer.open({ layer.open({
type: 2, type: 2,
title: '授权', title: '授权',
shade: 0.1, shade: 0.1,
area: ['320px', '400px'], area: ['320px', '400px'],
content: '/admin/role/power/' + obj.data['id'], content: '/admin/role/power/' + obj.data['id'],
}) });
} };
window.tool_edit = function (obj) { window.tool_edit = function(obj) {
layer.open({ layer.open({
type: 2, type: 2,
title: '修改', title: '修改',
shade: 0.1, shade: 0.1,
area: ['500px', '500px'], area: ['500px', '500px'],
content: '/admin/role/edit/' + obj.data['id'], content: '/admin/role/edit/' + obj.data['id'],
}) });
} };
window.tool_remove = function (obj) { window.tool_remove = function(obj) {
layer.confirm('确定要删除该角色', { icon: 3, title: '提示' }, function (index) { layer.confirm('确定要删除该角色', {icon: 3, title: '提示'}, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/roles/role_power/' + obj.data['id'], url: '/api/v1/roles/role_power/' + obj.data['id'],
dataType: 'json', dataType: 'json',
type: 'delete', type: 'delete',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
obj.del() obj.del();
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
}) });
} };
window.toolbar_remove = function (obj) { window.toolbar_remove = function(obj) {
let data = table.checkStatus(obj.config.id).data let data = table.checkStatus(obj.config.id).data;
if (data.length === 0) { if (data.length === 0) {
layer.msg('未选中数据', { layer.msg('未选中数据', {
icon: 3, icon: 3,
time: 1000, time: 1000,
}) });
return false return false;
} }
var ids = [] var ids = [];
var hasCheck = table.checkStatus('tables') var hasCheck = table.checkStatus('tables');
var hasCheckData = hasCheck.data var hasCheckData = hasCheck.data;
if (hasCheckData.length > 0) { if (hasCheckData.length > 0) {
$.each(hasCheckData, function (index, element) { $.each(hasCheckData, function(index, element) {
ids.push(element.id) ids.push(element.id);
}) });
} }
console.log(ids) console.log(ids);
layer.confirm('确定要删除选中角色', { layer.confirm('确定要删除选中角色', {
icon: 3, icon: 3,
title: '提示', title: '提示',
}, function (index) { }, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/roles/role', url: '/api/v1/roles/role',
data: { ids: ids }, data: {ids: ids},
dataType: 'json', dataType: 'json',
type: 'delete', type: 'delete',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message, function () { popup.success(result.message, function() {
table.reload('tables') table.reload('tables');
}) });
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
}) });
} };
window.refresh = function () { window.refresh = function() {
table.reload('tables') table.reload('tables');
} };
});
</script>
</body>
</html>
})
</script>
{% endblock %}
+28 -25
View File
@@ -1,10 +1,12 @@
{% extends 'admin/base.html' %} <!doctype html>
{% block title %} <html lang="zh-CN">
<head>
<title>角色新增</title> <title>角色新增</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<form class="layui-form" action=""> <form class="layui-form" action="">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="layui-form-item"> <div class="layui-form-item">
@@ -56,36 +58,37 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% block models_script %} {% include 'admin/common/footer.html' %}
<script> <script>
layui.use(['form', 'jquery'], function () { layui.use(['form', 'jquery'], function() {
let form = layui.form let form = layui.form;
let $ = layui.jquery let $ = layui.jquery;
form.on('submit(role-save)', function (data) { form.on('submit(role-save)', function(data) {
$.ajax({ $.ajax({
url: '/api/v1/roles/role/', url: '/api/v1/roles/role/',
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'post', type: 'post',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
parent.layui.table.reload('tables') parent.layui.table.reload('tables');
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+27 -27
View File
@@ -1,10 +1,11 @@
{% extends 'admin/base.html' %} <!doctype html>
{% block title %} <html lang="zh-CN">
<head>
<title>角色编辑</title> <title>角色编辑</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<form class="layui-form" action=""> <form class="layui-form" action="">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="main-container"> <div class="main-container">
@@ -69,36 +70,35 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% include 'admin/common/footer.html' %}
<script type="module">
layui.use(['form', 'jquery'], function() {
let form = layui.form;
let $ = layui.jquery;
{% block models_script %} form.on('submit(role-update)', function(data) {
<script type="module">
layui.use(['form', 'jquery'], function () {
let form = layui.form
let $ = layui.jquery
form.on('submit(role-update)', function (data) {
$.ajax({ $.ajax({
url: '/api/v1/roles/role/' + data.field.roleId, url: '/api/v1/roles/role/' + data.field.roleId,
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
parent.layui.table.reload('tables') parent.layui.table.reload('tables');
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+35 -33
View File
@@ -1,10 +1,12 @@
{% extends 'admin/base.html' %} <!doctype html>
{% block title %} <html lang="zh-CN">
<head>
<title>角色授权</title> <title>角色授权</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<form class="layui-form" action=""> <form class="layui-form" action="">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="main-container"> <div class="main-container">
@@ -25,16 +27,15 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% block models_script %} {% include 'admin/common/footer.html' %}
<script> <script>
layui.use(['dtree', 'form', 'jquery'], function () { layui.use(['dtree', 'form', 'jquery'], function() {
let dtree = layui.dtree let dtree = layui.dtree;
let form = layui.form let form = layui.form;
let $ = layui.jquery let $ = layui.jquery;
dtree.render({ dtree.render({
elem: '#role-power', elem: '#role-power',
@@ -45,38 +46,39 @@
skin: 'layui', skin: 'layui',
initLevel: '1', initLevel: '1',
checkbarType: 'self', checkbarType: 'self',
response: { treeId: 'powerId', parentId: 'parentId', title: 'powerName' }, response: {treeId: 'powerId', parentId: 'parentId', title: 'powerName'},
}) });
form.on('submit(power-save)', function (data) { form.on('submit(power-save)', function(data) {
let param = dtree.getCheckbarNodesParam('role-power') let param = dtree.getCheckbarNodesParam('role-power');
let ids = '' let ids = '';
for (let i = 0; i < param.length; i++) { for (let i = 0; i < param.length; i++) {
let id = param[i].nodeId let id = param[i].nodeId;
ids += id + ',' ids += id + ',';
} }
ids = ids.substr(0, ids.length - 1) ids = ids.substr(0, ids.length - 1);
data.field.roleId = {{role_id}}; data.field.roleId = {{role_id}};
data.field.powerIds = ids data.field.powerIds = ids;
$.ajax({ $.ajax({
url: '/api/v1/roles/role_power/' + data.field.roleId, url: '/api/v1/roles/role_power/' + data.field.roleId,
data: data.field, data: data.field,
dataType: 'json', dataType: 'json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name)) parent.layer.close(parent.layer.getFrameIndex(window.name));
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+46 -47
View File
@@ -1,6 +1,6 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>个人中心</title> <title>个人中心</title>
<style> <style>
.layui-form-item { .layui-form-item {
@@ -8,11 +8,11 @@
margin-bottom: 17px !important; margin-bottom: 17px !important;
} }
</style> </style>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
<body class="pear-container">
<div class="layui-row layui-col-space10">
{% block body %}
<div class="layui-row layui-col-space10">
{# 左侧栏 #} {# 左侧栏 #}
<div class="layui-col-md3"> <div class="layui-col-md3">
{# 个人信息卡片 #} {# 个人信息卡片 #}
@@ -183,9 +183,8 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<form id="edit_password_view" class="layui-form" action="" style="display: none">
<form id="edit_password_view" class="layui-form" action="" style="display: none">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="layui-form-item" style="display: none"> <div class="layui-form-item" style="display: none">
@@ -233,32 +232,31 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% block models_script %} {% include 'admin/common/footer.html' %}
<script> <script>
layui.use(['element', 'jquery', 'layer', 'form', 'popup'], function () { layui.use(['element', 'jquery', 'layer', 'form', 'popup'], function() {
let $ = layui.jquery let $ = layui.jquery;
let layer = layui.layer let layer = layui.layer;
let form = layui.form let form = layui.form;
let popup = layui.popup let popup = layui.popup;
// 修改密码页面 // 修改密码页面
$('.edit-password').click(function () { $('.edit-password').click(function() {
layer.open({ layer.open({
type: 1, type: 1,
title: '修改密码', title: '修改密码',
shade: 0.1, shade: 0.1,
area: ['550px', '280px'], area: ['550px', '280px'],
content: $('#edit_password_view'), content: $('#edit_password_view'),
}) });
return false return false;
}) });
// 修改头像 // 修改头像
$('#avatar').click(function () { $('#avatar').click(function() {
layer.open({ layer.open({
type: 2, type: 2,
title: '更换图片', title: '更换图片',
@@ -266,52 +264,53 @@
area: ['900px', '500px'], area: ['900px', '500px'],
content: '/users/avatar', content: '/users/avatar',
btn: ['确定', '取消'], btn: ['确定', '取消'],
yes: function (index, layero) { yes: function(index, layero) {
window['layui-layer-iframe' + index].submitForm() window['layui-layer-iframe' + index].submitForm();
}, },
}) });
}) });
// 表单提交更改个人信息数据 // 表单提交更改个人信息数据
form.on('submit(user-update)', function (data) { form.on('submit(user-update)', function(data) {
$.ajax({ $.ajax({
url: '/api/v1/users/user/' + data.field.user_id + '/info', url: '/api/v1/users/user/' + data.field.user_id + '/info',
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg('修改成功', { icon: 1, time: 1000 }) layer.msg('修改成功', {icon: 1, time: 1000});
} else { } else {
layer.msg('修改失败', { icon: 2, time: 1000 }) layer.msg('修改失败', {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
// 修改密码提交 // 修改密码提交
form.on('submit(edit-password)', function (data) { form.on('submit(edit-password)', function(data) {
$.ajax({ $.ajax({
url: '/api/v1/users/user/' + data.field.user_id + '/password', url: '/api/v1/users/user/' + data.field.user_id + '/password',
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
contentType: 'application/json', contentType: 'application/json',
dataType: 'json', dataType: 'json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
popup.success(result.message, function () { popup.success(result.message, function() {
// TODO 关闭修改密码成之后的窗口 // TODO 关闭修改密码成之后的窗口
parent.layer.close(parent.layer.getFrameIndex(window.name)) parent.layer.close(parent.layer.getFrameIndex(window.name));
}) });
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
return false return false;
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+62 -62
View File
@@ -1,11 +1,11 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>头像上传</title> <title>头像上传</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<div class="layui-row layui-col-space15"> <div class="layui-row layui-col-space15">
<div class="layui-col-xs9"> <div class="layui-col-xs9">
<div style="height:325px;background-color: rgb(247, 247, 247);"> <div style="height:325px;background-color: rgb(247, 247, 247);">
<img id="sourceImage" src=""> <img id="sourceImage" src="">
@@ -16,8 +16,8 @@
style="width:210px;height:210px;border: 1px solid rgb(200, 200, 200);border-radius: 50%;overflow:hidden;"> style="width:210px;height:210px;border: 1px solid rgb(200, 200, 200);border-radius: 50%;overflow:hidden;">
</div> </div>
</div> </div>
</div> </div>
<div class="layui-row"> <div class="layui-row">
<div class="layui-form-item"> <div class="layui-form-item">
<div class="layui-input-inline layui-btn-container" style="width: auto;vertical-align:top;"> <div class="layui-input-inline layui-btn-container" style="width: auto;vertical-align:top;">
<button class="pear-btn pear-btn-sm pear-btn-primary layui-icon layui-icon-left" cropper-event="rotate" <button class="pear-btn pear-btn-sm pear-btn-primary layui-icon layui-icon-left" cropper-event="rotate"
@@ -33,95 +33,95 @@
<div class="layui-form-mid layui-word-aux">建议:图片的尺寸宽高比为1:1,大小在5m以内。</div> <div class="layui-form-mid layui-word-aux">建议:图片的尺寸宽高比为1:1,大小在5m以内。</div>
<input type="text" hidden value="{{ current_user.id }}" id="user_id"> <input type="text" hidden value="{{ current_user.id }}" id="user_id">
</div> </div>
</div> </div>
{% endblock %}
{% block models_script %} {% include 'admin/common/footer.html' %}
<script> <script>
layui.use(['jquery', 'layer', 'cropper', 'popup'], function () { layui.use(['jquery', 'layer', 'cropper', 'popup'], function() {
let $ = layui.jquery let $ = layui.jquery;
let layer = layui.layer let layer = layui.layer;
let cropper = layui.cropper let cropper = layui.cropper;
let popup = layui.popup let popup = layui.popup;
let options = { let options = {
aspectRatio: 1 / 1, // 裁剪框比例 aspectRatio: 1 / 1, // 裁剪框比例
preview: '#previewImage', // 预览div preview: '#previewImage', // 预览div
viewmode: 1, viewmode: 1,
} };
$('#sourceImage').attr('src', parent.layui.$('#avatar').attr('src')) $('#sourceImage').attr('src', parent.layui.$('#avatar').attr('src'));
$('#sourceImage').cropper(options) $('#sourceImage').cropper(options);
window.submitForm = function () { window.submitForm = function() {
$('#sourceImage').crossOrigin = 'anonymous'//解决跨域图片问题 $('#sourceImage').crossOrigin = 'anonymous';//解决跨域图片问题
$('#sourceImage').cropper('getCroppedCanvas', { $('#sourceImage').cropper('getCroppedCanvas', {
width: 280, width: 280,
height: 140, height: 140,
}).toBlob(function (blob) { }).toBlob(function(blob) {
let timeStamp = Date.parse(new Date()) let timeStamp = Date.parse(new Date());
let fileName = timeStamp + '.jpg' let fileName = timeStamp + '.jpg';
let formData = new FormData() let formData = new FormData();
formData.append('file', blob, fileName) formData.append('file', blob, fileName);
formData.append('fileName', fileName) formData.append('fileName', fileName);
formData.append('fileToken', timeStamp) formData.append('fileToken', timeStamp);
$.ajax({ $.ajax({
method: 'post', method: 'post',
url: '/api/v1/file/photos', //用于文件上传的服务器端请求地址 url: '/api/v1/file/photos', //用于文件上传的服务器端请求地址
data: formData, data: formData,
processData: false, processData: false,
contentType: false, contentType: false,
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
// 修改 avatar 字段 // 修改 avatar 字段
$.ajax({ $.ajax({
method: 'put', method: 'put',
url: '/api/v1/users/user/' + $('#user_id').val() + '/avatar', url: '/api/v1/users/user/' + $('#user_id').val() + '/avatar',
data: JSON.stringify({ avatar: result.data }), data: JSON.stringify({avatar: result.data}),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
success: function (res) { success: function(res) {
if (res.success) { if (res.success) {
// 关闭当前弹层 // 关闭当前弹层
parent.layui.$('#avatar').attr('src', result.data.src) parent.layui.$('#avatar').attr('src', result.data.src);
top.layui.$('#avatar').attr('src', result.data.src) top.layui.$('#avatar').attr('src', result.data.src);
parent.layer.close(parent.layer.getFrameIndex(window.name)) parent.layer.close(parent.layer.getFrameIndex(window.name));
} else { } else {
popup.failure('上传失败') popup.failure('上传失败');
} }
}, },
}) });
} else { } else {
popup.failure('上传失败') popup.failure('上传失败');
} }
}, },
}) });
}) });
} };
$('.pear-btn').on('click', function () { $('.pear-btn').on('click', function() {
let event = $(this).attr('cropper-event') let event = $(this).attr('cropper-event');
if (event === 'rotate') { if (event === 'rotate') {
let option = $(this).attr('data-option') let option = $(this).attr('data-option');
$('#sourceImage').cropper('rotate', option) $('#sourceImage').cropper('rotate', option);
} else if (event === 'reset') { } else if (event === 'reset') {
$('#sourceImage').cropper('reset') $('#sourceImage').cropper('reset');
} }
$('#uploadPicture').change(function () { $('#uploadPicture').change(function() {
let r = new FileReader() let r = new FileReader();
let f = this.files[0] let f = this.files[0];
let uploadFileSize = f.size / 1024 let uploadFileSize = f.size / 1024;
if (uploadFileSize > 5120) { if (uploadFileSize > 5120) {
parent.layer.msg('上传文件不得超过5m', { icon: 5 }) parent.layer.msg('上传文件不得超过5m', {icon: 5});
return false return false;
} }
r.readAsDataURL(f) r.readAsDataURL(f);
r.onload = function (e) { r.onload = function(e) {
$('#sourceImage').cropper('destroy').attr('src', this.result).cropper(options) $('#sourceImage').cropper('destroy').attr('src', this.result).cropper(options);
} };
}) });
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+150 -149
View File
@@ -1,14 +1,15 @@
{% extends 'admin/base.html' %} <!doctype html>
<html lang="zh-CN">
{% block title %} <head>
<title>用户管理</title> <title>用户管理</title>
{% include 'admin/common/header.html' %}
<link rel="stylesheet" href="/static/admin/admin/css/other/user.css"/> <link rel="stylesheet" href="/static/admin/admin/css/other/user.css"/>
{% endblock %} </head>
<body class="pear-container">
{% block body %} {# 查询表单 #}
{# 查询表单 #} <div class="layui-card">
<div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<form class="layui-form" action="" lay-filter="user-query-form"> <form class="layui-form" action="" lay-filter="user-query-form">
<div class="layui-form-item"> <div class="layui-form-item">
@@ -31,8 +32,8 @@
</div> </div>
</form> </form>
</div> </div>
</div> </div>
<div class="user-left user-collasped"> <div class="user-left user-collasped">
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<div class="button button-primary user-group" user-group=""> 全 部 用 户</div> <div class="button button-primary user-group" user-group=""> 全 部 用 户</div>
@@ -42,20 +43,20 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{# 用户表格 #} {# 用户表格 #}
<div class="user-main user-collasped"> <div class="user-main user-collasped">
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-body"> <div class="layui-card-body">
<table id="tables" lay-filter="tables"></table> <table id="tables" lay-filter="tables"></table>
</div> </div>
</div> </div>
</div> </div>
{% endblock %}
{% block models_script %}
{# 表格操作 #} {% include 'admin/common/footer.html' %}
<script type="text/html" id="toolbar"> {# 表格操作 #}
<script type="text/html" id="toolbar">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add"> <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="toolbar-add">
<i class="pear-icon pear-icon-add"></i> <i class="pear-icon pear-icon-add"></i>
新增 新增
@@ -68,53 +69,52 @@
<i class="pear-icon pear-icon-modular"></i> <i class="pear-icon pear-icon-modular"></i>
高级 高级
</button> </button>
</script> </script>
{# 用户修改操作 #} {# 用户修改操作 #}
<script type="text/html" id="tool"> <script type="text/html" id="tool">
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool-edit"> <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tool-edit">
<i class="pear-icon pear-icon-edit"></i> <i class="pear-icon pear-icon-edit"></i>
</button> </button>
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove"> <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tool-remove">
<i class="pear-icon pear-icon-ashbin"></i> <i class="pear-icon pear-icon-ashbin"></i>
</button> </button>
</script> </script>
{# 启动与禁用 #} {# 启动与禁用 #}
<script type="text/html" id="tool-switch"> <script type="text/html" id="tool-switch">
<input type="checkbox" name="enable" value="{{ "{{ d.id }}" }}" lay-skin="switch" lay-text="启用|禁用" <input type="checkbox" name="enable" value="{{ "{{ d.id }}" }}" lay-skin="switch" lay-text="启用|禁用"
lay-filter="tool-switch" lay-filter="tool-switch"
{{ "{{# if(d.enable==1){ }} checked {{# } }}" }} /> {{ "{{# if(d.enable==1){ }} checked {{# } }}" }} />
</script> </script>
{# 用户注册时间 #} {# 用户注册时间 #}
<script type="text/html" id="user-createTime"> <script type="text/html" id="user-createTime">
{{ ' {{layui.util.toDateString(d.create_at, "yyyy-MM-dd HH:mm:ss")}' |safe }}} {{ ' {{layui.util.toDateString(d.create_at, "yyyy-MM-dd HH:mm:ss")}' |safe }}}
</script> </script>
{# 用户更新时间 #} {# 用户更新时间 #}
<script type="text/html" id="user-updateTime"> <script type="text/html" id="user-updateTime">
{{ ' {{layui.util.toDateString(d.update_at, "yyyy-MM-dd HH:mm:ss")}' |safe }}} {{ ' {{layui.util.toDateString(d.update_at, "yyyy-MM-dd HH:mm:ss")}' |safe }}}
</script> </script>
<script>
<script> layui.use(['table', 'dtree', 'form', 'jquery', 'popup', 'common'], function() {
layui.use(['table', 'dtree', 'form', 'jquery', 'popup', 'common'], function () { let table = layui.table;
let table = layui.table let form = layui.form;
let form = layui.form let $ = layui.jquery;
let $ = layui.jquery let dtree = layui.dtree;
let dtree = layui.dtree let popup = layui.popup;
let popup = layui.popup let common = layui.common;
let common = layui.common
// 表格数据 // 表格数据
const get_columns = () => [ const get_columns = () => [
[ [
{ type: 'checkbox' }, {type: 'checkbox'},
{ title: '姓名', field: 'realname', align: 'center', width: 110 }, {title: '姓名', field: 'realname', align: 'center', width: 110},
{ title: '账号', field: 'username', align: 'center' }, {title: '账号', field: 'username', align: 'center'},
{ title: '部门', field: 'dept', align: 'center' }, {title: '部门', field: 'dept', align: 'center'},
{ title: '启用', field: 'enable', align: 'center', templet: '#tool-switch', width: 120 }, {title: '启用', field: 'enable', align: 'center', templet: '#tool-switch', width: 120},
{ title: '注册时间', field: 'create_at', templet: '#user-createTime', align: 'center' }, {title: '注册时间', field: 'create_at', templet: '#user-createTime', align: 'center'},
{ title: '更新时间', field: 'update_at', templet: '#user-updateTime', align: 'center' }, {title: '更新时间', field: 'update_at', templet: '#user-updateTime', align: 'center'},
{ title: '操作', toolbar: '#tool', align: 'center', width: 130 }, {title: '操作', toolbar: '#tool', align: 'center', width: 130},
], ],
] ];
// 渲染表格数据 // 渲染表格数据
table.render({ table.render({
@@ -126,9 +126,9 @@
skin: 'line', skin: 'line',
height: 'full-148', height: 'full-148',
toolbar: '#toolbar', /*工具栏*/ toolbar: '#toolbar', /*工具栏*/
text: { none: '暂无人员信息' }, text: {none: '暂无人员信息'},
defaultToolbar: [{ layEvent: 'refresh', icon: 'layui-icon-refresh' }, 'filter', 'print', 'exports'], /*默认工具栏*/ defaultToolbar: [{layEvent: 'refresh', icon: 'layui-icon-refresh'}, 'filter', 'print', 'exports'], /*默认工具栏*/
}) });
// 公司部门树状图菜单 // 公司部门树状图菜单
dtree.render({ dtree.render({
@@ -139,176 +139,177 @@
line: true, line: true,
skin: 'laySimple', skin: 'laySimple',
icon: '-1', icon: '-1',
response: { treeId: 'deptId', parentId: 'parentId', title: 'deptName' }, response: {treeId: 'deptId', parentId: 'parentId', title: 'deptName'},
}) });
// 菜单栏渲染 // 菜单栏渲染
dtree.on('node(\'dept-tree\')', function (obj) { dtree.on('node(\'dept-tree\')', function(obj) {
let field = form.val('user-query-form') /*用户账号查询*/ let field = form.val('user-query-form'); /*用户账号查询*/
field.deptId = obj.param.nodeId field.deptId = obj.param.nodeId;
window.refresh(field) window.refresh(field);
}) });
// //
$('.user-group').click(function () { $('.user-group').click(function() {
let group = $(this).attr('user-group') let group = $(this).attr('user-group');
let field = form.val('user-query-form') let field = form.val('user-query-form');
if (group === '-1') { if (group === '-1') {
field.deptId = group field.deptId = group;
$(this).removeClass('button-default') $(this).removeClass('button-default');
$(this).prev().removeClass('button-primary') $(this).prev().removeClass('button-primary');
$(this).prev().addClass('button-default') $(this).prev().addClass('button-default');
$(this).addClass('button-primary') $(this).addClass('button-primary');
} else { } else {
field.deptId = group field.deptId = group;
$(this).removeClass('button-default') $(this).removeClass('button-default');
$(this).next().removeClass('button-primary') $(this).next().removeClass('button-primary');
$(this).next().addClass('button-default') $(this).next().addClass('button-default');
$(this).addClass('button-primary') $(this).addClass('button-primary');
} }
window.refresh(field) window.refresh(field);
}) });
table.on('tool(tables)', function (obj) { table.on('tool(tables)', function(obj) {
if (obj.event === 'tool-remove') { if (obj.event === 'tool-remove') {
window.tool_remove(obj) window.tool_remove(obj);
} else if (obj.event === 'tool-edit') { } else if (obj.event === 'tool-edit') {
window.tool_edit(obj) window.tool_edit(obj);
} }
}) });
table.on('toolbar(tables)', function (obj) { table.on('toolbar(tables)', function(obj) {
if (obj.event === 'toolbar-add') { if (obj.event === 'toolbar-add') {
window.toolbar_add() window.toolbar_add();
} else if (obj.event === 'refresh') { } else if (obj.event === 'refresh') {
window.refresh() window.refresh();
} else if (obj.event === 'toolbar-remove') { } else if (obj.event === 'toolbar-remove') {
window.toolbar_remove(obj) window.toolbar_remove(obj);
} else if (obj.event === 'toolbar-collasped') { } else if (obj.event === 'toolbar-collasped') {
$('.user-left').toggleClass('user-collasped') $('.user-left').toggleClass('user-collasped');
$('.user-main').toggleClass('user-collasped') $('.user-main').toggleClass('user-collasped');
table.resize() table.resize();
} }
}) });
form.on('submit(user-query)', function (data) { form.on('submit(user-query)', function(data) {
window.refresh(data.field) window.refresh(data.field);
return false return false;
}) });
form.on('switch(tool-switch)', function (obj) { form.on('switch(tool-switch)', function(obj) {
let operate let operate;
if (obj.elem.checked) { if (obj.elem.checked) {
operate = 1 operate = 1;
} else { } else {
operate = 0 operate = 0;
} }
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/users/user/' + this.value + '/status', url: '/api/v1/users/user/' + this.value + '/status',
data: JSON.stringify({ operate: operate, userId: this.value }), data: JSON.stringify({operate: operate, userId: this.value}),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message) popup.success(result.message);
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
}) });
window.toolbar_add = function () { window.toolbar_add = function() {
layer.open({ layer.open({
type: 2, type: 2,
title: '新增', title: '新增',
shade: 0.1, shade: 0.1,
area: ['550px', '550px'], area: ['550px', '550px'],
content: '/users/add', content: '/users/add',
}) });
} };
window.toolbar_remove = function (obj) { window.toolbar_remove = function(obj) {
let data = table.checkStatus(obj.config.id).data let data = table.checkStatus(obj.config.id).data;
if (data.length === 0) { if (data.length === 0) {
layer.msg('未选中数据', { layer.msg('未选中数据', {
icon: 3, icon: 3,
time: 1000, time: 1000,
}) });
return false return false;
} }
var ids = [] var ids = [];
var hasCheck = table.checkStatus('tables') var hasCheck = table.checkStatus('tables');
var hasCheckData = hasCheck.data var hasCheckData = hasCheck.data;
if (hasCheckData.length > 0) { if (hasCheckData.length > 0) {
$.each(hasCheckData, function (index, element) { $.each(hasCheckData, function(index, element) {
ids.push(element.id) ids.push(element.id);
}) });
} }
{#console.log(ids);#} {#console.log(ids);#}
layer.confirm('确定要删除选中角色', { layer.confirm('确定要删除选中角色', {
icon: 3, icon: 3,
title: '提示', title: '提示',
}, function (index) { }, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/users/user', url: '/api/v1/users/user',
data: { ids: ids }, data: {ids: ids},
dataType: 'json', dataType: 'json',
type: 'delete', type: 'delete',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message, function () { popup.success(result.message, function() {
table.reload('role-table') table.reload('role-table');
}) });
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
}) });
} };
window.refresh = function (param) { window.refresh = function(param) {
table.reload('tables', { where: param }) table.reload('tables', {where: param});
} };
window.tool_remove = function (obj) { window.tool_remove = function(obj) {
layer.confirm('确定要删除该用户', { icon: 3, title: '提示' }, function (index) { layer.confirm('确定要删除该用户', {icon: 3, title: '提示'}, function(index) {
layer.close(index) layer.close(index);
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/api/v1/users/user/' + obj.data['id'], url: '/api/v1/users/user/' + obj.data['id'],
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'delete', type: 'delete',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message, function () { popup.success(result.message, function() {
obj.del() obj.del();
}) });
} else { } else {
popup.failure(result.message) popup.failure(result.message);
} }
}, },
}) });
}) });
} };
window.tool_edit = function (obj) { window.tool_edit = function(obj) {
layer.open({ layer.open({
type: 2, type: 2,
title: '修改', title: '修改',
shade: 0.1, shade: 0.1,
area: ['550px', '500px'], area: ['550px', '500px'],
content: '/users/' + obj.data['id'], content: '/users/' + obj.data['id'],
}) });
} };
}) });
</script> </script>
{% endblock %} </body>
</html>
+34 -32
View File
@@ -1,10 +1,11 @@
{% extends 'admin/base.html' %} <!doctype html>
{% block title %} <html lang="zh-CN">
<head>
<title>用户管理</title> <title>用户管理</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
{% block body %} <body class="pear-container">
<form class="layui-form"> <form class="layui-form">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="main-container"> <div class="main-container">
@@ -58,22 +59,22 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% block models_script %}
<script>
layui.use(['form', 'jquery'], function () { {% include 'admin/common/footer.html' %}
let form = layui.form <script>
let $ = layui.jquery
form.on('submit(user-save)', function (data) { layui.use(['form', 'jquery'], function() {
let roleIds = '' let form = layui.form;
$('input[type=checkbox]:checked').each(function () { let $ = layui.jquery;
roleIds += $(this).val() + ',' form.on('submit(user-save)', function(data) {
}) let roleIds = '';
roleIds = roleIds.substr(0, roleIds.length - 1) $('input[type=checkbox]:checked').each(function() {
data.field.roleIds = roleIds roleIds += $(this).val() + ',';
});
roleIds = roleIds.substr(0, roleIds.length - 1);
data.field.roleIds = roleIds;
$.ajax({ $.ajax({
url: '/api/v1/users/user', url: '/api/v1/users/user',
@@ -81,19 +82,20 @@
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'post', type: 'post',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页 parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
parent.layui.table.reload('tables') parent.layui.table.reload('tables');
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+38 -37
View File
@@ -1,11 +1,11 @@
{% extends 'admin/base.html' %} <!doctype html>
{% block title %} <html lang="zh-CN">
<head>
<title>用户编辑</title> <title>用户编辑</title>
{% endblock %} {% include 'admin/common/header.html' %}
</head>
<body class="pear-container">
{% block body %} <form class="layui-form" action="">
<form class="layui-form" action="">
<div class="mainBox"> <div class="mainBox">
<div class="main-container"> <div class="main-container">
<div class="main-container"> <div class="main-container">
@@ -67,53 +67,54 @@
</button> </button>
</div> </div>
</div> </div>
</form> </form>
{% endblock %}
{% block models_script %}
<script> {% include 'admin/common/footer.html' %}
layui.use(['form', 'jquery', 'dtree'], function () { <script>
let form = layui.form layui.use(['form', 'jquery', 'dtree'], function() {
let $ = layui.jquery let form = layui.form;
let dtree = layui.dtree let $ = layui.jquery;
let dtree = layui.dtree;
dtree.renderSelect({ dtree.renderSelect({
elem: '#selectParent', elem: '#selectParent',
url: '/api/v1/dept/department', url: '/api/v1/dept/department',
method: 'get', method: 'get',
selectInputName: { nodeId: 'deptId', context: 'deptName' }, selectInputName: {nodeId: 'deptId', context: 'deptName'},
skin: 'layui', skin: 'layui',
dataFormat: 'list', dataFormat: 'list',
response: { treeId: 'deptId', parentId: 'parentId', title: 'deptName' }, response: {treeId: 'deptId', parentId: 'parentId', title: 'deptName'},
selectInitVal: "{{ user.dept_id }}", selectInitVal: "{{ user.dept_id }}",
}) });
form.on('submit(user-update)', function (data) { form.on('submit(user-update)', function(data) {
let roleIds = '' let roleIds = '';
$('input[type=checkbox]:checked').each(function () { $('input[type=checkbox]:checked').each(function() {
roleIds += $(this).val() + ',' roleIds += $(this).val() + ',';
}) });
roleIds = roleIds.substr(0, roleIds.length - 1) roleIds = roleIds.substr(0, roleIds.length - 1);
data.field.roleIds = roleIds data.field.roleIds = roleIds;
$.ajax({ $.ajax({
url: '/api/v1/users/user/' + data.field.userId + '/role', url: '/api/v1/users/user/' + data.field.userId + '/role',
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
dataType: 'json', dataType: 'json',
contentType: 'application/json', contentType: 'application/json',
type: 'put', type: 'put',
success: function (result) { success: function(result) {
if (result.success) { if (result.success) {
layer.msg(result.message, { icon: 1, time: 1000 }, function () { layer.msg(result.message, {icon: 1, time: 1000}, function() {
parent.layer.close(parent.layer.getFrameIndex(window.name)) //关闭当前页 parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
parent.layui.table.reload('tables') parent.layui.table.reload('tables');
}) });
} else { } else {
layer.msg(result.message, { icon: 2, time: 1000 }) layer.msg(result.message, {icon: 2, time: 1000});
} }
}, },
}) });
return false return false;
}) });
}) });
</script> </script>
{% endblock %} </body>
</html>
+23 -23
View File
@@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="zh-CN">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
@@ -79,43 +79,43 @@
<!-- 依 赖 脚 本 --> <!-- 依 赖 脚 本 -->
{% include 'admin/common/footer.html' %} {% include 'admin/common/footer.html' %}
<script> <script>
layui.use(['admin', 'jquery', 'layer', 'popup'], function () { layui.use(['admin', 'jquery', 'layer', 'popup'], function() {
let admin = layui.admin let admin = layui.admin;
let $ = layui.jquery let $ = layui.jquery;
let layer = layui.layer let layer = layui.layer;
let popup = layui.popup let popup = layui.popup;
let MODULE_PATH = '/api/v1/rights/' let MODULE_PATH = '/api/v1/rights/';
// 框架初始化时会读取 根目录下 pear.configs.yml 文件作为初始化配置 // 框架初始化时会读取 根目录下 pear.configs.yml 文件作为初始化配置
// 你可以通过 admin.setConfigPath 方法修改配置文件位置 // 你可以通过 admin.setConfigPath 方法修改配置文件位置
// 你可以通过 admin.setConfigType 方法修改配置文件类型 // 你可以通过 admin.setConfigType 方法修改配置文件类型
admin.setConfigType('json') admin.setConfigType('json');
admin.setConfigPath(MODULE_PATH + 'configs') admin.setConfigPath(MODULE_PATH + 'configs');
admin.render() admin.render();
// 注销实现 // 注销实现
admin.logout(function () { admin.logout(function() {
let loading = layer.load() let loading = layer.load();
$.ajax({ $.ajax({
url: '/passport/logout', url: '/passport/logout',
dataType: 'json', dataType: 'json',
type: 'post', type: 'post',
success: function (result) { success: function(result) {
layer.close(loading) layer.close(loading);
if (result.success) { if (result.success) {
popup.success(result.message, function () { popup.success(result.message, function() {
location.href = '/admin' location.href = '/admin';
}) });
return true return true;
} }
} },
}) });
}) });
// 初始化消息事件 // 初始化消息事件
admin.message() admin.message();
}) });
</script> </script>
</body> </body>
</html> </html>
+7 -7
View File
@@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>pear-admin-flask</title> <title>pear-admin-flask</title>
@@ -154,12 +154,12 @@
<script src="/static/admin/component/pear/pear.js"></script> <script src="/static/admin/component/pear/pear.js"></script>
<script> <script>
layui.use(['layer', 'form', 'jquery'], function () { layui.use(['layer', 'form', 'jquery'], function() {
var $ = layui.jquery var $ = layui.jquery;
var layer = layui.layer var layer = layui.layer;
var form = layui.form var form = layui.form;
var jquery = layui.jquery var jquery = layui.jquery;
}) });
</script> </script>
</body> </body>
</html> </html>
+37 -35
View File
@@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="zh-CN">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>登录</title> <title>登录</title>
@@ -37,20 +37,22 @@
</button> </button>
</div> </div>
</form> </form>
{% include 'admin/common/footer.html' %}
<script>
layui.use(['form', 'jquery', 'layer', 'button', 'popup'], function () {
let form = layui.form
let $ = layui.jquery
let layer = layui.layer
let button = layui.button
let popup = layui.popup
let captchaPath = '/passport/getCaptcha'
form.on('submit(login)', function (data) { <script src="/static/admin/component/layui/layui.js"></script>
<script src="/static/admin/component/pear/pear.js"></script>
<script>
layui.use(['form', 'jquery', 'layer', 'button', 'popup'], function() {
let form = layui.form;
let $ = layui.jquery;
let layer = layui.layer;
let button = layui.button;
let popup = layui.popup;
let captchaPath = '/passport/getCaptcha';
form.on('submit(login)', function(data) {
// data 是表单的数据 // data 是表单的数据
let loader = layer.load() // 加载按钮 let loader = layer.load(); // 加载按钮
let btn = button.load({ elem: '.login' }) let btn = button.load({elem: '.login'});
$.ajax({ $.ajax({
url: '/api/v1/passport/login', url: '/api/v1/passport/login',
data: JSON.stringify(data.field), data: JSON.stringify(data.field),
@@ -58,38 +60,38 @@
type: 'post', type: 'post',
dataType: 'json', dataType: 'json',
// 请求成功之后返回的数据 // 请求成功之后返回的数据
success: function (result) { success: function(result) {
layer.close(loader) // 关闭加载按钮 layer.close(loader); // 关闭加载按钮
btn.stop(function () { btn.stop(function() {
if (result.success) { if (result.success) {
popup.success(result.message, function () { popup.success(result.message, function() {
location.href = '/admin' location.href = '/admin';
}) });
} else { } else {
popup.failure(result.message, function () { popup.failure(result.message, function() {
document.getElementById('captchaImage').src = captchaPath + '?' + Math.random() document.getElementById('captchaImage').src = captchaPath + '?' + Math.random();
}) });
} }
}) });
} },
}) });
return false return false;
}) });
// 点击按钮更新验证码 // 点击按钮更新验证码
$('#captchaImage').click(function () { $('#captchaImage').click(function() {
document.getElementById('captchaImage').src = captchaPath + '?' + Math.random() document.getElementById('captchaImage').src = captchaPath + '?' + Math.random();
}) });
// 定时器,定时更新验证码 // 定时器,定时更新验证码
setInterval(function () { setInterval(function() {
document.getElementById('captchaImage').src = captchaPath + '?' + Math.random() document.getElementById('captchaImage').src = captchaPath + '?' + Math.random();
}, 30 * 1000) }, 30 * 1000);
}) });
</script> </script>
<script> <script>
if (window !== top) { if (window !== top) {
top.location.href = location.href top.location.href = location.href;
} }
</script> </script>
</body> </body>
+52 -44
View File
@@ -1,8 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="zh-CN">
<head> <head>
<title>首页</title> <title>首页</title>
{% include 'admin/common/header.html' %} <meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/static/admin/component/pear/css/pear.css"/>
<link rel="stylesheet" href="/static/admin/admin/css/other/console1.css"/> <link rel="stylesheet" href="/static/admin/admin/css/other/console1.css"/>
<!-- 主 题 更 换 --> <!-- 主 题 更 换 -->
@@ -290,82 +294,85 @@
</div> </div>
</div> </div>
</div> </div>
<!--</div>--> <script src="/static/admin/component/layui/layui.js"></script>
{% include 'admin/common/footer.html' %} <script src="/static/admin/component/pear/pear.js"></script>
<script> <script>
layui.use(['layer', 'echarts', 'element', 'count'], function () { layui.use(['layer', 'echarts', 'element', 'count'], function() {
var $ = layui.jquery, var $ = layui.jquery,
layer = layui.layer, layer = layui.layer,
element = layui.element, element = layui.element,
count = layui.count, count = layui.count,
echarts = layui.echarts echarts = layui.echarts;
count.up('value1', { count.up('value1', {
time: 4000, time: 4000,
num: 440.34, num: 440.34,
bit: 2, bit: 2,
regulator: 50 regulator: 50,
}) });
count.up('value2', { count.up('value2', {
time: 4000, time: 4000,
num: 236.30, num: 236.30,
bit: 2, bit: 2,
regulator: 50 regulator: 50,
}) });
count.up('value3', { count.up('value3', {
time: 4000, time: 4000,
num: 634.43, num: 634.43,
bit: 2, bit: 2,
regulator: 50 regulator: 50,
}) });
count.up('value4', { count.up('value4', {
time: 4000, time: 4000,
bit: 2, bit: 2,
num: 373.23, num: 373.23,
regulator: 50 regulator: 50,
}) });
var echartsRecords = echarts.init(document.getElementById('echarts-records'), 'walden') var echartsRecords = echarts.init(document.getElementById('echarts-records'), 'walden');
var option = { var option = {
tooltip: { tooltip: {
trigger: 'axis' trigger: 'axis',
}, },
xAxis: [{ xAxis: [
{
type: 'category', type: 'category',
data: ['2019-01', '2019-02', '2019-03', '2019-04', '2019-05', '2019-06'], data: ['2019-01', '2019-02', '2019-03', '2019-04', '2019-05', '2019-06'],
axisLine: { axisLine: {
lineStyle: { lineStyle: {
color: '#999' color: '#999',
} },
} },
}], }],
yAxis: [{ yAxis: [
{
type: 'value', type: 'value',
splitNumber: 4, splitNumber: 4,
splitLine: { splitLine: {
lineStyle: { lineStyle: {
type: 'dashed', type: 'dashed',
color: '#DDD' color: '#DDD',
} },
}, },
axisLine: { axisLine: {
show: false, show: false,
lineStyle: { lineStyle: {
color: '#333' color: '#333',
}, },
}, },
nameTextStyle: { nameTextStyle: {
color: '#999' color: '#999',
}, },
splitArea: { splitArea: {
show: false show: false,
} },
}], }],
series: [{ series: [
{
name: '课时', name: '课时',
type: 'line', type: 'line',
data: [23, 60, 20, 36, 23, 85], data: [23, 60, 20, 36, 23, 85],
@@ -375,19 +382,20 @@
color: { color: {
type: 'linear', type: 'linear',
colorStops: [{ colorStops: [
{
offset: 0, offset: 0,
color: '#A9F387' // 0% 处的颜色 color: '#A9F387', // 0% 处的颜色
}, { }, {
offset: 1, offset: 1,
color: '#48D8BF' // 100% 处的颜色 color: '#48D8BF', // 100% 处的颜色
}], }],
globalCoord: false // 缺省为 false globalCoord: false, // 缺省为 false
}, },
shadowColor: 'rgba(72,216,191, 0.3)', shadowColor: 'rgba(72,216,191, 0.3)',
shadowBlur: 10, shadowBlur: 10,
shadowOffsetY: 20 shadowOffsetY: 20,
} },
}, },
itemStyle: { itemStyle: {
normal: { normal: {
@@ -395,19 +403,19 @@
borderWidth: 10, borderWidth: 10,
/*shadowColor: 'rgba(72,216,191, 0.3)', /*shadowColor: 'rgba(72,216,191, 0.3)',
shadowBlur: 100,*/ shadowBlur: 100,*/
borderColor: '#A9F387' borderColor: '#A9F387',
}
}, },
smooth: true },
}] smooth: true,
} }],
echartsRecords.setOption(option) };
echartsRecords.setOption(option);
window.onresize = function () { window.onresize = function() {
echartsRecords.resize() echartsRecords.resize();
} };
}) });
</script> </script>
</body> </body>
</html> </html>