作者 Karson

新增Table.api.formatter.buttons方法

优化管理员列表和分组列表显示
btn-dialog,btn-addtabs,btn-ajax的URL新增{ids}可替换为表格选中项
禁用分类管理下的排序
新增Trace开启的情况下Ajax不打印trace信息
优化新增、编辑按钮,可动态传参到Layer弹窗
... ... @@ -34,13 +34,10 @@ class Ajax extends Backend
public function lang()
{
header('Content-Type: application/javascript');
$callback = $this->request->get('callback');
$controllername = input("controllername");
//默认只加载了控制器对应的语言名,你还根据控制器名来加载额外的语言包
$this->loadlang($controllername);
//强制输出JSON Object
$result = 'define(' . json_encode(Lang::get(), JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE) . ');';
return $result;
return jsonp(Lang::get(), 200, [], ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
}
/**
... ...
... ... @@ -43,6 +43,7 @@ class Admin extends Backend
}
$this->childrenIds = array_keys($groupdata);
$this->view->assign('groupdata', $groupdata);
$this->assignconfig("admin", ['id' => $this->auth->id]);
}
/**
... ... @@ -59,7 +60,7 @@ class Admin extends Backend
->field('uid,group_id')
->where('group_id', 'in', $this->childrenIds)
->select();
$adminGroupName = [];
foreach ($authGroupList as $k => $v)
{
... ...
... ... @@ -32,12 +32,14 @@ class Group extends Backend
// 取出所有分组
$grouplist = model('AuthGroup')->all(['status' => 'normal']);
$objlist = [];
$group_ids = [];
foreach ($groups as $K => $v)
{
// 取出包含自己的所有子节点
$childrenlist = Tree::instance()->init($grouplist)->getChildren($v['id'], TRUE);
$obj = Tree::instance()->init($childrenlist)->getTreeArray($v['pid']);
$objlist = array_merge($objlist, Tree::instance()->getTreeList($obj));
$group_ids[] = (int) $v['group_id'];
}
$groupdata = [];
... ... @@ -46,6 +48,7 @@ class Group extends Backend
$groupdata[$v['id']] = $v['name'];
}
$this->groupdata = $groupdata;
$this->assignconfig("admin", ['id' => $this->auth->id, 'group_ids' => $group_ids]);
$this->childrenIds = array_keys($groupdata);
$this->view->assign('groupdata', $groupdata);
}
... ... @@ -280,7 +283,7 @@ class Group extends Backend
$state = array('selected' => in_array($v['id'], $current_rule_ids) && !in_array($v['id'], $hasChildrens));
$nodelist[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => $v['title'], 'type' => 'menu', 'state' => $state);
}
$this->success('',null,$nodelist);
$this->success('', null, $nodelist);
}
else
{
... ...
... ... @@ -7,10 +7,10 @@ use think\Config;
class Common
{
public function run(&$params)
public function run(&$request)
{
// 如果修改了index.php入口地址,则需要手动修改cdnurl的值
$cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $params->root());
$cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $request->root());
// 如果未设置__CDN__则自动匹配得出
if (!Config::get('view_replace_str.__CDN__'))
{
... ... @@ -36,6 +36,11 @@ class Common
// 如果是开发模式修改异常页的模板
Config::set('exception_tmpl', APP_PATH . 'common' . DS . 'view' . DS . 'tpl' . DS . 'think_exception.tpl');
}
// 如果是trace模式且Ajax的情况下关闭trace
if (Config::get('app_trace') && $request->isAjax())
{
Config::set('app_trace', false);
}
}
}
... ...
... ... @@ -596,7 +596,7 @@ table.table-template {
box-shadow: 1px 1px 50px rgba(0, 0, 0, 0.3) !important;
}
.layui-layer-fast.layui-layer-iframe {
overflow: hidden!important;
overflow: visible;
}
.layui-layer-fast .layui-layer-moves {
-webkit-box-sizing: content-box;
... ... @@ -607,6 +607,7 @@ table.table-template {
text-align: center!important;
padding: 10px!important;
background: #ecf0f1;
overflow: hidden;
}
.layui-layer-fast .layui-layer-btn a {
background-color: #95a5a6!important;
... ...
... ... @@ -63,11 +63,24 @@ define(['fast', 'moment'], function (Fast, Moment) {
}
}
},
replaceids: function (elem, url) {
//如果有需要替换ids的
if (url.indexOf("{ids}") > -1) {
var ids = 0;
var tableId = $(elem).data("table-id");
if (tableId && $(tableId).size() > 0 && $(tableId).data("bootstrap.table")) {
var Table = require("table");
ids = Table.api.selectedids($(tableId)).join(",");
}
url = url.replace(/\{ids\}/g, ids);
}
return url;
}
},
init: function () {
//公共代码
//添加ios-fix兼容iOS下的iframe
if(/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream){
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
$("html").addClass("ios-fix");
}
//配置Toastr的参数
... ... @@ -75,28 +88,32 @@ define(['fast', 'moment'], function (Fast, Moment) {
//点击包含.btn-dialog的元素时弹出dialog
$(document).on('click', '.btn-dialog,.dialogit', function (e) {
e.preventDefault();
var options = $(this).data();
options = options ? options : {};
Backend.api.open(Backend.api.fixurl($(this).attr('href')), $(this).attr('title'), options);
var options = $(this).data() || {};
Backend.api.open(Backend.api.replaceids(this, $(this).attr('href')), $(this).attr('title'), options);
});
//点击包含.btn-addtabs的元素时事件
//点击包含.btn-addtabs的元素时新增选项卡
$(document).on('click', '.btn-addtabs,.addtabsit', function (e) {
e.preventDefault();
Backend.api.addtabs($(this).attr("href"), $(this).attr("title"));
Backend.api.addtabs(Backend.api.replaceids(this, $(this).attr('href')), $(this).attr("title"));
});
//点击包含.btn-ajax的元素时事件
//点击包含.btn-ajax的元素时发送Ajax请求
$(document).on('click', '.btn-ajax,.ajaxit', function (e) {
e.preventDefault();
var options = $(this).data();
if (typeof options.url === 'undefined' && $(this).attr("href")) {
options.url = $(this).attr("href");
}
options.url = Backend.api.replaceids(this, options.url);
Backend.api.ajax(options);
});
//修复含有fixed-footer类的body边距
if ($(".fixed-footer").size() > 0) {
$(document.body).css("padding-bottom", $(".fixed-footer").height());
}
//修复不在iframe时layer-footer隐藏的问题
if ($(".layer-footer").size() > 0 && self === top) {
$(".layer-footer").show();
}
}
};
Backend.api = $.extend(Fast.api, Backend.api);
... ...
... ... @@ -29,7 +29,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'status', title: __("Status"), formatter: Table.api.formatter.status},
{field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
if(row.id == 1){
if(row.id == Config.admin.id){
return '';
}
return Table.api.formatter.operate.call(this, value, row, index);
... ...
... ... @@ -32,7 +32,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
events: Table.api.events.operate,
buttons: [{
name: 'detail',
text: 'Detail',
text: __('Detail'),
icon: 'fa fa-list',
classname: 'btn btn-info btn-xs btn-detail btn-dialog',
url: 'auth/adminlog/detail'
... ...
... ... @@ -42,7 +42,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function (
{field: 'name', title: __('Name'), align: 'left'},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
if (row.id == 1) {
if (Config.admin.group_ids.indexOf(parseInt(row.id)) > -1) {
return '';
}
return Table.api.formatter.operate.call(this, value, row, index);
... ...
... ... @@ -10,6 +10,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit_url: 'category/edit',
del_url: 'category/del',
multi_url: 'category/multi',
dragsort_url: '',
table: 'category',
}
});
... ... @@ -33,7 +34,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'nickname', title: __('Nickname')},
{field: 'flag', title: __('Flag'), operate: false, formatter: Table.api.formatter.flag},
{field: 'image', title: __('Image'), operate: false, formatter: Table.api.formatter.image},
{field: 'weigh', title: __('Weigh'), operate: false},
{field: 'weigh', title: __('Weigh')},
{field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
... ...
... ... @@ -6774,11 +6774,24 @@ define('backend',['fast', 'moment'], function (Fast, Moment) {
}
}
},
replaceids: function (elem, url) {
//如果有需要替换ids的
if (url.indexOf("{ids}") > -1) {
var ids = 0;
var tableId = $(elem).data("table-id");
if (tableId && $(tableId).size() > 0 && $(tableId).data("bootstrap.table")) {
var Table = require("table");
ids = Table.api.selectedids($(tableId)).join(",");
}
url = url.replace(/\{ids\}/g, ids);
}
return url;
}
},
init: function () {
//公共代码
//添加ios-fix兼容iOS下的iframe
if(/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream){
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
$("html").addClass("ios-fix");
}
//配置Toastr的参数
... ... @@ -6786,28 +6799,32 @@ define('backend',['fast', 'moment'], function (Fast, Moment) {
//点击包含.btn-dialog的元素时弹出dialog
$(document).on('click', '.btn-dialog,.dialogit', function (e) {
e.preventDefault();
var options = $(this).data();
options = options ? options : {};
Backend.api.open(Backend.api.fixurl($(this).attr('href')), $(this).attr('title'), options);
var options = $(this).data() || {};
Backend.api.open(Backend.api.replaceids(this, $(this).attr('href')), $(this).attr('title'), options);
});
//点击包含.btn-addtabs的元素时事件
//点击包含.btn-addtabs的元素时新增选项卡
$(document).on('click', '.btn-addtabs,.addtabsit', function (e) {
e.preventDefault();
Backend.api.addtabs($(this).attr("href"), $(this).attr("title"));
Backend.api.addtabs(Backend.api.replaceids(this, $(this).attr('href')), $(this).attr("title"));
});
//点击包含.btn-ajax的元素时事件
//点击包含.btn-ajax的元素时发送Ajax请求
$(document).on('click', '.btn-ajax,.ajaxit', function (e) {
e.preventDefault();
var options = $(this).data();
if (typeof options.url === 'undefined' && $(this).attr("href")) {
options.url = $(this).attr("href");
}
options.url = Backend.api.replaceids(this, options.url);
Backend.api.ajax(options);
});
//修复含有fixed-footer类的body边距
if ($(".fixed-footer").size() > 0) {
$(document.body).css("padding-bottom", $(".fixed-footer").height());
}
//修复不在iframe时layer-footer隐藏的问题
if ($(".layer-footer").size() > 0 && self === top) {
$(".layer-footer").show();
}
}
};
Backend.api = $.extend(Fast.api, Backend.api);
... ... @@ -7858,14 +7875,14 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
// 添加按钮事件
$(toolbar).on('click', Table.config.addbtn, function () {
var ids = Table.api.selectedids(table);
Fast.api.open(options.extend.add_url + (ids.length > 0 ? (options.extend.add_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + ids.join(",") : ''), __('Add'));
Fast.api.open(options.extend.add_url + (ids.length > 0 ? (options.extend.add_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + ids.join(",") : ''), __('Add'), $(this).data() || {});
});
// 批量编辑按钮事件
$(toolbar).on('click', Table.config.editbtn, function () {
var ids = Table.api.selectedids(table);
//循环弹出多个编辑框
$.each(ids, function (i, j) {
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + j, __('Edit'));
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + j, __('Edit'), $(this).data() || {});
});
});
// 批量操作按钮事件
... ... @@ -7929,7 +7946,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
});
$(table).on("click", "[data-id].btn-edit", function (e) {
e.preventDefault();
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + $(this).data("id"), __('Edit'));
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + $(this).data("id"), __('Edit'), $(this).data() || {});
});
$(table).on("click", "[data-id].btn-del", function (e) {
e.preventDefault();
... ... @@ -7966,7 +7983,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
'click .btn-editone': function (e, value, row, index) {
e.stopPropagation();
var options = $(this).closest('table').bootstrapTable('getOptions');
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Edit'));
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Edit'), $(this).data() || {});
},
'click .btn-delone': function (e, value, row, index) {
e.stopPropagation();
... ... @@ -8085,11 +8102,33 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
if (j.name === 'dragsort' && typeof row[Table.config.dragsortfield] === 'undefined') {
return true;
}
if (['add', 'edit', 'del', 'multi', 'dragsort'].indexOf(j.name) > -1 && !options.extend[j.name + "_url"]) {
return true;
}
var attr = table.data("operate-" + j.name);
if (typeof attr === 'undefined' || attr) {
if (['add', 'edit', 'del', 'multi'].indexOf(j.name) > -1 && !options.extend[j.name + "_url"]) {
return true;
}
//自动加上ids
j.url = j.url ? j.url + (j.url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk] : '';
url = j.url ? Fast.api.fixurl(j.url) : 'javascript:;';
classname = j.classname ? j.classname : 'btn-primary btn-' + name + 'one';
icon = j.icon ? j.icon : '';
text = j.text ? j.text : '';
title = j.title ? j.title : text;
html.push('<a href="' + url + '" class="' + classname + '" title="' + title + '"><i class="' + icon + '"></i>' + (text ? ' ' + text : '') + '</a>');
}
});
return html.join(' ');
},
buttons: function (value, row, index) {
var table = this.table;
// 操作配置
var options = table ? table.bootstrapTable('getOptions') : {};
// 默认按钮组
var buttons = $.extend([], this.buttons || []);
var html = [];
$.each(buttons, function (i, j) {
var attr = table.data("buttons-" + j.name);
if (typeof attr === 'undefined' || attr) {
//自动加上ids
j.url = j.url ? j.url + (j.url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk] : '';
url = j.url ? Fast.api.fixurl(j.url) : 'javascript:;';
... ...
... ... @@ -153,14 +153,14 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
// 添加按钮事件
$(toolbar).on('click', Table.config.addbtn, function () {
var ids = Table.api.selectedids(table);
Fast.api.open(options.extend.add_url + (ids.length > 0 ? (options.extend.add_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + ids.join(",") : ''), __('Add'));
Fast.api.open(options.extend.add_url + (ids.length > 0 ? (options.extend.add_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + ids.join(",") : ''), __('Add'), $(this).data() || {});
});
// 批量编辑按钮事件
$(toolbar).on('click', Table.config.editbtn, function () {
var ids = Table.api.selectedids(table);
//循环弹出多个编辑框
$.each(ids, function (i, j) {
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + j, __('Edit'));
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + j, __('Edit'), $(this).data() || {});
});
});
// 批量操作按钮事件
... ... @@ -224,7 +224,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
});
$(table).on("click", "[data-id].btn-edit", function (e) {
e.preventDefault();
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + $(this).data("id"), __('Edit'));
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + $(this).data("id"), __('Edit'), $(this).data() || {});
});
$(table).on("click", "[data-id].btn-del", function (e) {
e.preventDefault();
... ... @@ -261,7 +261,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
'click .btn-editone': function (e, value, row, index) {
e.stopPropagation();
var options = $(this).closest('table').bootstrapTable('getOptions');
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Edit'));
Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Edit'), $(this).data() || {});
},
'click .btn-delone': function (e, value, row, index) {
e.stopPropagation();
... ... @@ -380,11 +380,33 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
if (j.name === 'dragsort' && typeof row[Table.config.dragsortfield] === 'undefined') {
return true;
}
if (['add', 'edit', 'del', 'multi', 'dragsort'].indexOf(j.name) > -1 && !options.extend[j.name + "_url"]) {
return true;
}
var attr = table.data("operate-" + j.name);
if (typeof attr === 'undefined' || attr) {
if (['add', 'edit', 'del', 'multi'].indexOf(j.name) > -1 && !options.extend[j.name + "_url"]) {
return true;
}
//自动加上ids
j.url = j.url ? j.url + (j.url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk] : '';
url = j.url ? Fast.api.fixurl(j.url) : 'javascript:;';
classname = j.classname ? j.classname : 'btn-primary btn-' + name + 'one';
icon = j.icon ? j.icon : '';
text = j.text ? j.text : '';
title = j.title ? j.title : text;
html.push('<a href="' + url + '" class="' + classname + '" title="' + title + '"><i class="' + icon + '"></i>' + (text ? ' ' + text : '') + '</a>');
}
});
return html.join(' ');
},
buttons: function (value, row, index) {
var table = this.table;
// 操作配置
var options = table ? table.bootstrapTable('getOptions') : {};
// 默认按钮组
var buttons = $.extend([], this.buttons || []);
var html = [];
$.each(buttons, function (i, j) {
var attr = table.data("buttons-" + j.name);
if (typeof attr === 'undefined' || attr) {
//自动加上ids
j.url = j.url ? j.url + (j.url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk] : '';
url = j.url ? Fast.api.fixurl(j.url) : 'javascript:;';
... ...
... ... @@ -621,7 +621,8 @@ table.table-template{
box-shadow: 1px 1px 50px rgba(0,0,0,.3)!important;
}
&.layui-layer-iframe {
overflow:hidden!important;
//overflow:hidden!important;
overflow:visible;
}
.layui-layer-moves{
.box-sizing(content-box);
... ... @@ -631,6 +632,7 @@ table.table-template{
text-align: center!important;
padding: 10px!important;
background: #ecf0f1;
overflow:hidden;
a {
background-color: #95a5a6!important;
border-color: #95a5a6!important;
... ...