作者 Karson

新增自动修复下拉列表功能

新增自定义弹窗标题功能
优化部分formatter格式化判断
@@ -48,6 +48,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -48,6 +48,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
48 iosCardView: true, //ios卡片视图 48 iosCardView: true, //ios卡片视图
49 checkOnInit: true, //是否在初始化时判断 49 checkOnInit: true, //是否在初始化时判断
50 escape: true, //是否对内容进行转义 50 escape: true, //是否对内容进行转义
  51 + fixDropdownPosition: true, //是否修复下拉的定位
51 selectedIds: [], 52 selectedIds: [],
52 selectedData: [], 53 selectedData: [],
53 extend: { 54 extend: {
@@ -307,7 +308,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -307,7 +308,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
307 if (url.indexOf("{ids}") !== -1) { 308 if (url.indexOf("{ids}") !== -1) {
308 url = Table.api.replaceurl(url, {ids: ids.length > 0 ? ids.join(",") : 0}, table); 309 url = Table.api.replaceurl(url, {ids: ids.length > 0 ? ids.join(",") : 0}, table);
309 } 310 }
310 - Fast.api.open(url, __('Add'), $(this).data() || {}); 311 + Fast.api.open(url, $(this).data("original-title") || $(this).attr("title") || __('Add'), $(this).data() || {});
311 }); 312 });
312 // 导入按钮事件 313 // 导入按钮事件
313 if ($(Table.config.importbtn, toolbar).size() > 0) { 314 if ($(Table.config.importbtn, toolbar).size() > 0) {
@@ -330,12 +331,15 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -330,12 +331,15 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
330 if (ids.length > 10) { 331 if (ids.length > 10) {
331 return; 332 return;
332 } 333 }
  334 + var title = $(that).data('title') || $(that).attr("title") || __('Edit');
  335 + var data = $(that).data() || {};
  336 + delete data.title;
333 //循环弹出多个编辑框 337 //循环弹出多个编辑框
334 $.each(Table.api.selecteddata(table), function (index, row) { 338 $.each(Table.api.selecteddata(table), function (index, row) {
335 var url = options.extend.edit_url; 339 var url = options.extend.edit_url;
336 row = $.extend({}, row ? row : {}, {ids: row[options.pk]}); 340 row = $.extend({}, row ? row : {}, {ids: row[options.pk]});
337 url = Table.api.replaceurl(url, row, table); 341 url = Table.api.replaceurl(url, row, table);
338 - Fast.api.open(url, __('Edit'), $(that).data() || {}); 342 + Fast.api.open(url, typeof title === 'function' ? title.call(table, row) : title, data);
339 }); 343 });
340 }); 344 });
341 //清空回收站 345 //清空回收站
@@ -472,7 +476,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -472,7 +476,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
472 var row = Table.api.getrowbyid(table, ids); 476 var row = Table.api.getrowbyid(table, ids);
473 row.ids = ids; 477 row.ids = ids;
474 var url = Table.api.replaceurl(options.extend.edit_url, row, table); 478 var url = Table.api.replaceurl(options.extend.edit_url, row, table);
475 - Fast.api.open(url, __('Edit'), $(this).data() || {}); 479 + Fast.api.open(url, $(this).data("original-title") || $(this).attr("title") || __('Edit'), $(this).data() || {});
476 }); 480 });
477 table.on("click", "[data-id].btn-del", function (e) { 481 table.on("click", "[data-id].btn-del", function (e) {
478 e.preventDefault(); 482 e.preventDefault();
@@ -487,6 +491,45 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -487,6 +491,45 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
487 } 491 }
488 ); 492 );
489 }); 493 });
  494 +
  495 + //修复dropdown定位溢出的情况
  496 + if (options.fixDropdownPosition) {
  497 + var tableBody = table.closest(".fixed-table-body");
  498 + table.on('show.bs.dropdown fa.event.refreshdropdown', ".btn-group", function (e) {
  499 + var dropdownMenu = $(".dropdown-menu", this);
  500 + var btnGroup = $(this);
  501 + var isPullRight = dropdownMenu.hasClass("pull-right") || dropdownMenu.hasClass("dropdown-menu-right");
  502 + var left, top, position;
  503 + if (dropdownMenu.outerHeight() + btnGroup.outerHeight() > tableBody.outerHeight() - 41) {
  504 + position = 'fixed';
  505 + top = btnGroup.offset().top - $(window).scrollTop() + btnGroup.outerHeight();
  506 + left = isPullRight ? btnGroup.offset().left + btnGroup.outerWidth() - dropdownMenu.outerWidth() : btnGroup.offset().left;
  507 + } else {
  508 + if (btnGroup.offset().top + btnGroup.outerHeight() + dropdownMenu.outerHeight() > tableBody.offset().top + tableBody.outerHeight() - 30) {
  509 + position = 'absolute';
  510 + left = isPullRight ? -(dropdownMenu.outerWidth() - btnGroup.outerWidth()) : 0;
  511 + top = -(dropdownMenu.outerHeight() + 3);
  512 + }
  513 + }
  514 + if (left || top) {
  515 + dropdownMenu.css({
  516 + position: position, left: left, top: top, right: 'inherit'
  517 + });
  518 + }
  519 + });
  520 + var checkdropdown = function () {
  521 + if ($(".btn-group.open", table).length > 0 && $(".btn-group.open .dropdown-menu", table).css("position") == 'fixed') {
  522 + $(".btn-group.open", table).trigger("fa.event.refreshdropdown");
  523 + }
  524 + };
  525 + $(window).on("scroll", function () {
  526 + checkdropdown();
  527 + });
  528 + tableBody.on("scroll", function () {
  529 + checkdropdown();
  530 + });
  531 + }
  532 +
490 var id = table.attr("id"); 533 var id = table.attr("id");
491 Table.list[id] = table; 534 Table.list[id] = table;
492 return table; 535 return table;
@@ -528,7 +571,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -528,7 +571,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
528 var ids = row[options.pk]; 571 var ids = row[options.pk];
529 row = $.extend({}, row ? row : {}, {ids: ids}); 572 row = $.extend({}, row ? row : {}, {ids: ids});
530 var url = options.extend.edit_url; 573 var url = options.extend.edit_url;
531 - Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {}); 574 + Fast.api.open(Table.api.replaceurl(url, row, table), $(this).data("original-title") || $(this).attr("title") || __('Edit'), $(this).data() || {});
532 }, 575 },
533 'click .btn-delone': function (e, value, row, index) { 576 'click .btn-delone': function (e, value, row, index) {
534 e.stopPropagation(); 577 e.stopPropagation();
@@ -557,8 +600,9 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -557,8 +600,9 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
557 image: { 600 image: {
558 'click .img-center': function (e, value, row, index) { 601 'click .img-center': function (e, value, row, index) {
559 var data = []; 602 var data = [];
560 - value = value.toString().split(",");  
561 - $.each(value, function (index, value) { 603 + value = value === null ? '' : value.toString();
  604 + var arr = value != '' ? split(",") : [];
  605 + $.each(arr, function (index, value) {
562 data.push({ 606 data.push({
563 src: Fast.api.cdnurl(value), 607 src: Fast.api.cdnurl(value),
564 }); 608 });
@@ -576,22 +620,21 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -576,22 +620,21 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
576 // 单元格数据格式化 620 // 单元格数据格式化
577 formatter: { 621 formatter: {
578 icon: function (value, row, index) { 622 icon: function (value, row, index) {
579 - if (!value)  
580 - return '';  
581 value = value === null ? '' : value.toString(); 623 value = value === null ? '' : value.toString();
582 value = value.indexOf(" ") > -1 ? value : "fa fa-" + value; 624 value = value.indexOf(" ") > -1 ? value : "fa fa-" + value;
583 //渲染fontawesome图标 625 //渲染fontawesome图标
584 return '<i class="' + value + '"></i> ' + value; 626 return '<i class="' + value + '"></i> ' + value;
585 }, 627 },
586 image: function (value, row, index) { 628 image: function (value, row, index) {
  629 + value = value == null || value.length === 0 ? '' : value.toString();
587 value = value ? value : '/assets/img/blank.gif'; 630 value = value ? value : '/assets/img/blank.gif';
588 var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center'; 631 var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
589 return '<a href="javascript:"><img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" /></a>'; 632 return '<a href="javascript:"><img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" /></a>';
590 }, 633 },
591 images: function (value, row, index) { 634 images: function (value, row, index) {
592 - value = value === null ? '' : value.toString(); 635 + value = value == null || value.length === 0 ? '' : value.toString();
593 var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center'; 636 var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
594 - var arr = value.split(','); 637 + var arr = value != '' ? value.split(',') : [];
595 var html = []; 638 var html = [];
596 $.each(arr, function (i, value) { 639 $.each(arr, function (i, value) {
597 value = value ? value : '/assets/img/blank.gif'; 640 value = value ? value : '/assets/img/blank.gif';
@@ -618,7 +661,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -618,7 +661,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
618 if (typeof this.custom !== 'undefined') { 661 if (typeof this.custom !== 'undefined') {
619 custom = $.extend(custom, this.custom); 662 custom = $.extend(custom, this.custom);
620 } 663 }
621 - value = value === null ? '' : value.toString(); 664 + value = value == null || value.length === 0 ? '' : value.toString();
622 var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : []; 665 var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
623 var index = keys.indexOf(value); 666 var index = keys.indexOf(value);
624 var color = value && typeof custom[value] !== 'undefined' ? custom[value] : null; 667 var color = value && typeof custom[value] !== 'undefined' ? custom[value] : null;
@@ -656,7 +699,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -656,7 +699,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
656 + row[pk] + "' " + (url ? "data-url='" + url + "'" : "") + (confirm ? "data-confirm='" + confirm + "'" : "") + " data-params='" + this.field + "=" + (value == yes ? no : yes) + "'><i class='fa fa-toggle-on text-success text-" + color + " " + (value == yes ? '' : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>"; 699 + row[pk] + "' " + (url ? "data-url='" + url + "'" : "") + (confirm ? "data-confirm='" + confirm + "'" : "") + " data-params='" + this.field + "=" + (value == yes ? no : yes) + "'><i class='fa fa-toggle-on text-success text-" + color + " " + (value == yes ? '' : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>";
657 }, 700 },
658 url: function (value, row, index) { 701 url: function (value, row, index) {
659 - value = value === null ? '' : value.toString(); 702 + value = value == null || value.length === 0 ? '' : value.toString();
660 return '<div class="input-group input-group-sm" style="width:250px;margin:0 auto;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>'; 703 return '<div class="input-group input-group-sm" style="width:250px;margin:0 auto;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
661 }, 704 },
662 search: function (value, row, index) { 705 search: function (value, row, index) {
@@ -668,18 +711,18 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -668,18 +711,18 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
668 return '<a href="javascript:;" class="searchit" data-toggle="tooltip" title="' + __('Click to search %s', value) + '" data-field="' + field + '" data-value="' + value + '">' + value + '</a>'; 711 return '<a href="javascript:;" class="searchit" data-toggle="tooltip" title="' + __('Click to search %s', value) + '" data-field="' + field + '" data-value="' + value + '">' + value + '</a>';
669 }, 712 },
670 addtabs: function (value, row, index) { 713 addtabs: function (value, row, index) {
671 - var url = Table.api.replaceurl(this.url, row, this.table); 714 + var url = Table.api.replaceurl(this.url || '', row, this.table);
672 var title = this.atitle ? this.atitle : __("Search %s", value); 715 var title = this.atitle ? this.atitle : __("Search %s", value);
673 return '<a href="' + Fast.api.fixurl(url) + '" class="addtabsit" data-value="' + value + '" title="' + title + '">' + value + '</a>'; 716 return '<a href="' + Fast.api.fixurl(url) + '" class="addtabsit" data-value="' + value + '" title="' + title + '">' + value + '</a>';
674 }, 717 },
675 dialog: function (value, row, index) { 718 dialog: function (value, row, index) {
676 - var url = Table.api.replaceurl(this.url, row, this.table); 719 + var url = Table.api.replaceurl(this.url || '', row, this.table);
677 var title = this.atitle ? this.atitle : __("View %s", value); 720 var title = this.atitle ? this.atitle : __("View %s", value);
678 return '<a href="' + Fast.api.fixurl(url) + '" class="dialogit" data-value="' + value + '" title="' + title + '">' + value + '</a>'; 721 return '<a href="' + Fast.api.fixurl(url) + '" class="dialogit" data-value="' + value + '" title="' + title + '">' + value + '</a>';
679 }, 722 },
680 flag: function (value, row, index) { 723 flag: function (value, row, index) {
681 var that = this; 724 var that = this;
682 - value = value === null ? '' : value.toString(); 725 + value = value == null || value.length === 0 ? '' : value.toString();
683 var colorArr = {index: 'success', hot: 'warning', recommend: 'danger', 'new': 'info'}; 726 var colorArr = {index: 'success', hot: 'warning', recommend: 'danger', 'new': 'info'};
684 //如果字段列有定义custom 727 //如果字段列有定义custom
685 if (typeof this.custom !== 'undefined') { 728 if (typeof this.custom !== 'undefined') {
@@ -693,10 +736,10 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -693,10 +736,10 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
693 736
694 //渲染Flag 737 //渲染Flag
695 var html = []; 738 var html = [];
696 - var arr = value.split(','); 739 + var arr = value != '' ? value.split(',') : [];
697 var color, display, label; 740 var color, display, label;
698 $.each(arr, function (i, value) { 741 $.each(arr, function (i, value) {
699 - value = value === null ? '' : value.toString(); 742 + value = value == null || value.length === 0 ? '' : value.toString();
700 if (value == '') 743 if (value == '')
701 return true; 744 return true;
702 color = value && typeof colorArr[value] !== 'undefined' ? colorArr[value] : 'primary'; 745 color = value && typeof colorArr[value] !== 'undefined' ? colorArr[value] : 'primary';
@@ -809,7 +852,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -809,7 +852,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
809 if (!$.isEmptyObject(dropdowns)) { 852 if (!$.isEmptyObject(dropdowns)) {
810 var dropdownHtml = []; 853 var dropdownHtml = [];
811 $.each(dropdowns, function (i, j) { 854 $.each(dropdowns, function (i, j) {
812 - dropdownHtml.push('<div class="btn-group"><button type="button" class="btn btn-primary dropdown-toggle btn-xs" data-toggle="dropdown">' + i + '</button><button type="button" class="btn btn-primary dropdown-toggle btn-xs" data-toggle="dropdown"><span class="caret"></span></button><ul class="dropdown-menu pull-right"><li>' + j.join('</li><li>') + '</li></ul></div>'); 855 + dropdownHtml.push('<div class="btn-group"><button type="button" class="btn btn-primary dropdown-toggle btn-xs" data-toggle="dropdown">' + i + '</button><button type="button" class="btn btn-primary dropdown-toggle btn-xs" data-toggle="dropdown"><span class="caret"></span></button><ul class="dropdown-menu dropdown-menu-right"><li>' + j.join('</li><li>') + '</li></ul></div>');
813 }); 856 });
814 html.unshift(dropdownHtml); 857 html.unshift(dropdownHtml);
815 } 858 }
@@ -820,6 +863,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -820,6 +863,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
820 var options = table ? table.bootstrapTable('getOptions') : null; 863 var options = table ? table.bootstrapTable('getOptions') : null;
821 var ids = options ? row[options.pk] : 0; 864 var ids = options ? row[options.pk] : 0;
822 row.ids = ids ? ids : (typeof row.ids !== 'undefined' ? row.ids : 0); 865 row.ids = ids ? ids : (typeof row.ids !== 'undefined' ? row.ids : 0);
  866 + url = url == null || url.length === 0 ? '' : url.toString();
823 //自动添加ids参数 867 //自动添加ids参数
824 url = !url.match(/\{ids\}/i) ? url + (url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + '{ids}' : url; 868 url = !url.match(/\{ids\}/i) ? url + (url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + '{ids}' : url;
825 url = url.replace(/\{(.*?)\}/gi, function (matched) { 869 url = url.replace(/\{(.*?)\}/gi, function (matched) {