首页 > 其他分享 >1.25

1.25

时间:2024-01-26 18:25:19浏览次数:18  
标签: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/zzqq1314/p/17990422

相关文章

  • 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......
  • centos7搭建kubernetes-v1.25.1集群(Containerd作为运行时)
    集群配置节点名称内存硬盘处理器内核总数ipmaster6GB40GB6192.168.67.166node16GB40GB6192.168.67.167node26GB40GB6192.168.67.168一、所有节点更改镜像源curl-o/etc/yum.repos.d/CentOS-Base.repo二、所有节点安装docker,注意:K8s在1.24以上......
  • 每日总结-23.11.25
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>SWFPlayer</title></he......
  • 【图论】差分约束与SPFA 11.25学习小结
    开篇碎碎念每次都是以开篇碎碎念开头,虽然不知道为什么,但似乎成为了惯例。本来是直接看的差分约束,一上来发现一堆不等式,以为是数学的一个tag乱入图论(x,结果发现还真的是建图来做的,然后学了一下之后...负边权?!跑不了dijkstra啊!!于是学了一下SPFA(虽然...SPFA已死)然后顺道写了一下关于......
  • 敏捷冲刺11.25
    所属课程软件工程导论作业要求项目冲刺作业目标连续七天的敏捷冲刺github链接CampusSecond-handMarket--NoBailanGroup目录一、团队介绍1、团队名称:摆烂就不队2、团队成员二、站立式会议三、任务情况1、昨天已完成任务2.今天计划完成任务3、工作中遇到的困......
  • 2023.11.25 日记 OI·与否
    我揉了揉疲劳的脖子。白天是照常的模拟赛,题目简单但我的分数并不如意。晚上回来做AtCoderabc。打得也不好,C题太着急了,思路乱了十几分钟。F题现在还没调过。赛前定了切G的目标,但好像实力未到。全榜居然只有3个人切。我大概已经有了一个较为放松的OI心态了。我深知......