Layui项目实战

news2024/10/5 18:30: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) {
                    alert('操作成功!');
                } 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) {
                    alert('操作成功!');
                } 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}$/, ' ');

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/638691.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如今做泛娱乐出海,你需要融云《社交泛娱乐出海作战地图》

出海需要的从来都不是上头&#xff0c;而是专业。关注【融云全球互联网通信云】了解更多 星期四的下午&#xff0c;笔者收到了一份特殊的“投喂”——一份详实到出乎意料的《社交泛娱乐出海作战地图》&#xff08;下称《作战地图》&#xff09;。 内容上&#xff0c;它覆盖了从…

英语、数学不精,还可以选择IT行业吗?

临近毕业季择校季&#xff0c;又有一群小伙伴面临着无法确定专业选择方向的难题。 就IT行业来说&#xff0c;有很多同学会有这样的疑问&#xff1a; 对计算机专业的不是十分了解&#xff0c;能学吗&#xff1f; 之前数学不太好&#xff0c;怎么学编程&#xff1f; 学编程对…

Python 接口测试之Excel表格数据操作方法封装

引言 我们在做接口测试&#xff0c;经常会用到excel去管理测试数据&#xff0c;对Excel的操作比较频繁&#xff0c;那么使用python如何操作Excel文件的读与写呢&#xff1f;由于之前讲的都是大的框框&#xff0c;没有讲这么小的模块使用&#xff0c;现在就化整为0的讲解。 读…

黑客工具软件大全

黑客工具软件大全100套 给大家准备了全套网络安全梓料&#xff0c;有web安全&#xff0c;还有渗透测试等等内容&#xff0c;还包含电子书、面试题、pdf文档、视频以及相关的网络安全笔记 &#x1f447;&#x1f447;&#x1f447; 《黑客&网络安全入门&进阶学习包》 &a…

深度学习笔记之Seq2seq(三)注意力机制的执行过程

深度学习笔记之Seq2seq——注意力机制的执行过程 引言回顾&#xff1a;经典 Seq2seq \text{Seq2seq} Seq2seq模型中 Context \text{Context} Context向量的缺陷注意力机制的动机 Seq2seq \text{Seq2seq} Seq2seq中的 Attention \text{Attention} Attention结构注意力模型的数学…

chatgpt赋能python:Python如何合并集合?

Python如何合并集合&#xff1f; 在Python编程中&#xff0c;合并多个集合是一项常见的任务。集合合并在数据处理和分析领域中极为常见&#xff0c;例如在合并用户数据时&#xff0c;需要将多个相同字段的集合合并为一个完整的集合。 本文将介绍如何在Python中合并集合&#…

【语音之家】AI产业沙龙 —— 解读火山语音团队在国际顶会ACL2023的创新突破

由CCF语音对话与听觉专委会 、中国人工智能产业发展联盟&#xff08;AIIA&#xff09;评估组、火山语音、语音之家、希尔贝壳共同主办的【语音之家】AI产业沙龙——解读火山语音团队在国际顶会ACL2023的创新突破&#xff0c;将于2023年6月14日19:00-20:20线上直播。 沙龙简介 …

JVM中方法区、永久代、元空间详解以及关系?

首先我们需要先复习一下jvm的大致内存图&#xff0c;如下&#xff1a; 哦~ &#xff0c;想起来了&#xff0c;原来方法区属于jvm的运行时数据区&#xff0c;且作用就是存储类信息、方法信息、常量池信息等静态数据。 &#xff08;补充一下&#xff1a;运行时数据区中的红色是指…

​跨部门网络搭建,核心在这30行里

大家好&#xff0c;我的网工朋友。 在企业网络中&#xff0c;想要实现跨部门的VLAN互联互通&#xff0c;其实有很多方式。 你可以通过子接口实现&#xff0c;也可以通过VLAN-Interface实现。但在实际工作中&#xff0c;很多网工朋友&#xff0c;遇到这种情况&#xff0c;很容…

【Selenium2+python】自动化unittest生成测试报告

前言 批量执行完用例后&#xff0c;生成的测试报告是文本形式的&#xff0c;不够直观&#xff0c;为了更好的展示测试报告&#xff0c;最好是生成HTML格式的。 unittest里面是不能生成html格式报告的&#xff0c;需要导入一个第三方的模块&#xff1a;HTMLTestRunner 一、导…

java小技能: 使用response方式下载txt文件(使用response的方式进行文件的传输)

文章目录 引言I 后端代码1.1 思路1.2 封装1.3 用法1.4 防止文件名称中文乱码1.5 指示哪些报头可以公开 Access-Control-Expose-Headers1.6 创建目录II 前端下载文件引言 项目需求:进行txt文件的下载 其他思路:写好文件在下载的方式 本文思路:使用response的方式进行文件的传…

【实战】minigpt4的体验和微调

MiniGPT-4 https://github.com/vision-cair/minigpt-4 1 环境配置 1.1 安装环境 git lfs install //如果报错 &#xff1a;git: lfs is not a git command. See git --help. //尝试使用&#xff1a; sudo apt-get install git-lfs git lfs install1.2 准备Vicuna权重 &…

树的概念和性质

文章目录 树的基本概念树的定义和术语树的遍历树的种类 二叉树二叉搜索树AVL 树红黑树 完全二叉树和满二叉树哈夫曼树 多叉树B 树及其变种B 树B 树和 B* 树 目录 树的基本概念 树的定义和术语 树是由零个或多个结点组成的具有层级关系的数据结构。 当树的结点数量等于零时&a…

暴力递归到动态规划(四)

⭐️前言⭐️ 本篇文章是从暴力递归到动态规划篇目的最后一篇文章&#xff0c;包含了几道题目还有最终的大总结&#xff0c;相信这篇文章能让各位读者对动态规划有更深一步的了解。 &#x1f349;欢迎点赞 &#x1f44d; 收藏 ⭐留言评论 &#x1f4dd;私信必回哟&#x1f601…

使用大型语言模(LLM)构建系统(五):输出结果检查

今天我学习了DeepLearning.AI的 Building Systems with LLM 的在线课程&#xff0c;我想和大家一起分享一下该门课程的一些主要内容。今天我们来学习输出结果检查。输出结果检查包含以下两部分内容&#xff1a; 检查输出是否存在潜在有害内容检查输出是否基于提供的产品信息 下…

easyrecovery2023永久免费版激活密钥,手把手教您用EasyRecovery快速恢复数据

Ontrack EasyRecovery Crack Professional是一个全面的备份和恢复实用程序&#xff0c;可以从多个数据丢失事件中恢复文件&#xff0c;例如常见的意外删除、更严重的&#xff08;有时是病毒引起的&#xff09;分区或驱动器格式化&#xff0c;甚至硬盘严重损坏后的数据丢失。免费…

Python实现ACO蚁群优化算法优化LightGBM回归模型(LGBMRegressor算法)项目实战

说明&#xff1a;这是一个机器学习实战项目&#xff08;附带数据代码文档视频讲解&#xff09;&#xff0c;如需数据代码文档视频讲解可以直接到文章最后获取。 1.项目背景 蚁群优化算法(Ant Colony Optimization, ACO)是一种源于大自然生物世界的新的仿生进化算法&#xff0c…

全球计算科学和人工智能领域Altair

作为全球计算科学和人工智能领域的领导者 Altair,全新数据分析与人工智能平台 Altair RapidMiner。此次启动仪式以 “数据科学&#xff0c;解码智能未来” 为主题。目的是为了更好的助力本土用户推进高效数字化转型&#xff0c;实现数据分析与人工智能应用的降本增效. 作为全球…

PR视频导出时出现编译影片出错的提示怎么解决?

大家使用PR软件的时候因为版本不兼容等各种原因&#xff0c;导致剪辑好的视频导不出来&#xff08;如下图所示&#xff09;&#xff0c;这种情况有两种方法可以解决。&#xff08;我用的版本是2022Pro&#xff0c;电脑需要Win10的系统&#xff0c;如有需要下载的&#xff0c;可…

使用 Terraform 在 GCP 上一键部署 EMQX MQTT Broker

引言 MQTT 是一种轻量级的消息传递协议&#xff0c;适用于物联网应用实现设备间通信。 作为一款主流的开源 MQTT Broker&#xff0c;EMQX 能够提供高扩展性、可靠性和安全性的 MQTT 消息传递服务。 借助广泛应用的基础设施即代码&#xff08;IaC&#xff09;工具 Terraform&a…