首页 > 其他分享 >11.27

11.27

时间:2023-12-18 12:44:56浏览次数:25  
标签:const tableContainer 11.27 alert error document data

delete2.html

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

</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><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><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;
            cDep(cardID);
            // display(); // 重新显示数据
        }
    });
</script>
<script>
    function cDep(id) {
        const requestUrl = `http://localhost:8080/user/cDep/${id}`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data === 0) {
                    deleteDep(id);
                } else {
                    alert("仍有员工处于此部门中 无法删除");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<script>
    function deleteDep(id) {
        const requestUrl = `http://localhost:8080/user/deleteDep/${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>

re.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">
            <label for="name">请输入工号</label>
            <input type="text" id="name">
            <button id="select" style="display: block; margin: 0 auto;">查询</button>
            <div id="container">

            </div>
        </div>
    </div>
</div>
</body>
<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);
        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><td><button class="reSet">密码重置</button>`;
        tableBody.appendChild(row);
        table.appendChild(tableBody);
        tableContainer.appendChild(table);
    }
</script>
<script>
    document.getElementById('select').addEventListener('click', function () {
        const id = document.getElementById('name').value;
        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);
                    generateTable(data.data);
                } else {
                    alert("学生信息不存在");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    });
</script>
<script>
    const tableContainer = document.getElementById("container");
    tableContainer.addEventListener("click", function (event) {
        // 获取到点击事件的目标元素
        let target = event.target;
        // 向上遍历DOM树,找到具有相应类名的祖先元素
        while (target !== tableContainer && ![...target.classList].some(className => ["reSet"].includes(className))) {
            target = target.parentNode;
        }
        if (target.classList.contains("reSet")) {
            // 点击了"审批通过"按钮
            const row = target.closest("tr");
            const id = row.querySelector("td:first-child").textContent;
            const new1 = "123456";
            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') {
                        console.log(data);
                        alert("重置成功")
                    } else {
                        alert("重置失败");
                    }
                })
                .catch(error => {
                    alert("请求失败,请重试");
                    console.error(error);
                });
        }
    });
</script>
</html>

set.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;
            dDep(cardID);
            // display(); // 重新显示数据
        }
    });
</script>
<script>
    function  dDep(id)
    {
        const requestUrl = `http://localhost:8080/user/dDep`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data===0) {
                    updateRole(id);
                } else {
                    alert("当前已存在经理,无法更改");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<script>
    function updateRole(id)
    {
        const requestUrl = `http://localhost:8080/user/updateRole/${id}`;
        fetch(requestUrl,
            {
                method: 'GET',
                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>

update1.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">请输入要修改的ID:</label>
                <input type="text" id="jobID" name="jobID" minlength="8" maxlength="8" required>
                <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>
                <button type="submit" style="display: block; margin: 0 auto;">添加</button>
            </form>
        </div>
    </div>
</div>
</body>
<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');
        console.log(jobID.value + "   " + name.value + "   " + s + "  " + birthday.value + "  ");
        updateStaff(jobID.value, name.value, s, birthday.value);
    });
</script>
<script>
    function updateStaff(jobID, name, s, birthday) {
        const requestUrl = 'http://localhost:8080/user/updateStaff';
        fetch(requestUrl,
            {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    jobID: jobID,
                    name: name,
                    sex: s,
                    birthday: birthday,
                })
            })
            .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>>

update2.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) {
                    alert("不存在此部门,请检查编号");
                } else if(data===1){
                    dDep(id,name);
                }
            })
            .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/updateDep';
        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>>

 

标签:const,tableContainer,11.27,alert,error,document,data
From: https://www.cnblogs.com/zzqq1314/p/17910897.html

相关文章

  • 11.27
    5.从键盘输入10名学生成绩(以空格为间隔),并按学生成绩降序排列,输出学生成绩排行榜到磁盘文件d:\score.txt中保存。(期末真题)【输入样例】Pleaseinput 10students’scores:81739562867483669352【文件输出样例】Thesortis:  95.00  93.00  86.00  ......
  • 一周总结(11.27—12.3)
    学习学了一下doob停时定理,q-analog(顺便阅读了一个相关的结论的论文)和欧拉数,q-analog还没写题,欧拉数只写了板。补全了一下斯特林数的知识。希望学习一下其他板块的东西,但是没有成功。发现Hanghang在学数学分析,大为震撼,计划略看,但是没有开始。考试本周仅一场,仅拿到了普......
  • 微信小程序开发周记(11.27-12.3)
    第二周周报(部分)云开发相关云开发是管理微信小程序的后端数据库、运营数据等逻辑核心的平台。前置前置知识资源环境用户开通云开发后即创建了一个独立的环境,包括数据库、存储空间、云函数等一整套云开发资源。实际开发中,建议每个正式环境都搭配一个测试环境,所有功能都在测试......
  • 「Log」做题记录 2023.11.27-
    \(2023.11.27-2023.12.3\)\(\color{black}{P6965}\)2-sat是显著的。对于无问号串,直接否定向自己连边即可,然后塞到Trie树里。Trie树上用子树、路径前缀优化建图即可。\(\color{blueviolet}{P4334}\)圆方树,点是显著的,割边转换为对应方点即可。\(\color{blueviolet}{CF855......
  • 聪明办法学python-11.27——11.29笔记打卡
    一、python中条件语句的应用总体代码结构为:ifTrue:dosomethingelse:doother简单描述为“True”为条件,当条件为真的时候,执行“dosomething”,否则就执行“doother”。例如:任务:实现一个函数,返......
  • 聪明办法学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:......
  • 11.27
    *设置-->构建执行部署-->maven-->用户设置文件-->conf/settings.xml*配置文件在src/main/resources/application.properties,一般情况下会把application.properties改为application.yml*可以通过@Value("${email.user}")获取application.yml配置文件中的值或者使用@Confi......
  • 11.27 erp系统博客总结
    在开发企业Erp中,我担任了财务这一模块的开发,在最近的一周里,我开发了erp系统的销售订单模块,主要完成订单的添加,订单的管理等功能.1.订单新增2.订单管理 ......
  • 2023.11.27——每日总结
    学习所花时间(包括上课):9h代码量(行):0行博客量(篇):1篇今天,上午学习,下午学习;我了解到的知识点:1.javaGUI2.百度翻译SDK明日计划:学习......
  • 11.27每日总结
    今天本来要验收但是老师说不能用组队的C#来替代C/S结构的实验,于是利用一下午的时间通过查询完成了一个用java+swing的C/S结构的软件。 ......