纪淼淼
2021-03-03 15:57
采纳率: 100%
浏览 54
已采纳

这段js是什么意思?

<script type="text/javascript">
    layui.use(['form', 'table', 'laydate', 'upload'], function () {
        var <!--声明--> form = layui.form;
        var table = layui.table;
        var upload = layui.upload;

        $("#search").click(function () {
            GetData();<!--获取数据的-->
            return false;
        });

        GetData();

        function GetData() {
            $.post("Training/checkSession", function (res) {
                if (res.code == 0) {
                    var para = "zxbt=" + $("#zxbt").val().trim() + "&zxfl=" + $("#zxfl").val() + "&zxzt=" + $("#zxzt").val()+ "&fbpt=" + $("#fbpt").val();
                    table.render({
                        elem/*元素*/: '#test'
                        , id: 'test'
                        , url: 'Training/zxggSearch?' + para
                        , height: 'full-150'////设置标头浮动
                        , limits: [20, 50, 100, 200, 500]//每页条数的选择项。如果 layout 参数开启了 limit,则会出现每页条数的select选择框
                        , limit: 50
                        , page: true
                        , even: true
                        , cols: [
                            [
                                {type: 'checkbox', fixed: 'left'},
                                {field: 'zxbt', align: 'left', title: '资讯标题', width: 300, fixed: 'left'},
                                {
                                    field: 'zxfl', align: 'center', title: '资讯分类', width: 120,
                                    templet: function (res) {
                                        if (res.zxfl == "0") {
                                            return "新闻资讯";
                                        } else if (res.zxfl == "1") {
                                            return "政策文件";
                                        } else if (res.zxfl == "2") {
                                            return "大师工匠";
                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field: 'zxzt', align: 'center', title: '资讯状态', width: 120,
                                    templet: function (res) {
                                        if (res.zxzt == "0") {
                                            return "未发布";
                                        } else if (res.zxzt == "1") {
                                            return "已发布";
                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field: 'fbpt', align: 'center', title: '发布平台', width: 200,
                                    templet: function (res) {
                                        if (res.fbpt == "0") {
                                            return "本溪职业培训在线";
                                        } else if (res.fbpt == "1") {
                                            return "本钢职业培训在线";
                                        } else {
                                            return "";
                                        }
                                    }
                                },
                                {
                                    field: '', align: 'center', title: '封面图片', width: 200,
                                    templet: function (res) {
                                        if (res.zxtplj == null || res.zxtplj == "") {
                                            return "<a class='layui-btn layui-btn-normal' onclick=\"upload('" + res.zxbh + "','ZXTP')\">上传</a>" +
                                                "<div class='layui-inline' style='width: 90px;'></div>";
                                        } else {
                                            return "<a class='layui-btn layui-btn-normal' onclick=\"upload('" + res.zxbh + "','ZXTP')\">上传</a>" +
                                                "<a class='layui-btn layui-btn-normal' onclick=\"preview('" + res.zxbh + "','" + res.zxbt + "')\">预览</a>";
                                        }
                                    }
                                },
                                {field: 'tjry', align: 'left', title: '添加人员', width: 150},
                                {field: 'tjsj', align: 'center', title: '添加时间', width: 200}
                            ]
                        ]
                    });
                } else if (res.code == 1) {
                    showMsg(res.msg);
                } else if (res.code == 2) {
                    window.parent.showLogin();
                }
            });
        }

        $("#add").click(function () {
            $.post("Training/zxggDoAdd", function (res) {
                if (res.code == 0) {
                    $("#search").click();
                    layer.open({
                        type: 2,
                        title: '添加资讯公告',
                        content: 'zxggEdit?zxbh=' + res.data.zxbh,
                        resize: false,
                        area: ['100%', '100%'],
                        success: function (layer, index) {
                        }
                    })
                } else if (res.code == 1) {
                    showMsg(res.msg);
                } else if (res.code == 2) {
                    window.parent.showLogin();
                }
            });
            return false;
        });

        $("#edit").click(function () {
            var checkStatus = table.checkStatus('test');
            if (checkStatus.data.length == 1) {
                layer.open({
                    type: 2,
                    title: '修改资讯公告',
                    content: 'zxggEdit?zxbh=' + checkStatus.data[0].zxbh,
                    resize: false,
                    area: ['100%', '100%'],
                    success: function (layer, index) {
                    }
                })
            } else {
                showMsg("请选择一条数据,进行修改。");
            }
            return false;
        });

        $("#delete").click(function () {
            var checkStatus = table.checkStatus('test');
            if (checkStatus.data.length > 0) {
                var index = layer.confirm('<span style="font-size: 16px;">确定删除【' + checkStatus.data.length + '】条数据?</span>', {
                    btn: ['确定', '取消']
                }, function () {
                    layer.close(index);
                    $.ajax({
                        url: "Training/zxggDelete",
                        type: 'POST',
                        dataType: 'json',
                        contentType: "application/json",
                        data: JSON.stringify(checkStatus.data),
                        success: function (res) {
                            if (res.code == 0) {
                                showConfirmMsg(res.msg);
                                setTimeout(function () {
                                    GetData();
                                }, 1000);
                            } else if (res.code == 1) {
                                showMsg(res.msg);
                            } else if (res.code == 2) {
                                window.parent.showLogin();
                            }
                        }
                    });
                });
            } else {
                showMsg("请选择要删除的数据。");
            }
            return false;
        });

        $("#upload").click(function () {
            return false;
        });

        var m_zxbh = '';
        var m_type = '';
        window.upload = function (zxbh, type) {
            m_zxbh = zxbh;
            m_type = type;
            $("#upload").click();
        };

        upload.render({
            elem: '#upload'
            , url: 'Training/fileUpload'
            , accept: 'file'
            , size: 0
            , acceptMime: 'image/jpeg, image/png'
            , exts: 'jpg|png'
            , data: {bh: m_zxbh, type: m_type}
            , before: function (obj) {
                this.data.bh = m_zxbh;
                this.data.type = m_type;
                showWaiting('数据上传中...');
            }
            , done: function (res) {
                layer.closeAll();
                if (res.code == 0) {
                    showMsg(res.msg);
                    setTimeout(function () {
                        GetData();
                    }, 1000);
                } else if (res.code == 1) {
                    showMsg(res.msg);
                } else if (res.code == 2) {
                    window.parent.showLogin();
                }
            }
        });

        window.preview = function (zxbh, zxbt) {
            layer.open({
                type: 2,
                title: zxbt,
                content: "zxggPreview?zxbh=" + zxbh,
                shadeClose: true,
                maxmin: true,
                area: ['1000px', '800px']
            });
            return false;
        };
    });

</script>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • AllPromise 2021-03-03 16:33
    已采纳

    基于layui框架的一个页面功能,包含表格数据的获取,表单新增,表单修改,删除数据,上传文件的功能

    已采纳该答案
    评论
    解决 1 无用
    打赏 举报

相关推荐 更多相似问题