Layui项目实战

2023-11-07

使用语言:C#,Js,Html
使用框架:MVC,Layui
使用插件:JQuery,Layui

一.Layui父窗体前端代码:

在这里插入图片描述
1.Html代码:

<div class="layui-col-md12" style="padding: 8px;">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">

            <div class="layui-col-md12">
                <blockquote class="layui-elem-quote quoteBox">
                    <form class="layui-form">
                        <div class="layui-inline">
                            <a class="layui-btn" onclick="RefreshData()">
                                <label class="x">刷新</label>
                            </a>
                            <a class="layui-btn" onclick="UnlockconfInfo('','','','','','','')">
                                <label class="x">增加</label>
                            </a>
                        </div>
                    </form>
                </blockquote>


                <div class="layui-card">
                    <p class="layui-card-header">列表标题</p>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <table id="unlocknearby" lay-filter="unlocknearby"></table>
                    </div>
                </div>



            </div>

        </div>
    </div>
</div>

2.Js代码:

申明Layui公共变量:

<script type="text/javascript">
        var form,
            layer,
            table,
            laydate;

RefreshData方法,列表刷新:

        function RefreshData() {
            table.reload("newListTable", {
                where: {
                    'userId': 0
                }
            });
        }

Del方法,列表参数删除方法:

        //删除
        function Del(Id, OperatorId) {
            if (confirm("确定要删除当前设置吗?")) {
                $.ajax({
                    url: '/Circle/DelUnlocknearby',
                    data: { 'Id': Id, 'OperatorId': OperatorId },
                    type: 'post',
                    success: function (res) {
                        if (res.code == 0) {
                            RefreshData();
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000, shade: [0.3, '#000', true] });
                        }
                    }
                });
            }
        };

UnlockconfInfo方法,打开子窗体界面,增加或者修改:

        //增加|修改
        function UnlockconfInfo(Id, Country, Sex, Num, Fee, State, OperatorId) {
            layer.open({
                type: 2,
                title: Id == "" ? "增加设置" : "修改设置",
                shadeClose: true,
                shade: 0.5,
                skin: 'layui-layer-rim',
                closeBtn: 1,
                area: ['550px', '550px'],
                content: '/Circle/UnlockconfInfo?ID=' + Id + '&country=' + Country + '&sex=' + Sex + '&num=' + Num + '&fee=' + Fee + '&state=' + State + '&operatorId=' + OperatorId
                , end: function () {	//子窗体关闭方法
                    RefreshData();
                }

            });
        };

Layui绑定列表:

        layui.use(['form', 'layer', 'table', 'laydate'], function () {
            form = layui.form,
                layer = parent.layer === undefined ? layui.layer : top.layer,
                table = layui.table,
                laydate = layui.laydate;

            //列表数据初始化加载
            var tableIns = table.render({
                elem: '#unlocknearby'
                , url: '/Circle/GetUnlockconfList', //数据接口
                page: true,
                height: "full-220",
                id: "newListTable",
                totalRow: true,
                limit: 10,
                toolbar: true,
                limits: [10, 25, 50, 100, 1000, 10000],
                cols: [[ //表头
                    {
                        type: 'numbers', title: '序号', totalRowText: '合计', width: "4%", templet: function (d) {
                            return d.numbers + 1;
                        }
                    },
                    { field: 'Country', title: '国家', align: "center" },
                    {
                        field: 'Sex', title: '性别', align: "center"
                        , templet: function (d) {
                            return d.Sex == 1 ? '男' : d.Sex == 2 ? '女' : '其他';
                        }
                    },
                    { field: 'Num', title: '解锁人数', align: "center", totalRow: true },
                    { field: 'Fee', title: '价格/h币', align: "center" },
                    {
                        field: 'State', title: '状态', align: "center"
                        , templet: function (d) {
                            if (d.State == 1) {
                                return '开启';
                            } else if (d.State == 0) {
                                return '关闭'; 
                            }
                        }
                    },
                    {
                        field: 'Time', title: '操作时间', align: "center",
                        templet: function (d) {
                            console.log(d.Time);
                            var date = new Date(parseInt(d.Time) * 1000);
                            return date.toLocaleString().replace(/:\d{1,2}$/, ' ');
                        }
                    },
                    { field: 'OperatorId', title: '操作人', align: "center" },
                    {
                        title: '操作', width: "10%", fixed: "right", align: "center"
                        , templet: function (d) {
                            var str = "";
                            str += ' <a class="layui-btn layui-btn-xs" onclick="UnlockconfInfo(' + d.Id + ",'" + d.Country + "'," + d.Sex + ',' + d.Num + ',' + d.Fee + ',' + d.State + ',' + d.OperatorId + ')">编辑</a>';
                            str += ' <a class="layui-btn layui-btn-xs layui-btn-danger" onclick="Del(' + d.Id + ',' + d.OperatorId + ')">删除</a>';
                            return str;
                        }
                    }
                ]]
            });

搜索刷新列表:

            //搜索框检索
            $('.search-btn').on("click", function () {
                RefreshData();
            });

        });
 </script>

二.C#后台代码:

注意:业务逻辑层代码不予展示,请根据自己的业务去写。

父窗体界面:

/// <summary>
    /// 解锁配置界面
    /// </summary>
    /// <returns></returns>
    public ActionResult Unlockconf()
    {
        return View();
    }

子窗体界面(增加|修改):

    /// <summary>
    /// 增加|修改 解锁配置界面 
    /// </summary>
    /// <returns></returns>
    public ActionResult UnlockconfInfo(string ID, string country, string sex, string num, string fee, string state, string operatorId)
    {
        ViewBag.ID = ID;
        ViewBag.Country = country;
        ViewBag.Sex = sex;
        ViewBag.Num = num;
        ViewBag.Fee = fee;
        ViewBag.State = state;
        ViewBag.OperatorId = operatorId;
        return View();
    }

搜索方法,绑定列表:

    /// <summary>
    /// 解锁配置列表
    /// </summary>
    /// <param name="userId"></param>
    /// <returns></returns>
    public ActionResult GetUnlockconfList(string userId, GridPager d)
    {
        int total = 0;
        var list = new LiveProider().GetUnlockconfList(userId);

        if (list != null)
        {
            if (list.Count > 0)
            {
                total = list.Count;
                list = list.OrderByDescending(t=>t.Time).Skip((d.page - 1) * d.limit).Take(d.limit).ToList();
            }
        }

        return Json(new
        {
            code = 0,
            msg = "",
            count = total,
            data = list
        }, JsonRequestBehavior.AllowGet);
    }

增加方法:

    /// <summary>
    /// 添加附近解锁设置
    /// </summary>
    /// <param name="country"></param>
    /// <param name="sex"></param>
    /// <param name="num"></param>
    /// <param name="fee"></param>
    /// <param name="state"></param>
    /// <param name="refresh"></param>
    /// <param name="operatorId"></param>
    /// <returns></returns>
    public ActionResult AddUnlocknearby(string country, string sex, string num, string fee, string state,  string operatorId)
    {
        var res = new LiveProider().AddUnlocknearby(country, sex, num, fee, state, operatorId);
        return Json(res);
    }

修改方法:

    /// <summary>
    /// 修改附近解锁设置
    /// </summary>
    /// <param name="country"></param>
    /// <param name="sex"></param>
    /// <param name="num"></param>
    /// <param name="fee"></param>
    /// <param name="state"></param>
    /// <param name="refresh"></param>
    /// <param name="operatorId"></param>
    /// <returns></returns>
    public ActionResult EditUnlocknearby(string ID, string country, string sex, string num, string fee, string state, string operatorId)
    {
        var res = new LiveProider().EditUnlocknearby(ID, country, sex, num, fee, state,operatorId);
        return Json(res);
    }

删除方法:

    /// <summary>
    /// 删除附近解锁设置
    /// </summary>
    /// <param name="ID"></param>
    /// <param name="operatorId"></param>
    /// <returns></returns>
    public ActionResult DelUnlocknearby(string ID, string operatorId)
    {
        var res = new LiveProider().DelUnlocknearby(ID, operatorId);
        return Json(res);
    }

三.子窗体前端代码:

在这里插入图片描述
1.Html代码:

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>NearbypeopleInfo</title>
<link href="~/Scripts/layui/css/layui.css" rel="stylesheet" />
<script src="~/Scripts/jquery-3.3.1.js"></script>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .box {
        margin: auto;
        width: 80%;
        height: 80vh;
    }

    p {
        height: 20px;
        margin: 20px 10px;
    }
</style>
</head>
<body>
<div>
    <div class="box">
        <table>
            <tr>
                <td><p>ID:</p></td>
                <td><p><input class="layui-input ID" type="number" name="name" value="@ViewBag.ID" autocomplete="off" /> </p></td>
            </tr>
            <tr>
                <td><p>国家:</p></td>
                <td>
                    <p>
                        <select class="Country layui-input">
                            <option value="">全部</option>
                            <option value="中国">中国</option>
                            <option value="俄罗斯">俄罗斯</option>
                            <option value="越南">越南</option>
                            <option value="其他">其他</option>
                        </select>
                    </p>
                </td>
            </tr>
            <tr>
                <td><p>性别:</p></td>
                <td>
                    <p>

                        <select class="Sex layui-input">
                            <option value="">全部</option>
                            <option value="1">男</option>
                            <option value="2">女</option>
                        </select>
                    </p>
                </td>
            </tr>
            <tr>
                <td><p>解锁数量:</p></td>
                <td><p><input class="layui-input Num" type="number" name="name" value="@ViewBag.Num" autocomplete="off" /></p></td>
            </tr>
            <tr>
                <td><p>价格/h币:</p></td>
                <td><p><input class="layui-input Fee" type="number" name="name" value="@ViewBag.Fee" autocomplete="off" /></p></td>
            </tr>

            <tr>
                <td><p>状态:</p></td>
                <td>
                    <p>
                        <select class="State layui-input">
                            <option value="">关闭</option>
                            <option value="1">开启</option>
                        </select>
                    </p>
                </td>
            </tr>
            <tr>
                <td><p>操作人:</p></td>
                <td><p><input class="layui-input OperatorId" type="number" name="name" value="@ViewBag.OperatorId" autocomplete="off" /></p></td>
            </tr>
            <tr>
                <td colspan="2">
                    <input class="layui-btn Add" onclick="AddUnlocknearby()" value="增加" /><input class="layui-btn Edit" onclick="EditUnlocknearby()" value="修改" />
                </td>
            </tr>
        </table>

    </div>
</div>、

2.Js代码:

Load方法,窗体加载:

<script>
    function Load() {
        var Id = $('.ID').val();

        if (Id == "") {
            $('.Edit').css('display', 'none');
        } else {
            $('.Add').css('display', 'none');
        }

        $('.ID').attr('readonly', 'readonly');

        var Country = '@ViewBag.Country';
        $('.Country').val(Country);

        var Sex = '@ViewBag.Sex';
        $('.Sex').val(Sex);

        var State = '@ViewBag.State';
        $('.State').val(State);
    }

    Load();

AddUnlocknearby方法,添加方法:

    //添加
    function AddUnlocknearby() {
        var Country = $('.Country').val();
        var Sex = $('.Sex').val();
        var Num = $('.Num').val();
        var Fee = $('.Fee').val();
        var State = $('.State').val();
        var OperatorId = $('.OperatorId').val();
        $.ajax({
            url: '/Circle/AddUnlocknearby',
            data: { 'country': Country, 'sex': Sex, 'num': Num, 'fee': Fee, 'state': State, 'operatorId': OperatorId },
            type: 'post',
            success: function (res) {
                console.log(res);
                if (res.code == 0) {
                	//子窗体自动关闭
                    var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引   
                    parent.layer.close(index);//再执行关闭
                } else {
                    alert(res.msg);
                }
            },
        });
    }

EditUnlocknearby方法,修改方法:

    //修改
    function EditUnlocknearby() {
        var Id = $('.ID').val();
        var Country = $('.Country').val();
        var Sex = $('.Sex').val();
        var Num = $('.Num').val();
        var Fee = $('.Fee').val();
        var State = $('.State').val();
        var OperatorId = $('.OperatorId').val();
        $.ajax({
            url: '/Circle/EditUnlocknearby',
            data: { 'ID': Id, 'country': Country, 'sex': Sex, 'num': Num, 'fee': Fee, 'state': State,  'operatorId': OperatorId },
            type: 'post',
            success: function (res) {
                console.log(res);
                if (res.code == 0) {
                	//子窗体自动关闭
                    var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引   
                    parent.layer.close(index);//再执行关闭
                } else {
                    alert(res.msg);
                }
            },
        });
    }


</script>

四.扩展:

Js时间戳与日期的相互转换:
1.日期转时间戳:

//$(".startDate")是一个日期文本框
var sjc = new Date($(".startDate").val()).valueOf()/1000;

2.时间戳转日期:

//d.joinTime是一个时间戳
var date = new Date(parseInt(d.joinTime) * 1000);
return date.toLocaleString().replace(/:\d{1,2}$/, ' ');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Layui项目实战 的相关文章

随机推荐

  • C++访问限定符private、public、protected的使用场景

    众所周知 C 中有3种访问符 分别是private public protected 其中private和public比较好理解 private 只能由该类中的函数 其友元函数访问 不能被任何其他访问 更不能由该类的对象在类外进行访问 类成
  • 软件连接设置_丰田Techstream软件初探(刷一键升窗)

    前面通过我介绍 丰田Mini vci J2534检测线在64位系统安装 不少同学已经购买了J2534数据线 并在64位系统下安装成功了 如安装不成功 可以通过公众号的文字输入栏 发文字给我 我尽量及时解答 今天给大家聊聊如何使用丰田Tech
  • 功能测试基础之界面测试

    功能测试基础之界面测试 文章目录 功能测试基础之界面测试 前言 一 易用性 简述 易用性细则 二 规范性 简述 规范性细则 三 合理性 简述 合理性细则 四 美观与协调性 简述 美观与协调性细则 五 菜单位置 简述 菜单测试细则 六 独特性
  • JSP页面UTF-8格式中文字符串乱码问题解决方法

    JSP页面使用utf8格式保存中文字符串到文件或进行socket传送接收数据时 常常会出现乱码 这里给出了一个解决方法 实践检验行之有效 0 页面属性设置
  • 在linux shell中使用ftp命令来实现自动登陆、上传与下载

    前段时间有个需求 需要利用crontab定时往某个FTP上传文件 原以为linux中带的ftp命令只支持交互式的操作 没法在命令行下使用 所以后来打算利用PHP中提供的ftp命令来做 但是很不幸的发现ftp模块不是PHP的标准模块 还需要自
  • 到底什么是“容器适配器”?

    首先 我们要明白适配器是干什么的 其实就是一个接口转换装置 是得我们能用特定的方法去操作一些我们本来无法操作的东西 举一个例子 比如你的一个设备支持串口线 而你的电脑支持的是usb口 这时候 我们没有必要重新买一个支持usb的设备 只需要一
  • 2020“闭关”跳槽季,啃透分布式三大技术:限流、缓存、通讯

    01 分布式限流 1 1 Nginx ZooKeeper面试常备题 附答案 请解释一下什么是 Nginx 请列举 x Nginx 的一些特性 请列举 x Nginx 和 和 Apache 之间的不同点 请解释 x Nginx 如何处理 P
  • el-input获取输入框光标位置

    今天接到需求 输入框在正常输入的同时 可以通过点击其他按钮在输入框光标位置添加内容 那么这时候就需要去获取输入框的光标内容 由于在点击其他按钮时 输入框会自动触发失焦事件 因此在blur的时候去触发方法即可
  • Linux-安装MySQL(详细教程)

    Linux 安装MySQL 前言 一 概述 二 下载 三 安装 四 卸载 五 常用设置 六 可能遇到的问题 前言 本文的主要内容是在 Linux 上安装 MySQL 以下内容是源于 B站 MySQL数据库入门到精通 整理而来 一 概述 My
  • QVariant的使用

    一 介绍 QT的官方文档这么写的 The QVariant class acts like a union for the most common Qt data types QVariant可以存储各种数据类型 QVariant行为类似于
  • 长整数相乘

    include
  • JS中的async/await的用法和理解

    1 首先需要理解async 和 await的基本含义 async 是一个修饰符 async 定义的函数会默认的返回一个Promise对象resolve的值 因此对async函数可以直接进行then操作 返回的值即为then方法的传入函数 0
  • Python技能树

    Python技能树 44条消息 三元表达式 进阶语法 CSDNPython技能树 输出偶数个数 不使用三元组 even count 1 if i 2 0 else 0 使用嵌套的三元组表达式统计数字频率 如果是2的倍数加1 如果是4的倍数加
  • python医学科研中能做什么-科研画图都用什么软件?

    作为一只理工狗 我们不仅可能需要熬夜编程 更需要在很多时候画图来展示自己的结果 如果不能用漂亮的图片来展示结果 别人对你的工作评价也许会大打折扣 这样熬夜编的程基本上算是白熬了 下面隆重向大家推荐十款主流画图软件 美好的生活从作出高品 bi
  • 实现一个vue3组件库 - scrollbar滚动条

    theme vue pro 前言 思来想去很久 我都不知道该最先介绍哪一个组件才好 虽然我写的第一个组件是button按钮 但是也是因为简单所以第一个写 逻辑代码不是很多 样式倒是一大堆 感觉不适合用作开篇介绍 最后选择了scrollbar
  • matlab练习程序(最大似然估计)

    clear all close all clc randn seed 0 一维情况 mu 0 N 100000 S 5 data mvnrnd mu S N me mean data S2 1 N sum data me 2 二维或多维情况
  • idea下方控制台显示多个springboot项目

    1 在idea打开View gt Tool Windows gt Services 2 添加服务 选择Spring Boot 3 效果图
  • ChatGPT的前世今生——混沌初开

    目录 ChatGPT的前世今生 混沌初开 ChatCPT简介 ChatCPT是什么 ChatCPT的火爆程度 ChatCPT火爆的原因 1 功能强大 应用范围广泛 2 训练数据量大 模型效果好 3 优秀的商业模式 OpenAI公司 公司创始
  • HTML5 canvas标签-2 简单的3种滤镜

    在发现canvas有这么多功能后 我首先尝试着去做一些滤镜 最基本的就是胶片 这个在w3school上有demo 假设原本颜色为rgb r g b 只需要将它变成rgb 255 r 255 g 255 b 即可 原图处理后的 for var
  • Layui项目实战

    使用语言 C Js Html 使用框架 MVC Layui 使用插件 JQuery Layui 一 Layui父窗体前端代码 1 Html代码 div class layui col md12 style padding 8px div c