首页 > 其他分享 >11.28

11.28

时间:2023-12-18 12:44:23浏览次数:21  
标签:11.28 console alert error var document data

今天实现职员的功能。

staff.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 = "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 = "update1.html?username=" + encodeURIComponent(username);
    });
    document.getElementById('daily').addEventListener('click', function () {
        window.location.href = "daily.html?username=" + encodeURIComponent(username);
    });
    document.getElementById("low").addEventListener("click", function () {
        window.location.href = "low.html?username=" + encodeURIComponent(username);
    });

</script>
</html>

daily.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <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>

<script>
    function getShanghaiTime() {
        var options = {timeZone: 'Asia/Shanghai'};
        return new Date().toLocaleString('en-US', options);
    }

    function formatDate(dateString) {
        var date = new Date(dateString);
        var hours = date.getHours();
        var minutes = date.getMinutes();

        hours = (hours < 10) ? "0" + hours : hours;
        minutes = (minutes < 10) ? "0" + minutes : minutes;

        return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " +
            hours + ":" + minutes;
    }

    function checkIn() {
        var attendanceTime = getShanghaiTime();
        var currentTime = new Date(attendanceTime);
        var hours = currentTime.getHours();
        if (hours >= 8 && hours < 9) {
            alert("打卡成功,已上班");
            document.getElementById("status").innerHTML = "已上班";
            document.getElementById("attendanceTime").innerHTML = "考勤时间:" + formatDate(attendanceTime);
            deal1(0, attendanceTime);
        } else {
            alert("已过上班打卡时间点,打卡无效");
        }
    }

    function checkOut() {
        var attendanceTime = getShanghaiTime();
        var currentTime = new Date(attendanceTime);
        var hours = currentTime.getHours();

        if (hours >= 17) {
            alert("打卡成功,已下班");
            document.getElementById("status").innerHTML = "已下班";
            document.getElementById("attendanceTime").innerHTML = "考勤时间:" + formatDate(attendanceTime);
            deal1(1, formatDate(attendanceTime));
            console.log(formatDate(attendanceTime));
        } else {
            alert("未到下班打卡时间点,打卡无效");
        }
    }
function deal1(type,attendanceTime)
{
    const requestUrl = `http://localhost:8080/staff/count`;
    fetch(requestUrl,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
        })
        .then(res => res.json())
        .then(data => {
            deal(data+1,type,attendanceTime);
        })
        .catch(error => {
            alert("请求失败,请重试");
            console.error(error);
        });
}
    function deal(count,type, attendanceTime) {
        var urlParams = new URLSearchParams(window.location.search);
        var id = urlParams.get('username');
        console.log(id);
        const requestUrl = `http://localhost:8080/user/selectById/${id}`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success') {
                    console.log(data);
                    add(count,data.data, type, attendanceTime);
                } else {
                    alert("查询失败  " + data.msg);
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }

    function add(count,data, type, attendanceTime) {
        const requestUrl = `http://localhost:8080/staff/add`;
        fetch(requestUrl, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                id:count,
                attendanceTime: attendanceTime,
                jobID: data.jobID,
                name: data.name,
                sex: data.sex,
                department: data.department,
                attendanceType: type
            })
        })
            .then(response => response.json())
            .then(data => {
                if (data.msg === 'success') {
                    alert("打卡信息已添加");
                    console.log(data);
                } else {
                    alert("修改失败");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<div class="centered-form">
    <div class="bordered-form">
        <h2>日常考勤管理</h2>
        <br>
        <br>
        <p id="attendanceTime"></p>
        <button onclick="checkIn()" style="display: block; margin: 0 auto;">上班</button>
        <br>
        <br>
        <button onclick="checkOut()" style="display: block; margin: 0 auto;">下班</button>
        <p id="status">考勤状态未知</p>
    </div>
</div>

</body>
</html>

low.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <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="leaveForm">
            <label for="startDate">开始时间:</label>
            <input type="date" id="startDate" required><br>

            <label for="endDate">结束时间:</label>
            <input type="date" id="endDate" required><br>

            <label for="leaveType">请假类型:</label>
            <select id="leaveType" required>
                <option value="病假">病假</option>
                <option value="事假">事假</option>
            </select><br>
            <label for="reason">请假原因:</label>
            <textarea id="reason" required></textarea><br>
            <button type="button" onclick="submitLeave()" style="display: block; margin: 0 auto;">提交</button>
        </form>
    </div>
</div>

<script>
    function submitLeave() {
        // Get form data
        var startDate = document.getElementById('startDate').value;
        var endDate = document.getElementById('endDate').value;
        var leaveType = document.getElementById('leaveType').value;
        var reason = document.getElementById('reason').value;
        const requestUrl = `http://localhost:8080/staff/count`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                deal(data + 1, startDate, endDate, leaveType, reason);
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<script>
    function deal(count, startDate, endDate, leaveType, reason) {
        var urlParams = new URLSearchParams(window.location.search);
        var id = urlParams.get('username');
        console.log(id);
        const requestUrl = `http://localhost:8080/user/selectById/${id}`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success') {
                    console.log(data);
                    add(count, data.data, startDate, endDate, leaveType, reason);
                } else {
                    alert("查询失败  " + data.msg);
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<script>
    function add(count, data, startDate, endDate, leaveType, reason) {
        let s;
        if (leaveType === "事假") {
            s = 2;
        } else if (leaveType === "病假") {
            s = 3;
        }

        // Convert start and end dates to JavaScript Date objects
        const start = new Date(startDate);
        const end = new Date(endDate);

        // Iterate through the date range
        while (start <= end) {
            var leaveRequest = {
                id: count++,
                jobID: data.jobID,
                name: data.name,
                sex: data.sex,
                attendanceTime: start.toISOString().split('T')[0], // Format date as YYYY-MM-DD
                department: data.department,
                attendanceType: s,
                notes: reason,
                approvedType: 0,
            };

            // Send a separate request for each day
            const requestUrl = `http://localhost:8080/staff/add`;
            fetch(requestUrl, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(leaveRequest),
            })
                .then(response => response.json())
                .then(data => {
                    console.log(`Leave record for ${start.toISOString().split('T')[0]} created`);
                })
                .catch(error => {
                    console.error('Error:', error);
                });

            // Move to the next day
            start.setDate(start.getDate() + 1);
        }

        alert("请假成功,请等待审批");
    }
</script>

</body>
</html>

select.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查询个人信息</title>
</head>
<body>
<div id="container">

</div>
</body>
<script>
    // 获取URL中的用户名参数
    var urlParams = new URLSearchParams(window.location.search);
    var id = urlParams.get('username');
    console.log(id);
    const requestUrl = `http://localhost:8080/user/selectById/${id}`;
    fetch(requestUrl,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
        })
        .then(res => res.json())
        .then(data => {
            if (data.msg === 'success') {
                console.log(data);
                generateTable(data.data);
            } else {
                alert("查询失败  " + data.msg);
            }
        })
        .catch(error => {
            alert("请求失败,请重试");
            console.error(error);
        });
</script>
<script>
    function generateTable(data) {
        const tableContainer = document.getElementById("container");
        // 清空 tableContainer 中的所有子节点
        while (tableContainer.hasChildNodes()) {
            tableContainer.removeChild(tableContainer.firstChild);
        }
        const table = document.createElement("table");
        const tableBody = document.createElement("tbody");
        let row = document.createElement("tr");
        row.innerHTML = '<td>工号</td><td>姓名</td><td>性别</td><td>出生日期</td><td>部门</td><td>角色</td><td>密码</td>';
        tableBody.appendChild(row);
        row = document.createElement("tr");
        row.innerHTML = `<td>${data.jobID}</td><td>${data.name}</td><td>${data.sex}</td><td>${data.birthday}</td><td>${data.department}</td><td>${data.role}</td><td>${data.password}</td>`;
        tableBody.appendChild(row);
        table.appendChild(tableBody);
        tableContainer.appendChild(table);
    }
</script>
</html>

update1.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>
<h1 style="text-align: center">修改密码</h1>
<div class="centered-form">
    <div class="bordered-form">

        <label for="old">旧密码</label>
        <input type="text" id="old" required>
        <br>
        <label for="new1">新密码</label>
        <input type="text" id="new1" required>
        <br>
        <label for="new2">确认新密码</label>
        <input type="text" id="new2" required>
        <div id="match"></div>
        <br>
        <button id="update" style="display: block; margin: 0 auto;">更改密码</button>
    </div>
</div>
</body>
<script>
    const newPassword1 = document.getElementById("new1");
    const newPassword2 = document.getElementById("new2");
    const passwordMatchMessage = document.getElementById("match");

    function checkPasswordMatch() {
        const password1 = newPassword1.value;
        const password2 = newPassword2.value;

        if (password1 === password2) {
            passwordMatchMessage.textContent = "两次密码一致";
            passwordMatchMessage.style.color = "green";
        } else {
            passwordMatchMessage.textContent = "两次密码不一致";
            passwordMatchMessage.style.color = "red";
        }
    }

    newPassword1.addEventListener("input", checkPasswordMatch);
    newPassword2.addEventListener("input", checkPasswordMatch);
</script>
<script>
    var urlParams = new URLSearchParams(window.location.search);
    var id = urlParams.get('username');
    console.log("用户名为:" + id);
    document.getElementById('update').addEventListener('click', function () {
        const requestUrl = `http://localhost:8080/user/selectById/${id}`;
        fetch(requestUrl, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
        })
            .then(response => response.json())
            .then(data => {
                if (data.msg === 'success') {
                    console.log(data);
                    deal(data.data);
                } else {
                    alert("此结果不存在");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    })
</script>
<script>
    function deal(data) {
        const old = document.getElementById('old').value;
        const new1 = document.getElementById('new1').value;
        const new2 = document.getElementById('new2').value;
        const password = data.password;
        console.log("密码为   " + password);
        if (old !== password) {
            alert("您输入的旧密码有误");
        } else if (old !== password && new1 !== new2) {
            alert("输入的两次密码不一致");
        } else if (old === password && new1 === new2) {
            const requestUrl = `http://localhost:8080/user/update/${id}/${new1}`;
            fetch(requestUrl, {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
                .then(response => response.json())
                .then(data => {
                    if (data.msg === 'success') {
                        alert("修改成功,请您重新登陆");
                        window.location.href = "http://localhost:8080/index.html";
                    } else {
                        alert("修改失败");
                    }
                })
                .catch(error => {
                    alert("请求失败,请重试");
                    console.error(error);
                });
        }
    }
</script>
</html>

 

标签:11.28,console,alert,error,var,document,data
From: https://www.cnblogs.com/zzqq1314/p/17910901.html

相关文章

  • 聪明办法学Python_task4_11.28-12.2
    聪明办法学Python_task4_11.28-12.2聪明办法学Python_task4_11.28-12.21.task06循环1.1while循环1.2for循环1.3循环控制语句1.4range()函数2.task07字符串2.1字符串构成2.2字符串操作2.2.1字符串运算2.2.2索引&切片2.2.3相关函数1.task06......
  • 聪明办法学Python_task3_11.27-11.28
    聪明办法学Python_task3_11.27-11.28聪明办法学Python_task3_11.27-11.281.task05条件1.1if-else语句1.2if-else推导式1.3match-case语句2.talk01代码风格1.task05条件1.1if-else语句分为if、if-else、if-elif-elseif条件1:语句1elif条件2:......
  • 2023.11.28 随笔 了却君
    无聊。又来犯点无病呻吟之病。今日语文考时,绞尽脑汁,未背出下阙三、四段。特此默之,温习。《破阵子·为陈同甫赋壮词以寄之》辛弃疾醉里挑灯看剑,梦回吹角连营。八百里分麾下炙,五十弦翻塞外声。沙场秋点兵。马作的卢飞快,弓如霹雳弦惊。了却君王天下事,赢得生前身后名。可怜白发......
  • 11.28闲话
    今天突然想起来几句歌词便是我掏空予你一半心房也借你一半替我浅吟低唱纵然纸片凉薄爱轻狂虚妄你歌声里亦浸着我的痴放越想越难受所以...推歌纸片人【ilem投稿九周年】这是图片V4:佬啊,佬啊怎么是纸片儿啊调啊,调啊调的我心动啊佬啊,佬啊怎么是纸片儿呐调啊,......
  • 11.28日记
    SQL方式操作1.实例化SparkContext和SparkSession对象2.创建caseclassEmp样例类,用于定义数据的结构信息3.通过SparkContext对象读取文件,生成RDD[String]4.将RDD[String]转换成RDD[Emp]5.引入spark隐式转换函数(必须引入)6.将RDD[Emp]转换成DataFrame7.将DataFrame注册成一张视图或......
  • 11.28每日总结
    今天首先完成了大型数据库的第四次实验,这一次实验是比较系统的对比了mysql,hbase,redis和mongoDB这几个数据库,其中包括关系型也包括非关系型。然后进一步完善了人机交互的实验和,大作业,并将其打包成册。最后作为企业文化课的组长,给我的组员安排了我们大作的分工。......
  • 11.28
    [实验任务一]:旅行方式的选择旅游的出行方式有乘坐飞机旅行、乘火车旅行和自行车游,不同的旅游方式有不同的实现过程,客户可以根据自己的需要选择一种合适的旅行方式。  JAVApackagerjsj.no23; publicclassBicycleStrategyimplementsTravelStrategy{   @Override......
  • 11.28-12.2周末总结
    目录MySQL数据库一、多表查询1.方式一:连表查询2.方式二:子查询二、python操作数据库1.python操作数据库的基本操作2.pymysql的中方法三、MySQL中的理论1.sql注入问题(1)现象一......
  • 2022.11.28-12.4 训练小记
    2022.11.28-12.4训练小记UVA12620FibonacciSum斐波那契数列在取模意义下是有循环节的(具体计算以后补),一个结论是在模\(p\)的意义下,循环节的大小不会大于\(6p\)。......
  • 2022.11.28 省选班
    2022.11.28省选班A.[HNOI2015]落忆枫音https://loj.ac/p/2115题目背景「恒逸,你相信灵魂的存在吗?」郭恒逸和姚枫茜漫步在枫音乡的街道上。望着漫天飞舞的红枫,枫茜突......