Просмотр исходного кода

采用新的URL方式来实现刷新返回之前的页面
移除示例中冗余的元素
修复commonsearch中searchit不兼容select的BUG
修复jsname为空时的BUG

Karson 8 лет назад
Родитель
Сommit
7f8e899948

+ 1 - 1
application/admin/view/example/bootstraptable/detail.html

@@ -17,6 +17,6 @@
 <div class="hide layer-footer">
     <label class="control-label col-xs-12 col-sm-2"></label>
     <div class="col-xs-12 col-sm-8">
-        <button type="reset" class="btn btn-primary btn-embossed btn-close">{:__('Close')}</button>
+        <button type="reset" class="btn btn-primary btn-embossed btn-close" onclick="Layer.closeAll();">{:__('Close')}</button>
     </div>
 </div>

+ 4 - 2
application/common/controller/Backend.php

@@ -92,9 +92,11 @@ class Backend extends Controller
         !defined('IS_AJAX') && define('IS_AJAX', $this->request->isAjax());
 
         // 非选项卡时重定向
-        if (!IS_AJAX && !IS_ADDTABS && !IS_DIALOG && !in_array($controllername, ['index', 'ajax']))
+        if (!$this->request->isPost() && !IS_AJAX && !IS_ADDTABS && !IS_DIALOG && input("ref") == 'addtabs')
         {
-            $url = $this->request->url();
+            $url = preg_replace_callback("/([\?|&]+)ref=addtabs(&?)/i", function($matches) {
+                return $matches[2] == '&' ? $matches[1] : '';
+            }, $this->request->url());
             $this->redirect('index/index', [], 302, ['referer' => $url]);
             exit;
         }

+ 1 - 1
public/assets/js/backend/example/bootstraptable.js

@@ -89,7 +89,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     'click .btn-ip': function (e, value, row, index) {
                         var options = $("#table").bootstrapTable('getOptions');
                         //这里我们手动将数据填充到表单然后提交
-                        $("#commonSearchContent_" + options.idTable + " form input[name='ip']").val(value);
+                        $("#commonSearchContent_" + options.idTable + " form [name='ip']").val(value);
                         $("#commonSearchContent_" + options.idTable + " form").trigger('submit');
                         Toastr.info("执行了自定义搜索操作");
                     }

+ 4 - 1
public/assets/js/backend/example/colorbadge.js

@@ -25,7 +25,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'title', title: __('Title')},
                         {field: 'ip', title: __('IP')},
                         {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime},
-                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
+                                return Table.api.formatter.operate(value, row, index, table);
+                            }
+                        }
                     ]
                 ],
                 onLoadSuccess: function (data) {

+ 4 - 1
public/assets/js/backend/example/controllerjump.js

@@ -26,7 +26,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'title', title: __('Title')},
                         {field: 'ip', title: __('IP'), formatter: Controller.api.formatter.ip},
                         {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime},
-                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
+                                return Table.api.formatter.operate(value, row, index, table);
+                            }
+                        }
                     ]
                 ]
             });

+ 5 - 2
public/assets/js/backend/example/relationmodel.js

@@ -28,7 +28,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'admin.nickname', title: __('Nickname'), operate: 'LIKE %...%', placeholder: '关键字,模糊搜索'},
                         {field: 'ip', title: __('IP'), operate: '='},
                         {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
-                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
+                                return Table.api.formatter.operate(value, row, index, table);
+                            }
+                        }
                     ]
                 ],
             });
@@ -41,7 +44,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         },
         edit: function () {
             Form.api.bindevent($("form[role=form]"));
-        }
+        },
     };
     return Controller;
 });

+ 6 - 3
public/assets/js/bootstrap-table-commonsearch.js

@@ -266,10 +266,13 @@
         });
 
         that.$container.on("click", "." + that.options.searchClass, function () {
-            $("form [name='" + $(this).data("field") + "']", searchContainer).val($(this).data("value"));
-            $("form", searchContainer).trigger("submit");
+            var obj = $("form [name='" + $(this).data("field") + "']", searchContainer);
+            if (obj.size() > 0) {
+                obj.val($(this).data("value"));
+                $("form", searchContainer).trigger("submit");
+            }
         });
-        
+
         var searchquery = getSearchQuery(this);
         this.options.queryParams = function (params) {
             return {

+ 8 - 6
public/assets/js/require-backend.js

@@ -174,12 +174,14 @@ require(['jquery', 'bootstrap'], function ($, undefined) {
                 }
             });
             //加载相应模块
-            require([Config.jsname], function (Controller) {
-                Controller[Config.actionname] != undefined && Controller[Config.actionname]();
-            }, function (e) {
-                console.error(e);
-                // 这里可捕获模块加载的错误
-            });
+            if (Config.jsname) {
+                require([Config.jsname], function (Controller) {
+                    Controller[Config.actionname] != undefined && Controller[Config.actionname]();
+                }, function (e) {
+                    console.error(e);
+                    // 这里可捕获模块加载的错误
+                });
+            }
         });
     });
 });

+ 27 - 10
public/assets/js/require-backend.min.js

@@ -188,12 +188,14 @@ require(['jquery', 'bootstrap'], function ($, undefined) {
                 }
             });
             //加载相应模块
-            require([Config.jsname], function (Controller) {
-                Controller[Config.actionname] != undefined && Controller[Config.actionname]();
-            }, function (e) {
-                console.error(e);
-                // 这里可捕获模块加载的错误
-            });
+            if (Config.jsname) {
+                require([Config.jsname], function (Controller) {
+                    Controller[Config.actionname] != undefined && Controller[Config.actionname]();
+                }, function (e) {
+                    console.error(e);
+                    // 这里可捕获模块加载的错误
+                });
+            }
         });
     });
 });
@@ -7480,10 +7482,13 @@ return d.keepInvalid=a,l},l.datepickerInput=function(a){if(0===arguments.length)
         });
 
         that.$container.on("click", "." + that.options.searchClass, function () {
-            $("form [name='" + $(this).data("field") + "']", searchContainer).val($(this).data("value"));
-            $("form", searchContainer).trigger("submit");
+            var obj = $("form [name='" + $(this).data("field") + "']", searchContainer);
+            if (obj.size() > 0) {
+                obj.val($(this).data("value"));
+                $("form", searchContainer).trigger("submit");
+            }
         });
-        
+
         var searchquery = getSearchQuery(this);
         this.options.queryParams = function (params) {
             return {
@@ -10940,6 +10945,17 @@ define('form',['jquery', 'bootstrap', 'backend', 'toastr', 'upload', 'validator'
                     formClass: 'n-default n-bootstrap',
                     msgClass: 'n-right',
                     stopOnError: true,
+                    display: function (elem) {
+                        return $(elem).closest('.form-group').find(".control-label").text().replace(/\:/, '');
+                    },
+                    target: function (input) {
+                        var $formitem = $(input).closest('.form-group'),
+                                $msgbox = $formitem.find('span.msg-box');
+                        if (!$msgbox.length) {
+                            $msgbox = $('<span class="msg-box"></span>').insertAfter(input);
+                        }
+                        return $msgbox;
+                    },
                     valid: function (ret) {
                         //验证通过提交表单
                         Form.api.submit($(ret), onBeforeSubmit, function (data) {
@@ -11198,7 +11214,8 @@ $.fn.addtabs = function (options) {
 
             document.title = title;
             if (history.pushState && !$(this).data("pushstate")) {
-                window.history.pushState(state, title, url);
+                var pushurl = url.indexOf("ref=addtabs") == -1 ? (url + (url.indexOf("?") > -1 ? "&" : "?") + "ref=addtabs") : url;
+                window.history.pushState(state, title, pushurl);
             }
             $(this).data("pushstate", null);
             _add({

+ 7 - 5
public/assets/js/require-frontend.js

@@ -170,11 +170,13 @@ require(['jquery', 'bootstrap'], function ($, undefined) {
                 }
             });
             //加载相应模块
-            require([Config.jsname], function (Controller) {
-                Controller[Config.actionname] != undefined && Controller[Config.actionname]();
-            }, function (e) {
-                // 这里可捕获模块加载的错误
-            });
+            if (Config.jsname) {
+                require([Config.jsname], function (Controller) {
+                    Controller[Config.actionname] != undefined && Controller[Config.actionname]();
+                }, function (e) {
+                    // 这里可捕获模块加载的错误
+                });
+            }
         });
     });
 });

+ 7 - 5
public/assets/js/require-frontend.min.js

@@ -184,11 +184,13 @@ require(['jquery', 'bootstrap'], function ($, undefined) {
                 }
             });
             //加载相应模块
-            require([Config.jsname], function (Controller) {
-                Controller[Config.actionname] != undefined && Controller[Config.actionname]();
-            }, function (e) {
-                // 这里可捕获模块加载的错误
-            });
+            if (Config.jsname) {
+                require([Config.jsname], function (Controller) {
+                    Controller[Config.actionname] != undefined && Controller[Config.actionname]();
+                }, function (e) {
+                    // 这里可捕获模块加载的错误
+                });
+            }
         });
     });
 });