首页 > 其他分享 >1.25

1.25

时间:2024-02-28 21:27:10浏览次数:12  
标签:const getElementById error console document data 1.25

今天实现前端职员的功能页面

1insert.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>申请出差</title>
    <link rel="stylesheet" href="../Style.css">
</head>
<script>

    var urlParams = new URLSearchParams(window.location.search);
    var username = urlParams.get('username');
    console.log("用户名为:" + username);

    const requestUrl = `http://localhost:8080/user/getName/${username}`;
    fetch(requestUrl,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
        })
        .then(response => response.json())
        .then(data => {
            if (data.msg === 'success') {
                document.getElementById('name').value = data.data.userName;
                document.getElementById('depart').value = data.data.department;
            } else {
                alert("查询失败");
            }
        })
        .catch(error => {
            alert("请求失败,请重试");
            console.error(error);
        });
</script>
<script>
    function generatePaperNumber() {
        var currentDate = new Date();
        var year = currentDate.getFullYear();
        let id = year;
        let count;
        const requestUrl = `http://localhost:8080/user/count/${id}`;
        fetch(requestUrl,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(response => response.json())
            .then(data => {
                if (data!=null) {
                    console.log(data);
                    count = data;
                    count = count + 1;
                    count = count.toString().padStart(4, '0');
                    id = id + count;
                    document.getElementById('paperNumber').value = id;
                } else {
                    alert("查询失败");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<body>
<h1 style="text-align: center">出差申请</h1>
<!--边框居中-->
<div class="centered-form">
    <!--    增加边框-->
    <div class="bordered-form">
        <!--        调整边框大小-->
        <div class="form">
            <form id="addForm">
                <label for="paperNumber">出差编号:</label>
                <input type="text" id="paperNumber" name="paperNumber" 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" name="name">
                <br>
                <br>
                <label for="depart">部门:</label>
                <input type="text" id="depart" name="depart">
                <br>
                <label for="dest">目的地:</label>
                <input type="text" id="dest" name="dest">
                <br>
                <label for="begin">出发日期:</label>
                <input type="datetime-local" id="begin" name="begin">
                <br>
                <label for="re">返回日期:</label>
                <input type="datetime-local" id="re" name="re">
                <br>
                出差类别:
                <div id="type">
                    <label><input type="radio" name="type" value="业务洽谈">业务洽谈</label>
                    <label><input type="radio" name="type" value="培训">培训</label>
                    <label><input type="radio" name="type" value="会议">会议</label>
                    <label>
                        <input type="radio" name="type" value="其他">其他
                        <input type="text" id="other" name="other">
                    </label>
                </div>
                <label for="reason">出差事由:</label>
                <br>
                <input type="text" id="reason" name="reason" style="width: 300px; height:300px"
                       required>
                <button type="submit" style="display: block; margin: 0 auto;">添加信息</button>
            </form>
        </div>
    </div>
</div>
</body>
<script>
    document.getElementById('addForm').addEventListener('submit', function (event) {
        event.preventDefault();
        const paperNumber = document.getElementById('paperNumber').value;
        const name = document.getElementById('name').value;
        const depart = document.getElementById('depart').value;
        const dest = document.getElementById('dest').value;
        const begin = document.getElementById('begin').value;
        const re = document.getElementById('re').value;
        const reason = document.getElementById('reason').value;
        const type = document.querySelectorAll('input[name="type"]');
        let t;
        type.forEach(radio => {
            if (radio.checked) {
                t = radio.value;
                console.log(t);
            }
        });
        let other1;
        let t1;
        if (t === "其他") {
            other1 = document.getElementById('other');
            t1 = "其他," + other1.value;
            console.log(other1.value);
        }
        const requestUrl = `http://localhost:8080/user/add1`;
        fetch(requestUrl,
            {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    id: paperNumber,
                    name: name,
                    department: depart,
                    destination: dest,
                    departureDate: begin,
                    returnDate: re,
                    type: t,
                    typeContent: t1,
                    reason: reason,
                    state: "待审批"
                })
            })
            .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>
复制代码

1select.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查询</title>
</head>
<body>
<h1 style="text-align: center">查询</h1>
<!--边框居中-->
<div class="centered-form">
    <!--    增加边框-->
    <div class="bordered-form">
        <!--        调整边框大小-->
        <div class="form">
            <div id="container">

            </div>
        </div>
    </div>
</div>
</body>
<script>
    var urlParams = new URLSearchParams(window.location.search);
    var username = urlParams.get('username');
    console.log("用户名为:" + username);
    const requestU = `http://localhost:8080/user/getName/${username}`;
    fetch(requestU,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
        })
        .then(res => res.json())
        .then(data => {
            if (data.msg === 'success' && data.data != null) {
                console.log(data.data.userName);
                g1(data.data.userName);
            } else {
                alert("未查询到此教师信息");
            }
        })
        .catch(error => {
            alert("请求失败,请重试");
            console.error(error);
        });
</script>
<script>
    function g1(data) {
        console.log(data);

        const requestU = `http://localhost:8080/user/SelectApp/${data}`;
        fetch(requestU,
            {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
            .then(res => res.json())
            .then(data => {
                if (data.msg === 'success' && data.data != null) {
                    generate(data.data);
                } else {
                    alert("未查询到此教师信息");
                }
            })
            .catch(error => {
                alert("请求失败,请重试");
                console.error(error);
            });
    }
</script>
<script>
    function generate(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>';

        tableBody.appendChild(row);
        // 查询方式是按姓名查询或多条查询
        for (let i = 0; i < data.length; i++) {
            let s;
            row = document.createElement("tr");
            row.innerHTML = `<td>${data[i].departureDate}</td><td>${data[i].reason}</td><td>${data[i].state}</td><td>${data[i].stateReason}</td>`;
            tableBody.appendChild(row);
            table.appendChild(tableBody);
            tableContainer.appendChild(table);
        }
    }
</script>
</html>
复制代码

标签:const,getElementById,error,console,document,data,1.25
From: https://www.cnblogs.com/gjsgjs/p/18041863

相关文章

  • 1.25
    学习JSP(JavaServerPages)了解Java编程语言的基础知识,包括语法、面向对象编程、异常处理等。JSP本质上是Servlet的一种简化方式,因此需要了解Servlet的基本概念、生命周期、请求和响应处理等。JSP用于生成动态Web页面,因此需要对HTML、CSS和JavaScript有一定的了解,用于页面的结构、样......
  • 2024.1.25
    想要使用IDEA去连接mysql等数据库需要先IDEA里先下载驱动,一般当你去配置的IDEA连接数据库这个过程,IDEA会提示你没有安装驱动,并问你需不需要自动下载这里如果你们遇到自动下载的途中,下载到一半进度条卡住了,或者直接下载失败,可以先到maven中导入相应的包,然后再回到上图重新下载驱......
  • 1.25 《梦断代码》读书博客2
    《梦断代码》和“乐高假设”为我们描绘了软件工程的现状和未来发展的方向。它们提醒我们,软件开发需要不断的奋斗和努力,而乐高假设的提出也引发了我们对软件开发未来的思考。或许,未来的软件开发将更加高效、便捷,这种变革可能会影响我们的工作方式和行业发展。在阅读《梦断代码》和......
  • 2024.01.25 近期练习
    CF1856E2如果\(n\le5000\)考虑怎么做。首先我们对于每个节点只考虑大小关系,最后只需要从小到大标号即可。我们考虑把答案放到LCA处统计。若其只有两个儿子\(v_1,v_2\),那最多只有\(siz_{v_1}\timessiz_{v_2}\)个会被统计,即令\(v_1\)所有数大于\(v_2\)。若有多个儿......
  • 1.25
    今天实现前端职员的功能页面1insert.html<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>申请出差</title><linkrel="stylesheet"href="../Style.css"></h......
  • 1.25 两道结论题的解法与思考
    背景1:今天确实没啥好活可以整。背景2:今天确实被两道结论题整破防了。背景3:拒绝偷跑!卑力下降!背景4:当学校寒假的学科答疑和做题冲突的时候,果断选择做题!背景5:背景怎么成碎碎念了。背景6:原来是吐槽役。1.ARC094FNormalization给定\(\Sigma=\{a,b,c\}\)的串,每次可以......
  • 闲话1.25
    我想放假啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊写一天题,越来越难受了,想回家。周日还有模拟赛,没法打CF然后好好睡觉,妈的我想放假我想回家。我他妈想回家妈的。......
  • 1.25
    不知不觉已经回家12天了 and 啥也没干 是时候重新计划一下了!!!距离开学还有正好一个月30天 今天腊月15 估计腊月二十九之前要除去几天 2526272829 五天+2天与朋友亲戚之类的聚会 7年后 正月1234515+1天走亲戚之类的活动730-14=16±2 也就是......
  • 1.25学习进度
    1.rdd的数据是过程数据rdd之间进行相互迭代计算,当执行开启后,新rdd的产生,代表老rdd的消失rdd的数据是过程数据,只在处理的过程中存在,一旦处理完成,就不见了这样可以最大化的利用资源2.rdd的缓存sparkt提供了缓存api,可以让我们通过调用api,将指定的rdd数据保留在内存或者硬盘上缓存特点......
  • springcloudalibabada搭建过程中springboot启动卡住起不来 (Started MoonceProviderApp
    如下图一样springcloudAlibaba在创建新模块之后启动新模块没有注册到nacos上,而是直接卡住起不来原因 原因是:引入了错误的web包: 解决办法:引入相应的 spring-boot-starter-web包:<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot......