From 4e1cec190088e30288f17497e97d16a84a440e46 Mon Sep 17 00:00:00 2001 From: Karson <karsonzhang@163.com> Date: Mon, 11 Sep 2017 19:35:10 +0800 Subject: [PATCH] 新增Auth的getGroupIds、getChildrenAdminIds和getChildrenGroupIds方法 移除require-table.js的label方法 修复commonsearch普通搜索中queryParmas的BUG 修复operate为小写字母导致的BUG 优化管理员、管理组的代码 --- application/admin/controller/auth/Admin.php | 55 +++++++++++++++++++++++-------------------------------- application/admin/controller/auth/Adminlog.php | 45 +++++++++++++++++---------------------------- application/admin/controller/auth/Group.php | 38 ++++++++++++-------------------------- application/admin/lang/zh-cn.php | 1 + application/admin/library/Auth.php | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ application/common/controller/Backend.php | 10 +++++++--- public/assets/js/backend/auth/adminlog.js | 2 +- public/assets/js/bootstrap-table-commonsearch.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------- public/assets/js/require-table.js | 20 ++++---------------- 9 files changed, 214 insertions(+), 158 deletions(-) diff --git a/application/admin/controller/auth/Admin.php b/application/admin/controller/auth/Admin.php index ac9f80b..f5d0c5d 100644 --- a/application/admin/controller/auth/Admin.php +++ b/application/admin/controller/auth/Admin.php @@ -2,6 +2,8 @@ namespace app\admin\controller\auth; +use app\admin\model\AuthGroup; +use app\admin\model\AuthGroupAccess; use app\common\controller\Backend; use fast\Random; use fast\Tree; @@ -16,33 +18,21 @@ class Admin extends Backend { protected $model = null; - //当前登录管理员所有子节点组别 - protected $childrenIds = []; + protected $childrenGroupIds = []; + protected $childrenAdminIds = []; public function _initialize() { parent::_initialize(); $this->model = model('Admin'); - $groups = $this->auth->getGroups(); + $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true); + $this->childrenGroupIds = $this->auth->getChildrenGroupIds(); - // 取出所有分组 - $grouplist = model('AuthGroup')->all(['status' => 'normal']); - $objlist = []; - 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)); - } - $groupdata = []; - foreach ($objlist as $k => $v) - { - $groupdata[$v['id']] = $v['name']; - } - $this->childrenIds = array_keys($groupdata); - $this->view->assign('groupdata', $groupdata); + $groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds) + ->column('id,name'); + + $this->view->assign('groupdata', $groupName); $this->assignconfig("admin", ['id' => $this->auth->id]); } @@ -53,31 +43,31 @@ class Admin extends Backend { if ($this->request->isAjax()) { - $groupData = model('AuthGroup')->where('status', 'normal')->column('id,name'); - $childrenAdminIds = []; - $authGroupList = model('AuthGroupAccess') + $childrenGroupIds = $this->auth->getChildrenAdminIds(true); + $groupName = AuthGroup::where('id', 'in', $childrenGroupIds) + ->column('id,name'); + $authGroupList = AuthGroupAccess::where('group_id', 'in', $childrenGroupIds) ->field('uid,group_id') - ->where('group_id', 'in', $this->childrenIds) ->select(); $adminGroupName = []; foreach ($authGroupList as $k => $v) { - $childrenAdminIds[] = $v['uid']; - if (isset($groupData[$v['group_id']])) - $adminGroupName[$v['uid']][$v['group_id']] = $groupData[$v['group_id']]; + if (isset($groupName[$v['group_id']])) + $adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']]; } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model ->where($where) - ->where('id', 'in', $childrenAdminIds) + ->where('id', 'in', $this->childrenAdminIds) ->order($sort, $order) ->count(); $list = $this->model ->where($where) - ->where('id', 'in', $childrenAdminIds) + ->where('id', 'in', $this->childrenAdminIds) ->field(['password', 'salt', 'token'], true) ->order($sort, $order) ->limit($offset, $limit) @@ -88,6 +78,7 @@ class Admin extends Backend $v['groups'] = implode(',', array_keys($groups)); $v['groups_text'] = implode(',', array_values($groups)); } + unset($v); $result = array("total" => $total, "rows" => $list); return json($result); @@ -113,7 +104,7 @@ class Admin extends Backend $group = $this->request->post("group/a"); //过滤不允许的组别,避免越权 - $group = array_intersect($this->childrenIds, $group); + $group = array_intersect($this->childrenGroupIds, $group); $dataset = []; foreach ($group as $value) { @@ -157,7 +148,7 @@ class Admin extends Backend $group = $this->request->post("group/a"); // 过滤不允许的组别,避免越权 - $group = array_intersect($this->childrenIds, $group); + $group = array_intersect($this->childrenGroupIds, $group); $dataset = []; foreach ($group as $value) @@ -188,7 +179,7 @@ class Admin extends Backend if ($ids) { // 避免越权删除管理员 - $childrenGroupIds = $this->childrenIds; + $childrenGroupIds = $this->childrenGroupIds; $adminList = $this->model->where('id', 'in', $ids)->where('id', 'in', function($query) use($childrenGroupIds) { $query->name('auth_group_access')->where('group_id', 'in', $childrenGroupIds)->field('uid'); })->select(); diff --git a/application/admin/controller/auth/Adminlog.php b/application/admin/controller/auth/Adminlog.php index a889846..cb743b6 100644 --- a/application/admin/controller/auth/Adminlog.php +++ b/application/admin/controller/auth/Adminlog.php @@ -2,8 +2,8 @@ namespace app\admin\controller\auth; +use app\admin\model\AuthGroup; use app\common\controller\Backend; -use fast\Tree; /** * 管理员日志 @@ -15,33 +15,21 @@ class Adminlog extends Backend { protected $model = null; - //当前登录管理员所有子节点组别 - protected $childrenIds = []; + protected $childrenGroupIds = []; + protected $childrenAdminIds = []; public function _initialize() { parent::_initialize(); $this->model = model('AdminLog'); - $groups = $this->auth->getGroups(); + $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true); + $this->childrenGroupIds = $this->auth->getChildrenGroupIds(); - // 取出所有分组 - $grouplist = model('AuthGroup')->all(['status' => 'normal']); - $objlist = []; - 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)); - } - $groupdata = []; - foreach ($objlist as $k => $v) - { - $groupdata[$v['id']] = $v['name']; - } - $this->childrenIds = array_keys($groupdata); - $this->view->assign('groupdata', $groupdata); + $groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds) + ->column('id,name'); + + $this->view->assign('groupdata', $groupName); } /** @@ -51,20 +39,16 @@ class Adminlog extends Backend { if ($this->request->isAjax()) { - $childrenAdminIds = model('AuthGroupAccess') - ->field('uid') - ->where('group_id', 'in', $this->childrenIds) - ->column('uid'); list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model ->where($where) - ->where('admin_id', 'in', $childrenAdminIds) + ->where('admin_id', 'in', $this->childrenAdminIds) ->order($sort, $order) ->count(); $list = $this->model ->where($where) - ->where('admin_id', 'in', $childrenAdminIds) + ->where('admin_id', 'in', $this->childrenAdminIds) ->order($sort, $order) ->limit($offset, $limit) ->select(); @@ -112,7 +96,7 @@ class Adminlog extends Backend { if ($ids) { - $childrenGroupIds = $this->childrenIds; + $childrenGroupIds = $this->childrenGroupIds; $adminList = $this->model->where('id', 'in', $ids)->where('admin_id', 'in', function($query) use($childrenGroupIds) { $query->name('auth_group_access')->field('uid'); })->select(); @@ -142,5 +126,10 @@ class Adminlog extends Backend // 管理员禁止批量操作 $this->error(); } + + public function selectpage() + { + return parent::selectpage(); + } } diff --git a/application/admin/controller/auth/Group.php b/application/admin/controller/auth/Group.php index 51e8eb7..d08cf7f 100644 --- a/application/admin/controller/auth/Group.php +++ b/application/admin/controller/auth/Group.php @@ -2,6 +2,7 @@ namespace app\admin\controller\auth; +use app\admin\model\AuthGroup; use app\common\controller\Backend; use fast\Tree; @@ -15,8 +16,8 @@ class Group extends Backend { protected $model = null; - //当前登录管理员所有子节点组别 - protected $childrenIds = []; + //当前登录管理员所有子组别 + protected $childrenGroupIds = []; //当前组别列表数据 protected $groupdata = []; //无需要权限判断的方法 @@ -27,30 +28,15 @@ class Group extends Backend parent::_initialize(); $this->model = model('AuthGroup'); - $groups = $this->auth->getGroups(); + $this->childrenGroupIds = $this->auth->getChildrenGroupIds(true); - // 取出所有分组 - $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']; - } + $groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds) + ->column('id,name'); - $groupdata = []; - foreach ($objlist as $k => $v) - { - $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); + $this->groupdata = $groupName; + $this->assignconfig("admin", ['id' => $this->auth->id, 'group_ids' => $this->auth->getGroupIds()]); + + $this->view->assign('groupdata', $this->groupdata); } /** @@ -84,7 +70,7 @@ class Group extends Backend { $params = $this->request->post("row/a", [], 'strip_tags'); $params['rules'] = explode(',', $params['rules']); - if (!in_array($params['pid'], $this->childrenIds)) + if (!in_array($params['pid'], $this->childrenGroupIds)) { $this->error(__('The parent group can not be its own child')); } @@ -125,7 +111,7 @@ class Group extends Backend { $params = $this->request->post("row/a", [], 'strip_tags'); // 父节点不能是它自身的子节点 - if (!in_array($params['pid'], $this->childrenIds)) + if (!in_array($params['pid'], $this->childrenGroupIds)) { $this->error(__('The parent group can not be its own child')); } diff --git a/application/admin/lang/zh-cn.php b/application/admin/lang/zh-cn.php index d9ad4c2..47246e3 100644 --- a/application/admin/lang/zh-cn.php +++ b/application/admin/lang/zh-cn.php @@ -91,6 +91,7 @@ return [ 'Wechat manager' => '微信管理', 'Common search' => '普通搜索', 'Search %s' => '搜索 %s', + 'View %s' => '查看 %s', '%d second%s ago' => '%d秒前', '%d minute%s ago' => '%d分钟前', '%d hour%s ago' => '%d小时前', diff --git a/application/admin/library/Auth.php b/application/admin/library/Auth.php index f966f51..a4e9e3d 100644 --- a/application/admin/library/Auth.php +++ b/application/admin/library/Auth.php @@ -205,6 +205,95 @@ class Auth extends \fast\Auth } /** + * 获取管理员所属于的分组ID + * @param int $uid + * @return array + */ + public function getGroupIds($uid = null) + { + $groups = $this->getGroups($uid); + $groupIds = []; + foreach ($groups as $K => $v) + { + $groupIds[] = (int) $v['group_id']; + } + return $groupIds; + } + + /** + * 取出当前管理员所拥有权限的分组 + * @param boolean $withself 是否包含当前所在的分组 + * @return array + */ + public function getChildrenGroupIds($withself = false) + { + //取出当前管理员所有的分组 + $groups = $this->getGroups(); + $groupIds = []; + foreach ($groups as $k => $v) + { + $groupIds[] = $v['id']; + } + // 取出所有分组 + $groupList = model('AuthGroup')->all(['status' => 'normal']); + $objList = []; + foreach ($groups as $K => $v) + { + if ($v['rules'] === '*') + { + $objList = $groupList; + break; + } + // 取出包含自己的所有子节点 + $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)); + } + $childrenGroupIds = []; + foreach ($objList as $k => $v) + { + $childrenGroupIds[] = $v['id']; + } + if (!$withself) + { + $childrenGroupIds = array_diff($childrenGroupIds, $groupIds); + } + return $childrenGroupIds; + } + + /** + * 取出当前管理员所拥有权限的管理员 + * @param boolean $withself 是否包含自身 + * @return array + */ + public function getChildrenAdminIds($withself = false) + { + $groupIds = $this->getChildrenGroupIds(false); + $childrenAdminIds = []; + $authGroupList = model('AuthGroupAccess') + ->field('uid,group_id') + ->where('group_id', 'in', $groupIds) + ->select(); + + foreach ($authGroupList as $k => $v) + { + $childrenAdminIds[] = $v['uid']; + } + if ($withself) + { + if (!in_array($this->id, $childrenAdminIds)) + { + $childrenAdminIds[] = $this->id; + } + } + else + { + $childrenAdminIds = array_diff($childrenAdminIds, [$this->id]); + } + return $childrenAdminIds; + } + + /** * 获得面包屑导航 * @param string $path * @return array diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index 0a85e21..cda6c6c 100644 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -239,14 +239,18 @@ class Backend extends Controller { $k = $tableName . $k; } - $sym = isset($op[$k]) ? $op[$k] : $sym; + $sym = strtoupper(isset($op[$k]) ? $op[$k] : $sym); switch ($sym) { case '=': case '!=': + $where[] = [$k, $sym, (string) $v]; + break; case 'LIKE': case 'NOT LIKE': - $where[] = [$k, $sym, (string) $v]; + case 'LIKE %...%': + case 'NOT LIKE %...%': + $where[] = [$k, trim(str_replace('%...%', '', $sym)), "%{$v}%"]; break; case '>': case '>=': @@ -348,7 +352,7 @@ class Backend extends Controller $field = $field ? $field : 'name'; //如果有primaryvalue,说明当前是初始化传值 - if ($primaryvalue) + if ($primaryvalue !== null) { $where = [$primarykey => ['in', $primaryvalue]]; } diff --git a/public/assets/js/backend/auth/adminlog.js b/public/assets/js/backend/auth/adminlog.js index e8a709c..52b291f 100644 --- a/public/assets/js/backend/auth/adminlog.js +++ b/public/assets/js/backend/auth/adminlog.js @@ -23,7 +23,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin {field: 'state', checkbox: true, }, {field: 'id', title: 'ID', operate: false}, {field: 'username', title: __('Username'), formatter: Table.api.formatter.search}, - {field: 'title', title: __('Title'), operate: 'LIKE %...%', placeholder: '模糊搜索,*表示任意字符', style: 'width:200px'}, + {field: 'title', title: __('Title'), operate: 'LIKE %...%', placeholder: '模糊搜索'}, {field: 'url', title: __('Url'), align: 'left', formatter: Table.api.formatter.url}, {field: 'ip', title: __('IP'), events: Table.api.events.ip, formatter: Table.api.formatter.search}, {field: 'browser', title: __('Browser'), operate: false, formatter: Controller.api.formatter.browser}, diff --git a/public/assets/js/bootstrap-table-commonsearch.js b/public/assets/js/bootstrap-table-commonsearch.js index 947a434..af88955 100644 --- a/public/assets/js/bootstrap-table-commonsearch.js +++ b/public/assets/js/bootstrap-table-commonsearch.js @@ -3,7 +3,7 @@ * @version: v0.0.1 * * @update 2017-05-07 <http://git.oschina.net/pp/fastadmin> - * @update 2017-09-03 <http://git.oschina.net/karson/fastadmin> + * @update 2017-09-09 <http://git.oschina.net/karson/fastadmin> */ !function ($) { @@ -178,41 +178,43 @@ return true; }; - var getSearchQuery = function (that) { + var getSearchQuery = function (that, removeempty) { var op = {}; var filter = {}; - $("form.form-commonsearch input.operate", that.$container).each(function (i) { + var value = ''; + $("form.form-commonsearch input.operate", that.$commonsearch).each(function (i) { var name = $(this).data("name"); var sym = $(this).val(); - var obj = $("[name='" + name + "']"); + var obj = $("[name='" + name + "']", that.$commonsearch); if (obj.size() == 0) return true; var vObjCol = ColumnsForSearch[i]; if (obj.size() > 1) { if (/BETWEEN$/.test(sym)) { - var value_begin = $.trim($("[name='" + name + "']:first").val()), value_end = $.trim($("[name='" + name + "']:last").val()); - if (!value_begin.length && !value_end.length) { - return true; - } - if (typeof vObjCol.process === 'function') { - value_begin = vObjCol.process(value_begin, 'begin'); - value_end = vObjCol.process(value_end, 'end'); - } else if ($("[name='" + name + "']:first").attr('type') === 'datetime') { //datetime类型字段转换成时间戳 - var Hms = Moment(value_begin).format("HH:mm:ss"); - value_begin = value_begin ? parseInt(Moment(value_begin) / 1000) : ''; - value_end = value_end ? parseInt(Moment(value_end) / 1000) : ''; - if (value_begin === value_end && '00:00:00' === Hms) { - value_end += 86399; + var value_begin = $.trim($("[name='" + name + "']:first", that.$commonsearch).val()), value_end = $.trim($("[name='" + name + "']:last", that.$commonsearch).val()); + if (value_begin.length || value_end.length) { + if (typeof vObjCol.process === 'function') { + value_begin = vObjCol.process(value_begin, 'begin'); + value_end = vObjCol.process(value_end, 'end'); + } else if ($("[name='" + name + "']:first", that.$commonsearch).attr('type') === 'datetime') { //datetime类型字段转换成时间戳 + var Hms = Moment(value_begin).format("HH:mm:ss"); + value_begin = value_begin ? parseInt(Moment(value_begin) / 1000) : ''; + value_end = value_end ? parseInt(Moment(value_end) / 1000) : ''; + if (value_begin === value_end && '00:00:00' === Hms) { + value_end += 86399; + } } + value = value_begin + ',' + value_end; + } else { + value = ''; } - var value = value_begin + ',' + value_end; } else { - var value = $("[name='" + name + "']:checked").val(); + value = $("[name='" + name + "']:checked", that.$commonsearch).val(); } } else { - var value = (typeof vObjCol.process === 'function') ? vObjCol.process(obj.val()) : (sym == 'LIKE %...%' ? obj.val().replace(/\*/g, '%') : obj.val()); + value = (typeof vObjCol.process === 'function') ? vObjCol.process(obj.val()) : (sym == 'LIKE %...%' ? obj.val().replace(/\*/g, '%') : obj.val()); } - if (value == '' && sym.indexOf("NULL") == -1) { + if (removeempty && value == '' && sym.indexOf("NULL") == -1) { return true; } @@ -222,6 +224,25 @@ return {op: op, filter: filter}; }; + var getQueryParams = function (params, searchQuery, removeempty) { + params.filter = typeof params.filter === 'Object' ? params.filter : (params.filter ? JSON.parse(params.filter) : {}); + params.op = typeof params.op === 'Object' ? params.op : (params.op ? JSON.parse(params.op) : {}); + params.filter = $.extend(params.filter, searchQuery.filter); + params.op = $.extend(params.op, searchQuery.op); + //移除empty的值 + if (removeempty) { + $.each(params.filter, function (i, j) { + if (j === '') { + delete params.filter[i]; + delete params.op[i]; + } + }); + } + params.filter = JSON.stringify(params.filter); + params.op = JSON.stringify(params.op); + return params; + }; + $.extend($.fn.bootstrapTable.defaults, { commonSearch: false, titleForm: "Common search", @@ -289,32 +310,39 @@ initCommonSearch(that.columns, that); - var searchContainer = $(".commonsearch-table", that.$container); - that.$toolbar.find('button[name="commonSearch"]') .off('click').on('click', function () { - searchContainer.toggleClass("hidden"); + that.$commonsearch.toggleClass("hidden"); return; }); that.$container.on("click", "." + that.options.searchClass, function () { - var obj = $("form [name='" + $(this).data("field") + "']", searchContainer); + var obj = $("form [name='" + $(this).data("field") + "']", that.$commonsearch); if (obj.size() > 0) { obj.val($(this).data("value")); - $("form", searchContainer).trigger("submit"); + $("form", that.$commonsearch).trigger("submit"); } }); + var searchQuery = getSearchQuery(that, true); + var queryParams = that.options.queryParams; + //匹配默认搜索值 + this.options.queryParams = function (params) { + var params = getQueryParams(queryParams(params), searchQuery); + return params; + }; + this.trigger('post-common-search', that); + }; + + BootstrapTable.prototype.onCommonSearch = function () { var searchQuery = getSearchQuery(this); - var queryParams = this.options.queryParams; + var params = getQueryParams(this.options.queryParams({}), searchQuery, true); + this.trigger('common-search', this, params, searchQuery); + this.options.pageNumber = 1; this.options.queryParams = function () { - var params = queryParams.apply(this, arguments); - params.filter = JSON.stringify($.extend(params.filter || {}, searchQuery.filter)); - params.op = JSON.stringify($.extend(params.op || {}, searchQuery.op)); return params; }; - this.trigger('post-common-search', that); - + this.refresh({query: params}); }; BootstrapTable.prototype.load = function (data) { @@ -351,24 +379,4 @@ return true; }) : this.data; }; - - BootstrapTable.prototype.onCommonSearch = function () { - var searchquery = getSearchQuery(this); - this.trigger('common-search', this, searchquery); - - // 追加查询关键字 - this.options.pageNumber = 1; - this.options.queryParams = function (params) { - return { - search: params.search, - sort: params.sort, - order: params.order, - filter: JSON.stringify(searchquery.filter), - op: JSON.stringify(searchquery.op), - offset: params.offset, - limit: params.limit, - }; - }; - this.refresh({query: {filter: JSON.stringify(searchquery.filter), op: JSON.stringify(searchquery.op)}}); - }; }(jQuery); diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js index 517c449..4ab9d67 100644 --- a/public/assets/js/require-table.js +++ b/public/assets/js/require-table.js @@ -302,6 +302,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table return '<img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" />'; }, images: function (value, row, index) { + value = value.toString(); var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center'; var arr = value.split(','); var html = []; @@ -332,12 +333,12 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table }, addtabs: function (value, row, index) { var url = Table.api.replaceurl(this.url, value, row, this.table); - var title = this.title ? this.title : __("Search %s", value); + var title = this.atitle ? this.atitle : __("Search %s", value); return '<a href="' + Fast.api.fixurl(url) + '" class="addtabsit" data-value="' + value + '" title="' + title + '">' + value + '</a>'; }, dialog: function (value, row, index) { var url = Table.api.replaceurl(this.url, value, row, this.table); - var title = this.title ? this.title : value; + var title = this.atitle ? this.atitle : __("View %s", value); return '<a href="' + Fast.api.fixurl(url) + '" class="dialogit" data-value="' + value + '" title="' + title + '">' + value + '</a>'; }, flag: function (value, row, index) { @@ -360,20 +361,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table return html.join(' '); }, label: function (value, row, index) { - var colorArr = ['success', 'warning', 'danger', 'info']; - //如果字段列有定义custom - if (typeof this.custom !== 'undefined') { - colorArr = $.merge(colorArr, this.custom); - } - //渲染Flag - var html = []; - var arr = value.split(','); - $.each(arr, function (i, value) { - value = value.toString(); - var color = colorArr[i % colorArr.length]; - html.push('<span class="label label-' + color + '">' + __(value) + '</span>'); - }); - return html.join(' '); + return Table.api.formatter.flag.call(this, value, row, index); }, datetime: function (value, row, index) { return value ? Moment(parseInt(value) * 1000).format("YYYY-MM-DD HH:mm:ss") : __('None'); -- libgit2 0.24.0