first commit
This commit is contained in:
38
public/admin/js/common.js
Executable file
38
public/admin/js/common.js
Executable file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 浏览页面顶部搜索框展开收回控制
|
||||
*/
|
||||
function toggleSearchFormShow()
|
||||
{
|
||||
let $ = layui.$;
|
||||
let items = $('.top-search-from .layui-form-item');
|
||||
if (items.length <= 2) {
|
||||
if (items.length <= 1) $('.top-search-from').parent().parent().remove();
|
||||
return;
|
||||
}
|
||||
let btns = $('.top-search-from .toggle-btn a');
|
||||
let toggle = toggleSearchFormShow;
|
||||
if (typeof toggle.hide === 'undefined') {
|
||||
btns.on('click', function () {
|
||||
toggle();
|
||||
});
|
||||
}
|
||||
let countPerRow = parseInt($('.top-search-from').width()/$('.layui-form-item').width());
|
||||
if (items.length <= countPerRow) {
|
||||
return;
|
||||
}
|
||||
btns.removeClass('layui-hide');
|
||||
toggle.hide = !toggle.hide;
|
||||
if (toggle.hide) {
|
||||
for (let i = countPerRow - 1; i < items.length - 1; i++) {
|
||||
$(items[i]).hide();
|
||||
}
|
||||
return $('.top-search-from .toggle-btn a:last').addClass('layui-hide');
|
||||
}
|
||||
items.show();
|
||||
$('.top-search-from .toggle-btn a:first').addClass('layui-hide');
|
||||
}
|
||||
|
||||
layui.$(function () {
|
||||
toggleSearchFormShow();
|
||||
});
|
||||
|
34
public/admin/js/permission.js
Executable file
34
public/admin/js/permission.js
Executable file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 获取控制器详细权限,并决定展示哪些按钮或dom元素
|
||||
*/
|
||||
layui.$(function () {
|
||||
let $ = layui.$;
|
||||
$.ajax({
|
||||
url: "/admin/api/permission",
|
||||
dataType: "json",
|
||||
success: function (res) {
|
||||
let style = '';
|
||||
let codes = res.data || [];
|
||||
let isSuperAdmin = false;
|
||||
// codes里有*,说明是超级管理员,拥有所有权限
|
||||
if (codes.indexOf('*') !== -1) {
|
||||
$("head").append("<style>*[permission]{display: initial}</style>");
|
||||
isSuperAdmin = true;
|
||||
}
|
||||
if (self !== top) {
|
||||
top.Admin.Account.isSuperAdmin = isSuperAdmin;
|
||||
} else {
|
||||
window.Admin.Account.isSuperAdmin = isSuperAdmin;
|
||||
}
|
||||
if (isSuperAdmin) return;
|
||||
|
||||
// 细分权限
|
||||
layui.each(codes, function (k, code) {
|
||||
codes[k] = '*[permission^="'+code+'"]';
|
||||
});
|
||||
if (codes.length) {
|
||||
$("head").append("<style>" + codes.join(",") + "{display: initial}</style>");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user