From 794f02c502ddb18e438b34d844f4d84bd49643bc Mon Sep 17 00:00:00 2001 From: Karson Date: Fri, 25 Dec 2020 10:17:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=B8=8B=E6=8B=89=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A=E4=B9=89=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E6=A0=87=E9=A2=98=E5=8A=9F=E8=83=BD=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=83=A8=E5=88=86formatter=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/require-table.js | 80 ++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js index 60447781..4699f6e5 100644 --- a/public/assets/js/require-table.js +++ b/public/assets/js/require-table.js @@ -48,6 +48,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table iosCardView: true, //ios卡片视图 checkOnInit: true, //是否在初始化时判断 escape: true, //是否对内容进行转义 + fixDropdownPosition: true, //是否修复下拉的定位 selectedIds: [], selectedData: [], extend: { @@ -307,7 +308,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table if (url.indexOf("{ids}") !== -1) { url = Table.api.replaceurl(url, {ids: ids.length > 0 ? ids.join(",") : 0}, table); } - Fast.api.open(url, __('Add'), $(this).data() || {}); + Fast.api.open(url, $(this).data("original-title") || $(this).attr("title") || __('Add'), $(this).data() || {}); }); // 导入按钮事件 if ($(Table.config.importbtn, toolbar).size() > 0) { @@ -330,12 +331,15 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table if (ids.length > 10) { return; } + var title = $(that).data('title') || $(that).attr("title") || __('Edit'); + var data = $(that).data() || {}; + delete data.title; //循环弹出多个编辑框 $.each(Table.api.selecteddata(table), function (index, row) { var url = options.extend.edit_url; row = $.extend({}, row ? row : {}, {ids: row[options.pk]}); url = Table.api.replaceurl(url, row, table); - Fast.api.open(url, __('Edit'), $(that).data() || {}); + Fast.api.open(url, typeof title === 'function' ? title.call(table, row) : title, data); }); }); //清空回收站 @@ -472,7 +476,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table var row = Table.api.getrowbyid(table, ids); row.ids = ids; var url = Table.api.replaceurl(options.extend.edit_url, row, table); - Fast.api.open(url, __('Edit'), $(this).data() || {}); + Fast.api.open(url, $(this).data("original-title") || $(this).attr("title") || __('Edit'), $(this).data() || {}); }); table.on("click", "[data-id].btn-del", function (e) { e.preventDefault(); @@ -487,6 +491,45 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table } ); }); + + //修复dropdown定位溢出的情况 + if (options.fixDropdownPosition) { + var tableBody = table.closest(".fixed-table-body"); + table.on('show.bs.dropdown fa.event.refreshdropdown', ".btn-group", function (e) { + var dropdownMenu = $(".dropdown-menu", this); + var btnGroup = $(this); + var isPullRight = dropdownMenu.hasClass("pull-right") || dropdownMenu.hasClass("dropdown-menu-right"); + var left, top, position; + if (dropdownMenu.outerHeight() + btnGroup.outerHeight() > tableBody.outerHeight() - 41) { + position = 'fixed'; + top = btnGroup.offset().top - $(window).scrollTop() + btnGroup.outerHeight(); + left = isPullRight ? btnGroup.offset().left + btnGroup.outerWidth() - dropdownMenu.outerWidth() : btnGroup.offset().left; + } else { + if (btnGroup.offset().top + btnGroup.outerHeight() + dropdownMenu.outerHeight() > tableBody.offset().top + tableBody.outerHeight() - 30) { + position = 'absolute'; + left = isPullRight ? -(dropdownMenu.outerWidth() - btnGroup.outerWidth()) : 0; + top = -(dropdownMenu.outerHeight() + 3); + } + } + if (left || top) { + dropdownMenu.css({ + position: position, left: left, top: top, right: 'inherit' + }); + } + }); + var checkdropdown = function () { + if ($(".btn-group.open", table).length > 0 && $(".btn-group.open .dropdown-menu", table).css("position") == 'fixed') { + $(".btn-group.open", table).trigger("fa.event.refreshdropdown"); + } + }; + $(window).on("scroll", function () { + checkdropdown(); + }); + tableBody.on("scroll", function () { + checkdropdown(); + }); + } + var id = table.attr("id"); Table.list[id] = table; return table; @@ -528,7 +571,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table var ids = row[options.pk]; row = $.extend({}, row ? row : {}, {ids: ids}); var url = options.extend.edit_url; - Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {}); + Fast.api.open(Table.api.replaceurl(url, row, table), $(this).data("original-title") || $(this).attr("title") || __('Edit'), $(this).data() || {}); }, 'click .btn-delone': function (e, value, row, index) { e.stopPropagation(); @@ -557,8 +600,9 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table image: { 'click .img-center': function (e, value, row, index) { var data = []; - value = value.toString().split(","); - $.each(value, function (index, value) { + value = value === null ? '' : value.toString(); + var arr = value != '' ? split(",") : []; + $.each(arr, function (index, value) { data.push({ src: Fast.api.cdnurl(value), }); @@ -576,22 +620,21 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table // 单元格数据格式化 formatter: { icon: function (value, row, index) { - if (!value) - return ''; value = value === null ? '' : value.toString(); value = value.indexOf(" ") > -1 ? value : "fa fa-" + value; //渲染fontawesome图标 return ' ' + value; }, image: function (value, row, index) { + value = value == null || value.length === 0 ? '' : value.toString(); value = value ? value : '/assets/img/blank.gif'; var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center'; return ''; }, images: function (value, row, index) { - value = value === null ? '' : value.toString(); + value = value == null || value.length === 0 ? '' : value.toString(); var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center'; - var arr = value.split(','); + var arr = value != '' ? value.split(',') : []; var html = []; $.each(arr, function (i, value) { value = value ? value : '/assets/img/blank.gif'; @@ -618,7 +661,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table if (typeof this.custom !== 'undefined') { custom = $.extend(custom, this.custom); } - value = value === null ? '' : value.toString(); + value = value == null || value.length === 0 ? '' : value.toString(); var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : []; var index = keys.indexOf(value); var color = value && typeof custom[value] !== 'undefined' ? custom[value] : null; @@ -656,7 +699,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table + row[pk] + "' " + (url ? "data-url='" + url + "'" : "") + (confirm ? "data-confirm='" + confirm + "'" : "") + " data-params='" + this.field + "=" + (value == yes ? no : yes) + "'>"; }, url: function (value, row, index) { - value = value === null ? '' : value.toString(); + value = value == null || value.length === 0 ? '' : value.toString(); return '
'; }, search: function (value, row, index) { @@ -668,18 +711,18 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table return '' + value + ''; }, addtabs: function (value, row, index) { - var url = Table.api.replaceurl(this.url, row, this.table); + var url = Table.api.replaceurl(this.url || '', row, this.table); var title = this.atitle ? this.atitle : __("Search %s", value); return '' + value + ''; }, dialog: function (value, row, index) { - var url = Table.api.replaceurl(this.url, row, this.table); + var url = Table.api.replaceurl(this.url || '', row, this.table); var title = this.atitle ? this.atitle : __("View %s", value); return '' + value + ''; }, flag: function (value, row, index) { var that = this; - value = value === null ? '' : value.toString(); + value = value == null || value.length === 0 ? '' : value.toString(); var colorArr = {index: 'success', hot: 'warning', recommend: 'danger', 'new': 'info'}; //如果字段列有定义custom if (typeof this.custom !== 'undefined') { @@ -693,10 +736,10 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table //渲染Flag var html = []; - var arr = value.split(','); + var arr = value != '' ? value.split(',') : []; var color, display, label; $.each(arr, function (i, value) { - value = value === null ? '' : value.toString(); + value = value == null || value.length === 0 ? '' : value.toString(); if (value == '') return true; color = value && typeof colorArr[value] !== 'undefined' ? colorArr[value] : 'primary'; @@ -809,7 +852,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table if (!$.isEmptyObject(dropdowns)) { var dropdownHtml = []; $.each(dropdowns, function (i, j) { - dropdownHtml.push('
'); + dropdownHtml.push('
'); }); html.unshift(dropdownHtml); } @@ -820,6 +863,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table var options = table ? table.bootstrapTable('getOptions') : null; var ids = options ? row[options.pk] : 0; row.ids = ids ? ids : (typeof row.ids !== 'undefined' ? row.ids : 0); + url = url == null || url.length === 0 ? '' : url.toString(); //自动添加ids参数 url = !url.match(/\{ids\}/i) ? url + (url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + '{ids}' : url; url = url.replace(/\{(.*?)\}/gi, function (matched) {