教务管理系统之js层

browseCourse.js

$(document).ready(function (){
    $("#addCourse").click(function (){
        $("#popup").css("display","block")
        $("#overlay").css("display","block")
    })
    $("#closebtn").click(function (){
        $("#popup").css("display","none")
        $("#overlay").css("display","none")
    })
    $("#myForm").bind("submit",function (event){
        event.preventDefault()
        $.ajax({
            url:"/manger/addCourse",
            method:"post",
            data:$("#myForm").serialize(),
            success:function (res){
                alert(res)
                location.reload()
            },
            error:function (){
                alert("出错了!")
            }
        })
    })
    $("#find").click(function (){
        location.replace("/manger/browseCourse?condition="+$("#condition").val()+"&teaCondition="+$("#teaCondition").val())
    })
    $("#stufind").click(function (){
        location.replace("/student/browseCourse?condition="+$("#condition").val()+"&teaCondition="+$("#teaCondition").val())
    })










})

browseHomework.js

$(document).ready(function (){
    $("#addVideo").click(function (){
        $("#popup").css("display","block")
        $("#overlay").css("display","block")
    })
    $("#closebtn").click(function (){
        $("#popup").css("display","none")
        $("#overlay").css("display","none")
    })
    $("#myForm").bind("submit",function (event){
        event.preventDefault()
        let data=new FormData()
        let f=$("#myForm").serializeArray()
        for (let i in f) {
            data.append(f[i].name,f[i].value)
            console.log(typeof (f[i].value))
        }
        data.append("workfile",$("#homework")[0].files[0])
        $.ajax({
            url:"/teacher/addHomework",
            method:"post",
            data:data,
            cache:false,
            contentType:false,
            processData:false,
            success:function (res){
                alert(res)
                location.reload()
            },
            error:function (){
                alert("出错了!")
            }
        })
    })
    $("#homeworkLab1").click(function (){
        location.replace("/student/browseHomework?kind="+$("input[type=radio]:checked").val())
    })
    $("#homeworkLab2").click(function (){
        location.replace("/teacher/browseHomework?kind="+$("input[type=radio]:checked").val())
    })





})

browseStudent.js

$(document).ready(function (){
    $("#find").click(function (){
        location.replace("/manger/browseStudent?condition="+$("#condition").val())
    })
})

browseTeacher.js

$(document).ready(function (){
    $("#find").click(function (){
        location.replace("/manger/browseTeacher?condition="+$("#condition").val())
    })
})

browseVideo.js

$(document).ready(function (){
    $("#addVideo").click(function (){
        $("#popup").css("display","block")
        $("#overlay").css("display","block")
    })
    $("#closebtn").click(function (){
        $("#popup").css("display","none")
        $("#overlay").css("display","none")
    })
    $("#myForm").bind("submit",function (event){
        event.preventDefault()
        let data=new FormData()
        let f=$("#myForm").serializeArray()
        for (let i in f) {
            data.append(f[i].name,f[i].value)
        }
        data.append("videoImg",$("#cover")[0].files[0])
        data.append("videos",$("#videos")[0].files[0])
        $.ajax({
            url:"/teacher/addVideo",
            method:"post",
            data:data,
            cache:false,
            contentType:false,
            processData:false,
            success:function (res){
                alert(res)
                location.reload()
            },
            error:function (){
                alert("出错了!")
            }
        })
    })
    $("#find").click(function (){
        location.replace("/teacher/browseVideo?condition="+$("#condition").val())
    })
    $("#find1").click(function (){
        location.replace("/student/browseVideo?condition="+$("#condition").val())
    })













})

changeMangerPwd.js

$(document).ready(function () {
    $("#myForm").bind("submit", function (event) {
        event.preventDefault()
        if ($("#newpwd1").val() !== $("#newpwd2").val()) {
            alert("新密码和确认密码不一致")
            return;
        }
        $.ajax({
            url: "/manger/changePwd",
            method: "post",
            data: $("#myForm").serialize(),
            success: function (res) {
                alert(res)
            },
            error: function () {
                alert("出错了!")
            }
        })
    })
}
)

changeStudentPwd.js

$(document).ready(function (){
    $("#myForm").bind("submit",function (event){
        event.preventDefault()
        if($("#newpwd1").val()!==$("#newpwd2").val()){
            alert("新密码和确认密码不一致")
            return;
        }
        $.ajax({
            url:"/student/changePwd",
            method:"post",
            data:$("#myForm").serialize(),
            success:function (res){
              alert(res)
            },
            error:function (){
                alert("出错了!")
            }
        })
    })







})

changeTeacherPwd.js

$(document).ready(function () {
    $("#myForm").bind("submit", function (event) {
        event.preventDefault()
        if ($("#newpwd1").val() !== $("#newpwd2").val()) {
            alert("新密码和确认密码不一致")
            return;
        }
        $.ajax({
            url: "/teacher/changePwd",
            method: "post",
            data: $("#myForm").serialize(),
            success: function (res) {
                alert(res)
            },
            error: function () {
                alert("出错了!")
            }
        })
    })
})

homeworkDetail.js

$(document).ready(function (){
    $("#myForm1").bind("submit",function (event){
        event.preventDefault()
        let data=new FormData()
        data.append("answerImg",$("#answerImg1")[0].files[0])
        $.ajax({
            url:"/student/addAnswer",
            method:"post",
            data:data,
            cache:false,
            contentType:false,
            processData:false,
            success:function (res){
                alert(res)
                location.reload()
            },
            error:function (){
                alert("出错了!")
            }
        })
    })
    $("#myForm2").bind("submit",function (event){
        event.preventDefault()
        let data=new FormData()
        data.append("answerImg",$("#answerImg2")[0].files[0])
        $.ajax({
            url:"/student/updateAnswer",
            method:"post",
            data:data,
            cache:false,
            contentType:false,
            processData:false,
            success:function (res){
                alert(res)
                location.reload()
            },
            error:function (){
                alert("出错了!")
            }
        })
    })
})

login.js

$(document).ready(function () {
    let sub;
    $("#sub1").click(function (){
        sub="登录"
    })
    $("#sub2").click(function (){
        sub="注册"
    })
    $("#myForm").bind("submit", function (event) {
        if(sub!="注册" || $("#kind").val()=="manger") {
            event.preventDefault()
            let data = $("#myForm").serialize()
            data = data + "&sub=" + sub
            $.ajax({
                url: "/login",
                method: "post",
                data: data,
                success: function (res) {
                    alert(res)
                    if (res === "登录成功") {
                        if ($("#kind").val() === "student") {
                            location.replace("/student/function")
                        } else if ($("#kind").val() === "teacher") {
                            location.replace("/teacher/function")
                        } else {
                            location.replace("/manger/function")
                        }
                    }
                },
                error: function () {
                    alert('出错了!')
                },
            })
        }
    })

})

mangerFunction.js

$(document).ready(function (){
    $("#closebtn").click(function (){
        $("#mySidenav").css("width","0px")
    })
    $("#openbtn").click(function (){
        $("#mySidenav").css("width","250px")
    })
    $("#a1").click(function (){
        $("#content").attr("src","/manger/toChangePwd")
        })
    $("#a2").click(function (){
        $("#content").attr("src","/manger/browseStudent")
    })
    $("#a3").click(function (){
        $("#content").attr("src","/manger/browseTeacher")
    })
    $("#a4").click(function (){
        $("#content").attr("src","/manger/browseCourse")
    })
    $("#a5").click(function (){
        location.replace("/")
    })













})

studentFunction.js

$(document).ready(function (){
    $("#closebtn").click(function (){
        $("#mySidenav").css("width","0px")
    })
    $("#openbtn").click(function (){
        $("#mySidenav").css("width","250px")
    })
    $("#a1").click(function (){
        $("#content").attr("src","/student/toChangePwd")
    })
    $("#a2").click(function (){
        $("#content").attr("src","/student/detail")
    })
    $("#a3").click(function (){
        $("#content").attr("src","/student/browseCourse")
    })
    $("#a4").click(function (){
        $("#content").attr("src","/student/myCourse")
    })
    $("#a5").click(function (){
        location.replace("/")
    })












})

stuRegister.js

$(document).ready(function (){
    let flag;
    $("#getflag").click(function (){
        $.ajax({
            url: "/student/getFlag",
            type:"post",
            data: {"phone":$("#phone").val()},
            success:function (res) {
                flag = res;
            },
            error:function (){
                alert("出错了!")
            }

        })
    })
    $("#myForm").bind("submit",function (event){
        event.preventDefault()
        if(flag!=$("#flag").val()){
            alert("验证码错误")
            $("#flag").css("value","")
            return;
        }
       let data=new FormData()
        let f=$("#myForm").serializeArray()
        for (let i in f) {
            data.append(f[i].name,f[i].value)
        }
        data.append("photo",$("#stuphoto")[0].files[0])
        $.ajax({
            url: "/student/register",
            method: "post",
            data: data,
            cache:false,
            contentType:false,
            processData:false,
            success: function (res) {
                alert(res)
                if (res === "注册成功") {
                    location.replace("/")
                }
            },
            error: function () {
                alert('出错了!')
            },
        })

    })
    $("#stucollege").change(function () {
        $("stumajor").append()
        let college = $("#stucollege").val()
        if (college === "信息科学与技术学院") {
            $("#stumajor").empty()
            $("#stumajor").append($("<option>").val("无").text("专业"))
            $("#stumajor").append($("<option>").val("计算机科学与技术").text("计算机科学与技术"))
            $("#stumajor").append($("<option>").val("软件工程").text("软件工程"))
            $("#stumajor").append($("<option>").val("数字媒体技术").text("数字媒体技术"))
            $("#stumajor").append($("<option>").val("信息工程").text("信息工程"))
            $("#stumajor").append($("<option>").val("人工智能").text("人工智能"))
            $("#stumajor").append($("<option>").val("网络工程").text("网络工程"))
        } else if (college === "土木工程学院"){
            $("#stumajor").empty()
            $("#stumajor").append($("<option>").val("无").text("专业"))
            $("#stumajor").append($("<option>").val("土木工程").text("土木工程"))
            $("#stumajor").append($("<option>").val("测绘工程").text("测绘工程"))
            $("#stumajor").append($("<option>").val("勘察技术与工程").text("勘察技术与工程"))
            $("#stumajor").append($("<option>").val("城市地下空间工程").text("城市地下空间工程"))
            $("#stumajor").append($("<option>").val("铁道工程").text("铁道工程"))
             $("#stumajor").append($("<option>").val("智能建造").text("智能建造"))

        }
        else if (college === "机械工程学院"){
            $("#stumajor").empty()
            $("#stumajor").append($("<option>").val("无").text("专业"))
            $("#stumajor").append($("<option>").val("机械设计制造及其自动化").text("机械设计制造及其自动化"))
            $("#stumajor").append($("<option>").val("机械电子工程").text("机械电子工程"))
            $("#stumajor").append($("<option>").val("建筑环境与能源应用工程").text("建筑环境与能源应用工程"))
            $("#stumajor").append($("<option>").val("测控技术与仪器").text("测控技术与仪器"))
            $("#stumajor").append($("<option>").val("车辆工程").text("车辆工程"))
            $("#stumajor").append($("<option>").val("工业设计专业").text("工业设计专业"))
        }
        else {
            $("#stumajor").empty()
            $("#stumajor").append($("<option>").val("无").text("专业"))
        }
    })
})

teacherFunction.js

$(document).ready(function (){
    $("#closebtn").click(function (){
        $("#mySidenav").css("width","0px")
    })
    $("#openbtn").click(function (){
        $("#mySidenav").css("width","250px")
    })
    $("#a1").click(function (){
        $("#content").attr("src","/teacher/toChangePwd")
    })
    $("#a2").click(function (){
        $("#content").attr("src","/teacher/detail")
    })
    $("#a3").click(function (){
        $("#content").attr("src","/teacher/myCourse")
    })
    $("#a4").click(function (){
        location.replace("/")
    })













})

teaRegister.js

$(document).ready(function (){
    let flag;
    $("#getflag").click(function (){
        $.ajax({
            url: "/teacher/getFlag",
            type:"post",
            data: {"phone":$("#phone").val()},
            success:function (res) {
                flag = res;
            },
            error:function (){
                alert("出错了!")
            }

        })
    })
    $("#myForm").bind("submit",function (event){
        event.preventDefault()
        if(flag!=$("#flag").val()){
            alert("验证码错误")
            return;
        }
        let data=new FormData()
        let f=$("#myForm").serializeArray()
        for (let i in f) {
            data.append(f[i].name,f[i].value)
        }
        data.append("photo",$("#teaphoto")[0].files[0])
        $.ajax({
            url: "/teacher/register",
            method: "post",
            data: data,
            cache:false,
            contentType:false,
            processData:false,
            success: function (res) {
                alert(res)
                if (res === "注册成功") {
                    location.replace("/")
                }
            },
            error: function () {
                alert('出错了!')
            },
        })

    })
})

 

posted @ 2023-06-10 11:46  突破铁皮  阅读(20)  评论(0编辑  收藏  举报