首页 > 其他分享 >11.24

11.24

时间:2023-12-18 12:45:36浏览次数:28  
标签:function const 11.24 alert error document data

今天实现ROOT层

root.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="add2">新添员工</button>
            </td>
        </tr>
        <tr>
            <td>2</td>
            <td>
                <button id="update2">修改员工</button>
            </td>
        </tr>
        <tr>
            <td>3</td>
            <td>
                <button id="delete2">删除员工</button>
            </td>
        </tr>
        <tr>
            <td>4</td>
            <td>
                <button id="add1">新添部门</button>
            </td>
        </tr>
        <tr>
            <td>5</td>
            <td>
                <button id="update1">修改部门</button>
            </td>
        </tr>
        <tr>
            <td>6</td>
            <td>
                <button id="delete1">删除部门</button>
            </td>
        </tr>
        <tr>
            <td>7</td>
            <td>
                <button id="set">设置角色</button>
            </td>
        </tr>
        <tr>
            <td>8</td>
            <td>
                <button id="re">密码重置</button>
            </td>
        </tr>
    </table>
</div>
</body>
<script>
    document.getElementById("add1").addEventListener("click", function () {
        window.location.href = "add2.html";
    });
    document.getElementById('update1').addEventListener('click', function () {
        window.location.href = "update2.html";
    });
    document.getElementById("delete1").addEventListener("click", function () {
        window.location.href = "delete2.html";
    });
    document.getElementById('add2').addEventListener('click', function () {
        window.location.href = "add1.html";
    });
    document.getElementById("update2").addEventListener("click", function () {
        window.location.href = "update1.html";
    });
    document.getElementById('delete2').addEventListener('click', function () {
        window.location.href = "delete1.html";
    });
    document.getElementById("set").addEventListener("click", function () {
        window.location.href = "set.html";
    });
    document.getElementById('re').addEventListener('click', function () {
        window.location.href = "re.html";
    });

</script>
</html>

add1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>员工信息添加</title>
    <style>
        .reSet {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            cursor: pointer;
        }

        .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;
        }

        .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>
<script>
    function generatePaperNumber() {
        const id = "2019";
        const requestUrl = "http://localhost:8080/user/count";
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(response => response.json())
            .then(data => {
                if (data != null) {
                    const count = data + 1;
                    const jobID = id + padNumber(count, 4);
                    document.getElementById('jobID').value = jobID;
                    console.log(jobID);
                } else {
                    alert("查询失败");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }

    function padNumber(number, width) {
        const str = number.toString();
        return str.length >= width ? str : new Array(width - str.length + 1).join('0') + str;
    }

</script>
<body>
<h1 style="text-align: center">添加信息</h1>
<div class="centered-form">
    <div class="bordered-form">
        <div class="form">
            <form id="addForm">
                <label for="jobID">员工ID:</label>
                <input type="text" id="jobID" name="jobID" readonly>
                <br>
                <br>

                <button type="button" style="display: block; margin: 0 auto;" onclick="generatePaperNumber()">生成编号
                </button>
                <br>
                <label for="name">请输入姓名</label>
                <input type="text" id="name">
                <br>
                <label>性别:</label>
                <div id="sex">
                    <label><input type="radio" name="sex" value="男">男</label>
                    <label><input type="radio" name="sex" value="女">女</label>
                </div>
                <br>
                <label for="birthday">请输入出生日期</label>
                <input type="date" id="birthday">
                <br>
                <div id="container">

                </div>
                <label for="major">请输入所属部门</label>
                <input type="text" id="major">
                <button type="submit" style="display: block; margin: 0 auto;">添加</button>
            </form>
        </div>
    </div>
</div>
</body>
<script>
    display();

    function display() {
        const requestUrl = 'http://localhost:8080/user/selectCount';
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success') {
                    generateTable(data.data);
                    console.log(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>';

        tableBody.appendChild(row);
        // 查询方式是按姓名查询或多条查询
        for (let i = 0; i < data.length; i++) {
            row = document.createElement("tr");
            row.innerHTML = `<td>${data[i].departmentID}</td><td>${data[i].departmentName}</td>`;
            tableBody.appendChild(row);
            table.appendChild(tableBody);
            tableContainer.appendChild(table);
        }
    }
</script>
<script>
    document.getElementById('addForm').addEventListener('submit', function (e) {
        e.preventDefault();
        const jobID = document.getElementById('jobID');
        const name = document.getElementById('name');
        const sex = document.querySelectorAll('input[name="sex"]');
        let s;
        sex.forEach(radio => {
            if (radio.checked) {
                s = radio.value;
            }
        });
        const birthday = document.getElementById('birthday');
        const major = document.getElementById('major');
        console.log(jobID.value + "   " + name.value + "   " + s + "  " + birthday.value + "  " + major.value);
        addStaff(jobID.value, name.value, s, birthday.value, major.value);
    });
</script>
<script>
    function addStaff(jobID, name, s, birthday, major) {
        const requestUrl = 'http://localhost:8080/user/addStaff';
        fetch(requestUrl,
            {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    jobID: jobID,
                    name: name,
                    sex: s,
                    birthday: birthday,
                    department: major,
                    role: "员工",
                    password: "123456"
                })
            })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success') {
                    alert("添加员工成功");
                    console.log(data);
                } else {
                    alert("添加失败  " + data.msg);
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
</html>>

add2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增部门信息</title>
    <style>
        .reSet {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            cursor: pointer;
        }

        .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;
        }

        .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">
        <div class="form">
            <form id="addForm">
                <label for="jobID">部门编号:</label>
                <input type="text" id="jobID" name="jobID" minlength="2" maxlength="2">
                <br>
                <label for="name">请输入名称</label>
                <input type="text" id="name">
                <br>
                <div id="container">

                </div>
                <button type="submit" style="display: block; margin: 0 auto;">添加</button>
            </form>
        </div>
    </div>
</div>
</body>
<script>
    display();

    function display() {
        const requestUrl = 'http://localhost:8080/user/selectCount';
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success') {
                    generateTable(data.data);
                    console.log(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>';

        tableBody.appendChild(row);
        // 查询方式是按姓名查询或多条查询
        for (let i = 0; i < data.length; i++) {
            row = document.createElement("tr");
            row.innerHTML = `<td>${data[i].departmentID}</td><td>${data[i].departmentName}</td>`;
            tableBody.appendChild(row);
            table.appendChild(tableBody);
            tableContainer.appendChild(table);
        }
    }
</script>
<script>
    document.getElementById('addForm').addEventListener('submit', function (e) {
        e.preventDefault();
        const jobID = document.getElementById('jobID');
        const name = document.getElementById('name');
        console.log(jobID.value + "   " + name.value);
        cDep(jobID.value, name.value);
    });
</script>
<script>
    function cDep(id, name) {
        const requestUrl = `http://localhost:8080/user/aDep/${id}`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data === 0) {
                    dDep(id, name);
                } else {
                    alert("已存在所填编号 ");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<script>
    function dDep(id, name) {
        const requestUrl = `http://localhost:8080/user/bDep/${name}`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data === 0) {
                    addDep(id, name);
                } else {
                    alert("已存在所填名称  ");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<script>
    function addDep(jobID, name) {
        const requestUrl = 'http://localhost:8080/user/addDep';
        fetch(requestUrl,
            {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    departmentID: jobID,
                    departmentName: name
                })
            })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success') {
                    alert("添加部门成功");
                    console.log(data);
                } else {
                    alert("添加失败  " + data.msg);
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
</html>>

delete1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>删除员工</title>
</head>
<body>
<div id="container">

</div>
</body>
<script>
    const requestUrl = 'http://localhost:8080/user/getStaff';
    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><td>是否删除</td>';
            tableBody.appendChild(row);
        for (let i = 0; i < data.length; i++) {
            row = document.createElement("tr");
            row.innerHTML = `<td>${data[i].jobID}</td><td>${data[i].name}</td><td>${data[i].sex}</td><td>${data[i].birthday}</td><td>${data[i].department}</td><td>${data[i].role}</td><td>${data[i].password}</td><td><button class="deleteButton">删除</button></td>`;
            tableBody.appendChild(row);
            table.appendChild(tableBody);
            tableContainer.appendChild(table);
        }
    }
</script>
<script>
    const tableContainer = document.getElementById("container");
    tableContainer.addEventListener("click", function (event) {
        // 获取到点击事件的目标元素
        let target = event.target;
        // 向上遍历DOM树,找到具有相应类名的祖先元素
        while (target !== tableContainer && ![...target.classList].some(className => ["deleteButton"].includes(className))) {
            target = target.parentNode;
        }
        if (target.classList.contains("deleteButton")) {
            // 点击了"审批通过"按钮
            const row = target.closest("tr");
            const cardID = row.querySelector("td:first-child").textContent;
            deleteStaff(cardID);
            // display(); // 重新显示数据
        }
    });
</script>
<script>
    function deleteStaff(id)
    {
        const requestUrl = `http://localhost:8080/user/deleteStaff/${id}`;
        fetch(requestUrl,
            {
                method: 'DELETE',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success') {
                    alert("删除成功")
                } else {
                    alert("删除失败  " + data.msg);
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
</html>

 

标签:function,const,11.24,alert,error,document,data
From: https://www.cnblogs.com/zzqq1314/p/17910893.html

相关文章

  • 11.24
    4.输入n(n<=20)名职工的姓名(姓名的长度小于10)及计算机水平考试成绩,输出及格人数和及格的职工姓名。(期末真题)【设计要求】(1)定义职工结构体类型structStaff(2)定义输入函数voidinput(structStaffwork[],intn)完成职工信息的输入,各输入信息间以空格为间隔。(3)定义输出函数......
  • 11.24
    今日学习内容document.getElementById("login-form").addEventListener("submit",function(event){event.preventDefault();//阻止表单默认提交行为varusername=document.getElementById("username").value;varpassword=document.getEl......
  • 11.24周五补交
    importjava.util.Scanner;publicclassMain{staticfinalintN=100010;staticint[]a=newint[N];staticint[]b=newint[N];publicstaticvoidinsert(intl,intr,intc){b[l]+=c;b[r+1]-=c;}publicstatic......
  • 11.24-task3数据类型
    数据类型与操作基本类型整型int浮点数float布尔值bool(tureorfalse)类型Typetype的use:类型的类型就是类型。。。还有一些更多类型。。。常用内置常数python中是内置了一些常量的-常用内置运算符andornot类似于c语言的&&||!=运算顺序为not>and>......
  • 敏捷冲刺11.24
    所属课程软件工程导论作业要求项目冲刺作业目标连续七天的敏捷冲刺github链接CampusSecond-handMarket--NoBailanGroup目录一、团队介绍1、团队名称:摆烂就不队2、团队成员二、站立式会议三、任务情况1、昨天已完成任务2.今天计划完成任务3、工作中遇到的困......
  • 11.24每日总结
    代码:1000时长7h今日学习了大数据的测试知识,做了一上午,终于完成1MathorCup高校数学建模挑战赛——大数据竞赛练习题:观影大数据分析王S聪想要在海外开拓万D电影的市场,这次他在考虑:怎么拍商业电影才能赚钱?毕竟一些制作成本超过1亿美元的大型电影也会失败。这个问题对电......
  • 11.24每日总结
    今天完成建民老师布置的大数据测试 1MathorCup高校数学建模挑战赛——大数据竞赛练习题:观影大数据分析王S聪想要在海外开拓万D电影的市场,这次他在考虑:怎么拍商业电影才能赚钱?毕竟一些制作成本超过1亿美元的大型电影也会失败。这个问题对电影业来说比以往任何时候都......
  • 2023.11.24 日记 夜浓浓
    轻闲的一天。夜浓浓地笼罩在窗外,远远地依稀见到明暗的城市灯火。白日久违地听孙佳讲课,内容是没细听了,只是边学着英语的《语法通霸》边挂着一只耳朵听讲(纪中的英语老师笑着对我们仨说,挂着一只耳朵听课。她没有解释下去,我约摸是边做自己的事边听课,偶尔会被课堂吸引。不知这样是否是......
  • 11.24日记
    前面有提到MapReduce框架采用非循环式的数据流模型,把中间结果写入到HDFS中,带来了大量的数据复制、磁盘IO和序列化开销。且这些框架只能支持一些特定的计算模式(map/reduce),并没有提供一种通用的数据抽象。因此出现了RDD这个概念。RDD(ResilientDistributedDataset)叫做弹性......
  • 2023.11.24——每日总结
    学习所花时间(包括上课):9h代码量(行):0行博客量(篇):1篇今天,上午学习,下午学习;我了解到的知识点:1.JavaGUI2.会话跟踪技术明日计划:学习......