From 7e07967092cf21b2c9351880b11a0e486d995b1b Mon Sep 17 00:00:00 2001 From: bettleChen <2207153529@qq.com> Date: Tue, 12 Sep 2023 17:59:44 +0800 Subject: [PATCH] update code --- front/src/components/login.vue | 9 +- front/src/main.js | 28 ++- front/src/router/index.js | 26 +-- front/src/views/student/courseInfo.vue | 2 +- front/src/views/student/grade.vue | 2 +- front/src/views/student/home.vue | 2 +- front/src/views/student/index.vue | 7 +- front/src/views/student/studentInfo.vue | 2 +- front/src/views/teacher/courseManage.vue | 253 ++++++++++++++++++++++- front/src/views/teacher/index.vue | 2 +- front/vue.config.js | 5 +- 11 files changed, 307 insertions(+), 31 deletions(-) diff --git a/front/src/components/login.vue b/front/src/components/login.vue index 8695df5..5bb8928 100644 --- a/front/src/components/login.vue +++ b/front/src/components/login.vue @@ -47,7 +47,7 @@ ruleForm: { username: null, password: null, - type: null, + type: "student", }, rules: { username: [ @@ -76,6 +76,7 @@ sessionStorage.setItem("username", this.ruleForm.username) sessionStorage.setItem("type", this.ruleForm.type) sessionStorage.setItem("name", resp.data.data.name) + sessionStorage.setItem("token", resp.data.token) if (that.ruleForm.type == "student"){ this.$router.push("/student/home") }else if (that.ruleForm.type == "teacher") { @@ -97,6 +98,12 @@ resetForm(formName) { this.$refs[formName].resetFields(); }, + }, + mounted() { + if (this.$route.query.message) { + this.$message({message: this.$route.query.message, type: "warning"}) + this.$router.push("/login") + } } } diff --git a/front/src/main.js b/front/src/main.js index b414a76..15020d5 100644 --- a/front/src/main.js +++ b/front/src/main.js @@ -4,7 +4,6 @@ import router from './router' import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; import axios from "axios"; -import Cookies from 'js-cookie'; // axios.defaults.withCredentials = true; let config = { @@ -16,6 +15,33 @@ let config = { const axiosInstance = axios.create(config); axiosInstance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; +axiosInstance.interceptors.request.use(config => { + if (sessionStorage.getItem("token")) { + config.headers.Authorization = `${sessionStorage.getItem("token")}`; + } + return config; +}, err => { + return Promise.reject(err); +}) + +axiosInstance.interceptors.response.use( + response => { + return response; + }, + error => { //默认除了2XX之外的都是错误的,就会走这里 + if(error.response){ + switch(error.response.status){ + case 401: + sessionStorage.clear() + router.push({ //跳转到登录页面 + path: '/login', + query: { message: error.response.data.message } // 将跳转的路由path作为参数,登录成功后跳转到该路由 + }); + } + } + return Promise.reject(error.response.data); + } +); Vue.config.productionTip = false Vue.use(ElementUI); diff --git a/front/src/router/index.js b/front/src/router/index.js index 8c2f8ae..878cf05 100644 --- a/front/src/router/index.js +++ b/front/src/router/index.js @@ -9,6 +9,7 @@ const routes = [ { path: '/login', name: 'login', + props: true, component: login }, { @@ -91,16 +92,15 @@ const router = new VueRouter({ export default router -router.beforeEach((to, from, next) => { - if (to.path === "/login") { - next() - }else { - if (sessionStorage.getItem("username") && sessionStorage.getItem("type")) { - const _type = sessionStorage.getItem("type") - next() - }else{ - console.log("fdsafd") - next({path: "/login"}) - } - } -}) +// router.beforeEach((to, from, next) => { +// if (to.path === "/login") { +// next() +// }else { +// if (sessionStorage.getItem("username") && sessionStorage.getItem("type")) { +// const _type = sessionStorage.getItem("type") +// next() +// }else{ +// next({path: "/login"}) +// } +// } +// }) diff --git a/front/src/views/student/courseInfo.vue b/front/src/views/student/courseInfo.vue index c7d5def..a6605af 100644 --- a/front/src/views/student/courseInfo.vue +++ b/front/src/views/student/courseInfo.vue @@ -56,7 +56,7 @@ export default { }, methods: { getSelectCourse() { - this.$axios.get("/course/getCourseById?username="+sessionStorage.getItem("username")).then(resp => { + this.$axios.get("/course/getCourseById").then(resp => { if (resp.data.code === 0){ this.tableData = resp.data.data }else{ diff --git a/front/src/views/student/grade.vue b/front/src/views/student/grade.vue index e95b217..e91a9d2 100644 --- a/front/src/views/student/grade.vue +++ b/front/src/views/student/grade.vue @@ -60,7 +60,7 @@ export default { }, methods: { getGrade(){ - this.$axios.get("/student/getGrade?username="+sessionStorage.getItem("username")).then(resp => { + this.$axios.get("/student/getGrade").then(resp => { if (resp.data.code === 0){ this.tableData = resp.data.data }else { diff --git a/front/src/views/student/home.vue b/front/src/views/student/home.vue index 1ca61e9..7cfaecb 100644 --- a/front/src/views/student/home.vue +++ b/front/src/views/student/home.vue @@ -68,7 +68,7 @@ export default { } }, mounted() { - this.$axios.get("/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { + this.$axios.get("/userinfo").then(resp => { if (resp.data.code === 0 ){ const data = resp.data.data this.sid = data.sid diff --git a/front/src/views/student/index.vue b/front/src/views/student/index.vue index a88f4c4..c166f86 100644 --- a/front/src/views/student/index.vue +++ b/front/src/views/student/index.vue @@ -45,7 +45,12 @@ methods: { out() { sessionStorage.clear(); - this.$router.push('/login') + this.$router.push({ + path: "/login", + query: { + message: "退出登录!" + } + }) } } } diff --git a/front/src/views/student/studentInfo.vue b/front/src/views/student/studentInfo.vue index f5dac32..d647bb1 100644 --- a/front/src/views/student/studentInfo.vue +++ b/front/src/views/student/studentInfo.vue @@ -70,7 +70,7 @@ export default { } }, mounted() { - this.$axios("/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { + this.$axios("/userinfo").then(resp => { if (resp.data.code === 0 ){ const data = resp.data.data this.form.sid = data.sid diff --git a/front/src/views/teacher/courseManage.vue b/front/src/views/teacher/courseManage.vue index 99734be..583dcd9 100644 --- a/front/src/views/teacher/courseManage.vue +++ b/front/src/views/teacher/courseManage.vue @@ -1,13 +1,248 @@ - - \ No newline at end of file + export default { + data() { + return { + currentPage: 1, + total: 0, + dialog: false, + loading: false, + title: "新增学生", + tableData: [{ + sid: "", + sname: "", + className: "", + cname: "", + ctype: "", + endGrade: "", + middleGrade: "", + cid: "" + }], + form: { + sname: '', + className: '', + courseName: '', + courseType: '', + }, + addForm: { + sid: "", + sname: "", + className: "", + cname: "", + ctype: "", + endGrade: "", + middleGrade: "", + cid: "", + } + } + }, + methods: { + handleEdit(index, row) { + console.log(row) + this.addForm = new Object(row) + this.dialog = true + this.isAdd = false + this.loading = false + }, + handleCurrentChange(val){ + this.currentPage = val + this.getAllStudent() + }, + getAllStudent() { + this.$axios.post("/course/getStudentCourse?currentPage="+this.currentPage, this.form).then(resp => { + console.log(resp.data) + if (resp.data.code === 0) { + this.total = resp.data.pageTotal + this.tableData = resp.data.data + } + }) + }, + search(){ + this.getAllStudent() + }, + handleClose(done) { + if (this.loading) { + return; + } + this.$confirm('确定要提交表单吗?') + .then(_ => { + this.loading = true; + this.timer = setTimeout(() => { + done(); + this.$axios.post("/course/editGrade", this.addForm).then(resp => { + if(resp.data.code === 0){ + this.$message({message: resp.data.message, type: "success"}) + this.getAllStudent() + this.loading = false + this.addForm = { + sid: "", + sname: "", + className: "", + cname: "", + ctype: "", + endGrade: "", + middleGrade: "", + cid: "" + } + }else{ + this.$message({message: resp.data.message, type: "error"}) + } + }) + }, 1000); + }) + .catch(_ => {}); + console.log("close") + }, + cancelForm() { + this.loading = false; + this.dialog = false; + this.addForm = { + sid: "", + sname: "", + className: "", + cname: "", + ctype: "", + endGrade: "", + middleGrade: "", + cid: "" + } + clearTimeout(this.timer); + } + }, + mounted() { + this.getAllStudent() + } + } + \ No newline at end of file diff --git a/front/src/views/teacher/index.vue b/front/src/views/teacher/index.vue index 1565f9e..4a18e5f 100644 --- a/front/src/views/teacher/index.vue +++ b/front/src/views/teacher/index.vue @@ -19,7 +19,7 @@ - + diff --git a/front/vue.config.js b/front/vue.config.js index 4678fc9..54a9c34 100644 --- a/front/vue.config.js +++ b/front/vue.config.js @@ -3,6 +3,9 @@ module.exports = defineConfig({ transpileDependencies: true, lintOnSave: false, devServer: { - proxy: "http://127.0.0.1:8000" + proxy: "http://127.0.0.1:8000", + client: { + overlay: false + } } })