NutzCN Logo
问答 nutzwk代码生成器生成页面如何加搜索 刷新当前页面
发布于 2987天前 作者 Hamming 1918 次浏览 复制 上一个帖子 下一个帖子
标签:

自动生成的代码如下 index 添加搜搜字段传过去搜索结果后 刷新当前页面呢

<%
layout("/layouts/private.html"){
%>
<section class="content-wrap bg-white">
    <header class="header navbar bg-white shadow">
        <div class="btn-group tool-button" style="display:block">
            <!--<a id="add" class="btn btn-primary navbar-btn" href="${base}/private/app/app_users/add" data-pjax><i class="ti-plus"></i> 新建 App_user</a>-->
            <button class="btn btn-danger navbar-btn" onclick="delCheck()"><i class="ti-close"></i> 删除选中</button>
        </div>
        <div class="btn-group tool-button col-lg-6">
            <div class="input-group navbar-btn">
                <input id="search" name="search" type="text" class="form-control" onkeydown="onKeyDown(event)"/>
                <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
            </div>
        </div>
    </header>
    <div class=panel-body style="padding-top: 50px;">
        <div class="table-responsive no-border">
            <input id="id" type="hidden">
            <table class="table table-bordered table-striped mg-t datatable">
                <thead>
                    <tr>
                        <th>用户名</th>
                        <th>昵称</th>
                        <th>用户手机</th>
                        <th>用户头像</th>
                        <th>用户生日</th>
                        <th>用户性别</th>
                        <th>是否禁用</th>
                        <th>充值金额</th>
                        <th>操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</section>
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">删除App_user</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        App_user删除后无法恢复。<br/>
                        <br/>确定删除吗?
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取  消</button>
                <button id="okDel" type="button" class="btn btn-primary" data-loading-text="正在删除...">确  定</button>
            </div>
        </div>
    </div>
</div>
<div id="dialogDetail" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>
<script language="JavaScript">
    function onKeyDown(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if(e && e.keyCode==13){ // enter 键
//            var result1 = $("#search").val();
//            alert("此处回车触发搜索事件"+$("#search").val());
//            initDatatable();
        }
    }
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching":false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/private/app/app_users/data",//+ $("#search").val()
                "type": "post",
                "data": function (d) {
                    d.unitid = $('#unitid').val();
                }
            },
//            "order": [[0, "desc"]],
            "columns": [
                    {"data": "loginname", "bSortable": true},
                    {"data": "nickname", "bSortable": true},
                    {"data": "phone", "bSortable": true},
                    {"data": "icon", "bSortable": true},
                    {"data": "birthday", "bSortable": true},
                    {"data": "gender", "bSortable": true},
                    {"data": "disabled", "bSortable": true},
                    {"data": "user_recharge", "bSortable": true},
                /*  {"data": "password", "bSortable": true},
                    {"data": "payPassword", "bSortable": true},
                    {"data": "salt", "bSortable": true},
                    {"data": "isOnline", "bSortable": true},*/
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        if (data) {
                            return '<img src='+"${base}" + data + ' style="width:20px;height:20px">';
                        }
                        return "";
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row) {
                        if (data) {
                            var date = new Date(data);
                            var str = date.getFullYear() + "年" + (date.getMonth() + 1)  + "月" + date.getDate() + "日";
                            return str;
                        }
                        return "";
                    },
                    "targets": 4
                },
                {
                    "render": function (data, type, row) {
                        if (!data) {
                            return '<i id="disable_' + row.id + '" class="fa fa-circle text-success ml5"></i>';
                        } else {
                            return '<i id="disable_' + row.id + '" class="fa fa-circle text-danger ml5"></i>';
                        }
                    },
                    "targets": 6
                },
                {
                    "render": function (data, type, row) {
                        return '<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">' +
                                ' <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">' +
                                '<li><a href="${base}/private/app/app_users/detail/' + row.id + '" data-toggle="modal" data-target="#dialogDetail">查看信息</a></li>' +
                                '<li class="divider"></li>' +
                                '<li><a href="javascript:;" onclick="del(\'' + row.id + '\')">删除</a></li>' +
                                '<li class="divider"></li>' +
                                '<li><a href="javascript:;" onclick="enableTask(\'' + row.id + '\')">启用</a></li>' +
                                '<li><a href="javascript:;" onclick="disableTask(\'' + row.id + '\')">禁用</a></li>' +
                                '</ul></div>';
                    },
                    "targets": 8
                }
            ]
        });
        datatable.on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });
        $("#searchBtn").on('click', function () {
            datatable.ajax.reload();
        });
    }
    function del(id) {
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#okDel").unbind("click");
        dialog.find("#okDel").bind("click", function (event) {
            var btn = $(this);
            btn.button("loading");
            $.post("${base}/private/app/app_users/delete/" + id, {}, function (data) {
                if (data.code == 0) {
                    datatable.ajax.reload(null,false);
                } else {
                    Toast.error(data.msg);
                }
                //重置按钮状态,关闭提示框
                btn.button("reset");
                dialog.modal("hide");
            }, "json");
        });
    }
    function delCheck() {
        var chks = datatable.rows('.selected').data();
        if (chks.length > 0) {
            var ids = [];
            $.each(datatable.rows('.selected').data(), function (i, n) {
                ids.push(n.id);
            });
            var dialog = $("#dialogDelete");
            dialog.modal("show");
            dialog.find("#okDel").unbind("click");
            dialog.find("#okDel").bind("click", function (event) {
                var btn = $(this);
                btn.button("loading");
                $.post("${base}/private/app/app_users/delete", {ids: ids.toString()}, function (data) {
                    if (data.code == 0) {
                        datatable.ajax.reload(null,false);
                    } else {
                        Toast.error(data.msg);
                    }
                    btn.button("reset");
                    dialog.modal("hide");
                }, "json");
            });
        } else {
            Toast.warning("请先选择要删除的App_user!");
        }
    }
    function enableTask(id) {
        $.post("${base}/private/app/app_users/enable/" + id, {}, function (data) {
            if (data.code == 0) {
                $("#disable_" + id).attr("class", "fa fa-circle text-success ml5");
            } else {
                Toast.error(data.msg);
            }
        }, "json");
    }
    function disableTask(id) {
        $.post("${base}/private/app/app_users/disable/" + id, {}, function (data) {
            if (data.code == 0) {
                $("#disable_" + id).attr("class", "fa fa-circle text-danger ml5");
            } else {
                Toast.error(data.msg);
            }
        }, "json");
    }
    $(function () {
        initDatatable();
    });

</script>

<%}%>
3 回复

这是让人家给你写代码,当然没人理

系统管理--用户管理--右上角筛选 右击查看源代码。

添加回复
请先登陆
回到顶部