首页 > 其他分享 >11.23

11.23

时间:2023-12-18 12:46:08浏览次数:25  
标签:username console 11.23 employeeLeaveInfo const data employeeName

今天实现前端的主页登录和管理员代码

index.HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <style>
        button {
            display: block;
            margin-top: 10px;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

        .centered-form {
            text-align: center;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        .bordered-form {
            border: 2px solid #000; /* 边框样式 */
            padding: 20px; /* 可选的内边距 */
            background-color: #f0f0f0; /* 可选的背景颜色 */
        }
    </style>
</head>
<body>
<div class="centered-form">
    <div class="bordered-form">
        <h1>用户登录</h1>
        <form id="login">
            <label for="username">用户名:</label><input type="text" id="username">
            <br>
            <label for="password">密码:</label><input type="password" id="password">
            <br>
            <div class="centered-buttons">
                <button type="submit" style="display: block; margin: 0 auto;">登录</button>
                <br>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    document.getElementById("login").addEventListener("submit", function (event) {
        event.preventDefault();
        const username = document.getElementById("username").value;
        const password = document.getElementById("password").value;
        // const loginUser = document.querySelectorAll('input[name="loginUser"]');
        // let l;
        //
        // loginUser.forEach(radio => {
        //   if (radio.checked) {
        //     l = radio.value;
        //   }
        // });
        const url = `user/getByUser?username=${username}&password=${password}`;
        fetch(url, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            }
        })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success' && data.data != null) {
                    alert("登录成功");
                    if (data.data.role === '管理员') {
                        window.location.href = "ROOT/root.html?username=" + encodeURIComponent(username);
                    } else if (data.data.role === '员工') {
                        window.location.href = "STAFF/staff.html?username=" + encodeURIComponent(username);
                    } else if (data.data.role === '经理') {
                        window.location.href = "MANAGE/manage.html?username=" + encodeURIComponent(username);
                    }
                } else {
                    alert("登录失败");
                    console.log(data);
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    });
</script>
</html>

MANAGE.manage.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>经理页面</title>
    <style>
        .form {
            width: 600px;
            margin: 0 auto;
            /*border: 1px solid red;*/
        }

        .form table {
            margin: 0 auto;
        }

        .form table tr td {
            width: 100px;
            height: 30px;
            border: 1px solid #000;
            text-align: center;
        }

        button {
            display: block;
            margin-top: 10px;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<h1 style="text-align: center">经理系统</h1>
<script>
    // 获取URL中的用户名参数
    var urlParams = new URLSearchParams(window.location.search);
    var username = urlParams.get('username');
    console.log(username);
</script>
<div class="form">
    <table border="1px" cellspacing="0" width="600px">
        <tr>
            <th>编号</th>
            <th>功能</th>
        </tr>
        <tr>
            <td>1</td>
            <td>
                <button id="select">查看个人信息</button>
            </td>
        </tr>
        <tr>
            <td>2</td>
            <td>
                <button id="update">修改信息</button>
            </td>
        </tr>
        <tr>
            <td>3</td>
            <td>
                <button id="update2">修改个人密码</button>
            </td>
        </tr>
        <tr>
            <td>4</td>
            <td>
                <button id="daily">统计部门考勤情况</button>
            </td>
        </tr>
        <tr>
            <td>5</td>
            <td>
                <button id="low">审批请假</button>
            </td>
        </tr>
    </table>
</div>
</body>
<script>
    document.getElementById("select").addEventListener("click", function () {
        window.location.href = "../STAFF/select.html?username=" + encodeURIComponent(username);
    });
    document.getElementById('update').addEventListener('click', function () {
        window.location.href = "../ROOT/update2.html?username=" + encodeURIComponent(username);
    });
    document.getElementById("update2").addEventListener("click", function () {
        window.location.href = "../STAFF/update1.html?username=" + encodeURIComponent(username);
    });
    document.getElementById('daily').addEventListener('click', function () {
        window.location.href = "count.html?username=" + encodeURIComponent(username);
    });
    document.getElementById("low").addEventListener("click", function () {
        window.location.href = "pass.html?username=" + encodeURIComponent(username);
    });

</script>
</html>

pass.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审批请假</title>
</head>
<body>
<div id="container">

</div>
<div id="summaryContainer">

</div>
</body>
<script>
    var urlParams = new URLSearchParams(window.location.search);
    var id = urlParams.get('username');
    console.log(id);
    const requestUrl = `http://localhost:8080/staff/low`;
    fetch(requestUrl,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
        })
        .then(res => res.json())
        .then(data => {
            if (data.msg === 'success') {
                console.log(data);
                generateSummary(data.data);
                // generateTable(data.data);
            } else {
                alert("查询失败  " + data.msg);
            }
        })
        .catch(error => {
            alert("请求失败,请重试");
            console.error(error);
        });
</script>
<script>
    function generateSummary(data) {
        const summaryContainer = document.getElementById("summaryContainer");

        // Clear all child nodes in summaryContainer
        while (summaryContainer.hasChildNodes()) {
            summaryContainer.removeChild(summaryContainer.firstChild);
        }

        // Use an object to store employee names as keys and corresponding leave information as values
        const employeeLeaveInfo = {};

        // Iterate through the original data and group data by employee name
        for (let i = 0; i < data.length; i++) {
            const employeeName = data[i].name;
            if (!employeeLeaveInfo[employeeName]) {
                employeeLeaveInfo[employeeName] = {
                    gender: data[i].sex,
                    startDate: data[i].attendanceTime,
                    endDate: data[i].attendanceTime,
                    leaveType: data[i].attendanceType,
                    reasons: [data[i].notes],
                };
            } else {
                employeeLeaveInfo[employeeName].endDate = data[i].attendanceTime;
                employeeLeaveInfo[employeeName].reasons.push(data[i].notes);
            }
        }

        // Generate summary information and add it to summaryContainer
        for (const employeeName in employeeLeaveInfo) {
            const summary = document.createElement("div");
            summary.innerHTML = `<p>员工姓名: ${employeeName}</p>
                             <p>性别: ${employeeLeaveInfo[employeeName].gender}</p>
                             <p>请假开始日期: ${employeeLeaveInfo[employeeName].startDate}</p>
                             <p>结束日期: ${employeeLeaveInfo[employeeName].endDate}</p>
                             <p>请假类型: ${employeeLeaveInfo[employeeName].leaveType}</p>
                             <p>请假事由: ${employeeLeaveInfo[employeeName].reasons.join(', ')}</p>`;

            // Create approve and reject buttons
            const approveButton = document.createElement("button");
            approveButton.textContent = "批准";
            approveButton.addEventListener("click", () => handleApproval(employeeName, employeeLeaveInfo[employeeName].leaveType));

            const rejectButton = document.createElement("button");
            rejectButton.textContent = "驳回";
            rejectButton.addEventListener("click", () => handleRejection(employeeName, employeeLeaveInfo[employeeName].leaveType));
            // Append buttons to the summary
            summary.appendChild(approveButton);
            summary.appendChild(rejectButton);
            // Append the summary to the container
            summaryContainer.appendChild(summary);
        }

        // Handle approval logic
        function handleApproval(name, type) {
            // Implement logic for approving leave for the specified employee
            console.log(`Leave approved for ${name}`);
            const i = 1;
            console.log(name + " " + type + " " + i);
            const requestUrl = `http://localhost:8080/staff/approve/${name}/${type}/${i}`;
            fetch(requestUrl,
                {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                })
                .then(res => res.json())
                .then(data => {
                    if (data.msg === 'success') {
                        console.log(data);
                        alert("申请批准!")
                    } else {
                        alert("查询失败  " + data.msg);
                    }
                })
                .catch(error => {
                    alert("请求失败,请重试");
                    console.error(error);
                });
        }

        // Handle rejection logic
        function handleRejection(name, type) {
            // Implement logic for rejecting leave for the specified employee
            console.log(`Leave approved for ${name}`);
            const i = -1;
            console.log(name + " " + type + " " + i);
            const requestUrl = `http://localhost:8080/staff/approve/${name}/${type}/${i}`;
            fetch(requestUrl,
                {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                })
                .then(res => res.json())
                .then(data => {
                    if (data.msg === 'success') {
                        console.log(data);
                        alert("申请驳回!")
                    } else {
                        alert("查询失败  " + data.msg);
                    }
                })
                .catch(error => {
                    alert("请求失败,请重试");
                    console.error(error);
                });
        }
    }

</script>

</html>

 

标签:username,console,11.23,employeeLeaveInfo,const,data,employeeName
From: https://www.cnblogs.com/zzqq1314/p/17910890.html

相关文章

  • 11.23
    1.编写程序,输入10个学生的学号、姓名、性别、年龄,统计其中女生有多少,男生有多少,并根据年龄从小到大对这10个学生重新排序。 程序代码:#include<stdio.h>#include<string.h> #defineN10 typedefstruct{   charid[10];   charname[20];   chargend......
  • 11.23
    今日学习内容<%@pageimport="java.sql.DriverManager"%><%@pageimport="java.sql.*"%><%--CreatedbyIntelliJIDEA.TochangethistemplateuseFile|Settings|FileTemplates.--%><%@pagecontentType="text/htm......
  • KubeSphere 社区双周报 | 苏州 Meetup 报名开启 | 2023.11.23-12.07
    KubeSphere社区双周报主要整理展示新增的贡献者名单和证书、新增的讲师证书以及两周内提交过commit的贡献者,并对近期重要的PR进行解析,同时还包含了线上/线下活动和布道推广等一系列社区动态。本次双周报涵盖时间为:2023.11.23-2023.12.07。贡献者名单新晋KubeSphereTale......
  • 聪明办法学python-11.23——11.26笔记打卡
      python的数据类型和操作1.数据类型和运算符:基本类型是:整形int  如1、34、-12浮点型float  如 1.23、-2.44布尔值bool  有真“True”假“False”  类型type 如:print(type(2))输出为:<class......
  • 11.23日记
    MapReduce是面向大数据并行处理的计算模型、框架和平台,它隐含了以下三层含义:(1)MapReduce是一个基于集群的高性能并行计算平台(ClusterInfrastructure)。它允许用市场上普通的商用服务器构成一个包含数十、数百至数千个节点的分布和并行计算集群。(2)MapReduce是一个并行计算与运行软件......
  • KubeSphere 社区双周报 | Fluent Operator 2.6.0 发布 | 2023.11.10-11.23
    KubeSphere社区双周报主要整理展示新增的贡献者名单和证书、新增的讲师证书以及两周内提交过commit的贡献者,并对近期重要的PR进行解析,同时还包含了线上/线下活动和布道推广等一系列社区动态。本次双周报涵盖时间为:2023.11.10-2023.11.23。贡献者名单新晋KubeSphereCont......
  • 敏捷冲刺11.23
    所属课程软件工程导论作业要求项目冲刺作业目标连续七天的敏捷冲刺github链接CampusSecond-handMarket--NoBailanGroup目录一、团队介绍1、团队名称:摆烂就不队2、团队成员二、站立式会议三、任务情况1、昨天已完成任务2.今天计划完成任务3、工作中遇到的困......
  • 2023.11.23——每日总结
    学习所花时间(包括上课):9h代码量(行):0行博客量(篇):1篇今天,上午学习,下午学习;我了解到的知识点:1.JavaGUI2.会话跟踪技术明日计划:学习......
  • 11.23每日总结
    /AbstractChatroom.javapackageorg.example.test017;importjavax.swing.plaf.basic.BasicTreeUI;publicabstractclassAbstractChatroom{publicabstractvoidregister(Membermember);publicabstractvoidsendText(Stringfrom,Stringto,Stringme......
  • 虚拟机linux系统配置安装redis(每日总结11.23)
    1.进入到root模式下cd/export/server/2.下载wgethttp://download.redis.io/releases/redis-5.0.7.tar.gz3.解压tar-zvxfredis-5.0.7.tar.gz4.把文件移动到redis文件夹里mvredis-5.0.7/export/server/redis5.进入redis文件夹里cdredis6.编译m......